Beispiel #1
0
        private void AddRepository(string folder_path)
        {
            SparkleRepoBase repo        = null;
            string          folder_name = Path.GetFileName(folder_path);
            string          backend     = this.config.GetBackendForFolder(folder_name);

            try {
                repo = (SparkleRepoBase)Activator.CreateInstance(
                    Type.GetType("SparkleLib." + backend + ".SparkleRepo, SparkleLib." + backend),
                    new object [] { folder_path, this.config }
                    );
            } catch (Exception e) {
                SparkleLogger.LogInfo("Controller",
                                      "Failed to load '" + backend + "' backend for '" + folder_name + "': " + e.Message);

                return;
            }

            repo.ChangesDetected += delegate {
                UpdateState();
            };

            repo.SyncStatusChanged += delegate(SyncStatus status) {
                if (status == SyncStatus.Idle)
                {
                    ProgressPercentage = 0.0;
                    ProgressSpeed      = "";
                }

                UpdateState();
            };

            repo.ProgressChanged += delegate(double percentage, string speed) {
                ProgressPercentage = percentage;
                ProgressSpeed      = speed;

                UpdateState();
            };

            repo.NewChangeSet += delegate(SparkleChangeSet change_set) {
                if (NotificationsEnabled)
                {
                    NotificationRaised(change_set);
                }
            };

            repo.ConflictResolved += delegate {
                if (NotificationsEnabled)
                {
                    AlertNotificationRaised("Conflict detected",
                                            "Don't worry, SparkleShare made a copy of each conflicting file.");
                }
            };

            this.repositories.Add(repo);
            repo.Initialize();
        }
Beispiel #2
0
        private void AddRepository(string folder_path)
        {
            SparkleRepoBase repo        = null;
            string          folder_name = Path.GetFileName(folder_path);
            string          backend     = Config.GetBackendForFolder(folder_name);

            try {
                repo = (SparkleRepoBase)Activator.CreateInstance(
                    Type.GetType("SparkleLib." + backend + ".SparkleRepo, SparkleLib." + backend),
                    new object [] { folder_path, Config });
            } catch (Exception e) {
                SparkleLogger.LogInfo("Controller", "Failed to load backend '" + backend + "' for '" + folder_name + "': ", e);
                return;
            }

            repo.ChangesDetected += delegate {
                UpdateState();
            };

            repo.SyncStatusChanged += delegate(SyncStatus status) {
                if (status == SyncStatus.Idle)
                {
                    ProgressPercentage = 0.0;
                    ProgressSpeedUp    = 0.0;
                    ProgressSpeedDown  = 0.0;
                }

                UpdateState();
            };

            repo.ProgressChanged += delegate {
                ProgressPercentage = 0.0;
                ProgressSpeedUp    = 0.0;
                ProgressSpeedDown  = 0.0;

                double percentage = 0.0;
                int    repo_count = 0;

                foreach (SparkleRepoBase rep in Repositories)
                {
                    if (rep.ProgressPercentage > 0)
                    {
                        percentage += rep.ProgressPercentage;
                        repo_count++;
                    }

                    if (rep.Status == SyncStatus.SyncUp)
                    {
                        ProgressSpeedUp += rep.ProgressSpeed;
                    }

                    if (rep.Status == SyncStatus.SyncDown)
                    {
                        ProgressSpeedDown += rep.ProgressSpeed;
                    }
                }

                if (repo_count > 0)
                {
                    ProgressPercentage = percentage / repo_count;
                }

                UpdateState();
            };

            repo.NewChangeSet += delegate(SparkleChangeSet change_set) {
                if (AvatarsEnabled)
                {
                    change_set.User.AvatarFilePath = SparkleAvatars.GetAvatar(change_set.User.Email, 48, Config.FullPath);
                }

                NotificationRaised(change_set);
            };

            repo.ConflictResolved += delegate {
                AlertNotificationRaised("Resolved a file collision",
                                        "Local and server versions were kept.");
            };

            AddRepository(repo);
            repo.Initialize();
        }
