コード例 #1
0
        private void EncryptFiles(DiscDataStore store, string domain, IEnumerable <string> files, string logParent, ILog log)
        {
            foreach (var file in files)
            {
                var logItem = string.Format("{0}, File: {1}", logParent, file);

                log.Debug(logItem);

                try
                {
                    if (IsEncryption)
                    {
                        store.Encrypt(domain, file);
                    }
                    else
                    {
                        store.Decrypt(domain, file);
                    }

                    WriteProgress(store, file, UseProgressFile);
                }
                catch (Exception e)
                {
                    HasErrors = true;
                    log.Error(logItem + " " + e.Message, e);

                    // ERROR_DISK_FULL: There is not enough space on the disk.
                    // if (e is IOException && e.HResult == unchecked((int)0x80070070)) break;
                }
            }
        }
コード例 #2
0
        private List <string> ReadProgress(DiscDataStore store)
        {
            var encryptedFiles = new List <string>();

            if (!UseProgressFile)
            {
                return(encryptedFiles);
            }

            if (store.IsFile(string.Empty, ProgressFileName))
            {
                using var stream = store.GetReadStream(string.Empty, ProgressFileName);
                using var reader = new StreamReader(stream);
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    encryptedFiles.Add(line);
                }
            }
            else
            {
                store.GetWriteStream(string.Empty, ProgressFileName).Close();
            }

            return(encryptedFiles);
        }
コード例 #3
0
        private void WriteProgress(DiscDataStore store, string file, bool useProgressFile)
        {
            if (!useProgressFile)
            {
                return;
            }

            using var stream = store.GetWriteStream(string.Empty, ProgressFileName, FileMode.Append);
            using var writer = new StreamWriter(stream);
            writer.WriteLine(file);
        }
コード例 #4
0
        private void EncryptStore(Tenant tenant, string module, DiscDataStore store, StorageFactoryConfig storageFactoryConfig, ILog log)
        {
            var domains = storageFactoryConfig.GetDomainList(ConfigPath, module).ToList();

            domains.Add(string.Empty);

            var progress = ReadProgress(store);

            foreach (var domain in domains)
            {
                var logParent = string.Format("Tenant: {0}, Module: {1}, Domain: {2}", tenant.TenantAlias, module, domain);

                var files = GetFiles(domains, progress, store, domain);

                EncryptFiles(store, domain, files, logParent, log);
            }

            StepDone();

            log.DebugFormat("Percentage: {0}", Percentage);
        }
コード例 #5
0
        private IEnumerable <string> GetFiles(List <string> domains, List <string> progress, DiscDataStore targetStore, string targetDomain)
        {
            IEnumerable <string> files = targetStore.ListFilesRelative(targetDomain, "\\", "*.*", true);

            if (progress.Any())
            {
                files = files.Where(path => !progress.Contains(path));
            }

            if (!string.IsNullOrEmpty(targetDomain))
            {
                return(files);
            }

            var notEmptyDomains = domains.Where(domain => !string.IsNullOrEmpty(domain));

            if (notEmptyDomains.Any())
            {
                files = files.Where(path => notEmptyDomains.All(domain => !path.Contains(domain + Path.DirectorySeparatorChar)));
            }

            files = files.Where(path => !path.EndsWith(ProgressFileName));

            return(files);
        }