private void Registration_PropertyChanged(SyncRegistration sender, PropertyChangedEventArgs e) { // Get the actual registered object var source = sender.Instance; // Get the property from the sender var property = source.GetType().GetProperty(e.PropertyName); // Look for a strategy var strategy = property.GetCustomAttribute <PropertyStrategyAttribute>(true); // If strategy was found, execute it if (strategy != null) { // Create the message SyncMessage message = new SyncMessage() { SyncId = sender.Id }; // Ask the strategy to add the actions strategy.AddActions(message, source, property); // TODO: Send the message } }
static void Main() { var platformInfo = CloudFilter.GetPlatformInfo(); var registration = new SyncRegistration(); var policies = new SyncPolicies(); var registerFlags = RegisterFlags.None; CloudFilter.RegisterSyncRoot(@"C:\Users\JDani\SyncRoot", registration, policies, registerFlags); }
/// <summary> /// Starts synchronization of the object. /// </summary> /// <param name="instance"> /// The instance of the object to synchronize. /// </param> /// <param name="id"> /// The unique ID of the instance. /// </param> /// <param name="isHost"> /// <c>true</c> if the instance should act as the host instance; otherwise <c>false</c>. /// </param> /// <remarks> /// <para> /// If <paramref name="isHost"/> is <c>true</c>, <see cref="SynchronizationManager"/> will /// automatically send a <c>FullState</c> message with the current state of the object /// provided at least one other client is currently connected. In addition, this instance /// will be used to respond to <c>GetFullState</c> messages in the future. /// </para> /// <para> /// If<paramref name="isHost"/> is <c>false</c>, <see cref = "SynchronizationManager" /> will /// automatically send a <c>GetFullState</c> message provided at least one other client is /// currently connected. /// </para> /// </remarks> public void StartSync(INotifyPropertyChanged instance, string id, bool isHost = false) { // Validate if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (string.IsNullOrEmpty(id)) { throw new ArgumentException(nameof(id)); } // Thread safe lock (registrations) { // Look for an existing registration if (registrations.ContainsKey(id)) { throw new InvalidOperationException($"The ID '{id}' is already registered."); } // Create Registration var reg = new SyncRegistration() { Id = id, Instance = instance, IsHost = isHost }; // Register registrations[id] = reg; // Setup property changed to registration changed delegate reg.PropertyChanged = (o, e) => Registration_PropertyChanged(reg, e); // Subscribe to changes instance.PropertyChanged += reg.PropertyChanged; } if (isHost) { // TODO: Send full state } }