upstream: apply changes

This commit is contained in:
ZavaruKitsu 2022-10-15 18:16:22 +03:00
parent 8d02b54b05
commit 77242a200f
12 changed files with 48 additions and 154 deletions

View File

@ -1,74 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{673A56F5-6110-4AED-A68D-562FD6ED3EA6}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>AsyncFormUpdates</RootNamespace>
<AssemblyName>AsyncFormUpdates</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile/>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib"/>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>
<Reference Include="Microsoft.CSharp"/>
<Reference Include="System.Data"/>
<Reference Include="System.Net.Http"/>
<Reference Include="System.Xml"/>
<Reference Include="Telegram.Bot, Version=17.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Telegram.Bot.17.0.0\lib\netstandard2.0\Telegram.Bot.dll</HintPath>
</Reference>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9" />
</ItemGroup>
<ItemGroup>
<Compile Include="forms\AsyncFormEdit.cs"/>
<Compile Include="forms\AsyncFormUpdate.cs"/>
<Compile Include="forms\Start.cs"/>
<Compile Include="Program.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="App.config"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj">
<Project>{0bd16fb9-7ed4-4ccb-83eb-5cee538e1b6c}</Project>
<Name>TelegramBotBase</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="System.Net.Requests" Version="4.3.0"/>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0"/>
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4"/>
<PackageReference Include="Telegram.Bot" Version="18.0.0"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
</Project>

View File

@ -1,8 +1,8 @@
using System;
using System.Timers;
using System.Timers;
using AsyncFormUpdates.forms;
using TelegramBotBase;
using TelegramBotBase.Builder;
using Timer = System.Timers.Timer;
namespace AsyncFormUpdates
{
@ -10,7 +10,7 @@ namespace AsyncFormUpdates
{
private static BotBase __bot;
private static void Main(string[] args)
private static async Task Main(string[] args)
{
var apiKey = "APIKey";
@ -18,7 +18,7 @@ namespace AsyncFormUpdates
.QuickStart<Start>(apiKey)
.Build();
__bot.Start();
await __bot.Start();
var timer = new Timer(5000);
@ -28,7 +28,7 @@ namespace AsyncFormUpdates
Console.ReadLine();
timer.Stop();
__bot.Stop();
await __bot.Stop();
}
private static async void Timer_Elapsed(object sender, ElapsedEventArgs e)
@ -46,4 +46,4 @@ namespace AsyncFormUpdates
}
}
}
}
}

View File

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("AsyncFormUpdates")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AsyncFormUpdates")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("673a56f5-6110-4aed-a68d-562fd6ed3ea6")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -123,7 +123,7 @@ public class MessageResult : ResultBase
}
/// <summary>
/// Confirm incomming action (i.e. Button click)
/// Confirm incoming action (i.e. Button click)
/// </summary>
/// <param name="message"></param>
/// <returns></returns>

View File

@ -18,9 +18,9 @@ namespace TelegramBotBase;
/// Bot base class for full Device/Context and Messagehandling
/// </summary>
/// <typeparam name="T"></typeparam>
public class BotBase
public sealed class BotBase
{
public BotBase()
internal BotBase()
{
SystemSettings = new Dictionary<ESettings, uint>();
@ -32,10 +32,7 @@ public class BotBase
BotCommandScopes = new Dictionary<BotCommandScope, List<BotCommand>>();
Sessions = new SessionBase
{
BotBase = this
};
Sessions = new SessionManager(this);
}
public MessageClient Client { get; set; }
@ -48,7 +45,7 @@ public class BotBase
/// <summary>
/// List of all running/active sessions
/// </summary>
public SessionBase Sessions { get; set; }
public SessionManager Sessions { get; set; }
/// <summary>
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
@ -94,9 +91,10 @@ public class BotBase
await Sessions.LoadSessionStates(StateMachine);
}
//Enable auto session saving
// Enable auto session saving
if (GetSetting(ESettings.SaveSessionsOnConsoleExit, false))
{
// should be waited until finish
Console.SetHandler(() => { Sessions.SaveSessionStates().GetAwaiter().GetResult(); });
}
@ -329,8 +327,6 @@ public class BotBase
private static readonly object EvMessage = new();
private static object __evSystemCall = new();
public delegate Task BotCommandEventHandler(object sender, BotCommandEventArgs e);
private static readonly object EvException = new();
@ -356,7 +352,7 @@ public class BotBase
}
/// <summary>
/// Will be called on incomming message
/// Will be called on incoming message
/// </summary>
public event EventHandler<MessageIncomeEventArgs> Message
{

View File

@ -48,8 +48,6 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
Client = _client
};
bot.Sessions.Client = bot.Client;
bot.BotCommandScopes = BotCommandScopes;
bot.StateMachine = _statemachine;

