Skip to content

Commit

Permalink
트랜젝션 기능 개선중
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Apr 26, 2018
1 parent b7ff55a commit 3f0be99
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ private void Domains_DomainCreated(object sender, DomainEventArgs e)
if (sender is IDomainCollection domainCollection)
{
var domain = e.Domain;
var dispatcher = domain.Dispatcher;
if (dispatcher == null)
return;
var viewModel = domain.Dispatcher.Invoke(() => new DomainListItemBase(this.authenticator, domain, true, this));
this.Dispatcher.InvokeAsync(() =>
{
Expand Down
12 changes: 5 additions & 7 deletions client/Ntreev.Crema.Services/Data/DataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class DataBase : DataBaseBase<Type, TypeCategory, TypeCollection, TypeCategoryCo
private EventHandler<AuthenticationEventArgs> authenticationLeft;

private readonly HashSet<AuthenticationToken> authentications = new HashSet<AuthenticationToken>();
public Guid loadID;
private bool isResetting;

public DataBase(CremaHost cremaHost, DataBaseInfo dataBaseInfo)
Expand Down Expand Up @@ -344,6 +343,7 @@ public void SetUnloaded(Authentication authentication)

public void SetResetting(Authentication authentication)
{
System.Diagnostics.Trace.WriteLine("Resetting");
this.typeContext?.Dispose();
this.tableContext?.Dispose();
this.isResetting = true;
Expand Down Expand Up @@ -374,14 +374,15 @@ public void SetReset(Authentication authentication, DomainMetaData[] metaDatas)
var result = this.service.GetMetaData();
this.typeContext = new TypeContext(this, result.Value);
this.tableContext = new TableContext(this, result.Value);
base.ResetDataBase(authentication);
this.AttachDomainHost();
base.UpdateLockParent();
base.UpdateAccessParent();
this.AttachDomainHost();
}

this.isResetting = false;
base.ResetDataBase(authentication);
this.DataBases.InvokeItemsResetEvent(authentication, new IDataBase[] { this, });
System.Diagnostics.Trace.WriteLine("Reset");
}

public void SetAuthenticationEntered(Authentication authentication)
Expand Down Expand Up @@ -820,7 +821,6 @@ private void AttachDomainHost()
{
var target = this.FindDomainHost(item);
target.Restore(item);
item.LoadID = this.loadID;
item.Host = target;
item.AttachUser();
}
Expand All @@ -834,12 +834,11 @@ private void AttachDomainHost()
private void DetachDomainHost()
{
var domainContext = this.CremaHost.DomainContext;
var domains = domainContext.Domains.Where<Domain>(item => item.DataBaseID == this.ID && item.LoadID == this.loadID).ToArray();
var domains = domainContext.Domains.Where<Domain>(item => item.DataBaseID == this.ID).ToArray();

foreach (var item in domains)
{
item.Host?.Detach();
item.LoadID = Guid.Empty;
item.Host = null;
item.DetachUser();
}
Expand Down Expand Up @@ -950,7 +949,6 @@ private void OnEnter(Authentication authentication)
});
this.typeContext = new TypeContext(this, metaData);
this.tableContext = new TableContext(this, metaData);
this.loadID = Guid.NewGuid();
this.AttachDomainHost();
this.cremaHost.AddService(this);
base.UpdateAccessParent();
Expand Down
17 changes: 16 additions & 1 deletion client/Ntreev.Crema.Services/Data/DataBaseTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using Ntreev.Crema.ServiceModel;
using Ntreev.Crema.Services.DataBaseCollectionService;
using Ntreev.Crema.Services.Domains;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -55,10 +56,24 @@ public void Rollback(Authentication authentication)
throw new InvalidOperationException();
var result = this.service.CancelTransaction(this.dataBase.Name);
this.Sign(authentication, result);
//this.dataBase.SetReset(authentication);
this.RollbackDomains(authentication);
this.OnDisposed(EventArgs.Empty);
}

private void RollbackDomains(Authentication authentication)
{
if (this.dataBase.GetService(typeof(DomainContext)) is DomainContext domainContext)
{
this.dataBase.SetResetting(authentication);
var metaDatas = domainContext.Restore(this.dataBase);
this.dataBase.SetReset(authentication, metaDatas);
}
else
{
throw new NotImplementedException();
}
}

public void Dispose()
{
this.authentication = null;
Expand Down
2 changes: 0 additions & 2 deletions client/Ntreev.Crema.Services/Domains/Domain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,6 @@ private IDomainService Service
get { return this.Context.Service; }
}

internal Guid LoadID { get; set; }

#region IDomain

IDomainUserCollection IDomain.Users
Expand Down
1 change: 1 addition & 0 deletions client/Ntreev.Crema.Services/Domains/DomainCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public Domain Create(Authentication authentication, DomainMetaData metaData)
{
domain = new TypeDomain(metaData.DomainInfo, this.Context.CremaHost.Dispatcher);
}

this.Add(domain);
domain.Category = this.Context.Categories.Prepare(metaData.DomainInfo.CategoryPath);
domain.Initialize(authentication, metaData);
Expand Down
21 changes: 21 additions & 0 deletions client/Ntreev.Crema.Services/Domains/DomainContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ public DomainContext(CremaHost cremaHost, string address, ServiceInfo serviceInf
this.cremaHost.AddService(this);
}

