void IDomainServiceCallback.OnServiceClosed(SignatureDate signatureDate, CloseInfo closeInfo) { this.service.Abort(); this.service = null; this.timer?.Dispose(); this.timer = null; this.serviceDispatcher.Dispose(); this.serviceDispatcher = null; this.InvokeAsync(() => { this.cremaHost.RemoveService(this); }, nameof(IDomainServiceCallback.OnServiceClosed)); }
private void Service_Faulted(object sender, EventArgs e) { this.serviceDispatcher.Invoke(() => { try { this.service.Abort(); this.service = null; } catch { } this.timer?.Dispose(); this.timer = null; this.serviceDispatcher.Dispose(); this.serviceDispatcher = null; }); this.InvokeAsync(() => { this.cremaHost.RemoveService(this); }, nameof(Service_Faulted)); }
public DomainContext(CremaHost cremaHost, string address, ServiceInfo serviceInfo) { this.cremaHost = cremaHost; this.userContext = cremaHost.UserContext; this.serviceDispatcher = new CremaDispatcher(this); var metaData = this.serviceDispatcher.Invoke(() => { var binding = CremaHost.CreateBinding(serviceInfo); var endPointAddress = new EndpointAddress($"net.tcp://{address}:{serviceInfo.Port}/DomainService"); var instanceContext = new InstanceContext(this); if (Environment.OSVersion.Platform != PlatformID.Unix) { instanceContext.SynchronizationContext = System.Threading.SynchronizationContext.Current; } this.service = new DomainServiceClient(instanceContext, binding, endPointAddress); this.service.Open(); if (this.service is ICommunicationObject service) { service.Faulted += Service_Faulted; } var result = this.service.Subscribe(this.cremaHost.AuthenticationToken); result.Validate(); #if !DEBUG this.timer = new Timer(30000); this.timer.Elapsed += Timer_Elapsed; this.timer.Start(); #endif return(result.Value); }); this.Initialize(metaData); this.cremaHost.DataBases.ItemsCreated += DataBases_ItemsCreated; this.cremaHost.DataBases.ItemsRenamed += DataBases_ItemsRenamed; this.cremaHost.DataBases.ItemsDeleted += DataBases_ItemDeleted; this.cremaHost.AddService(this); }
public void Close(CloseInfo closeInfo) { this.serviceDispatcher?.Invoke(() => { this.timer?.Dispose(); this.timer = null; if (this.service != null) { try { if (closeInfo.Reason != CloseReason.NoResponding) { this.service.Unsubscribe(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { this.service.Close(); } else { this.service.Abort(); } } else { this.service.Abort(); } } catch { this.service.Abort(); } this.service = null; } this.serviceDispatcher.Dispose(); this.serviceDispatcher = null; }); }