Ejemplo n.º 1
0
 public void SetCredentials(string serviceId, IBackupSettings serviceSettings)
 {
     BACKUP_SETTINGS_SERVICE.Set(serviceId, serviceSettings);
     m_serviceSettings = serviceSettings;
     m_service.SetCredentials(serviceSettings);
     UpdateUI();
 }
Ejemplo n.º 2
0
        private static string GetBackupFilePattern(FileInfo file, IBackupSettings setting)
        {
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.FullName);
            var pattern = $"{fileNameWithoutExtension}*{setting.Extension}";

            return(pattern);
        }
Ejemplo n.º 3
0
        private BackupFile(FileInfo file, IBackupSettings setting)
        {
            Ensure.Exists(file);
            Ensure.NotNull(setting, nameof(setting));

            this.File      = file;
            this.TimeStamp = file.GetTimeStamp(setting);
        }
Ejemplo n.º 4
0
        internal static FileInfo GetRestoreFileFor(FileInfo file, IBackupSettings setting)
        {
            var allBackups = GetAllBackupsFor(file, setting);

            if (!allBackups.Any())
            {
                return(null);
            }
            return(allBackups.MaxBy(x => x.TimeStamp).File);
        }
Ejemplo n.º 5
0
        internal static IList <BackupFile> GetAllBackupsFor(FileInfo file, IBackupSettings setting)
        {
            var pattern = GetBackupFilePattern(file, setting);
            var backups = Directory.EnumerateFiles(setting.Directory, pattern)
                          .Select(x => new BackupFile(new FileInfo(x), setting))
                          .OrderBy(x => x.TimeStamp)
                          .ToList();

            return(backups);
        }
Ejemplo n.º 6
0
        internal static string TimeStampPattern(this IBackupSettings setting)
        {
            if (setting == null || string.IsNullOrEmpty(setting.TimeStampFormat))
            {
                return("");
            }
            var format  = setting.TimeStampFormat;
            var pattern = TimeStampPatternMap.GetOrAdd(format, CreateTimeStampPattern);

            return(pattern);
        }
Ejemplo n.º 7
0
        internal static FileInfo CreateFor(FileInfo file, IBackupSettings setting)
        {
            var backup = file.WithNewExtension(setting.Extension)
                         .InDirectory(setting.DirectoryPath.CreateDirectoryInfo());

            if (string.IsNullOrEmpty(setting.TimeStampFormat))
            {
                return(backup);
            }
            return(backup.WithTimeStamp(DateTime.Now, setting));
        }
Ejemplo n.º 8
0
        internal static FileInfo WithRemovedTimeStamp(this FileInfo file, IBackupSettings setting)
        {
            if (setting.TimeStampFormat is null)
            {
                return(file);
            }

            var pattern  = setting.TimeStampPattern();
            var stripped = Regex.Replace(file.FullName, pattern, string.Empty, RegexOptions.RightToLeft | RegexOptions.Singleline);

            return(new FileInfo(stripped));
        }
Ejemplo n.º 9
0
        internal static FileInfo WithTimeStamp(this FileInfo file, DateTime time, IBackupSettings setting)
        {
            if (string.IsNullOrWhiteSpace(setting.TimeStampFormat) && setting.NumberOfBackups <= 1)
            {
                return(file);
            }

            var timestamp   = $".{time.ToString(setting.TimeStampFormat, CultureInfo.InvariantCulture)}{file.Extension}";
            var timestamped = file.WithNewExtension(timestamp);

            return(timestamped);
        }
Ejemplo n.º 10
0
        internal static FileInfo WithRemovedTimeStamp(this FileInfo file, IBackupSettings setting)
        {
            Ensure.NotNull(file, nameof(file));
            Ensure.NotNull(setting, nameof(setting));
            if (setting.TimeStampFormat == null)
            {
                return(file);
            }
            var pattern  = setting.TimeStampPattern();
            var stripped = Regex.Replace(file.FullName, pattern, "", RegexOptions.RightToLeft | RegexOptions.Singleline);

            return(new FileInfo(stripped));
        }
Ejemplo n.º 11
0
        internal static FileInfo WithTimeStamp(this FileInfo file, DateTime time, IBackupSettings setting)
        {
            Ensure.NotNull(file, nameof(file));
            Ensure.NotNull(setting, nameof(setting));

            if (String.IsNullOrWhiteSpace(setting.TimeStampFormat) && setting.NumberOfBackups <= 1)
            {
                return(file);
            }
            var timestamp   = string.Format(".{0}{1}", time.ToString(setting.TimeStampFormat, CultureInfo.InvariantCulture), file.Extension);
            var timestamped = file.WithNewExtension(timestamp);

            return(timestamped);
        }
Ejemplo n.º 12
0
        public override bool SetCredentials(IBackupSettings credentials)
        {
            if (credentials is GitlabSettings settings)
            {
                Username   = settings.Username;
                PublicKey  = settings.PublicKey;
                PrivateKey = settings.PrivateKey;

                m_gitlabService = new GitlabAPIService(Username, PublicKey, PrivateKey);

                //InitWithCredentials(m_gitlabService.GetAllRepositories().Count);

                return(true);
            }
            return(false);
        }
Ejemplo n.º 13
0
        private BackupFile(FileInfo file, IBackupSettings setting)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (setting is null)
            {
                throw new ArgumentNullException(nameof(setting));
            }

            Ensure.Exists(file);

            this.File      = file;
            this.TimeStamp = file.GetTimeStamp(setting);
        }
