From 4b240b7258469aa11233dcc80cac98a64232e7ec Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Wed, 19 Mar 2025 16:30:27 +0100 Subject: [PATCH] zwischenstand blablacar --- BeWo/BeWo.csproj | 3 + BeWo/DebugConfig.cs | 2 +- .../GeneratedOperationsEnhancedService.cs | 20 +- BeWo/ServiceProxy/ServiceFacade.cs | 56 +- BeWo/Styles/Colors/Colors.xaml | 4 +- BeWo/View/BargeldkassenView.xaml | 694 ++++++++++++++---- BeWo/View/Master/AiConversationView.xaml | 239 ++++-- BeWo/View/Master/AiConversationView.xaml.cs | 54 +- .../Navigation/CustomerNavigationView.xaml | 419 +++++++---- BeWo/ViewModel/AiConversationMessageVM.cs | 111 +++ BeWo/ViewModel/AiConversationVM.cs | 147 ++++ .../ListViewModel/AiConversationListVM.cs | 47 ++ Service/Service.csproj | 2 + .../IOperationsEnhancedService.cs | 4 + .../OperationsEnhancedServiceImp.cs | 23 + Service/ServiceProxy/MikePHPScriptFacade.cs | 34 + Service/ServiceProxy/ServiceFacade.cs | 15 + Shared/Core/WebClientFacade.cs | 126 ++++ Shared/DataContracts/AiConversationDC.cs | 23 + .../DataContracts/AiConversationMessageDC.cs | 19 + Shared/DataContracts/AiModelDC.cs | 63 ++ Shared/DataContracts/AiSettingDC.cs | 18 + Shared/DataContracts/AiSettingsDC.cs | 1 - Shared/Shared.csproj | 5 + 24 files changed, 1743 insertions(+), 386 deletions(-) create mode 100644 BeWo/ViewModel/AiConversationMessageVM.cs create mode 100644 BeWo/ViewModel/AiConversationVM.cs create mode 100644 BeWo/ViewModel/ListViewModel/AiConversationListVM.cs create mode 100644 Service/ServiceProxy/MikePHPScriptFacade.cs create mode 100644 Service/ServiceProxy/ServiceFacade.cs create mode 100644 Shared/Core/WebClientFacade.cs create mode 100644 Shared/DataContracts/AiConversationDC.cs create mode 100644 Shared/DataContracts/AiConversationMessageDC.cs create mode 100644 Shared/DataContracts/AiModelDC.cs create mode 100644 Shared/DataContracts/AiSettingDC.cs diff --git a/BeWo/BeWo.csproj b/BeWo/BeWo.csproj index 6dd67e287..e7b683cf4 100644 --- a/BeWo/BeWo.csproj +++ b/BeWo/BeWo.csproj @@ -1203,9 +1203,12 @@ + + + diff --git a/BeWo/DebugConfig.cs b/BeWo/DebugConfig.cs index ded744c46..704874282 100644 --- a/BeWo/DebugConfig.cs +++ b/BeWo/DebugConfig.cs @@ -145,7 +145,7 @@ namespace BeWo { DebugConfigMode = DebugConfigMode.FeatureAiModule, AutoLogin = true, - //SelectView = UIContext.Finance, + SelectView = UIContext.AiConversation, //SelectIndex = 8, //DefaultLoginUsername = "m1", //DefaultLoginPassword = "bewobewo", diff --git a/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs b/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs index acab0db92..edf7be5a1 100644 --- a/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs +++ b/BeWo/ServiceProxy/GeneratedOperationsEnhancedService.cs @@ -9,34 +9,47 @@ //------------------------------------------------------------------------------ namespace BeWo.ServiceProxy -{ +{ [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] [System.ServiceModel.ServiceContractAttribute(ConfigurationName="BeWo.ServiceProxy.IOperationsEnhancedService")] public interface IOperationsEnhancedService { + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOperationsEnhancedService/Method1", ReplyAction="http://tempuri.org/IOperationsEnhancedService/Method1Response")] [System.ServiceModel.FaultContractAttribute(typeof(BeWo.ServiceProxy.BeWoFault), Action="http://tempuri.org/IOperationsEnhancedService/Method1BeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BeWo.Service.ServiceContracts")] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFault))] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFaultType))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.AiModelDC))] object Method1(object input, object input2); [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOperationsEnhancedService/Method2", ReplyAction="http://tempuri.org/IOperationsEnhancedService/Method2Response")] [System.ServiceModel.FaultContractAttribute(typeof(BeWo.ServiceProxy.BeWoFault), Action="http://tempuri.org/IOperationsEnhancedService/Method2BeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BeWo.Service.ServiceContracts")] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFault))] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFaultType))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.AiModelDC))] object Method2(object input, object input2); [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOperationsEnhancedService/Method3", ReplyAction="http://tempuri.org/IOperationsEnhancedService/Method3Response")] [System.ServiceModel.FaultContractAttribute(typeof(BeWo.ServiceProxy.BeWoFault), Action="http://tempuri.org/IOperationsEnhancedService/Method3BeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BeWo.Service.ServiceContracts")] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFault))] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFaultType))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.AiModelDC))] object Method3(object input, object input2); [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOperationsEnhancedService/Method4", ReplyAction="http://tempuri.org/IOperationsEnhancedService/Method4Response")] [System.ServiceModel.FaultContractAttribute(typeof(BeWo.ServiceProxy.BeWoFault), Action="http://tempuri.org/IOperationsEnhancedService/Method4BeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BeWo.Service.ServiceContracts")] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFault))] [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BeWo.ServiceProxy.BeWoFaultType))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List))] + [System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.AiModelDC))] object Method4(object input, object input2); + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IOperationsEnhancedService/GetAiModels", ReplyAction="http://tempuri.org/IOperationsEnhancedService/GetAiModelsResponse")] + [System.ServiceModel.FaultContractAttribute(typeof(BeWo.ServiceProxy.BeWoFault), Action="http://tempuri.org/IOperationsEnhancedService/GetAiModelsBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BeWo.Service.ServiceContracts")] + System.Collections.Generic.List GetAiModels(); } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] @@ -92,5 +105,10 @@ namespace BeWo.ServiceProxy { return base.Channel.Method4(input, input2); } + + public System.Collections.Generic.List GetAiModels() + { + return base.Channel.GetAiModels(); + } } } diff --git a/BeWo/ServiceProxy/ServiceFacade.cs b/BeWo/ServiceProxy/ServiceFacade.cs index c08ad4336..5ef6f7a0e 100644 --- a/BeWo/ServiceProxy/ServiceFacade.cs +++ b/BeWo/ServiceProxy/ServiceFacade.cs @@ -15,6 +15,7 @@ using BS.Shared; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using DevExpress.CodeParser; +using DevExpress.Export.Xl; namespace BeWo.ServiceProxy { @@ -77,10 +78,10 @@ namespace BeWo.ServiceProxy => DoSync(pAction); public static void DoOperationsEnhancedServiceSnyc(Func pFunc) => DoSync(pFunc); - public static void DoOperationsEnhancedServiceAsnyc(Action pAction, Action pCallback = null, bool showWaitDialog = true) - => DoAsync(pAction, pCallback, showWaitDialog); - public static void DoOperationsEnhancedServiceAsnyc(Func pFunc, Action pCallback = null, bool showWaitDialog = true) - => DoAsync(pFunc, pCallback, showWaitDialog); + public static void DoOperationsEnhancedServiceAsnyc(Action pAction, Action pCallback = null, bool showWaitDialog = true, UserControl caller = null) + => DoAsync(pAction, pCallback, showWaitDialog, caller?.Dispatcher); + public static void DoOperationsEnhancedServiceAsnyc(Func < IOperationsEnhancedService, T> pFunc, Action pCallback = null, bool showWaitDialog = true, UserControl caller = null) + => DoAsync(pFunc, pCallback, showWaitDialog, caller?.Dispatcher); public static void DoAccountingServiceAsync(Func pFunc, Action pCallBack, bool showWaitDialog) { @@ -295,14 +296,7 @@ namespace BeWo.ServiceProxy } public static void DoGkvAccountingServiceAsyncGUI(Func pFunc, Action pCallBack, Dispatcher dispatcher) { - Action action = (t) => dispatcher.BeginInvoke( - DispatcherPriority.Normal, - (Action)delegate - { - pCallBack(t); - }); - - DoAsync(pFunc, action, true); + DoAsync(pFunc, pCallBack, true, dispatcher); } public static void DoGkvAccountingServiceAsync(Action pAction) @@ -685,6 +679,25 @@ namespace BeWo.ServiceProxy DoAsync(pFunc, pCallback, null, showWaitDialog); } + private static void DoAsync(Func pFunc, Action pCallback, bool showWaitDialog, Dispatcher dispatcher) + where TClient : ClientBase, TInterface, new() + where TInterface : class + { + Action action = pCallback; + + if (dispatcher != null) + { + action = (t) => dispatcher.BeginInvoke( + DispatcherPriority.Normal, + (Action)delegate + { + pCallback(t); + }); + } + + DoAsync(pFunc, action, showWaitDialog); + } + private static void DoAsync(Func pFunc, Action pCallback, Action pErrorCallback, bool showWaitDialog) where TClient : ClientBase, TInterface, new() where TInterface : class @@ -756,6 +769,25 @@ namespace BeWo.ServiceProxy DoAsync(pAction, null, showWaitDialog); } + private static void DoAsync(Action pAction, Action pCallback, bool showWaitDialog, Dispatcher dispatcher) + where TClient : ClientBase, TInterface, new() + where TInterface : class + { + Action action = pCallback; + + if(dispatcher != null) + { + action = () => dispatcher.BeginInvoke( + DispatcherPriority.Normal, + (Action)delegate + { + pCallback(); + }); + } + + DoAsync(pAction, action, showWaitDialog); + } + // private static void DoAsync(Action pAction, Action pCallback, bool ) // void with callback private static void DoAsync(Action pAction, Action pCallback, bool showWaitDialog) diff --git a/BeWo/Styles/Colors/Colors.xaml b/BeWo/Styles/Colors/Colors.xaml index 204277501..20de95df6 100644 --- a/BeWo/Styles/Colors/Colors.xaml +++ b/BeWo/Styles/Colors/Colors.xaml @@ -94,7 +94,7 @@ - - + + \ No newline at end of file diff --git a/BeWo/View/BargeldkassenView.xaml b/BeWo/View/BargeldkassenView.xaml index b46d6f045..8123910c5 100644 --- a/BeWo/View/BargeldkassenView.xaml +++ b/BeWo/View/BargeldkassenView.xaml @@ -1,17 +1,22 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/BeWo/ViewModel/AiConversationMessageVM.cs b/BeWo/ViewModel/AiConversationMessageVM.cs new file mode 100644 index 000000000..90e269819 --- /dev/null +++ b/BeWo/ViewModel/AiConversationMessageVM.cs @@ -0,0 +1,111 @@ +using System; + +using BS.Shared; +using BS.Shared.DataContracts; + +namespace BeWo.ViewModel +{ + public class AiConversationMessageVM : AbstractDCMapperVM + { + private long? _Oid; + private string _Context; + private string _Prompt; + private string _Model; + private string _Result; + + public AiConversationMessageVM(AiConversationMessageDC dc) : base(dc, dc.Oid is null) + { + + } + + public long? Oid + { + get { return _Oid; } + set + { + if (!AreDifferent(_Oid, value)) + return; + + _Oid = value; + StoreDirtyInformation(AreDifferent(DataContract.Oid, value), nameof(Oid)); + FirePropertyChanged(nameof(Oid)); + } + } + + public string Context + { + get { return _Context; } + set + { + if (!AreDifferent(_Context, value)) + return; + + _Context = value; + StoreDirtyInformation(AreDifferent(DataContract.Context, value), nameof(Context)); + FirePropertyChanged(nameof(Context)); + } + } + + public string Prompt + { + get { return _Prompt; } + set + { + if (!AreDifferent(_Prompt, value)) + return; + + _Prompt = value; + StoreDirtyInformation(AreDifferent(DataContract.Prompt, value), nameof(Prompt)); + FirePropertyChanged(nameof(Prompt)); + } + } + + public string Model + { + get { return _Model; } + set + { + if (!AreDifferent(_Model, value)) + return; + + _Model = value; + StoreDirtyInformation(AreDifferent(DataContract.Model, value), nameof(Model)); + FirePropertyChanged(nameof(Model)); + } + } + + public string Result + { + get { return _Result; } + set + { + if (!AreDifferent(_Result, value)) + return; + + _Result = value; + StoreDirtyInformation(AreDifferent(DataContract.Result, value), nameof(Result)); + FirePropertyChanged(nameof(Result)); + } + } + + protected override void InitByDataContract(AiConversationMessageDC pDataContract) + { + _Oid = pDataContract.Oid; + _Context = pDataContract.Context; + _Prompt = pDataContract.Prompt; + _Model = pDataContract.Model; + _Result = pDataContract.Result; + } + + protected override AiConversationMessageDC MapToDataContract(AiConversationMessageDC pDataContract, bool doCommit) + { + pDataContract.Oid = _Oid; + pDataContract.Context = _Context; + pDataContract.Prompt = _Prompt; + pDataContract.Model = _Model; + pDataContract.Result = _Result; + + return pDataContract; + } + } +} diff --git a/BeWo/ViewModel/AiConversationVM.cs b/BeWo/ViewModel/AiConversationVM.cs new file mode 100644 index 000000000..4e4868dae --- /dev/null +++ b/BeWo/ViewModel/AiConversationVM.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using BeWo.ViewModel.ListViewModel; +using BS.Shared; +using BS.Shared.DataContracts; +using Newtonsoft.Json; + +namespace BeWo.ViewModel +{ + [JsonObject(MemberSerialization.OptIn)] + public class AiConversationVM : AbstractDCMapperVM + { + private string _Displayname; + private DateTime _Created; + private string _Modell; + private string _View; + private AiSettingDC _Setting; + private ObservableCollection _Messages; + + public AiConversationVM() : this(new AiConversationDC()) { } + public AiConversationVM(AiConversationDC dc) : base(dc, dc.Oid is null) + { + + } + + public string Json + { + get => JsonConvert.SerializeObject(this, Formatting.Indented); + } + + [JsonProperty] + public string Displayname + { + get { return _Displayname; } + set + { + if (!AreDifferent(_Displayname, value)) + return; + + _Displayname = value; + StoreDirtyInformation(AreDifferent(DataContract.Displayname, value), nameof(Displayname)); + FirePropertyChanged(nameof(Displayname)); + FirePropertyChanged(nameof(Json)); + } + } + + [JsonProperty] + public DateTime Created + { + get { return _Created; } + set + { + if (!AreDifferent(_Created, value)) + return; + + _Created = value; + StoreDirtyInformation(AreDifferent(DataContract.Created, value), nameof(Created)); + FirePropertyChanged(nameof(Created)); + } + } + + [JsonProperty] + public string Modell + { + get { return _Modell; } + set + { + if (!AreDifferent(_Modell, value)) + return; + + _Modell = value; + StoreDirtyInformation(AreDifferent(DataContract.Modell, value), nameof(Modell)); + FirePropertyChanged(nameof(Modell)); + } + } + + public string View + { + get { return _View; } + set + { + if (!AreDifferent(_View, value)) + return; + + _View = value; + StoreDirtyInformation(AreDifferent(DataContract.View, value), nameof(View)); + FirePropertyChanged(nameof(View)); + } + } + + public AiSettingDC Setting + { + get { return _Setting; } + set + { + if (!AreDifferent(_Setting, value)) + return; + + _Setting = value; + StoreDirtyInformation(AreDifferent(DataContract.Setting, value), nameof(Setting)); + FirePropertyChanged(nameof(Setting)); + } + } + + public ObservableCollection Messages + { + get { return _Messages; } + set + { + if (!AreDifferent(_Messages, value)) + return; + + _Messages = value; + StoreDirtyInformation(AreDifferent(DataContract.Messages, value), nameof(Messages)); + FirePropertyChanged(nameof(Messages)); + } + } + + protected override void InitByDataContract(AiConversationDC pDataContract) + { + _Displayname = pDataContract.Displayname; + _Created = pDataContract.Created; + _Modell = pDataContract.Modell; + _View = pDataContract.View; + _Setting = pDataContract.Setting; + + if (pDataContract.Messages is object) + _Messages = new ObservableCollection(pDataContract.Messages); + else + _Messages = new ObservableCollection(); + } + + protected override AiConversationDC MapToDataContract(AiConversationDC pDataContract, bool doCommit) + { + pDataContract.Displayname = _Displayname; + pDataContract.Created = _Created; + pDataContract.Modell = _Modell; + pDataContract.View = _View; + pDataContract.Setting = _Setting; + pDataContract.Messages = _Messages.ToList(); + + return pDataContract; + } + } +} \ No newline at end of file diff --git a/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs b/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs new file mode 100644 index 000000000..e83b6cc84 --- /dev/null +++ b/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs @@ -0,0 +1,47 @@ +using BeWo.ServiceProxy; +using BS.Shared.DataContracts; +using BS.Shared.Extensions; +using ChatController.Utilities.Extensions; +using DevExpress.Mvvm; +using DevExpress.XtraPrinting.Native; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Threading; + +namespace BeWo.ViewModel.ListViewModel +{ + public class AiConversationListVM : AbstractDCListMapperVM + { + private AiModelDC _SelectedModel; + + public AiConversationListVM() : this(null) + { + VMList.Add(new AiConversationVM() + { + Created = DateTime.Now, + Displayname = "Chat1" + }); + } + public AiConversationListVM(List pDCs) : base(pDCs) + { + Models = new ObservableSortCollection(); + } + + public ObservableCollection Models { get; set; } + public AiModelDC SelectedModel { + get { return _SelectedModel; } + set + { + if (_SelectedModel == value) + return; + + _SelectedModel = value; + FirePropertyChanged(nameof(SelectedModel)); + } + } + } +} diff --git a/Service/Service.csproj b/Service/Service.csproj index 8b3e4f726..8bdcbb9d5 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -538,11 +538,13 @@ + + diff --git a/Service/ServiceContracts/IOperationsEnhancedService.cs b/Service/ServiceContracts/IOperationsEnhancedService.cs index 9e778dad1..b613e7f2b 100644 --- a/Service/ServiceContracts/IOperationsEnhancedService.cs +++ b/Service/ServiceContracts/IOperationsEnhancedService.cs @@ -26,6 +26,10 @@ namespace BeWo.Service.ServiceContracts [FaultContract(typeof(BeWoFault))] [OperationContract] object Method4(object input, object input2); + + [FaultContract(typeof(BeWoFault))] + [OperationContract] + List GetAiModels(); } } diff --git a/Service/ServiceImplementations/OperationsEnhancedServiceImp.cs b/Service/ServiceImplementations/OperationsEnhancedServiceImp.cs index 48a7ebc97..835c7366f 100644 --- a/Service/ServiceImplementations/OperationsEnhancedServiceImp.cs +++ b/Service/ServiceImplementations/OperationsEnhancedServiceImp.cs @@ -1,4 +1,6 @@ using BeWo.Service.ServiceContracts; +using BeWo.Service.ServiceProxy; +using BS.Shared.DataContracts; using System; using System.Collections.Generic; using System.Linq; @@ -13,6 +15,22 @@ namespace BeWo.Service.ServiceImplementations { public object Method1(object input, object input2) { + if(input is int i) + { + if(i == 1) + { + return new AiSettingDC(); + } + if(i == 2) + { + return new List(); + } + if (i == 3) + { + return ServiceFacade.MikePHPScriptFacade.GetAiModelle(); + } + } + throw new NotImplementedException(); } @@ -30,5 +48,10 @@ namespace BeWo.Service.ServiceImplementations { throw new NotImplementedException(); } + + public List GetAiModels() + { + return ServiceFacade.MikePHPScriptFacade.GetAiModelle(); + } } } diff --git a/Service/ServiceProxy/MikePHPScriptFacade.cs b/Service/ServiceProxy/MikePHPScriptFacade.cs new file mode 100644 index 000000000..071578ffe --- /dev/null +++ b/Service/ServiceProxy/MikePHPScriptFacade.cs @@ -0,0 +1,34 @@ +using BS.Shared.Core; +using BS.Shared.DataContracts; +using DevExpress.DataAccess.Native.EntityFramework; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.ServiceProxy +{ + public class MikePHPScriptFacade : WebClientFacade + { + public List GetAiModelle() + { + var url = "https://ai1.ownsoft.de/osaimodels.php?show"; + var dictList = SendGet>>(url); + + var rtn = new List(); + + foreach (var item in dictList) + { + foreach (var kvp in item) + { + rtn.Add(new AiModelDC(kvp.Key, kvp.Value)); + } + } + + return rtn; + } + } +} diff --git a/Service/ServiceProxy/ServiceFacade.cs b/Service/ServiceProxy/ServiceFacade.cs new file mode 100644 index 000000000..8ba02f76a --- /dev/null +++ b/Service/ServiceProxy/ServiceFacade.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.ServiceProxy +{ + public static class ServiceFacade + { + private static readonly Lazy _MikePHPScriptFacade = new Lazy(() => new MikePHPScriptFacade()); + + public static MikePHPScriptFacade MikePHPScriptFacade => _MikePHPScriptFacade.Value; + } +} diff --git a/Shared/Core/WebClientFacade.cs b/Shared/Core/WebClientFacade.cs new file mode 100644 index 000000000..2061092cd --- /dev/null +++ b/Shared/Core/WebClientFacade.cs @@ -0,0 +1,126 @@ +using DevExpress.DataAccess.Native.EntityFramework; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Security.Policy; +using System.Text; +using System.Threading.Tasks; + +namespace BS.Shared.Core +{ + public class WebClientFacade + { + // + // GET + // + protected TRes SendGet(string url) + => Get(url); + protected Task SendGetAsync(string url) + => GetAsync(url); + + // + // POST + // + protected TRes SendPost(string url, TReq req) + => Send(url, "POST", req); + public Task SendPostAsync(string url, TReq req) + => SendAsync(url, "POST", req); + + + #region private + // + // Requests + // + private TRes Get(string url) + { + string response = Get(url); + + return deserialize(response); + } + private TRes Send(string url, string method, TReq req) + { + string dataString = serialize(req); + + string response = Send(url, method, dataString); + + return deserialize(response); + } + private async Task GetAsync(string url) + { + string response = await GetAsync(url); + + return deserialize(response); + } + private async Task SendAsync(string url, string method, TReq req) + { + string dataString = serialize(req); + + string response = await SendAsync(url, method, method); + + return deserialize(response); + } + + // + // String + // + private string Get(string url) + => exec(client => client.DownloadString(url)); + private string Send(string url, string method, string dataString) + => exec(client => client.UploadString(url, method, dataString)); + private async Task GetAsync(string url) + => await execasync(client => client.DownloadStringTaskAsync(url)); + private async Task SendAsync(string url, string method, string dataString) + => await execasync(client => client.UploadStringTaskAsync(url, method, dataString)); + + // + // Base + // + private string exec(Func action) + { + string response; + + using (WebClient client = new WebClient()) + { + client.Encoding = Encoding.UTF8; + + client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); + + response = action(client); + } + + return response; + } + private async Task execasync(Func> action) + { + string response; + + using (WebClient client = new WebClient()) + { + client.Encoding = Encoding.UTF8; + + client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); + + response = await action(client); + } + + return response; + } + + private T deserialize(string input) + { + if(string.IsNullOrEmpty(input)) + return default(T); + + return JsonConvert.DeserializeObject(input); + } + private string serialize(T input) + { + if(input is T) + return JsonConvert.SerializeObject(input); + return string.Empty; + } + #endregion + } +} diff --git a/Shared/DataContracts/AiConversationDC.cs b/Shared/DataContracts/AiConversationDC.cs new file mode 100644 index 000000000..c103479d2 --- /dev/null +++ b/Shared/DataContracts/AiConversationDC.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace BS.Shared.DataContracts +{ + [DataContract] + public class AiConversationDC : IDataContract + { + [DataMember] public long? Oid { get; set; } + [DataMember] public long Version { get; set; } + [DataMember] public string Displayname { get; set; } + [DataMember] public DateTime Created { get; set; } + [DataMember] public string Modell { get; set; } + [DataMember] public string View { get; set; } + + [DataMember] public AiSettingDC Setting { get; set; } + [DataMember] public List Messages { get; set; } + } +} diff --git a/Shared/DataContracts/AiConversationMessageDC.cs b/Shared/DataContracts/AiConversationMessageDC.cs new file mode 100644 index 000000000..35ca5a6bb --- /dev/null +++ b/Shared/DataContracts/AiConversationMessageDC.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace BS.Shared.DataContracts +{ + [DataContract] + public class AiConversationMessageDC : IDataContract + { + public long? Oid { get; set; } + public string Model { get; set; } + public string Context { get; set; } + public string Prompt { get; set; } + public string Result { get; set; } + } +} diff --git a/Shared/DataContracts/AiModelDC.cs b/Shared/DataContracts/AiModelDC.cs new file mode 100644 index 000000000..03fbc790d --- /dev/null +++ b/Shared/DataContracts/AiModelDC.cs @@ -0,0 +1,63 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BS.Shared.DataContracts +{ + public class AiModelDC : IDataContract, IComparable + { + public AiModelDC() + { + + } + + public AiModelDC(string name, int value) + { + ModelName = name; + Value = value; + } + + public string ModelName { get; set; } + + public int Value { get; set; } + + public int CompareTo(AiModelDC other) + { + if(other == null) return 1; + + var comp = ModelName.CompareTo(other.ModelName); + + if(comp != 0) return comp; + + var comp2 = Value.CompareTo(other.Value); + + return comp2; + } + + public override bool Equals(object obj) + { + return obj is AiModelDC dc && + ModelName == dc.ModelName && + Value == dc.Value; + } + + public override int GetHashCode() + { + unchecked + { + var result = 0; + result = (result * 397) ^ ModelName.GetHashCode(); + result = (result * 397) ^ Value.GetHashCode(); + return result; + } + } + + public override string ToString() + { + return $"{ModelName}:{Value}"; + } + } +} diff --git a/Shared/DataContracts/AiSettingDC.cs b/Shared/DataContracts/AiSettingDC.cs new file mode 100644 index 000000000..b4ed4f900 --- /dev/null +++ b/Shared/DataContracts/AiSettingDC.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace BS.Shared.DataContracts +{ + [DataContract] + public class AiSettingDC : IDataContract + { + [DataMember] public long Oid { get; set; } + [DataMember] public long Version { get; set; } + + [DataMember] public string SelectedModel { get; set; } + } +} diff --git a/Shared/DataContracts/AiSettingsDC.cs b/Shared/DataContracts/AiSettingsDC.cs index caf1b6431..b08d4e3dc 100644 --- a/Shared/DataContracts/AiSettingsDC.cs +++ b/Shared/DataContracts/AiSettingsDC.cs @@ -16,6 +16,5 @@ namespace BS.Shared.DataContracts [DataMember] public string Settings { get; set; } - } } \ No newline at end of file diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index 6b3a43365..a8c31c2cf 100644 --- a/Shared/Shared.csproj +++ b/Shared/Shared.csproj @@ -168,10 +168,15 @@ + + + + +