Пример #1
0
 private static IList<String> GetDashboardLogConfigs(DashboardEntities ef)
 {
     IList<string> list = new List<string>();
     foreach (var config in ef.tbl_SLA_DashboardLogConfig)
     {
        list.Add(config.Location);
     }
     return list;
 }
Пример #2
0
 public IQueryable<vu_DashboardLogsLatest> Refresh()
 {
     IQueryable<vu_DashboardLogsLatest> data;
     var transactionOptions = new System.Transactions.TransactionOptions();
     transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
     using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
     {
         if (_bitsDashboardContext != null)
             _bitsDashboardContext.Connection.Close();
         _bitsDashboardContext = new DashboardEntities();
         data =  _bitsDashboardContext.vu_DashboardLogsLatest.OrderByDescending(logData => logData.StartTime);
         transactionScope.Complete();
         return data;
     }
 }
Пример #3
0
      public static void RunScheduledTasks()
      {
          
            var transactionOptions = new System.Transactions.TransactionOptions();
            transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
          
            using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
            {
                using (DashboardEntities ef = new DashboardEntities())
                {

                    IList<string> listConfig = GetDashboardLogConfigs(ef);
                    foreach (string config in listConfig)
                    {
                        string dir = config;
                        string ext = "*.*";
                        DataTable dt = GetDataTable();
                        DataTable dtStats = GetStatsDataTable();
                        List<string> listOfSupressedErrors = GetListOfSupressedErrors();
                        foreach (String file in Directory.GetFiles(dir, ext))
                        {

                            if (File.GetLastWriteTime(file) > DateTime.Now.AddDays(-1))
                            {

                                try
                                {
                                    using (var r = new StreamReader(file))
                                    {

                                        FileInfo fi = new FileInfo(file);
                                        _bitsList = file.Split('\\').ToList<string>();
                                        string record = "";


                                        string server = _bitsList[2];
                                        string bitsInstance = _bitsList[4];
                                        foreach (
                                            var source in
                                                ef.tbl_SLA_DashboardLogs.OrderByDescending(a => a.StartTime)
                                                    .Where(a => a.Server == server && a.BITSInstance == bitsInstance))
                                        {
                                            tbl_SLA_DashboardLogs logstemp = source;
                                            maxDateTime = (DateTime)logstemp.StartTime;
                                            break;
                                        }
                                        //  maxDateTime = maxDateTime.AddDays(-2);
                                        maxDateTime = maxDateTime.AddMinutes(-10);

                                        while ((record = r.ReadLine()) != null)
                                        {
                                            try
                                            {
                                                DateTime recDate;
                                                if (record.Length < 19 ||
                                                    !DateTime.TryParse(record.Substring(0, 19), out recDate))
                                                    continue;

                                                DataRow dr = dt.NewRow();
                                                dr["Date"] = Convert.ToDateTime(record.Substring(0, 19));
                                                dr["Level"] =
                                                    record.Substring(24, 6).Trim().ToString(CultureInfo.InvariantCulture);

                                                int idx1 = record.IndexOf("ID=", StringComparison.Ordinal);
                                                if (idx1 < 0)
                                                    continue;

                                                string kc = record.Substring(idx1);
                                                int idx2 = kc.IndexOf(" -", StringComparison.Ordinal);
                                                kc = kc.Substring(3, idx2 - 3);
                                                if (kc != "(null)")
                                                {
                                                    dr["KeyCode"] = kc;
                                                    dr["Message"] = record.Substring(idx1 + idx2);
                                                    if (dr["Level"].ToString() != "INFO")
                                                        dt.Rows.Add(dr);

                                                    if (record.Contains("Beginning executing job") &&
                                                        record.Contains("Execution mode"))
                                                    {
                                                        DataRow drStat = dtStats.NewRow();

                                                        drStat["KeyCode"] = kc;
                                                        drStat["Name"] =
                                                            record.Substring(record.IndexOf("Beginning executing job ",
                                                                StringComparison.Ordinal))
                                                                .Replace("Beginning executing job ", "")
                                                                .Replace("_Job in Execution mode.", "");
                                                        drStat["StartTime"] = dr["Date"];
                                                        try
                                                        {
                                                            if (maxDateTime <= (DateTime)drStat["StartTime"])
                                                                dtStats.Rows.Add(drStat);
                                                        }
                                                        catch
                                                        {
                                                        }
                                                    }

                                                    DataRow foundRow = dtStats.Rows.Find(kc);
                                                    if (foundRow != null)
                                                    {
                                                        foundRow.BeginEdit();
                                                        foundRow["EndTime"] = dr["Date"];
                                                        foundRow["Seconds"] =
                                                            ((DateTime)foundRow["EndTime"] - (DateTime)foundRow["StartTime"])
                                                                .Seconds;
                                                        foundRow["Server"] = _bitsList[2];
                                                        foundRow["BITSInstance"] = _bitsList[4];
                                                        foundRow["Message"] = dr["Message"].ToString().Replace(",", " ;");

                                                        // Todo:  
                                                        if (
                                                            dr["Message"].ToString()
                                                                .Contains("Beginning write to file"))
                                                        {
                                                            String[] data = record.Replace("  ", " ").Split(new char[] { ' ' });
                                                            tbl_SLA_FileChecker filesChecker = new tbl_SLA_FileChecker();

                                                            filesChecker.jobKeyCode = kc;
                                                            filesChecker.FileName = data[9];


                                                            if (Convert.ToDateTime(record.Substring(0, 19)) >= maxDateTime)
                                                                ef.AddTotbl_SLA_FileChecker(filesChecker);

                                                        }

                                                        foundRow.EndEdit();
                                                    }

                                                    else if (foundRow == null)
                                                    {

                                                        if (maxDateTime <= (DateTime)dr["Date"])
                                                        {
                                                            DataRow runRow = dtStats.NewRow();
                                                            runRow["KeyCode"] = kc;
                                                            runRow["BITSInstance"] = _bitsList[4];
                                                            runRow["Message"] = record.Substring(idx1 + idx2);
                                                            runRow["Name"] = record.Substring(
                                                                record.IndexOf("Beginning executing job ",
                                                                    System.StringComparison.Ordinal))
                                                                .Replace("Beginning executing job ", "")
                                                                .Replace("_Job in Execution mode.", "");
                                                            runRow["StartTime"] = dr["Date"];
                                                            dtStats.Rows.Add(runRow);

                                                        }
                                                    }

                                                }
                                                Console.WriteLine("KEycode=" + kc);


                                                String[] data1 = record.Replace("  ", " ").Split(new[] { ' ' });
                                                tbl_SLA_BITSJobRequest reuestRequest = new tbl_SLA_BITSJobRequest();
                                                reuestRequest.RequestTime = Convert.ToDateTime(record.Substring(0, 19));
                                                reuestRequest.JobName = data1[7].Replace("_Job.", "");
                                                reuestRequest.RequestedBy = data1[10].Replace("FOUNTAINHEAD\\", "");
                                                reuestRequest.MachineName = data1[12];
                                                foreach (var s in dtStats.Select("Name Like '%" + reuestRequest.JobName + "%'"))
                                                {
                                                    reuestRequest.KeyCode = s["KeyCode"].ToString();
                                                }

                                                if (Convert.ToDateTime(record.Substring(0, 19)) >= maxDateTime && reuestRequest.JobName.Contains("ADHOC") && reuestRequest.KeyCode != String.Empty)
                                                    ef.AddTotbl_SLA_BITSJobRequest(reuestRequest);

                                            }

                                            catch (Exception ex)
                                            {
                                                Console.Write(ex);
                                            }

                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    ;
                                }

                                foreach (DataRow drStat in dtStats.Rows)
                                {
                                    tbl_SLA_DashboardLogs logs = new tbl_SLA_DashboardLogs();
                                    logs.Server = drStat["Server"].ToString();
                                    logs.BITSInstance = drStat["BITSInstance"].ToString();
                                    logs.KeyCode = drStat["KeyCode"].ToString();
                                    logs.Name = drStat["Name"].ToString().Replace("_Job in Initialization mode.", "");
                                    logs.StartTime = (DateTime?)drStat["StartTime"];
                                    logs.EndTime = (DateTime?)drStat["EndTime"];
                                    TimeSpan diffTime = (TimeSpan)(logs.EndTime - logs.StartTime);
                                    logs.Seconds = (int?)diffTime.TotalMinutes;
                                    logs.Message = drStat["Message"].ToString().Replace("\n", "|").Replace("\t", " ");



                                    // Error handeling 

                                    if (IsError(logs.Message) && listOfSupressedErrors.Contains(logs.Message))
                                        logs.Status = "Error";


                                    else if (drStat["Status"].ToString() == String.Empty)
                                    {

                                        double timeDiff = diffTime.TotalMinutes * 60;

                                        logs.Status = timeDiff > 0 ? "Completed" : "Running";
                                    }
                                    else if (drStat["Status"].ToString() == "Started")
                                    {
                                        logs.Status = "Running";
                                    }


                                    if (logs.StartTime >= maxDateTime)
                                        ef.AddTotbl_SLA_DashboardLogs(logs);


                                }
                                try
                                {
                                    ef.SaveChanges();

                                }
                                catch
                                {
                                    ;
                                }
                                finally {
                                    transactionScope.Complete();
                                }
                            }
                        }


                    }

                }
            }
      }
Пример #4
0
      private static List<string> GetListOfSupressedErrors()
        {
            DashboardEntities ef = new DashboardEntities();

            var query = (from msg in ef.tbl_SLA_DashboardSupressErorrs select msg.IgnoreError).Distinct();

            return query.ToList();

        }