101 lines
2.5 KiB
C#
101 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Feature.AI;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace BeWo.ViewModel
|
|
{
|
|
[JsonObject(MemberSerialization.OptIn)]
|
|
public class AiConversationVM : AbstractDCMapperVM<AiConversationDC>
|
|
{
|
|
private string _Displayname;
|
|
private DateTime _Updated;
|
|
private AiConversationMessageListVM _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 Updated
|
|
{
|
|
get { return _Updated; }
|
|
set
|
|
{
|
|
if (!AreDifferent(Updated, value))
|
|
return;
|
|
|
|
_Updated = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.Updated, value), nameof(Updated));
|
|
FirePropertyChanged(nameof(Updated));
|
|
}
|
|
}
|
|
|
|
public AiConversationMessageListVM Messages
|
|
{
|
|
get { return _Messages ?? (_Messages = new AiConversationMessageListVM()); }
|
|
set
|
|
{
|
|
if (!AreDifferent(_Messages, value))
|
|
return;
|
|
|
|
_Messages = value;
|
|
StoreDirtyInformation(AreDifferent(DataContract.Messages, value), nameof(Messages));
|
|
FirePropertyChanged(nameof(Messages));
|
|
}
|
|
}
|
|
|
|
[JsonProperty]
|
|
public DateTime Created => DataContract.Created;
|
|
|
|
[JsonProperty]
|
|
public AiModelDC Modell => DataContract.Modell;
|
|
|
|
protected override void InitByDataContract(AiConversationDC pDataContract)
|
|
{
|
|
_Displayname = pDataContract.Displayname;
|
|
_Updated = pDataContract.Updated;
|
|
|
|
if (pDataContract.Messages is object)
|
|
_Messages = new AiConversationMessageListVM(pDataContract.Messages);
|
|
}
|
|
|
|
protected override AiConversationDC MapToDataContract(AiConversationDC pDataContract, bool doCommit)
|
|
{
|
|
pDataContract.Displayname = _Displayname;
|
|
pDataContract.Updated = _Updated;
|
|
pDataContract.Messages = _Messages?.CopyToDCList(doCommit);
|
|
|
|
return pDataContract;
|
|
}
|
|
}
|
|
} |