예제 #1
0
        public void SaveLog(string type, string message)
        {
            string      hostName    = Dns.GetHostName();
            string      hostIP      = "";
            IPHostEntry ipHostEntry = Dns.GetHostEntry(hostName);

            foreach (IPAddress ipAddress in ipHostEntry.AddressList)
            {
                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    hostIP = ipAddress.ToString();
                }
            }
            LogDbContext context = new LogDbContext();
            var          log     = new LOG()
            {
                LOGDATE  = DateTime.Now,
                LOGLEVEL = type,
                USERNAME = userName,
                HOSTNAME = hostName,
                HOSTIP   = hostIP,
                MESSAGE  = message.Length > 4000 ? message.Substring(0, 4000) : message,
                VERSION  = Assembly.GetExecutingAssembly().GetName().Version.ToString()
            };

            context.LOG.Add(log);
            try
            {
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger.Error("Connection error to logging server!\r\n" + ex.Message);
                Console.ReadKey();
                Environment.Exit(0);
            }
        }
예제 #2
0
        private static void GetStat(List <Issue> jira_issues)
        {
            LogDbContext context = new LogDbContext();

            foreach (Issue jira_issue in jira_issues)
            {
                try
                {
                    ISSUE issue = context.ISSUE.Where(x => x.JIRAIDENTIFIER == jira_issue.JiraIdentifier).FirstOrDefault();
                    if (issue == null)
                    {
                        issue = new ISSUE
                        {
                            JIRAIDENTIFIER = jira_issue.JiraIdentifier
                        };
                        context.ISSUE.Add(issue);
                    }
                    if (jira_issue.Updated != issue.UPDATED)
                    {
                        issue.KEY          = jira_issue.Key.Value;
                        issue.PRIORITY     = jira_issue.Priority?.Name;
                        issue.CREATED      = jira_issue.Created;
                        issue.REPORTERUSER = jira_issue.ReporterUser.DisplayName;
                        issue.ASSIGNEEUSER = jira_issue.AssigneeUser?.DisplayName;
                        issue.SUMMARY      = jira_issue.Summary;
                        issue.STATUSNAME   = jira_issue.Status.Name;
                        issue.STORYPOINTS  = jira_issue["Story Points"] == null ? 0 : Convert.ToDecimal(jira_issue["Story Points"].Value.Replace('.', ','));
                        issue.CATEGORY     = jira_issue["Категория"]?.Value;
                        issue.DIRECTION    = jira_issue["Направление"]?.Value;
                        issue.UPDATED      = jira_issue.Updated;
                        issue.TYPE         = jira_issue.Type.Name;

                        var changeLog = jira_issue.GetChangeLogsAsync().Result;
                        foreach (var history in changeLog)
                        {
                            foreach (var item in history.Items)
                            {
                                if (item.FieldName == "status" /* || item.FieldName == "issuetype"*/)
                                {
                                    ISSUE_HISTORY issue_History = context.ISSUE_HISTORY.Where(x => x.ID == history.Id && x.FIELDNAME == item.FieldName).FirstOrDefault();
                                    if (issue_History == null)
                                    {
                                        issue_History = new ISSUE_HISTORY
                                        {
                                            ID        = history.Id,
                                            FIELDNAME = item.FieldName
                                        };
                                        context.ISSUE_HISTORY.Add(issue_History);
                                    }
                                    issue_History.JIRAIDENTIFIER = jira_issue.JiraIdentifier;
                                    issue_History.CREATEDDATE    = history.CreatedDate;
                                    issue_History.FROMVALUE      = item.FromValue;
                                    issue_History.TOVALUE        = item.ToValue;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error($"Ошибка обработки задачи {jira_issue.Key}!\r\n" + ex.Message);
                }
            }
            context.SaveChanges();
        }