Exemple #1
0
        public static LINEData[] checkFreezeVM()
        {
            var msgList = new List <LINEData>();

            string[] VMs     = Config.checkFreezeVM.Split(',');
            bool     isError = false;
            // Check Database
            var dt = SQL.sendSqlQuery(@"SELECT TOP (" + VMs.Length + @") 
                [statusid]
                ,[BPASession].[lastupdated]
                ,[laststage]
	            ,name
                FROM [dbo].[BPASession] 
                inner join [BPAResource] on starterresourceid  = [BPAResource].[resourceid]
                where name in ('" + Config.checkFreezeVM.Replace(",", "','") + @"')
                order by [BPASession].[lastupdated] DESC"
                                      , ref isError);

            if (!isError)
            {
                if (dt.Rows.Count > 0 && savedStatusDt.Rows.Count > 0)
                {
                    foreach (string vm in VMs)
                    {
                        bool      success   = false;
                        DataRow[] curStatus = dt.Select("[name]='" + vm + "'");
                        DataRow[] saved     = savedStatusDt.Select("[name]='" + vm + "'");
                        int       status;

                        success = Int32.TryParse(curStatus[0][0].ToString(), out status); // index 0 = statusid
                        if (success && (status == (int)BPStatus.Running || status == (int)BPStatus.Warning))
                        {
                            if (curStatus[0][2].ToString() == saved[0][2].ToString() && curStatus[0][1].ToString() == saved[0][1].ToString()) // index 2 = laststage, 1 = lastupdated
                            {
                                LINEData expTotalData = new LINEData();
                                expTotalData.message = "\nVM : " + vm + " has been showing same stage for " + Config.checkFreezeInterval + " Seconds" +
                                                       "\nStage : " + curStatus[0][2].ToString() +      // index 2 = laststage
                                                       "\nLast Update : " + curStatus[0][2].ToString(); // index 2 = laststage
                                expTotalData.stickerid  = 173;
                                expTotalData.stickerPkg = 2;
                                msgList.Add(expTotalData);
                            }
                        }
                    }
                }
                savedStatusDt = dt.Copy();
            }

            return(msgList.ToArray());
        }
Exemple #2
0
        public static LINEData[] getStatus()
        {
            var msgList = new List <LINEData>();

            // Check Database
            var dt = SQL.sendSqlQuery("SELECT 1");

            if (dt.Rows.Count == 0)
            {
                LINEData expData = new LINEData();
                expData.message    = "Unable to Connect Database";
                expData.stickerid  = 123;
                expData.stickerPkg = 1;
                msgList.Add(expData);
            }

            // Check App Server
            Ping pingSender = new Ping();

            try
            {
                PingReply reply = pingSender.Send(Config.appServer);
                if (reply.Status != IPStatus.Success)
                {
                    LINEData expData = new LINEData();
                    expData.message    = "Unable to Connect Application Server : " + Config.appServer;
                    expData.stickerid  = 123;
                    expData.stickerPkg = 1;
                    msgList.Add(expData);
                }
            }
            catch (Exception)
            {
                LINEData expData = new LINEData();
                expData.message    = "Unable to Connect Application Server : " + Config.appServer;
                expData.stickerid  = 123;
                expData.stickerPkg = 1;
                msgList.Add(expData);
            }
            return(msgList.ToArray());
        }
