add projects
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 13s

This commit is contained in:
2026-03-18 15:37:59 +03:00
parent ed55e77e98
commit bf51924adb
158 changed files with 82479 additions and 1 deletions
+13
View File
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "8.0.5",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}
+21
View File
@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace LC_Api
{
public class Cam
{
[Key]
public string? Id { get; set; }
public string? Type { get; set; }
public string? Ip { get; set; }
public string? Access { get; set; }
public string? ImgUrl { get; set; }
public string? RecPoint { get; set; }
public string? ChannelRec { get; set; }
public string? SwitchConnect { get; set; }
public string? SwitchPort { get; set; }
public string? Name { get; set; }
public string? Map { get; set; }
}
}
+24
View File
@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
namespace LC_Api;
public partial class Db : DbContext
{
public Db() => Database.EnsureCreated();
public virtual DbSet<Error> Errors { get; set; }
public virtual DbSet<Cam> Cams { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//optionsBuilder.UseNpgsql("Host=172.24.12.201;Port=5432;Database=Notifications;Username=postgres;Password=4NUDZhJ7");
optionsBuilder.UseSqlite("Data Source=Error.db");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
+34
View File
@@ -0,0 +1,34 @@
using System.ComponentModel.DataAnnotations;
namespace LC_Api
{
public class Error
{
[Key]
public Guid Id { get; set; }
public string? TypeDev { get; set; }
public int MsgId { get; set; }
public string? Status { get; set; }
public string? Name { get; set; }
public string? Ip { get; set; }
public string? Map { get; set; }
public DateTime? DataError { get; set; }
}
public enum typeDev
{
Unknown = 0,
Camera,
SABRA,
vServer,
Server,
Switch,
DVR,
ARM
}
public enum statusDev
{
Off = 0,
On,
Unknown
}
}
BIN
View File
Binary file not shown.
Binary file not shown.
+17
View File
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>
</Project>
+6
View File
@@ -0,0 +1,6 @@
@LC_Api_HostAddress = http://localhost:5224
GET {{LC_Api_HostAddress}}/weatherforecast/
Accept: application/json
###
+176
View File
@@ -0,0 +1,176 @@
using Telegram.Bot;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using System.Text.Json;
using Telegram.Bot.Types.ReplyMarkups;
namespace LC_Api
{
public class Program
{
public static string token = "7055214362:AAFL1aroXt1S00pACH6jMs7OiNQtmK8pI_Y";
public static TelegramBotClient botClient = null;
public static void Main(string[] args)
{
botClient = new TelegramBotClient(token);
using CancellationTokenSource cts = new();
var builder = WebApplication.CreateBuilder(args);
using var db = new Db();
builder.Services.AddAuthorization();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapGet("/", () => "status:ok");
app.MapGet("/error", () =>
{
var re = db.Errors.ToList();
if (re.Count > 0)
{
return re;
}
return null;
});
app.MapGet("/error/{countDay}", (int countDay) =>
{
DateTime d = DateTime.Now.AddDays(-countDay);
List<Error> re;
switch (countDay)
{
case 0:
re = db.Errors.Where(e => e.DataError == DateTime.Now).ToList();
break;
case 3:
re = db.Errors.Where(e => e.DataError <= DateTime.Now && e.DataError > d).ToList();
break;
case 7:
re = db.Errors.Where(e => e.DataError <= DateTime.Now && e.DataError > d).ToList();
break;
default:
re = new List<Error>();
break;
}
//var data = content.Content.ToString();
//var er = JsonSerializer.Deserialize<Error>(content);
//db.Error.Add(content);
//db.SaveChanges();
return re;
});
app.MapPost("/error", async (Error content) =>
{
var txt = string.Empty;
content.DataError = DateTime.Now;
InlineKeyboardMarkup inlineKeyboard = new(new[]
{
new []
{
InlineKeyboardButton.WithCallbackData(text: "Перезагрузить", callbackData: $"reboot|{content.Ip}")
}
});
if (content.Status == "off")
{
txt = "<b>‼ НЕИСПРАВНОСТЬ ‼</b>\n" +
$"----------------------------------------------\n" +
$"<b>Объект:</b> {content.Map}\n" +
$"<b>Устройство:</b> {content.TypeDev}\n" +
$"<b>Имя:</b> {content.Name}\n" +
$"<b>Адрес:</b> {content.Ip}\n" +
$"<b>Состояние:</b> 🔴 - не доступна\n" +
$"----------------------------------------------";
var msgId = botClient.SendTextMessageAsync(chatId: 6882856105, parseMode: ParseMode.Html, replyMarkup: inlineKeyboard, text: txt).Result.MessageId;
content.MsgId = msgId;
db.Errors.Add(content);
db.SaveChanges();
}
else if (content.Status == "error")
{
var re = db.Errors.SingleOrDefault(e => e.Ip == content.Ip && e.Status == "off");
if (re != null)
{
re.Status = "error";
re.DataError = content.DataError;
txt = "<b>⚠ ВНИМАНИЕ ⚠</b>\n" +
$"----------------------------------------------\n" +
$"<b>Объект:</b> {content.Map}\n" +
$"<b>Устройство:</b> {content.TypeDev}\n" +
$"<b>Имя:</b> {content.Name}\n" +
$"<b>Адрес:</b> {content.Ip}\n" +
$"<b>Состояние:</b> 🟡 - ошибка\n" +
$"----------------------------------------------";
//var mi = Convert.ToInt32(re.MsgId);
//await botClient.DeleteMessageAsync(6882856105, mi);
var msgId = botClient.EditMessageTextAsync(6882856105, re.MsgId, txt, parseMode: ParseMode.Html);
re.MsgId = msgId.Id;
db.SaveChanges();
}
else
{
txt = "<b>⚠ ВНИМАНИЕ ⚠</b>\n" +
$"----------------------------------------------\n" +
$"<b>Объект:</b> {content.Map}\n" +
$"<b>Устройство:</b> {content.TypeDev}\n" +
$"<b>Имя:</b> {content.Name}\n" +
$"<b>Адрес:</b> {content.Ip}\n" +
$"<b>Состояние:</b> 🟡 - ошибка\n" +
$"----------------------------------------------";
var msgId = botClient.SendTextMessageAsync(chatId: 6882856105, parseMode: ParseMode.Html, text: txt).Result.MessageId;
content.MsgId = msgId;
db.Errors.Add(content);
db.SaveChanges();
}
}
else
{
var re = db.Errors.FirstOrDefault(e => e.Ip == content.Ip && (e.Status == "off" || e.Status == "error") && e.Name == content.Name);
if (re != null)
{
re.Status = "on";
re.DataError = content.DataError;
txt = "<b>✅ ИСПРАВНО ✅</b>\n" +
$"----------------------------------------------\n" +
$"<b>Объект:</b> {content.Map}\n" +
$"<b>Устройство:</b> {content.TypeDev}\n" +
$"<b>Имя:</b> {content.Name}\n" +
$"<b>Адрес:</b> {content.Ip}\n" +
$"<b>Состояние:</b> 🟢 - исправно\n" +
$"----------------------------------------------";
var msgId = botClient.DeleteMessageAsync(6882856105, re.MsgId);// EditMessageTextAsync(6882856105, re.MsgId, txt, parseMode: ParseMode.Html);
re.MsgId = msgId.Id;
}
db.SaveChanges();
}
return;
});
app.Run();
}
private static async Task HandlePollingErrorAsync(ITelegramBotClient client, Exception exception, CancellationToken token)
{
throw new NotImplementedException();
}
private static async Task HandleUpdateAsync(ITelegramBotClient client, Update update, CancellationToken token)
{
return;
}
}
}
+31
View File
@@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:10075",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5224",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}