Пример #1
0
        static internal CommandLineArgs InitalParse(string[] args)
        {
            var options = new CommandLineArgs();

            options.ShowHelp = true;

            // fake
            MappingFile configuration = new MappingFile();
            var         p             = MakeOptionSet(configuration, options);

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }//try

            if (options.ShowHelp)
            {
                p.WriteOptionDescriptions(Console.Out);
                return(null);
            }
            return(options);
        }
Пример #2
0
        private static OptionSet MakeOptionSet(MappingFile configuration, CommandLineArgs options)
        {
            var p = new OptionSet()
            {
                { "h|help", "Shows this message and exit",
                  value => options.ShowHelp = value != null },
                { "m|configuration:", "Configuration & Mapping file",
                  value => { options.MappingFile = value; options.ShowHelp = false; } },
                { "g|generate:", "Generate sample configuration file",
                  value => { options.SampleFile = value; options.ShowHelp = false; } },
                // pipeline behavior
                { "e|stopOnError", "Stops if pipeline stage fails",
                  value => configuration.StopPipelineOnFirstError = value != null },
                { "t|test", "Test and does not save changes to target",
                  value => configuration.TestOnly = value != null },
                //logging
                { "l|log:", "Write complete log to file",
                  value => configuration.LogFile = value },
                { "v|verbosity:", string.Format("Verbosity level: {0}", string.Join(",", Enum.GetNames(typeof(LoggingLevel)))),
                  value => configuration.Logging = (LoggingLevel)Enum.Parse(typeof(LoggingLevel), value) },
                // data files
                { "i|index:", "Index file, e.g. MyIndex.xml",
                  value => configuration.WorkItemsStage.IndexFile = value },
                { "c|changeLog:", "ChangeLog file, e.g. ChangeLog.csv",
                  value => configuration.ChangeLogFile = value },
                // connection group
                { "sc|sourceCollection:", "Source Collection Url, e.g. http://localhost:8080/tfs/DefaultCollection",
                  value => configuration.SourceConnection.CollectionUrl = value },
                { "dc|destinationCollection:", "Destination Collection Url, e.g. http://localhost:8080/tfs/DefaultCollection",
                  value => configuration.DestinationConnection.CollectionUrl = value },
                { "sp|sourceProject:", "Source Project Name",
                  value => configuration.SourceConnection.ProjectName = value },
                { "dp|destinationProject:", "Destination Project Name",
                  value => configuration.DestinationConnection.ProjectName = value },
                { "su|sourceUser:"******"Username connecting to Source",
                  value => configuration.SourceConnection.User = value },
                { "du|destinationUser:"******"Username connecting to Destination",
                  value => configuration.DestinationConnection.User = value },
                { "sw|sourcePassword:"******"Password for Source user",
                  value => configuration.SourceConnection.Password = value },
                { "dw|destinationPassword:"******"Password for Destination user",
                  value => configuration.DestinationConnection.Password = value },
            };

            return(p);
        }
Пример #3
0
        internal static MappingFile ParseAndMerge(string[] args, MappingFile configuration)
        {
            configuration.FixNulls();

            var options = new CommandLineArgs();

            var p = MakeOptionSet(configuration, options);

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }//try

            return(configuration);
        }
Пример #4
0
        static int Main(string[] args)
        {
            string logHeader = CommandLineParser.GetHeader();

            Console.WriteLine(logHeader);

            var initialOptions = CommandLineParser.InitalParse(args);

            if (initialOptions == null)
            {
                // parsing failed
                return(-1);
            }

            if (initialOptions.SampleFile != null)
            {
                Console.WriteLine("Generating sample file '{0}'.", initialOptions.SampleFile);
                MappingFile.Generate().SaveAsYaml(initialOptions.SampleFile);
                return(1);
            }

            MappingFile configuration = new MappingFile();

            if (System.IO.File.Exists(initialOptions.MappingFile))
            {
                configuration = MappingFile.LoadFrom(initialOptions.MappingFile);
            }
            else
            {
                Console.WriteLine("Mapping file '{0}' not found.", initialOptions.MappingFile);
                return(-2);
            }//if

            configuration = CommandLineParser.ParseAndMerge(args, configuration);
            if (configuration == null)
            {
                // parsing failed
                return(-1);
            }

            // command line parsing succeeded
            if (configuration.TestOnly)
            {
                Console.WriteLine("** TEST MODE: no data will be written on destination **");
            }


            // with user's need in hand, build the pipeline
            var eventHandler = new EngineEventHandler(Convert(configuration.Logging), EventHandlerBase.TraceDevice.All, configuration.LogFile);

            eventHandler.FirstMessage(logHeader);
            //TODO eventHandler.DumpOptions(configuration);

            if (!configuration.Validate())
            {
                return(-1);
            }

            // build the pipeline
            var pipeline = new SyncPipeline(configuration, eventHandler);
            int rc       = pipeline.Execute();

            if (!string.IsNullOrWhiteSpace(configuration.ChangeLogFile))
            {
                eventHandler.SavingChangeLogToFile(configuration.ChangeLogFile);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(configuration.ChangeLogFile))
                {
                    //CSV header
                    file.WriteLine("Source,SourceId,TargetId,ChangeType,Message");
                    foreach (var entry in pipeline.ChangeLog.GetEntries())
                    {
                        file.WriteLine("{0},{1},{2},{3},\"{4}\"",
                                       entry.Source,
                                       entry.SourceId,
                                       entry.TargetId,
                                       entry.Succeeded ? entry.ChangeType : "Failure",
                                       entry.Message);
                    } //for
                }     //using
                eventHandler.SavedChangeLog(pipeline.ChangeLog.Count);
            }         //if

            eventHandler.LastMessage(rc);
            return(rc);
        }