Пример #1
0
        private static void Load([NotNull] string folder)
        {
            Debug.ArgumentNotNull(folder, nameof(folder));

            foreach (var fileName in AppHost.Files.GetFiles(folder, "*.xml"))
            {
                XDocument doc;
                try
                {
                    doc = XDocument.Load(fileName);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.Message);
                    continue;
                }

                var root = doc.Root;
                if (root == null)
                {
                    continue;
                }

                var customValidation = new CustomValidation();
                customValidation.Load(root);
                customValidation.FileName = Path.GetFileName(fileName);

                validations.Add(customValidation);
            }

            foreach (var subfolder in AppHost.Files.GetDirectories(folder))
            {
                Load(subfolder);
            }
        }
Пример #2
0
        public static void Add([NotNull] CustomValidation customValidation)
        {
            Assert.ArgumentNotNull(customValidation, nameof(customValidation));

            customValidation.FileName = Path.ChangeExtension(customValidation.Title.Replace("\\W", string.Empty), ".xml");

            Save(customValidation);

            validations.Add(customValidation);
        }
Пример #3
0
        public static void Delete([NotNull] CustomValidation customValidation)
        {
            Assert.ArgumentNotNull(customValidation, nameof(customValidation));

            var fileName = Path.Combine(GetFolder(), customValidation.FileName);

            File.Delete(fileName);

            validations.Remove(customValidation);
        }
Пример #4
0
        private static void Save([NotNull] CustomValidation customValidation)
        {
            Debug.ArgumentNotNull(customValidation, nameof(customValidation));

            var fileName = Path.Combine(GetFolder(), customValidation.FileName);

            using (var output = new XmlTextWriter(fileName, Encoding.UTF8))
            {
                output.Formatting  = Formatting.Indented;
                output.Indentation = 2;

                customValidation.Save(output);
            }
        }
Пример #5
0
        public static void Update([NotNull] CustomValidation customValidation)
        {
            Assert.ArgumentNotNull(customValidation, nameof(customValidation));

            Save(customValidation);
        }