Ejemplo n.º 14
0
        public void Set(string serviceId, IBackupSettings serviceSettings)
        {
            if (BackupSettings != null)
            {
                IBackupSettings existingSettings = BackupSettings.FirstOrDefault(x => x.ServiceId == serviceId);
                if (existingSettings != null)
                {
                    BackupSettings.Remove(existingSettings);
                }

                BackupSettings.Add(serviceSettings);
                SaveToFile();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 15
0
        public override bool SetCredentials(IBackupSettings credentials)
        {
            if (credentials is GithubSettings prefs)
            {
                Username = prefs.Username;
                Token    = prefs.PublicKey;

                m_githubApiService = new GithubAPIService(prefs.Username, prefs.PublicKey);

                var allRepos = m_githubApiService.GetAllRepositories();
                InitializeWithCredentials(allRepos != null ? allRepos.Count : 0);
                return(true);
            }
            else
            {
                LOGGER.Info($"Unable to set GitHub credentials");
                return(false);
            }
        }
Ejemplo n.º 16
0
        internal static DateTime GetTimeStamp(this FileInfo file, IBackupSettings setting)
        {
            Ensure.NotNull(file, nameof(file));
            Ensure.NotNull(setting, nameof(setting));
            if (setting.TimeStampFormat == null)
            {
                return(file.CreationTime);
            }
            var pattern      = setting.TimeStampPattern();
            var timeAsString = Regex.Match(file.FullName, pattern, RegexOptions.RightToLeft | RegexOptions.Singleline)
                               .Groups["timestamp"]
                               .Value;

            if (string.IsNullOrEmpty(timeAsString))
            {
                return(file.CreationTime);
            }
            var timeStamp = DateTime.ParseExact(timeAsString, setting.TimeStampFormat, CultureInfo.InvariantCulture);

            return(timeStamp);
        }
Ejemplo n.º 17
0
        public override bool SetCredentials(IBackupSettings credentials)
        {
            if (credentials is BitBucketSettings)
            {
                BitBucketSettings bbPrefs = credentials as BitBucketSettings;
                Username   = bbPrefs.Username;
                PublicKey  = bbPrefs.PublicKey;
                PrivateKey = bbPrefs.PrivateKey;

                m_bitbucketAPI = new BitbucketAPIService(Username, PublicKey, PrivateKey);
                int count = m_bitbucketAPI.IsAuthorized() ? m_bitbucketAPI.GetAllRepos(m_bitbucketAPI.Username).Count : 0;
                InitializeWithCredentials(count);
                return(true);
            }
            else
            {
                LOGGER.Info($"Not correct credentials type");
                IsAuthorized = CanBackup = false;
                return(false);
            }
        }
Ejemplo n.º 18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="BackupProjectDlg"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="helpTopicProvider">The help topic provider.</param>
        /// ------------------------------------------------------------------------------------
        public BackupProjectDlg(LcmCache cache,
                                IHelpTopicProvider helpTopicProvider) : this()
        {
            m_cache             = cache;
            m_helpTopicProvider = helpTopicProvider;

            m_presenter = new BackupProjectPresenter(this, m_cache);

            //It should only be displayed if the SupportingFiles folder has content.
            if (!m_presenter.SupportingFilesFolderContainsFiles)
            {
                m_supportingFiles.Enabled = false;
            }

            DestinationFolder = FwDirectoryFinder.DefaultBackupDirectory;
            if (File.Exists(m_presenter.PersistanceFilePath))
            {
                // If something bad happens when loading the previous dialog settings (probably just a
                // pre-7.0 version), just log the error and use the defaults.
                ExceptionHelper.LogAndIgnoreErrors(() =>
                {
                    //If the dialog settings file does exist then read it in and set the dialog to match
                    //the last values set.
                    using (FileStream fs = new FileStream(m_presenter.PersistanceFilePath, FileMode.Open))
                    {
                        IBackupSettings backupSettings = BackupFileSettings.CreateFromStream(fs);
                        // Per FWR-2748, we do NOT want to copy a previous comment into the dialog.
                        //Comment = backupSettings.Comment;
                        //Show SupportingFiles, unchecked by default
                        //SupportingFiles = backupSettings.IncludeSupportingFiles;
                        IncludeConfigurationSettings = backupSettings.IncludeConfigurationSettings;
                        IncludeLinkedFiles           = backupSettings.IncludeLinkedFiles;
                    }
                });
            }
        }
Ejemplo n.º 19
0
 protected Backuper(IBackupSettings setting)
 {
     Ensure.NotNull(setting, nameof(setting));
     this.Setting = setting;
     new DirectoryInfo(setting.Directory).CreateIfNotExists();
 }
Ejemplo n.º 20
0
 public bool SetCredentials(IBackupSettings credentials)
 {
     return(true);
 }
Ejemplo n.º 21
0
 public abstract bool SetCredentials(IBackupSettings credentials);
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Backuper"/> class.
 /// </summary>
 /// <param name="setting">The <see cref="IBackupSettings"/>.</param>
 protected Backuper(IBackupSettings setting)
 {
     this.Setting = setting ?? throw new ArgumentNullException(nameof(setting));
     new DirectoryInfo(setting.Directory).CreateIfNotExists();
 }
Ejemplo n.º 23
0
 protected Backuper(IBackupSettings setting)
 {
     Ensure.NotNull(setting, nameof(setting));
     Setting = setting;
     setting.DirectoryPath.CreateDirectoryInfo().CreateIfNotExists();
 }