コード例 #1
0
        private bool ValidateOutputDirectory(string outputFilePath)
        {
            try
            {
                var outputFile = new FileInfo(outputFilePath);
                if (outputFile.Directory == null ||
                    outputFile.DirectoryName == null)
                {
                    OnErrorEvent("Unable to determine the parent directory of output file: " + outputFile);
                    return(false);
                }

                if (!outputFile.Directory.Exists)
                {
                    OnStatusEvent("Creating output directory: " + outputFile.Directory.FullName);
                    outputFile.Directory.Create();
                }

                return(true);
            }
            catch (Exception ex)
            {
                OnErrorEvent("Unable to determine the parent directory of output file: " + outputFilePath);
                Console.WriteLine(StackTraceFormatter.GetExceptionStackTraceMultiLine(ex));
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// this function controls the class behavior
        /// </summary>
        /// <param name="fileName">The command line file to run</param>
        /// <param name="args">the parameters to pass to the program</param>
        private void Init(string fileName, string args)
        {
            // create a process
            var process = new Process();
            // apply all required elements for process
            var startInfo = new ProcessStartInfo(fileName, args)
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                UseShellExecute        = false
            };

            process.StartInfo = startInfo;
            try
            {
                // start the process
                process.Start();
                process.WaitForExit();
                StandardOut   = process.StandardOutput.ReadToEnd();
                StandardError = process.StandardError.ReadToEnd();
                // if error set status code
                if (!process.ExitCode.Equals(0))
                {
                    Status = StatusCode.Error;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error starting the process: " + ex.Message);
                Console.WriteLine(StackTraceFormatter.GetExceptionStackTraceMultiLine(ex));

                // exception from process starting
                Status = StatusCode.FileNotFound;
            }
        }
コード例 #3
0
        private static void ShowGUI()
        {
            Application.EnableVisualStyles();
            Application.DoEvents();
            try
            {
                var handle = GetConsoleWindow();

                if (!mDebugMode)
                {
                    // Hide the console
                    ShowWindow(handle, SW_HIDE);
                }

                var objFormMain = new GUI()
                {
                    KeepDB = mKeepDB
                };

                objFormMain.ShowDialog();

                if (!mDebugMode)
                {
                    // Show the console
                    ShowWindow(handle, SW_SHOW);
                }
            }
            catch (Exception ex)
            {
                ConsoleMsgUtils.ShowWarning("Error in ShowGUI: " + ex.Message);
                ConsoleMsgUtils.ShowWarning(StackTraceFormatter.GetExceptionStackTraceMultiLine(ex));

                MessageBox.Show("Error in ShowGUI: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #4
0
        public string FormatStackTrace(string stackTraceText)
        {
            if (string.IsNullOrWhiteSpace(stackTraceText))
            {
                return(string.Empty);
            }

            string html;

            try
            {
                var formattedStackTrace = StackTraceFormatter.FormatHtml(stackTraceText,
                                                                         new StackTraceHtmlFragments
                {
                    BeforeFrame = "<span class='frame'>",
                    AfterFrame  = "</span>",
                });

                html = $"<pre><code>{formattedStackTrace}</code></pre>";
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Could not parse Stack Trace for \n{stackTraceText}");
                html = $"Stack Trace could not be parsed/formatted:<br /> {ex.Message}";
            }

            return(html);
        }
コード例 #5
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main()
        {
            // Start the main program running
            try
            {
                if (mMainProcess == null)
                {
                    mMainProcess = new MainProgram();
                    if (!mMainProcess.InitMgr())
                    {
                        PRISM.Logging.FileLogger.FlushPendingMessages();
                        return;
                    }
                    mMainProcess.DoDirectoryCreation();
                }
            }
            catch (Exception ex)
            {
                var errMsg = "Critical exception starting application: " + ex.Message;
                ConsoleMsgUtils.ShowWarning(errMsg + "; " + StackTraceFormatter.GetExceptionStackTrace(ex));
                ConsoleMsgUtils.ShowWarning("Exiting clsMainProcess.Main with error code = 1");
            }

            PRISM.Logging.FileLogger.FlushPendingMessages();
        }
コード例 #6
0
 public NonEscapedString StackTrace(string stackTrace)
 {
     try
     {
         return(new NonEscapedString(StackTraceFormatter.FormatHtml(stackTrace, StackTraceHtmlFragments)));
     }
     catch (RegexMatchTimeoutException)
     {
         return(new NonEscapedString(HtmlEncode(stackTrace)));
     }
 }
コード例 #7
0
        private void ShowStackTraceNow(IReadOnlyCollection <string> parents, int depth, bool multiLine)
        {
            Assert.AreEqual(depth, parents.Count, "Parent list length invalid");

            string stackTrace;

            if (multiLine)
            {
                stackTrace = StackTraceFormatter.GetCurrentStackTraceMultiLine();
            }
            else
            {
                stackTrace = StackTraceFormatter.GetCurrentStackTrace();
            }

            Console.WriteLine(stackTrace);
        }
コード例 #8
0
        private void ShowErrorMessage(string message, Exception ex = null)
        {
            if (ex == null || message.Contains(ex.Message))
            {
                AppendProcessingStatus(message, true);
            }
            else
            {
                AppendProcessingStatus(message + ": " + ex.Message, true);
            }

            if (ex == null)
            {
                return;
            }

            var stackTrace = StackTraceFormatter.GetExceptionStackTraceMultiLine(ex, true, false);

            AppendProcessingStatus(stackTrace, true);
        }
コード例 #9
0
        public void VerifyExceptionStackTrace(ExceptionTypes targetException, int depth, bool multiLine, bool includeMethodParams = false)
        {
            var parents = new List <string>();

            try
            {
                RecursiveMethodA(targetException, parents, 1, depth);
            }
            catch (Exception ex)
            {
                string stackTrace;

                if (multiLine)
                {
                    stackTrace = StackTraceFormatter.GetExceptionStackTraceMultiLine(ex, true, includeMethodParams);
                }
                else
                {
                    stackTrace = StackTraceFormatter.GetExceptionStackTrace(ex);
                }

                Console.WriteLine(stackTrace);
            }
        }
コード例 #10
0
        /// <summary>
        /// Initialization function that controls the program
        /// </summary>
        /// <param name="options">Processing options</param>
        /// <returns>True on success, false if an error</returns>
        private bool ProcessMetabolites(MetaboliteValidatorOptions options)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(options.InputFile))
                {
                    Console.WriteLine();
                    Console.WriteLine("Error, input file not defined");
                    return(false);
                }

                var inputFile = new FileInfo(options.InputFile);

                if (!inputFile.Exists)
                {
                    Console.WriteLine();
                    Console.WriteLine("Error, input file not found: " + inputFile.FullName);
                    return(false);
                }

                // init github api interaction with the repo and owner
                var github = new Github("MetabolomicsCCS", "PNNL-Comp-Mass-Spec", options.Preview);

                if (!string.IsNullOrEmpty(options.Username))
                {
                    github.Username = options.Username;

                    if (!string.IsNullOrEmpty(options.Password))
                    {
                        if (options.Password.StartsWith("*"))
                        {
                            github.Password = MetaboliteValidatorOptions.DecodePassword(options.Password.Substring(1));
                        }
                        else
                        {
                            github.Password = options.Password;
                        }
                    }
                }

                // get main data file from github
                var dataFile = github.GetFile("data/" + MASTER_TSV_FILE);

                // parse the new data to append to current data
                var fileToAppend = new DelimitedFileParser();
                fileToAppend.ParseFile(inputFile.FullName, '\t');

                Console.WriteLine();
                Console.WriteLine("Found {0} records in local file {1}", fileToAppend.Count(), inputFile.Name);

                // Update column names if necessary
                UpdateHeaders(fileToAppend);

                // parse the main data file from github
                var mainFile = new DelimitedFileParser();
                if (dataFile == null)
                {
                    mainFile.SetDelimiter('\t');
                    mainFile.SetHeaders(fileToAppend.GetHeaders());
                }
                else
                {
                    mainFile.ParseString(dataFile, '\t');

                    Console.WriteLine();
                    Console.WriteLine("Found {0} records in file {1} retrieved from GitHub", mainFile.Count(), MASTER_TSV_FILE);
                    Console.WriteLine();
                }

                // Update column names if necessary
                UpdateHeaders(mainFile);

                var duplicateRowCount = 0;

                if (!options.IgnoreErrors)
                {
                    // Get ids for Kegg and PubChem
                    var keggIds    = fileToAppend.GetColumnAt("kegg").Where(x => !string.IsNullOrEmpty(x)).ToList();
                    var cidIds     = fileToAppend.GetColumnAt("pubchem cid").Where(x => !string.IsNullOrEmpty(x)).ToList();
                    var mainCasIds = mainFile.GetColumnAt("cas").Where(x => !string.IsNullOrEmpty(x)).ToList();

                    // generate PubChem and Kegg utils
                    var pub  = new PubchemUtil(cidIds.ToArray());
                    var kegg = new KeggUtil(keggIds.ToArray());
                    var file = new StreamWriter("ValidationApi.txt");

                    var dupRows = new DelimitedFileParser();
                    dupRows.SetHeaders(fileToAppend.GetHeaders());
                    dupRows.SetDelimiter('\t');

                    var warningRows = new DelimitedFileParser();
                    warningRows.SetHeaders(fileToAppend.GetHeaders());
                    warningRows.SetDelimiter('\t');

                    var missingKegg = new DelimitedFileParser();
                    missingKegg.SetHeaders(fileToAppend.GetHeaders());
                    missingKegg.SetDelimiter('\t');

                    var dataMap = fileToAppend.GetMap();

                    // compare fileToAppend to utils
                    for (var i = dataMap.Count - 1; i >= 0; i--)
                    {
                        Compound     p = null;
                        CompoundData k = null;
                        if (!string.IsNullOrEmpty(dataMap[i]["pubchem cid"]))
                        {
                            p = pub.PubChemMap[int.Parse(dataMap[i]["pubchem cid"])];
                        }
                        if (!string.IsNullOrEmpty(dataMap[i]["kegg"]) && kegg.CompoundsMap.ContainsKey(dataMap[i]["kegg"]))
                        {
                            k = kegg.CompoundsMap[dataMap[i]["kegg"]];
                        }
                        if (mainCasIds.Contains(dataMap[i]["cas"]))
                        {
                            dupRows.Add(dataMap[i]);
                            fileToAppend.Remove(dataMap[i]);
                        }
                        else
                        {
                            if (k == null && CheckRow(dataMap[i], p, null))
                            {
                                missingKegg.Add(dataMap[i]);
                            }
                            else if (!CheckRow(dataMap[i], p, k))
                            {
                                // remove from list add to warning file
                                WriteContentToFile(file, dataMap[i], p, k, warningRows.Count() + 2);
                                warningRows.Add(dataMap[i]);
                                fileToAppend.Remove(dataMap[i]);
                            }
                        }
                    }

                    duplicateRowCount = dupRows.Count();

                    file.Close();

                    if (fileToAppend.Count() > 0)
                    {
                        Console.WriteLine("Validating data file with GoodTables");
                        var goodTables = new GoodTables(fileToAppend.ToString(true), SchemaUrl);
                        if (!goodTables.Response.success)
                        {
                            //foreach(var result in goodTables.Response.report.results)
                            //{
                            //    fileToAppend.Remove(result["0"].result_context[0]);
                            //}

                            goodTables.OutputResponse(new StreamWriter(GOOD_TABLES_WARNING_FILE));

                            Console.WriteLine();
                            Console.WriteLine("GoodTables reports errors; see " + GOOD_TABLES_WARNING_FILE);
                            Console.WriteLine("Note that data with N/A in columns that expect a number will be flagged as an error by GoodTables; those errors can be ignored");
                        }
                    }

                    streamToFile(DUPLICATE_ROWS_FILE, dupRows);
                    streamToFile(WARNING_ROWS_FILE, warningRows);
                    streamToFile(MISSING_KEGG_FILE, missingKegg);

                    if (warningRows.Count() > 0)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Warnings were encountered; see file " + WARNING_ROWS_FILE);
                    }

                    if (missingKegg.Count() > 0)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Warnings were encountered; see file " + MISSING_KEGG_FILE);
                    }
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Ignoring validation, skipping to file upload.");
                }

                if (fileToAppend.Count() == 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("No new compounds were found; see {0} for the {1} skipped compounds", DUPLICATE_ROWS_FILE, duplicateRowCount);
                }
                else
                {
                    // this will add the new data tsv to the existing tsv downloaded from github
                    var success = mainFile.Concat(fileToAppend);

                    if (!success)
                    {
                        // Concatenation of new records failed; do not upload
                        return(false);
                    }

                    // Start command line process for GoodTables
                    //
                    // string userDirPath = Environment.GetEnvironmentVariable("GOODTABLES_PATH");
                    // string commandLine = $"schema \"{options.InputFile}\" --schema \"{SchemaUrl}\"";
                    // string GoodTablesPath = $"{userDirPath}\\GoodTables";
                    //CommandLineProcess pro = new CommandLineProcess(GoodTablesPath, commandLine);
                    //// if error display errors and exit
                    //if (pro.Status.Equals(CommandLineProcess.StatusCode.Error))
                    //{
                    //    Console.WriteLine($"GoodTables Validation error\n\n{pro.StandardOut}{pro.StandardError}\nExiting program please check that the data is valid.");
                    //    Console.ReadKey();
                    //    Environment.Exit(1);
                    //}
                    //// if the GoodTables.exe file isn't found display message and exit
                    //else if (pro.Status.Equals(CommandLineProcess.StatusCode.FileNotFound))
                    //{
                    //    Console.WriteLine("File not found. Please make sure you have installed python and GoodTables.\n"
                    //        +"Check that the folder path for GoodTables.exe is added to an environment variable named GOODTABLES_PATH.\n"
                    //        +"Press any key to continue.");
                    //    Console.ReadKey();
                    //    Environment.Exit(1);
                    //}
                    //else
                    //{
                    //    Console.WriteLine($"GoodTables validation\n\n{pro.StandardOut}");
                    //
                    // This will send the completed tsv back to github
                    github.SendFileAsync(mainFile.ToString(true), "data/" + MASTER_TSV_FILE);

                    // send Agilent file to github
                    github.SendFileAsync(mainFile.PrintAgilent(), "data/metabolitedataAgilent.tsv");
                    //}
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("Error processing data: " + ex.Message);
                Console.WriteLine(StackTraceFormatter.GetExceptionStackTraceMultiLine(ex));
                return(false);
            }
        }
コード例 #11
0
        /// <summary>
        /// 解析格式化字符串
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public static List <IPartFormatter> ParseFormat(string format)
        {
            int start = -1;
            int tag   = 0;
            var parts = new List <string>();
            int len   = format.Length;
            int idx   = format.IndexOf('{');

            parts.Add(format.Substring(0, idx));
            for (int i = idx; i < len; ++i)
            {
                switch (format[i])
                {
                case '{':
                    if (start != -1)
                    {
                        parts.Add(format.Substring(start, i - start));
                    }
                    start = i;
                    break;

                case '}':
                    parts.Add(format.Substring(start, i - start));
                    start = i + 1;
                    tag   = start;  //标记最后面的填充字符的开始位置
                    break;
                }
            }
            parts.Add(format.Substring(tag, len - tag));

            // {Date:yyyy-MM-dd HH:mm:ss.ffff} {ThreadId} {StackTrace:3,40} {Message}
            var formatters = new List <IPartFormatter>();

            foreach (string part in parts)
            {
                if (part.StartsWith("{DateTime"))
                {
                    if (part.Length > 9 && part[9] == ':')
                    {
                        formatters.Add(new DateTimeFormatter {
                            FormatString = part.Substring(10)
                        });
                    }
                    else
                    {
                        formatters.Add(new DateTimeFormatter());
                    }
                }
                else if (part.StartsWith("{ThreadId"))
                {
                    formatters.Add(new ThreadIdFormatter());
                }
                else if (part.StartsWith("{StackTrace"))
                {
                    if (!part.StartsWith("{StackTrace:"))
                    {
                        formatters.Add(new StackTraceFormatter());
                        continue;
                    }

                    string[] subparts  = part.Substring(12).Split(',');
                    var      formatter = new StackTraceFormatter();
                    if (subparts.Length > 0)
                    {
                        formatter.Count = int.Parse(subparts[0]);
                    }
                    if (subparts.Length > 1)
                    {
                        formatter.PadLength = int.Parse(subparts[1]);
                    }
                    if (subparts.Length > 2)
                    {
                        formatter.SkipCount = int.Parse(subparts[2]);
                    }
                    formatters.Add(formatter);
                }
                else if (part.StartsWith("{Message"))
                {
                    formatters.Add(new MessageFormatter());
                }
                else if (part.StartsWith("{LogLevel"))
                {
                    formatters.Add(new LogLevelFormatter());
                }
                else
                {
                    formatters.Add(new TextFormatter {
                        Text = part
                    });
                }
            }
            return(formatters);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: PNNL-Comp-Mass-Spec/AScore
        private static void ShowError(string message, Exception ex = null)
        {
            Console.WriteLine();
            var msg = "Error: " + message;

            ConsoleMsgUtils.ShowError(msg, ex);
            mLogFile?.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\t" + msg);

            if (ex != null)
            {
                mLogFile?.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\t" + StackTraceFormatter.GetExceptionStackTrace(ex));
            }
        }
コード例 #13
0
 private void LinuxSystemInfo_ErrorEvent(string message, Exception ex)
 {
     Console.WriteLine("Error: " + message);
     Console.WriteLine(StackTraceFormatter.GetExceptionStackTraceMultiLine(ex));
 }
コード例 #14
0
        public override void Execute()
        {
            WriteLiteral("\r\n");



            #line 5 "..\..\Views\Dashboard\LogInfo.cshtml"


            var log = (ILogModel)ViewData["Model"];



            #line default
            #line hidden
            WriteLiteral(@"<div class=""container-fluid"">
    <div class=""mb-4 open"">
        <ul class=""nav nav-tabs"" role=""tablist"">
            <li class=""nav-item"">
                <a class=""nav-link active"" data-toggle=""tab"" href=""#overview"" role=""tab"" aria-controls=""overview"" aria-selected=""true"">概览</a>
            </li>
            <li class=""nav-item"">
                <a class=""nav-link"" data-toggle=""tab"" href=""#environment"" role=""tab"" aria-controls=""environment"" aria-selected=""false"">其他</a>
            </li>
");



            #line 19 "..\..\Views\Dashboard\LogInfo.cshtml"

            if (typeof(IRequestTraceLogModel).IsAssignableFrom(Context.Options.LogModelType))
            {
            #line default
            #line hidden
                WriteLiteral("                    <li class=\"nav-item\">\r\n\r\n                        <a class=\"na" +
                             "v-link\" data-toggle=\"tab\" href=\"#requestTrace\" role=\"tab\" aria-controls=\"request" +
                             "Trace\" onclick=\"requestTrace(\'");



            #line 24 "..\..\Views\Dashboard\LogInfo.cshtml"
                Write(log.Id.ToString());


            #line default
            #line hidden
                WriteLiteral("\')\" aria-selected=\"false\">请求追踪</a>\r\n                    </li>\r\n");



            #line 26 "..\..\Views\Dashboard\LogInfo.cshtml"
            }



            #line default
            #line hidden
            WriteLiteral(@"        </ul>
        <div class=""tab-content"">
            <div class=""tab-pane active"" id=""overview"" role=""tabpanel"">
                <div class=""table-responsive"">
                    <table class=""table table-bordered"">
                        <tbody>
                            <tr>
                                <td>Id</td>
                                <td class=""text-nowrap"">");



            #line 37 "..\..\Views\Dashboard\LogInfo.cshtml"
            Write(log.Id.ToString());


            #line default
            #line hidden
            WriteLiteral("</td>\r\n                            </tr>\r\n                            <tr>\r\n     " +
                         "                           <td>时间</td>\r\n                                <td clas" +
                         "s=\"text-nowrap\">");



            #line 41 "..\..\Views\Dashboard\LogInfo.cshtml"
            Write(log.LongDate.ToString("yyyy-MM-dd HH:mm:ss"));


            #line default
            #line hidden
            WriteLiteral("</td>\r\n                            </tr>\r\n                            <tr>\r\n     " +
                         "                           <td>级别</td>\r\n                                <td clas" +
                         "s=\"text-nowrap\"><button class=\"btn btn-outline-");



            #line 45 "..\..\Views\Dashboard\LogInfo.cshtml"
            Write(log.Level.ToUpper());


            #line default
            #line hidden
            WriteLiteral("\">");



            #line 45 "..\..\Views\Dashboard\LogInfo.cshtml"
            Write(log.Level.ToUpper());


            #line default
            #line hidden
            WriteLiteral("</button></td>\r\n                            </tr>\r\n                            <t" +
                         "r>\r\n                                <td>Logger</td>\r\n                           " +
                         "     <td class=\"text-nowrap\">");



            #line 49 "..\..\Views\Dashboard\LogInfo.cshtml"
            Write(log.Logger);


            #line default
            #line hidden
            WriteLiteral("</td>\r\n                            </tr>\r\n                            <tr>\r\n     " +
                         "                           <td>消息</td>\r\n                                <td clas" +
                         "s=\"text-nowrap\">");



            #line 53 "..\..\Views\Dashboard\LogInfo.cshtml"
            Write(log.Message);


            #line default
            #line hidden
            WriteLiteral(@"</td>
                            </tr>

                        </tbody>
                    </table>
                    <div class=""card"">
                        <div class=""card-header bg-light"">
                            堆栈信息
                        </div>
                        <div class=""card-body"">
                            <pre>");



            #line 63 "..\..\Views\Dashboard\LogInfo.cshtml"
            Write(Raw(StackTraceFormatter.FormatHtml(log.Exception)));


            #line default
            #line hidden
            WriteLiteral(@"</pre>
                        </div>
                    </div>
                </div>
            </div>

            <div class=""tab-pane"" id=""environment"" role=""tabpanel"">
                <div class=""table-responsive"">
                    <table class=""table table-bordered"">
                        <tbody>
");



            #line 73 "..\..\Views\Dashboard\LogInfo.cshtml"

            foreach (var propertyInfo in Context.Options.CustomPropertyInfos)
            {
            #line default
            #line hidden
                WriteLiteral("                                    <tr>\r\n                                       " +
                             " <td style=\"width: 13%\">");



            #line 77 "..\..\Views\Dashboard\LogInfo.cshtml"
                Write(propertyInfo.Name);


            #line default
            #line hidden
                WriteLiteral("</td>\r\n                                        <td class=\"text-nowrap\">");



            #line 78 "..\..\Views\Dashboard\LogInfo.cshtml"
                Write(propertyInfo.GetValue(log));


            #line default
            #line hidden
                WriteLiteral("</td>\r\n                                    </tr>\r\n");



            #line 80 "..\..\Views\Dashboard\LogInfo.cshtml"
            }



            #line default
            #line hidden
            WriteLiteral(@"                        </tbody>
                    </table>
                </div>
            </div>

            <div class=""tab-pane"" id=""requestTrace"" role=""tabpanel"">
                <div class=""table-responsive"">
                    <div id=""traceLogList"">

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>");
        }
コード例 #15
0
 public NonEscapedString StackTrace(string stackTrace)
 {
     return(new NonEscapedString(StackTraceFormatter.FormatHtml(stackTrace, StackTraceHtmlFragments)));
 }