// -i $/Designs -e Customers/customer1,test.txt -p .ipt,.iam,.txt -s all -w -d $/Designs/Customers/Block Customer/Blocks.iam -lf test.exe,test2.exe -fm source=$designs/test;target=E:\project,source=$designs/test2;target=E:\project2
        public static SynchronizationItem ReadString(string item)
        {
            SynchronizationItem syncItem = new SynchronizationItem();

            syncItem.TempFilesAndFinalPath = new List <Tuple <string, string> >();
            syncItem.TacTonPath            = FetchString(item, "-TacF|");
            syncItem.VaultPath             = FetchString(item, "-i|");

            if (String.IsNullOrWhiteSpace(syncItem.VaultPath))
            {
                syncItem.VaultPath = "$";
            }

            syncItem.Excludes = new List <string>();
            /*syncItem.Excludes*/ List <string> tempExcludes = FetchItems(item, "-e|");

            foreach (string tempExclude in tempExcludes)
            {
                syncItem.Excludes.Add(Regex.Replace(tempExclude, @"\t|\n|\r", ""));
            }

            syncItem.PatternsToSynchronize = FetchItems(item, "-p|").ToArray();
            syncItem.DownloadOnState       = FetchItems(item, "-s|");//FetchDownloadOnState(item);
            syncItem.InvalidStates         = FetchItems(item, "-is|").ToArray();
            syncItem.SkipFolders           = FetchItems(item, "-sf|").ToArray();
            syncItem.Writable       = FetchBool(item, "-w|");
            syncItem.Recursive      = FetchBool(item, "-r|");
            syncItem.Force          = FetchBool(item, "-f|");
            syncItem.DownloadToTemp = FetchBool(item, "-lck|");
            if (syncItem.DownloadToTemp)
            {
                syncItem.TempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString());
            }

            syncItem.Output = Environment.ExpandEnvironmentVariables(FetchString(item, "-o|"));
            if (!String.IsNullOrWhiteSpace(syncItem.Output) && !syncItem.Output.EndsWith("\\"))
            {
                syncItem.Output += "\\";
            }
            syncItem.RunPatterns = FetchItems(item, "-run|").ToArray();
            syncItem.Deletes     = AddVaultRootToStrings(FetchItems(item, "-d|").ToList(), syncItem.VaultPath).ToArray();
            // syncItem.LockedFiles = FetchItems(item, "-lf|").ToArray();
            syncItem.Mirrors        = AddVaultRootToStrings(FetchItemsWithRoot(item, "-m|", syncItem.VaultPath).ToList(), syncItem.VaultPath).ToArray();
            syncItem.FolderMappings = FetchFolderMappings(item, syncItem.VaultPath);
            syncItem.MirrorsToFiles = new List <Tuple <string, List <File> > > {
            };

            foreach (string mirror in syncItem.Mirrors)
            {
                syncItem.MirrorsToFiles.Add(new Tuple <string, List <File> >(mirror, new List <File>()));
            }

            syncItem.RecursiveMirrors = new List <string>();
            if (syncItem.Recursive)
            {
                syncItem.RecursiveMirrors.AddRange(syncItem.Mirrors);
            }

            syncItem.SearchPath    = syncItem.VaultPath;
            syncItem.ComponentName = Option.None;
            return(syncItem);
        }
        public static SynchronizerSettings Read(int networkRetries, Option <MCADCommon.LogCommon.DisposableFileLogger> logger, string configurationPath = "")
        {
            SynchronizerSettings configuration = new SynchronizerSettings();
            FileInfo             configurationFile;

            if (!String.IsNullOrWhiteSpace(configurationPath))
            {
                configurationFile = new FileInfo(configurationPath);
            }
            else
            {
                configurationFile = ConfigurationFile;
            }

            if (!configurationFile.Exists)
            {
                configurationFile = new FileInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), configurationPath));
            }

            if (configurationFile.Exists)
            {
                XmlDocument document = new XmlDocument();
                document.Load(configurationFile.FullName);

                configuration.configPath = Environment.ExpandEnvironmentVariables(MCAD.XmlCommon.XmlTools.ReadString(document.DocumentElement, "configuration_path"));

                try
                {
                    configuration.GetAndRun = MCAD.XmlCommon.XmlTools.ReadStringValues(document.DocumentElement, "run_files", "get_and_run");
                }
                catch
                {
                    configuration.GetAndRun = new List <string>();
                }
                configuration.VaultRoot = Environment.ExpandEnvironmentVariables(MCAD.XmlCommon.XmlTools.ReadString(document.DocumentElement, "vault_root"));
                List <SynchronizationItem> items = new List <SynchronizationItem>();
                foreach (string syncItem in MCAD.XmlCommon.XmlTools.ReadStringValues(document.DocumentElement, "synchronization_commands", "synchronization_command"))
                {
                    try
                    {
                        items.Add(SynchronizationItem.ReadString(syncItem));
                    }
                    catch (Exception ex) { logger.IfSomeDo(l => l.Error(ex.Message)); }
                }

                List <SynchronizationItem> RemoveItemsNotLegal = new List <SynchronizationItem>();
                foreach (SynchronizationItem item in items)
                {
                    try
                    {
                        if (!item.HasIllegalItems(configuration.VaultRoot))
                        {
                            RemoveItemsNotLegal.Add(item);
                        }
                    }
                    catch (Exception ex) { logger.IfSomeDo(l => l.Error(ex.Message)); }
                }



                configuration.Items = RemoveItemsNotLegal;

                configuration.LastSyncFile = MCAD.XmlCommon.XmlTools.SafeReadString(document.DocumentElement, "last_sync_file");
                configuration.UseLastSync  = false;
                if ((configuration.LastSyncFile.IsSome) && (VaultEagle.VaultUtils.HandleNetworkErrors(() => File.Exists(Path.Combine(configuration.configPath, configuration.LastSyncFile.Get() + ".txt")), networkRetries)))
                {
                    configuration.UseLastSync = true;
                    try { configuration.LastSyncTime = DateTime.ParseExact(VaultEagle.VaultUtils.HandleNetworkErrors(() => File.ReadLines(Path.Combine(configuration.configPath, configuration.LastSyncFile.Get() + ".txt")).First(), networkRetries), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); }
                    catch { configuration.LastSyncTime = DateTime.ParseExact("1990-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); }
                }
                else
                {
                    configuration.LastSyncTime = DateTime.ParseExact("1990-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                }

                configuration.OverrideMailSender = MCAD.XmlCommon.XmlTools.SafeReadString(document.DocumentElement, "override_mail_sender");
                configuration.LogLevel           = MCADCommon.LogCommon.Utils.ParseLogLevel(MCAD.XmlCommon.XmlTools.SafeReadString(document.DocumentElement, "log_level").IsSome ? MCAD.XmlCommon.XmlTools.ReadString(document.DocumentElement, "log_level") : "Info");
                configuration.LogFile            = MCAD.XmlCommon.XmlTools.SafeReadString(document.DocumentElement, "log_name");
                try
                {
                    configuration.SavedLogCount = MCAD.XmlCommon.XmlTools.SafeReadString(document.DocumentElement, "saved_log_count").IsSome ? Convert.ToInt32(MCAD.XmlCommon.XmlTools.ReadString(document.DocumentElement, "saved_log_count")) : 60;
                }
                catch
                {
                    configuration.SavedLogCount = 60;
                }
            }
            else
            {
                configuration.configPath = "";
            }

            return(configuration);
        }