Exemple #3
0
        public static LINEData[] getScheduleTerminatedStatus()
        {
            var      msgList  = new List <LINEData>();
            DateTime endUtc   = DateTime.UtcNow;
            DateTime startUtc = endUtc.AddSeconds(Config.availInterval * -1);
            bool     isError  = false;
            // Check Database
            var dt = SQL.sendSqlQuery(@"SELECT 
	              BPASchedule.name as ScheduleName
	              ,BPATask.name as TaskName
                  ,[entrytime]
                  ,[terminationreason]
              FROM [PTTRPA].[dbo].[BPAScheduleLogEntry]
              JOIN [BPAScheduleLog] ON [BPAScheduleLog].[id] = BPAScheduleLogEntry.schedulelogid
              JOIN [BPASchedule] ON BPASchedule.id = BPAScheduleLog.scheduleid
              JOIN BPATask ON BPATask.[id] = BPAScheduleLogEntry.taskid
              Where  (entrytime BETWEEN '" + startUtc.ToString("yyyy-MM-dd HH:mm:ss.fff") + @"' AND  '" + endUtc.ToString("yyyy-MM-dd HH:mm:ss.fff") + @"') AND (terminationreason is not null)
              ORDER BY entrytime DESC"
                                      , ref isError);

            if (isError)
            {
                LINEData expData = new LINEData();
                expData.message    = "Unable to Connect Database";
                expData.stickerid  = 123;
                expData.stickerPkg = 1;
                msgList.Add(expData);
            }
            else if (dt.Rows.Count > 0)
            {
                string[] ignoreList = Config.ignoreAvailSchedule.Split(',');
                foreach (DataRow dr in dt.Rows)
                {
                    bool isIgnore = false;
                    foreach (string ignore in ignoreList)
                    {
                        if (dr["ScheduleName"].ToString().Contains(ignore))
                        {
                            isIgnore = true;
                        }
                    }
                    if (isIgnore == false)
                    {
                        LINEData expData = new LINEData();
                        expData.message  = "Schedule : " + dr["ScheduleName"].ToString();
                        expData.message += "\nTask : " + dr["TaskName"].ToString();
                        expData.message += "\nReason : " + dr["terminationreason"].ToString();
                        expData.message += "\nTime : " + DateTime.Parse(dr["entrytime"].ToString()).AddHours(7).ToString("yyyy-MM-dd HH:mm:ss");
                        msgList.Add(expData);
                    }
                }
                if (msgList.Count > 0)
                {
                    LINEData expTotalData = new LINEData();
                    expTotalData.message    = "Total Terminated : " + msgList.Count;
                    expTotalData.stickerid  = 173;
                    expTotalData.stickerPkg = 2;
                    msgList.Add(expTotalData);
                }
            }
            var resDt = SQL.sendSqlQuery(@"SELECT
                  [name]
                  ,[status]
                  ,[DisplayStatus]
              FROM [BPAResource]
              Where DisplayStatus = 'Missing' And name NOT Like '%-U%'");

            if (resDt.Rows.Count > 0)
            {
                foreach (DataRow dr in resDt.Rows)
                {
                    LINEData expData = new LINEData();
                    expData.message  = "Resource : " + dr["name"].ToString();
                    expData.message += "\nDisplayStatus : " + dr["DisplayStatus"].ToString();
                    msgList.Add(expData);
                }
            }
            return(msgList.ToArray());
        }
        public static LINEData[] getStatus()
        {
            var      msgList        = new List <LINEData>();
            var      date           = DateTime.Now;
            string   inputPath      = Config.mecInputPath;
            string   robotLogPath   = Path.Combine(Config.mecDailyPath, DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyyMMdd"), "Robot Logs");
            string   path           = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp");
            string   dailyfile      = Path.Combine(path, "mecDaily.xlsx");
            string   msgFile        = Path.Combine(path, "mecMsg.xlsx");
            string   inputFile      = Path.Combine(path, "mecInput.xlsm");
            string   configFile     = Path.Combine(path, "mecConfig.xlsx");
            bool     isCompleted    = false;
            bool     isSysException = false;
            bool     isException    = false;
            LINEData data           = new LINEData();
            string   status         = "\n";

            status += "================\n";
            status += "|      MEC Status      |\n";
            status += "================\n";

            int curWorkingDay = BusinessDay.getCurrentWorkingDay(Config.calendarPTT);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (Directory.Exists(robotLogPath) && Directory.Exists(inputPath))
            {
                DirectoryInfo info  = new DirectoryInfo(robotLogPath);
                FileInfo[]    files = info.GetFiles("*.xlsx", SearchOption.TopDirectoryOnly).OrderByDescending(p => p.CreationTime).ToArray();
                info = new DirectoryInfo(inputPath);
                FileInfo[] inputFiles = info.GetFiles("*.xlsm", SearchOption.TopDirectoryOnly).Where(f => !f.Attributes.HasFlag(FileAttributes.Hidden)).ToArray();
                if (files.Count() > 0 && inputFiles.Count() > 0 && File.Exists(files[0].FullName) && File.Exists(inputFiles[0].FullName))
                {
                    if (File.Exists(dailyfile))
                    {
                        File.SetAttributes(dailyfile, FileAttributes.Normal);
                    }
                    File.Copy(files[0].FullName, dailyfile, true);

                    if (File.Exists(inputFile))
                    {
                        File.SetAttributes(inputFile, FileAttributes.Normal);
                    }
                    File.Copy(inputFiles[0].FullName, inputFile, true);

                    if (File.Exists(configFile))
                    {
                        File.SetAttributes(configFile, FileAttributes.Normal);
                    }
                    File.Copy(Config.mecConfig, configFile, true);

                    DataTable dailyDt   = ExcelData.readData(dailyfile);
                    DataTable inputDt   = ExcelData.readData(inputFile);
                    DataTable configDt  = ExcelData.readData(configFile, 1);
                    string    dateField = "Monthly Date";
                    string    schedule  = "Monthly";

                    if ((date.Month % 3) == 1)
                    {
                        dateField = "Quarterly Date";
                        schedule  = "Quarterly";
                    }
                    string expression = "((([" + dateField + "] = '" + date.Day + "') AND ([Calendar Type] = 'Calendar')) OR (([" + dateField + "] = '" + curWorkingDay + "') AND ([Calendar Type] = 'Workday')) OR ([Calendar Type] = 'Custom1')) AND ([Schedule] = '" + schedule + "')";
                    var    selected   = inputDt.Select(expression);
                    if (selected.Length > 0)
                    {
                        inputDt = selected.CopyToDataTable();

                        foreach (DataRow dr in dailyDt.Rows)
                        {
                            if (!inputDt.AsEnumerable().Select(x => x["Mail Trigger Process Name"]).ToList().Contains(dr["Mail Trigger Process Name"]))
                            {
                                DataRow toInsert = inputDt.NewRow();
                                toInsert["Mail Trigger Process Name"] = dr["Mail Trigger Process Name"];
                                toInsert["Task Status"]          = dr["Task Status"];
                                toInsert["Parameter"]            = dr["Parameter"];
                                toInsert["Trigger"]              = dr["Trigger"];
                                toInsert["Notification Time"]    = dr["Notification Time"];
                                toInsert["Process Dependencies"] = dr["Process Dependencies"];
                                toInsert["Remark"]        = dr["Remark"];
                                toInsert["VM Assignment"] = dr["VM Assignment"];
                                inputDt.Rows.InsertAt(toInsert, inputDt.Rows.Count - 1);
                            }
                        }

                        DataRow[] filterDr = inputDt.Select();
                        if (filterDr.Length > 0)
                        {
                            data.message    = status;
                            data.stickerid  = 0;
                            data.stickerPkg = 0;
                            var customDr  = inputDt.Select("[Calendar Type]='Custom1'");
                            int skipCount = 0;
                            foreach (var dr in customDr)
                            {
                                if (dr["Task Status"].ToString() == "")
                                {
                                    skipCount++;
                                }
                            }
                            msgList.Add(data);
                            foreach (DataRow dr in filterDr)
                            {
                                if (dr["Calendar Type"].ToString() == "Custom1" && DateTime.Now.Day != BusinessDay.getSalaryDay(Config.calendarPTT, Int32.Parse(dr[dateField].ToString())))
                                {
                                    continue;
                                }
                                else if (dr["Calendar Type"].ToString() == "Custom1" && DateTime.Now.Day == BusinessDay.getSalaryDay(Config.calendarPTT, Int32.Parse(dr[dateField].ToString())))
                                {
                                    skipCount--;
                                    if (skipCount < 0)
                                    {
                                        skipCount = 0;
                                    }
                                }
                                string processName = dr["Mail Trigger Process Name"].ToString();
                                isSysException = false;
                                isException    = false;
                                if (processName != "")
                                {
                                    string taskStatus = dr["Task Status"].ToString();
                                    string parameter  = dr["Parameter"].ToString();
                                    if (isCompleted == false)
                                    {
                                        int total        = filterDr.Length - skipCount;
                                        int completedCnt = inputDt.Select("[Task Status]='Completed'").Length;
                                        msgList[0].message += "Completed Processes (" + completedCnt + "/" + total + ") : ";
                                        if (total == completedCnt)
                                        {
                                            msgList[0].stickerid  = 22;
                                            msgList[0].stickerPkg = 2;
                                        }
                                        msgList[0].notificationDisabled = true;
                                        isCompleted = true;
                                    }

                                    if (taskStatus == "Completed")
                                    {
                                        msgList[0].message += "\n" + processName;
                                    }
                                    else if (taskStatus == "")
                                    {
                                        string msg     = processName + "\n";
                                        string trigger = dr["Trigger"].ToString();
                                        if (trigger == "Mail")
                                        {
                                            msg += "Status : Waiting for Mail\n";
                                            msg += "Run Command : " + getRerunCmd(processName, parameter) + "\n";
                                            msg += "Time : " + convertNotification(dr["Notification Time"]) + "\n";
                                            DataRow[] configDr = configDt.Select("[Mail Trigger Process Name] = '" + processName + "'");
                                            msg += "Robot Controller : " + configDr[0]["Email_BotController"];
                                        }
                                        else if (trigger == "Task")
                                        {
                                            msg += "Status : Waiting for Task(s) to complete\n";
                                            msg += "Dependencies : " + dr["Process Dependencies"];
                                        }
                                        else
                                        {
                                            msg += "Trigger : " + trigger + "\n";
                                            msg += "Dependencies : " + dr["Process Dependencies"];
                                        }
                                        LINEData pendingData = new LINEData();
                                        pendingData.message    = msg;
                                        pendingData.stickerid  = 0;
                                        pendingData.stickerPkg = 0;
                                        msgList.Add(pendingData);
                                    }
                                    else
                                    {
                                        string   remark       = dr["Remark"].ToString();
                                        string   exceptionMsg = processName + "\n";
                                        LINEData expData      = new LINEData();
                                        exceptionMsg += "Status : " + taskStatus + "\n";
                                        if (taskStatus == "In Progress")
                                        {
                                            exceptionMsg += "Running on : " + dr["VM Assignment"];
                                        }
                                        else if (taskStatus.Contains("Exception"))
                                        {
                                            exceptionMsg += "Reason : " + remark;


                                            exceptionMsg += "\nRerun : Run " + getRerunCmd(processName, parameter);

                                            if (!remark.Contains("Business"))
                                            {
                                                isSysException = true;
                                            }
                                            isException = true;
                                        }
                                        else if (taskStatus.Contains("SCHEDULED"))
                                        {
                                            exceptionMsg += "Expected Time : " + convertNotification(dr["Start Time"]);
                                        }
                                        if (isSysException)
                                        {
                                            expData.message              = exceptionMsg;
                                            expData.stickerid            = 173;
                                            expData.stickerPkg           = 2;
                                            expData.notificationDisabled = false;
                                            msgList.Add(expData);
                                        }
                                        else
                                        {
                                            if (isException)
                                            {
                                                expData.notificationDisabled = false;
                                            }
                                            else
                                            {
                                                expData.notificationDisabled = true;
                                            }
                                            expData.message    = exceptionMsg;
                                            expData.stickerid  = 0;
                                            expData.stickerPkg = 0;
                                            msgList.Add(expData);
                                        }
                                    }
                                }
                            }
                        }

                        if (isCompleted == false)
                        {
                            msgList[0].message += "\n No Completed Found";
                        }
                    }
                }
            }
            DataTable msgDt      = ExcelData.readData(msgFile);
            var       newMsgList = new List <LINEData>();

            foreach (LINEData msg in msgList)
            {
                var found = msgDt.Select("[message]='" + msg.message.Replace("\r", "") + "'");
                if (found.Length == 0)
                {
                    LINEData newMsg = new LINEData();
                    newMsg.message              = msg.message;
                    newMsg.stickerid            = msg.stickerid;
                    newMsg.stickerPkg           = msg.stickerPkg;
                    newMsg.notificationDisabled = msg.notificationDisabled;
                    newMsgList.Add(newMsg);
                }
            }
            ExcelData.saveTableToExcel(msgFile, "Message", CreateDataTable(msgList));

            return(newMsgList.ToArray());
        }