Beispiel #3
0
        private void AddRepository(string folder_path)
        {
            SparkleRepoBase repo        = null;
            string          folder_name = Path.GetFileName(folder_path);
            string          backend     = this.config.GetBackendForFolder(folder_name);

            try {
                repo = (SparkleRepoBase)Activator.CreateInstance(
                    Type.GetType("SparkleLib." + backend + ".SparkleRepo, SparkleLib." + backend),
                    new object [] { folder_path, this.config });
            } catch (Exception e) {
                SparkleLogger.LogInfo("Controller", "Failed to load backend '" + backend + "' for '" + folder_name + "': ", e);
                return;
            }

            repo.ChangesDetected += delegate {
                UpdateState();
            };

            repo.SyncStatusChanged += delegate(SyncStatus status) {
                if (status == SyncStatus.Idle)
                {
                    ProgressPercentage = 0.0;
                    ProgressSpeedUp    = 0.0;
                    ProgressSpeedDown  = 0.0;
                }

                UpdateState();
            };

            repo.ProgressChanged += delegate {
                ProgressPercentage = 0.0;
                ProgressSpeedUp    = 0.0;
                ProgressSpeedDown  = 0.0;

                double percentage = 0.0;
                int    repo_count = 0;

                foreach (SparkleRepoBase rep in Repositories)
                {
                    if (rep.ProgressPercentage > 0)
                    {
                        percentage += rep.ProgressPercentage;
                        repo_count++;
                    }

                    if (rep.Status == SyncStatus.SyncUp)
                    {
                        ProgressSpeedUp += rep.ProgressSpeed;
                    }

                    if (rep.Status == SyncStatus.SyncDown)
                    {
                        ProgressSpeedDown += rep.ProgressSpeed;
                    }
                }

                if (repo_count > 0)
                {
                    ProgressPercentage = percentage / repo_count;
                }

                UpdateState();
            };

            repo.NewChangeSet += delegate(SparkleChangeSet change_set) {
                NotificationRaised(change_set);
            };

            repo.ConflictResolved += delegate {
                AlertNotificationRaised("Conflict happened", "Don't worry, we've made a copy of each conflicting file.");
            };

            this.repositories.Add(repo);
            repo.Initialize();
        }
Beispiel #4
0
        // Adds a repository to the list of repositories
        private void AddRepository(string folder_path)
        {
            SparkleRepoBase repo        = null;
            string          folder_name = Path.GetFileName(folder_path);
            string          backend     = SparkleConfig.DefaultConfig.GetBackendForFolder(folder_name);

            try {
                repo = (SparkleRepoBase)Activator.CreateInstance(
                    Type.GetType("SparkleLib." + backend + ".SparkleRepo, SparkleLib." + backend),
                    folder_path
                    );
            } catch {
                SparkleHelpers.DebugInfo("Controller",
                                         "Failed to load \"" + backend + "\" backend for \"" + folder_name + "\"");

                return;
            }


            repo.NewChangeSet += delegate(SparkleChangeSet change_set) {
                if (NotificationRaised != null)
                {
                    NotificationRaised(change_set);
                }
            };

            repo.ConflictResolved += delegate {
                if (AlertNotificationRaised != null)
                {
                    AlertNotificationRaised("Conflict detected",
                                            "Don't worry, SparkleShare made a copy of each conflicting file.");
                }
            };

            repo.SyncStatusChanged += delegate(SyncStatus status) {
                if (status == SyncStatus.Idle)
                {
                    ProgressPercentage = 0.0;
                    ProgressSpeed      = "";
                }

                if (status == SyncStatus.Idle ||
                    status == SyncStatus.SyncUp ||
                    status == SyncStatus.SyncDown ||
                    status == SyncStatus.Error)
                {
                    UpdateState();
                }
            };

            repo.ProgressChanged += delegate(double percentage, string speed) {
                ProgressPercentage = percentage;
                ProgressSpeed      = speed;

                UpdateState();
            };

            repo.ChangesDetected += delegate {
                UpdateState();
            };

            this.repositories.Add(repo);
            repo.Initialize();
        }