Example #1
0
        public Watcher()
        {
            Manager         = new OptionsManager(true);
            Options         = Manager.GetOptions <WatcherOptions>(Options);
            SourceDirectory = Options.SourceDirectory;
            TargetDirectory = Options.TargetDirectory;
            IsLoggerEnable  = Options.IsLoggerEnable;
            enabled         = true;
            logger          = new Logger();
            Cryptor         = new Cryptor();
            Archive         = new Archive();
            watchers        = new List <FileSystemWatcher>
            {
                new FileSystemWatcher(SourceDirectory),
                new FileSystemWatcher(TargetDirectory)
            };

            watchers[0].Deleted += ChangeWatcher_Deleted;
            watchers[1].Deleted += ChangeWatcher_Deleted;
            watchers[0].Created += ChangeWatcher_Created;
            watchers[1].Created += ChangeWatcher_Created;

            //watchers[0].Changed += ChangeWatcher_Changed;
            //watchers[1].Changed += ChangeWatcher_Changed;
            watchers[0].Renamed += ChangeWatcher_Renamed;
            watchers[1].Renamed += ChangeWatcher_Renamed;
        }
Example #2
0
        public OptionsManager(bool isJson = true)
        {
            IsJson     = isJson;
            JsonReader = new JsonParser();
            JsonReader.Parse(JsonPath);
            ArchiveOptions ArchiveSet = new ArchiveOptions()
            {
                IsCompressEnable = string.Format(JsonReader.GetJsonElement("IsCompressEnable")).Contains("true"),
                CompressionLevel = (System.IO.Compression.CompressionLevel)Int32.Parse(JsonReader.GetJsonElement("CompressionLevel")),
                SourceDirectory  = JsonReader.GetJsonElement("SourceDirectory"),
                TargetDirectory  = JsonReader.GetJsonElement("TargetDirectory"),
                IsLoggerEnable   = bool.Parse(JsonReader.GetJsonElement("IsLoggerEnable"))
            };
            CryptingOptions CryptorSet = new CryptingOptions()
            {
                IsEncryptEnable = bool.Parse(JsonReader.GetJsonElement("IsEncryptEnable")),
                SourceDirectory = JsonReader.GetJsonElement("SourceDirectory"),
                TargetDirectory = JsonReader.GetJsonElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(JsonReader.GetJsonElement("IsLoggerEnable"))
            };
            LoggerOptions LoggerSet = new LoggerOptions()
            {
                LogFile         = JsonReader.GetJsonElement("LogFile"),
                SourceDirectory = JsonReader.GetJsonElement("SourceDirectory"),
                TargetDirectory = JsonReader.GetJsonElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(JsonReader.GetJsonElement("IsLoggerEnable"))
            };
            WatcherOptions WatcherSet = new WatcherOptions()
            {
                SourceDirectory = JsonReader.GetJsonElement("SourceDirectory"),
                TargetDirectory = JsonReader.GetJsonElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(JsonReader.GetJsonElement("IsLoggerEnable"))
            };
            Options DefaultOptionsSet = new Options()
            {
                SourceDirectory = JsonReader.GetJsonElement("SourceDirectory"),
                TargetDirectory = JsonReader.GetJsonElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(JsonReader.GetJsonElement("IsLoggerEnable"))
            };

            EtlJsonOptions = new EtlJsonOptions(ArchiveSet, CryptorSet, LoggerSet, WatcherSet, DefaultOptionsSet);

            XmlReader = new XmlParser();
            XmlReader.Parse(XmlPath);
            ArchiveOptions ArchiveSetXml = new ArchiveOptions()
            {
                IsCompressEnable = string.Format(XmlReader.GetXmlElement("IsCompressEnable")).Contains("true"),
                CompressionLevel = (System.IO.Compression.CompressionLevel)Int32.Parse(XmlReader.GetXmlElement("CompressionLevel")),
                SourceDirectory  = XmlReader.GetXmlElement("SourceDirectory"),
                TargetDirectory  = XmlReader.GetXmlElement("TargetDirectory"),
                IsLoggerEnable   = bool.Parse(XmlReader.GetXmlElement("IsLoggerEnable"))
            };
            CryptingOptions CryptorSetXml = new CryptingOptions()
            {
                IsEncryptEnable = bool.Parse(XmlReader.GetXmlElement("IsEncryptEnable")),
                SourceDirectory = XmlReader.GetXmlElement("SourceDirectory"),
                TargetDirectory = XmlReader.GetXmlElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(XmlReader.GetXmlElement("IsLoggerEnable"))
            };
            LoggerOptions LoggerSetXml = new LoggerOptions()
            {
                LogFile         = JsonReader.GetJsonElement("LogFile"),
                SourceDirectory = XmlReader.GetXmlElement("SourceDirectory"),
                TargetDirectory = XmlReader.GetXmlElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(XmlReader.GetXmlElement("IsLoggerEnable"))
            };
            WatcherOptions WatcherSetXml = new WatcherOptions()
            {
                SourceDirectory = XmlReader.GetXmlElement("SourceDirectory"),
                TargetDirectory = XmlReader.GetXmlElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(XmlReader.GetXmlElement("IsLoggerEnable"))
            };
            Options DefaultOptionsSetXml = new Options()
            {
                SourceDirectory = XmlReader.GetXmlElement("SourceDirectory"),
                TargetDirectory = XmlReader.GetXmlElement("TargetDirectory"),
                IsLoggerEnable  = bool.Parse(XmlReader.GetXmlElement("IsLoggerEnable"))
            };

            EtlXmlOptions = new EtlXmlOptions(ArchiveSetXml, CryptorSetXml, LoggerSetXml, WatcherSetXml, DefaultOptionsSetXml);
        }
Example #3
0
 public WatcherOptions GetOptions <Type>(WatcherOptions o)
 => IsJson ? EtlJsonOptions.WatcherOptions : EtlXmlOptions.WatcherOptions;