Example #1
0
        /// <summary>
        ///     Restores the given snapshot back to the application
        /// </summary>
        /// <param name="snapshot">Deserialzable object created by Backup()</param>
        /// <param name="form">If given, its visual representation will also be restored</param>
        public static void Restore(SettingsSnapshot snapshot, Form form = null)
        {
            Singleton <SyncthingInstanceManager> .Instance.Clear();

            foreach (var definition in snapshot.Instances)
            {
                try
                {
                    var instance = new ManagedInstance
                    {
                        Id         = definition.Id,
                        CustomName = definition.Name,
                        UseHttps   = definition.UseHttps,
                        ApiKey     = definition.ApiKey
                    };

                    foreach (var storedEndpoint in definition.Endpoints)
                    {
                        instance.PossibleEndpoints.Add(new RestEndpoint
                        {
                            Hostname   = storedEndpoint.Hostname,
                            Port       = storedEndpoint.Port,
                            Priority   = storedEndpoint.Priority,
                            IsPingable = true
                        });
                    }

                    Singleton <SyncthingInstanceManager> .Instance.Add(instance);
                }
                catch (InvalidOperationException)
                {
                    // Ignore instances without an endpoint
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Captures and returns the current settings
        /// </summary>
        /// <param name="form">If given, its visual representation is also be captured and returned</param>
        /// <returns>Current settings in a serializable object</returns>
        public static SettingsSnapshot Backup(Form form = null)
        {
            var snapshot = new SettingsSnapshot();

            // Instance settings
            foreach (var instance in Singleton <SyncthingInstanceManager> .Instance)
            {
                // Convert instance
                snapshot.Instances.Add(new SettingsSnapshot.Instance
                {
                    Id        = instance.Id,
                    Name      = instance.CustomName,
                    UseHttps  = instance.UseHttps,
                    ApiKey    = instance.ApiKey,
                    Endpoints =
                        instance.PossibleEndpoints.Select(endpoint => new SettingsSnapshot.InstanceEndpoint(endpoint))
                        .ToList()
                });
            }

            return(snapshot);
        }
Example #3
0
        /// <summary>
        ///     Captures and returns the current settings
        /// </summary>
        /// <param name="form">If given, its visual representation is also be captured and returned</param>
        /// <returns>Current settings in a serializable object</returns>
        public static SettingsSnapshot Backup(Form form = null)
        {
            var snapshot = new SettingsSnapshot();

            // Instance settings
            foreach (var instance in Singleton<SyncthingInstanceManager>.Instance)
            {
                // Convert instance
                snapshot.Instances.Add(new SettingsSnapshot.Instance
                {
                    Id = instance.Id,
                    Name = instance.CustomName,
                    UseHttps = instance.UseHttps,
                    ApiKey = instance.ApiKey,
                    Endpoints =
                        instance.PossibleEndpoints.Select(endpoint => new SettingsSnapshot.InstanceEndpoint(endpoint))
                            .ToList()
                });
            }

            return snapshot;
        }
Example #4
0
        /// <summary>
        ///     Restores the given snapshot back to the application
        /// </summary>
        /// <param name="snapshot">Deserialzable object created by Backup()</param>
        /// <param name="form">If given, its visual representation will also be restored</param>
        public static void Restore(SettingsSnapshot snapshot, Form form = null)
        {
            Singleton<SyncthingInstanceManager>.Instance.Clear();

            foreach (var definition in snapshot.Instances)
            {
                try
                {
                    var instance = new ManagedInstance
                    {
                        Id = definition.Id,
                        CustomName = definition.Name,
                        UseHttps = definition.UseHttps,
                        ApiKey = definition.ApiKey
                    };

                    foreach (var storedEndpoint in definition.Endpoints)
                    {
                        instance.PossibleEndpoints.Add(new RestEndpoint
                        {
                            Hostname = storedEndpoint.Hostname,
                            Port = storedEndpoint.Port,
                            Priority = storedEndpoint.Priority,
                            IsPingable = true
                        });
                    }

                    Singleton<SyncthingInstanceManager>.Instance.Add(instance);
                }
                catch (InvalidOperationException)
                {
                    // Ignore instances without an endpoint
                }
            }
        }