public DomainMetaData[] Restore(DataBase dataBase)
{
var result = this.service.GetMetaData();
result.Validate();
var metaData = result.Value;

var metaDataList = new List<DomainMetaData>();
foreach (var item in metaData.Domains)
{
if (item.DomainInfo.DataBaseID == dataBase.ID)
{
metaDataList.Add(item);
}
}
return metaDataList.ToArray();
}

public void InvokeItemsCreatedEvent(Authentication authentication, IDomainItem[] items, object[] args)
{
this.OnItemsCreated(new ItemsCreatedEventArgs<IDomainItem>(authentication, items, args));
Expand Down Expand Up @@ -122,8 +139,10 @@ public Domain AddDomain(Authentication authentication, DomainInfo domainInfo)

public void AddDomains(DomainMetaData[] metaDatas)
{
System.Diagnostics.Trace.WriteLine(metaDatas.Length);
foreach (var item in metaDatas)
{
System.Diagnostics.Trace.WriteLine(item.DomainID);
var domain = this.Domains.AddDomain(null, item.DomainInfo);
if (domain == null)
continue;
Expand Down Expand Up @@ -487,6 +506,8 @@ void IDomainServiceCallback.OnDomainStateChanged(SignatureDate signatureDate, Gu
this.InvokeAsync(() =>
{
var domain = this.Domains[domainID];
if (domain == null)
return;
var authentication = this.userContext.Authenticate(signatureDate);
domain.InvokeDomainStateChanged(authentication, domainState);
}, nameof(IDomainServiceCallback.OnDomainStateChanged));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ internal interface IDomainService {
[System.ServiceModel.OperationContractAttribute(Action="http://www.ntreev.com/IDomainService/Unsubscribe", ReplyAction="http://www.ntreev.com/IDomainService/UnsubscribeResponse")]
Ntreev.Crema.ServiceModel.ResultBase Unsubscribe();

[System.ServiceModel.OperationContractAttribute(Action="http://www.ntreev.com/IDomainService/GetMetaData", ReplyAction="http://www.ntreev.com/IDomainService/GetMetaDataResponse")]
Ntreev.Crema.ServiceModel.ResultBase<Ntreev.Crema.ServiceModel.DomainContextMetaData> GetMetaData();

[System.ServiceModel.OperationContractAttribute(Action="http://www.ntreev.com/IDomainService/SetUserLocation", ReplyAction="http://www.ntreev.com/IDomainService/SetUserLocationResponse")]
Ntreev.Crema.ServiceModel.ResultBase SetUserLocation(System.Guid domainID, Ntreev.Crema.ServiceModel.DomainLocationInfo location);

Expand Down Expand Up @@ -161,6 +164,10 @@ public Ntreev.Crema.ServiceModel.ResultBase Unsubscribe() {
return base.Channel.Unsubscribe();
}

public Ntreev.Crema.ServiceModel.ResultBase<Ntreev.Crema.ServiceModel.DomainContextMetaData> GetMetaData() {
return base.Channel.GetMetaData();
}

public Ntreev.Crema.ServiceModel.ResultBase SetUserLocation(System.Guid domainID, Ntreev.Crema.ServiceModel.DomainLocationInfo location) {
return base.Channel.SetUserLocation(domainID, location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetMetaData">
<soap12:operation soapAction="http://www.ntreev.com/IDomainService/GetMetaData" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SetUserLocation">
<soap12:operation soapAction="http://www.ntreev.com/IDomainService/SetUserLocation" style="document" />
<wsdl:input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<wsdl:message name="IDomainService_Unsubscribe_OutputMessage">
<wsdl:part name="parameters" element="tns:UnsubscribeResponse" />
</wsdl:message>
<wsdl:message name="IDomainService_GetMetaData_InputMessage">
<wsdl:part name="parameters" element="tns:GetMetaData" />
</wsdl:message>
<wsdl:message name="IDomainService_GetMetaData_OutputMessage">
<wsdl:part name="parameters" element="tns:GetMetaDataResponse" />
</wsdl:message>
<wsdl:message name="IDomainService_SetUserLocation_InputMessage">
<wsdl:part name="parameters" element="tns:SetUserLocation" />
</wsdl:message>
Expand Down Expand Up @@ -131,6 +137,10 @@
<wsdl:input wsaw:Action="http://www.ntreev.com/IDomainService/Unsubscribe" message="tns:IDomainService_Unsubscribe_InputMessage" />
<wsdl:output wsaw:Action="http://www.ntreev.com/IDomainService/UnsubscribeResponse" message="tns:IDomainService_Unsubscribe_OutputMessage" />
</wsdl:operation>
<wsdl:operation msc:isInitiating="true" msc:isTerminating="false" name="GetMetaData">
<wsdl:input wsaw:Action="http://www.ntreev.com/IDomainService/GetMetaData" message="tns:IDomainService_GetMetaData_InputMessage" />
<wsdl:output wsaw:Action="http://www.ntreev.com/IDomainService/GetMetaDataResponse" message="tns:IDomainService_GetMetaData_OutputMessage" />
</wsdl:operation>
<wsdl:operation msc:isInitiating="true" msc:isTerminating="false" name="SetUserLocation">
<wsdl:input wsaw:Action="http://www.ntreev.com/IDomainService/SetUserLocation" message="tns:IDomainService_SetUserLocation_InputMessage" />
<wsdl:output wsaw:Action="http://www.ntreev.com/IDomainService/SetUserLocationResponse" message="tns:IDomainService_SetUserLocation_OutputMessage" />
Expand Down
Loading

0 comments on commit 3f0be99

Please sign in to comment.