/// <summary> /// Установить объект для репликации /// </summary> public Boolean SetObject(IReplicationObject replicationObject) { var result = true; try { replicationObject.PropertyChanged += PropertyChangedHandler; _replicationObjects.Add(replicationObject); _channel.SetObject(GetReplicationInfo(replicationObject), OperationType.Create); } catch (Exception) { replicationObject.PropertyChanged -= PropertyChangedHandler; _replicationObjects.Remove(replicationObject); result = false; } return(result); }
/// <summary> /// Клиент для репликации объектов /// </summary> public ReplicationClient() { var settings = ReplicationSettingsReader.ReadSettings(); String serviceAddress = String.IsNullOrEmpty(settings.ServiceAddress)? DefaultserviceAddress: settings.ServiceAddress; var pipeChannelFactory = new DuplexChannelFactory <IReplicationService>(new InstanceContext(this), new NetNamedPipeBinding(), new EndpointAddress(serviceAddress)); _channel = pipeChannelFactory.CreateChannel(); _replicationObjects = new List <IReplicationObject>(); PropertyChangedHandler += async(sender, args) => { var replicationInfo = GetReplicationInfo(sender, UidKey, args.PropertyName); try { await Task.Factory.StartNew(() => _channel.SetObject(replicationInfo, OperationType.Update)); } catch (Exception) { } }; }