Ejemplo n.º 1
0
        private static void PrepareSaveFile(FileAppearanceSettingsClient fileConfig)
        {
            var dir = new DirectoryInfo(fileConfig.Root);

            if (!dir.Exists)
            {
                try
                {
                    dir.Create();
                }
                catch (Exception ex)
                {
                    throw new DeveloperException("Не удалось создать папку для сохранения настроек.", ex);
                }
            }

            if (!string.IsNullOrEmpty(fileConfig.CurrentFullFileName))
            {
                var fi = new FileInfo(fileConfig.CurrentFullFileName);
                if (fi.Exists)
                {
                    fi.Delete();
                }
            }

            if (!string.IsNullOrEmpty(fileConfig.GetFullFileNameClient()))
            {
                var fi = new FileInfo(fileConfig.GetFullFileNameClient());
                if (fi.Exists)
                {
                    fi.Delete();
                }
            }
        }
Ejemplo n.º 2
0
        private static void Clear(FileAppearanceSettingsClient fileNames, IDictionary <string, FileAppearanceSettingsDb> filesDb)
        {
            //Сначала удаляем текущий файл
            if (!string.IsNullOrEmpty(fileNames.CurrentFullFileName))
            {
                var filenameClient = fileNames.CurrentFullFileName;
                if (LayoutInfo.ContainsKey(filenameClient))
                {
                    LayoutInfo.Remove(filenameClient);
                }
                var fi = new FileInfo(filenameClient);
                if (fi.Exists)
                {
                    fi.Delete();
                }
            }

            //Затем, если настройки есть в БД, восстанавливаем их
            if (filesDb != null)
            {
                byte[] filedb;
                var    filenameBd = fileNames.GetFileNameBd();
                if (filesDb.ContainsKey(filenameBd) && (filedb = filesDb[filenameBd].Text) != null)
                {
                    fileNames.Version = filesDb[filenameBd].Version;
                    fileNames.SetCurrentFileName();
                    File.WriteAllBytes(fileNames.CurrentFullFileName, filedb);
                }
            }
        }