View File

@ -39,7 +39,7 @@ public class ButtonFormDataSource : IDataSource<ButtonRow>
/// <summary>
/// Returns the amount of rows exisiting.
/// Returns the amount of rows existing.
/// </summary>
/// <returns></returns>
public virtual int Count => ButtonForm.Count;
@ -134,4 +134,4 @@ public class ButtonFormDataSource : IDataSource<ButtonRow>
{
return ds.ButtonForm;
}
}
}

View File

@ -5,7 +5,7 @@ using TelegramBotBase.Base;
namespace TelegramBotBase.Form;
/// <summary>
/// This is used to split incomming requests depending on the chat type.
/// This is used to split incoming requests depending on the chat type.
/// </summary>
public class SplitterForm : FormBase
{
@ -90,4 +90,4 @@ public class SplitterForm : FormBase
{
return base.SentData(message);
}
}
}

View File

@ -25,11 +25,11 @@ public class English : Localization
Values["ToggleButton_OnIcon"] = "⚫";
Values["ToggleButton_OffIcon"] = "⚪";
Values["ToggleButton_Title"] = "Toggle";
Values["ToggleButton_Changed"] = "Choosen";
Values["ToggleButton_Changed"] = "Chosen";
Values["MultiToggleButton_SelectedIcon"] = "✅";
Values["MultiToggleButton_Title"] = "Multi-Toggle";
Values["MultiToggleButton_Changed"] = "Choosen";
Values["MultiToggleButton_Changed"] = "Chosen";
Values["PromptDialog_Back"] = "Back";
Values["ToggleButton_Changed"] = "Setting changed";
}
}
}

View File

@ -16,17 +16,18 @@ namespace TelegramBotBase;
/// <summary>
/// Base class for managing all active sessions
/// </summary>
public class SessionBase
public class SessionManager
{
public SessionBase()
public SessionManager(BotBase botBase)
{
BotBase = botBase;
SessionList = new Dictionary<long, DeviceSession>();
}
/// <summary>
/// The Basic message client.
/// </summary>
public MessageClient Client { get; set; }
public MessageClient Client => BotBase.Client;
/// <summary>
/// A list of all active sessions.
@ -37,18 +38,7 @@ public class SessionBase
/// <summary>
/// Reference to the Main BotBase instance for later use.
/// </summary>
public BotBase BotBase { get; set; }
/// <summary>
/// Get device session from Device/ChatId
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public DeviceSession this[long key]
{
get => SessionList[key];
set => SessionList[key] = value;
}
public BotBase BotBase { get; }
/// <summary>
/// Get device session from Device/ChatId
@ -80,7 +70,7 @@ public class SessionBase
await start.OnOpened(EventArgs.Empty);
this[deviceId] = ds;
SessionList[deviceId] = ds;
return ds;
}
@ -90,7 +80,7 @@ public class SessionBase
/// <param name="deviceId"></param>
public void EndSession(long deviceId)
{
var d = this[deviceId];
var d = SessionList[deviceId];
if (d != null)
{
SessionList.Remove(deviceId);

View File

@ -125,7 +125,7 @@ public class DeviceSession : IDeviceSession
/// <summary>
/// Confirm incomming action (i.e. Button click)
/// Confirm incoming action (i.e. Button click)
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
@ -992,4 +992,4 @@ public class DeviceSession : IDeviceSession
}
#endregion
}
}

View File

@ -22,8 +22,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
@ -50,15 +50,15 @@
<ItemGroup>
<Compile Remove="Archive\**"/>
<EmbeddedResource Remove="Archive\**"/>
<None Remove="Archive\**"/>
<Compile Remove="Archive\**" />
<EmbeddedResource Remove="Archive\**" />
<None Remove="Archive\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="18.0.0"/>
<PackageReference Include="Telegram.Bot.Extensions.Polling" Version="1.0.2"/>
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="Telegram.Bot.Extensions.Polling" Version="1.0.2" />
</ItemGroup>
</Project>