Esempio n. 1
0
File: seems.cs Progetto: zrolfs/pwiz
        public void ParseArgs(string[] args)
        {
            if (InvokeRequired)
            {
                ParseArgsCallback d = new ParseArgsCallback(ParseArgs);
                Invoke(d, new object[] { args });
                return;
            }

            try
            {
                if (args.Any(o => Regex.Match(o, "(-{1,2}|/)(help|\\?)").Success))
                {
                    Console.WriteLine("TODO");
                    Close();
                    return;
                }

                BringToFront();
                Focus();
                Activate();
                Show();
                Application.DoEvents();

                string      datasource          = null;
                IAnnotation annotation          = null;
                var         idOrIndexList       = new List <object>();
                var         idOrIndexListByFile = new Dictionary <string, List <object> >();
                var         annotationByFile    = new Dictionary <string, IAnnotation>();

                for (int i = 0; i < args.Length; ++i)
                {
                    string arg = args[i];
                    // does the arg specify a data source?
                    if (arg.StartsWith("--index"))
                    {
                        idOrIndexList.Add(Convert.ToInt32(args[i + 1]));
                        ++i;
                    }
                    else if (arg.StartsWith("--id"))
                    {
                        idOrIndexList.Add(args[i + 1]);
                        ++i;
                    }
                    else if (arg.StartsWith("--annotation"))
                    {
                        annotation = AnnotationFactory.ParseArgument(args[i + 1]);
                        ++i;
                    }
                    else
                    {
                        if (datasource != null)
                        {
                            idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                            annotationByFile[datasource] = annotation;

                            idOrIndexList.Clear();
                            annotation = null;
                        }

                        datasource = arg;
                        if (!idOrIndexListByFile.ContainsKey(datasource))
                        {
                            idOrIndexListByFile[datasource] = new List <object>();
                        }
                    }
                }

                if (datasource != null)
                {
                    idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                    annotationByFile[datasource] = annotation;

                    idOrIndexList.Clear();
                    annotation = null;
                }

                foreach (var fileListPair in idOrIndexListByFile)
                {
                    if (fileListPair.Value.Count > 0)
                    {
                        Manager.OpenFile(fileListPair.Key, fileListPair.Value, annotationByFile[fileListPair.Key]);
                    }
                    else
                    {
                        Manager.OpenFile(fileListPair.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "\n\nAdditional information: " + ex.InnerException.Message;
                }
                MessageBox.Show(message,
                                "Error parsing command line arguments",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }
Esempio n. 2
0
        public void ParseArgs(string[] args)
        {
            if (InvokeRequired)
            {
                ParseArgsCallback d = new ParseArgsCallback(ParseArgs);
                Invoke(d, new object[] { args });
                return;
            }

            try
            {
                if (args.Any(o => Regex.Match(o, "(-{1,2}|/)(help|\\?)").Success))
                {
                    Console.WriteLine("TODO");
                    Close();
                    return;
                }

                BringToFront();
                Focus();
                Activate();
                Show();
                Application.DoEvents();

                string      datasource          = null;
                IAnnotation annotation          = null;
                var         idOrIndexList       = new List <object>();
                var         idOrIndexListByFile = new Dictionary <string, List <object> >();
                var         annotationByFile    = new Dictionary <string, IAnnotation>();
                bool        testMode            = false;

                for (int i = 0; i < args.Length; ++i)
                {
                    string arg = args[i];
                    // does the arg specify a data source?
                    if (arg.StartsWith("--index"))
                    {
                        idOrIndexList.Add(Convert.ToInt32(args[i + 1]));
                        ++i;
                    }
                    else if (arg.StartsWith("--id"))
                    {
                        idOrIndexList.Add(args[i + 1]);
                        ++i;
                    }
                    else if (arg.StartsWith("--annotation"))
                    {
                        annotation = AnnotationFactory.ParseArgument(args[i + 1]);
                        ++i;
                    }
                    else if (arg == "--test")
                    {
                        testMode = true;
                    }
                    else
                    {
                        if (datasource != null)
                        {
                            idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                            annotationByFile[datasource] = annotation;

                            idOrIndexList.Clear();
                            annotation = null;
                        }

                        datasource = arg;
                        if (!idOrIndexListByFile.ContainsKey(datasource))
                        {
                            idOrIndexListByFile[datasource] = new List <object>();
                        }
                    }
                }

                if (datasource != null)
                {
                    idOrIndexListByFile[datasource].AddRange(idOrIndexList);
                    annotationByFile[datasource] = annotation;

                    idOrIndexList.Clear();
                    annotation = null;
                }

                bool success = true;
                foreach (var fileListPair in idOrIndexListByFile)
                {
                    if (fileListPair.Value.Count > 0)
                    {
                        success &= Manager.OpenFile(fileListPair.Key, fileListPair.Value, annotationByFile[fileListPair.Key]);
                    }
                    else
                    {
                        success &= Manager.OpenFile(fileListPair.Key);
                    }
                }

                if (testMode)
                {
                    Environment.ExitCode = success ? 0 : 1;
                    Close();
                }
            }
            catch (Exception ex)
            {
                Program.HandleException("Error parsing command line arguments", ex);
            }
        }
Esempio n. 3
0
        public void ParseArgs (string[] args)
        {
            if (InvokeRequired)
            {
                ParseArgsCallback d = new ParseArgsCallback(ParseArgs);
                Invoke(d, new object[] { args });
                return;
            }

            try
            {
                Arguments argParser = new Arguments(args);

                if (argParser["help"] != null ||
                    argParser["h"] != null ||
                    argParser["?"] != null)
                {
                    Console.WriteLine("TODO");
                    Close();
                    return;
                }

                BringToFront();
                Focus();
                Activate();
                Show();
                Application.DoEvents();

                string datasource = null;
                foreach (string arg in args)
                    if (!arg.StartsWith("--index") && !arg.StartsWith("id") && !arg.StartsWith("annotation"))
                    {
                        datasource = arg;
                        break;
                    }

                IAnnotation annotation = null;
                if (argParser["annotation"] != null)
                    annotation = AnnotationFactory.ParseArgument(argParser["annotation"]);

                if (datasource != null)
                {
                    if (argParser["index"] != null)
                    {
                        Manager.OpenFile(datasource, Convert.ToInt32(argParser["index"]), annotation);
                    }
                    else if (argParser["id"] != null)
                    {
                        Manager.OpenFile(datasource, argParser["id"], annotation);
                    }
                    else
                        Manager.OpenFile(datasource);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null)
                    message += "\n\nAdditional information: " + ex.InnerException.Message;
                MessageBox.Show(message,
                                "Error parsing command line arguments",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }
Esempio n. 4
0
        public void ParseArgs(string[] args)
        {
            if (InvokeRequired)
            {
                ParseArgsCallback d = new ParseArgsCallback(ParseArgs);
                Invoke(d, new object[] { args });
                return;
            }

            try
            {
                Arguments argParser = new Arguments(args);

                if (argParser["help"] != null ||
                    argParser["h"] != null ||
                    argParser["?"] != null)
                {
                    Console.WriteLine("TODO");
                    Close();
                    return;
                }

                BringToFront();
                Focus();
                Activate();
                Show();
                Application.DoEvents();

                string datasource = null;
                foreach (string arg in args)
                {
                    if (!arg.StartsWith("--index") && !arg.StartsWith("id") && !arg.StartsWith("annotation"))
                    {
                        datasource = arg;
                        break;
                    }
                }

                IAnnotation annotation = null;
                if (argParser["annotation"] != null)
                {
                    annotation = AnnotationFactory.ParseArgument(argParser["annotation"]);
                }

                if (datasource != null)
                {
                    if (argParser["index"] != null)
                    {
                        Manager.OpenFile(datasource, Convert.ToInt32(argParser["index"]), annotation);
                    }
                    else if (argParser["id"] != null)
                    {
                        Manager.OpenFile(datasource, argParser["id"], annotation);
                    }
                    else
                    {
                        Manager.OpenFile(datasource);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "\n\nAdditional information: " + ex.InnerException.Message;
                }
                MessageBox.Show(message,
                                "Error parsing command line arguments",
                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                0, false);
            }
        }