Пример #1
0
 internal static RuntimeException NewInterpreterExceptionByMessage(Type exceptionType, IScriptExtent errorPosition, string message, string errorId, Exception innerException)
 {
     RuntimeException exception;
     if (exceptionType == typeof(ParseException))
     {
         exception = new ParseException(message, errorId, innerException);
     }
     else if (exceptionType == typeof(IncompleteParseException))
     {
         exception = new IncompleteParseException(message, errorId, innerException);
     }
     else
     {
         exception = new RuntimeException(message, innerException);
         exception.SetErrorId(errorId);
         exception.SetErrorCategory(ErrorCategory.InvalidOperation);
     }
     if (errorPosition != null)
     {
         exception.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition));
     }
     return exception;
 }
Пример #2
0
        internal static RuntimeException NewInterpreterExceptionByMessage(Type exceptionType, IScriptExtent errorPosition, string message, string errorId, Exception innerException)
        {
            RuntimeException exception;

            if (exceptionType == typeof(ParseException))
            {
                exception = new ParseException(message, errorId, innerException);
            }
            else if (exceptionType == typeof(IncompleteParseException))
            {
                exception = new IncompleteParseException(message, errorId, innerException);
            }
            else
            {
                exception = new RuntimeException(message, innerException);
                exception.SetErrorId(errorId);
                exception.SetErrorCategory(ErrorCategory.InvalidOperation);
            }
            if (errorPosition != null)
            {
                exception.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition));
            }
            return(exception);
        }
Пример #3
0
        protected override void ProcessRecord()
        {
            qryStartDt = DateTime.Now;
            if (!String.IsNullOrEmpty(TestDateParam))
            {
                if (!DateTime.TryParse(TestDateParam, out qryStartDt))
                {
                    WriteVerbose("TestDate parameter is not in correct date time format.");
                    Exception tex = new IncompleteParseException("TestDate parameter is not in correct date time format.");
                    throw tex;

                }
            }

            WriteVerbose("Test Date:" + TestDate.ToString());

            List< patch_history_log> patchHistList = new List<patch_history_log>();

            string cnStr = Properties.Settings.Default.dbConnString;
            try
            {
                using (SqlConnection cn = new SqlConnection(cnStr))
                {
                    string sql = @"select * from apss_patch_history_log
                                    where action='ADD' and patch_status not in('COMPLETED','ARCHIVED','FAILED') and submit_status = 'SUCCESS'
                                    and scheduled_dt between DATEADD(hh,-24,@start) and DATEADD(hh,-6,@end)";
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, cn))
                    {
                        cmd.Parameters.AddWithValue("@start", qryStartDt);
                        cmd.Parameters.AddWithValue("@end", qryStartDt);

                        using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                        {
                            DataSet ds = new DataSet();

                            sda.Fill(ds);
                            if (ds.Tables.Count > 0)
                            {
                                if (ds.Tables[0].Rows.Count == 1)
                                {

                                }
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    patch_history_log logRec = new patch_history_log();
                                    logRec.compliance_status = dr["compliance_status"].ToString();
                                    logRec.created_dt = DateTime.Parse(dr["created_dt"].ToString());
                                    logRec.month_code = dr["month_code"].ToString();
                                    logRec.patch_engine = dr["patch_engine"].ToString();
                                    logRec.patch_status_msg = dr["patch_status"].ToString();
                                    logRec.patch_status_msg = dr["patch_status_msg"].ToString();
                                    if (!String.IsNullOrEmpty(dr["scheduled_dt"].ToString()))
                                    {
                                        logRec.scheduled_dt = DateTime.Parse(dr["scheduled_dt"].ToString());
                                    }
                                    logRec.server_environment = dr["server_environment"].ToString();
                                    logRec.server_name = dr["server_name"].ToString();
                                    if (!String.IsNullOrEmpty(dr["submitted_dt"].ToString()))
                                    {
                                        logRec.submitted_dt = DateTime.Parse(dr["submitted_dt"].ToString());
                                    }
                                    logRec.submit_status_msg = dr["submit_status"].ToString();
                                    logRec.submit_status_msg = dr["submit_status_msg"].ToString();
                                    logRec.svc_id = int.Parse(dr["svc_id"].ToString());
                                    logRec.collection_name = dr["collection_name"].ToString();
                                    logRec.action = dr["action"].ToString();

                                    patchHistList.Add(logRec);
                                }

                            }

                        }

                    }

                }
            }
            catch (Exception ex)
            {
                WriteVerbose(ex.Message);
                throw ex;
                //MessageBox.Show(recins + " Records processed. Error: " + ex.Message);
            }

            WriteObject(patchHistList);

            base.ProcessRecord();
        }
Пример #4
0
        protected override void ProcessRecord()
        {
            string retVal = "";

            DateTime currSchDt = DateTime.Now;
            if(!String.IsNullOrEmpty(DateParam))
            {
                if(!DateTime.TryParse(DateParam,out currSchDt))
                {
                    WriteVerbose("TestDate parameter is not in correct date time format.");
                    Exception tex = new IncompleteParseException("TestDate parameter is not in correct date time format.");
                    throw tex;
                    //WriteObject(new List<patching_data>());
                    //return;
                }
            }

            currSchDt = currSchDt.AddHours(24);

            List<patching_data> allPatchingData = new List<patching_data>();

            DateTime ckProcessedDtTm = DateTime.Parse(currSchDt.ToShortDateString() + " " + ((currSchDt.Hour < 10 ? "0" + currSchDt.Hour : "" + currSchDt.Hour) + ":00"));

            WriteVerbose("ckProcessedDtTm: " + ckProcessedDtTm.ToString());

            List<string> processedServersForHr = getProcessedForHour(ckProcessedDtTm);

            string cnStr = Properties.Settings.Default.dbConnString;
            try
            {
                using (SqlConnection cn = new SqlConnection(cnStr))
                {
                    string sql = @"usp_GetServerPatchList";

                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand("", cn))
                    {
                        cmd.CommandText = "select * from apss_emergency_config where emergency_status = 1";
                        bool isProdStopActive = false;
                        bool isNonProdStopActive = false;

                        using (SqlDataAdapter esda = new SqlDataAdapter(cmd))
                        {
                            DataSet eds = new DataSet();
                            esda.Fill(eds);
                            DataTable edt = eds.Tables[0];
                            if (edt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in edt.Rows)
                                {
                                    if (dr["server_category"].ToString() == "PRODUCTION SERVERS")
                                    {
                                        isProdStopActive = true;
                                    }
                                    if (dr["server_category"].ToString() == "NON-PRODUCTION SERVERS")
                                    {
                                        isNonProdStopActive = true;
                                    }
                                }
                            }
                        }

                        cmd.CommandText = "select * from apss_frozen_config where can_schedule = 0";
                        bool isFreezeActive = false;

                        using (SqlDataAdapter fsda = new SqlDataAdapter(cmd))
                        {
                            DataSet fds = new DataSet();
                            fsda.Fill(fds);
                            DataTable fdt = fds.Tables[0];
                            if (fdt.Rows.Count > 0)
                            {
                                foreach (DataRow dr in fdt.Rows)
                                {
                                    DateTime frzDtStart = DateTime.Parse(dr["event_date"].ToString().Split(' ')[0] + " " + dr["event_start"].ToString());
                                    DateTime frzDtEnd = DateTime.Parse(dr["event_date"].ToString().Split(' ')[0] + " " + dr["event_end"].ToString());
                                    if (currSchDt >= frzDtStart && currSchDt <= frzDtEnd)
                                    {
                                        isFreezeActive = true;
                                        break;
                                    }
                                }
                            }
                        }

                        if ((isProdStopActive && isNonProdStopActive) || isFreezeActive)
                        { //all stop = create one record where server name = ''ADMINSTOP'
                            string startTm = ((currSchDt.Hour < 10 ? "0" + currSchDt.Hour : "" + currSchDt.Hour) + ":00");
                            patching_data patchingData = new patching_data();
                            DayOfWeek dow = currSchDt.DayOfWeek;
                            //WriteVerbose("DOW: " + currSchDt.DayOfWeek.ToString());

                            patchingData.server_name = "ADMINSTOP";
                            patchingData.scheduled_dt = DateTime.Parse(currSchDt.ToShortDateString() + " " + startTm);

                            patchingData.month_code = "";
                            patchingData.server_os = "Windows";
                            patchingData.server_environment ="Prod";
                            patchingData.dow = dow.ToString();
                            patchingData.sched_start_time = startTm;
                            patchingData.time_zone = "";
                            sccm_collection_data collData = getCollectionData(startTm, currSchDt.DayOfWeek.ToString());
                            if (collData == null)
                            {
                                WriteVerbose("No Collection Info Found.");
                            }
                            else
                            {
                                patchingData.sccm_collection_name = collData.sccm_collection_name;
                            }
                            allPatchingData.Add(patchingData);
                        }
                        else
                        {
                            cmd.CommandType = CommandType.StoredProcedure;

                            cmd.Parameters.AddWithValue("@schDt", currSchDt.ToShortDateString());
                            cmd.Parameters.AddWithValue("@schTm", ((currSchDt.Hour < 10 ? "0" + currSchDt.Hour : "" + currSchDt.Hour) + ":00"));

                            if (isNonProdStopActive)
                            {
                                sql += " and s.server_environment = 'Prod' ";
                            }
                            if (isProdStopActive)
                            {
                                sql += " and s.server_environment = 'Non Prod' ";
                            }

                            cmd.CommandText = sql;

                            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                            {
                                DataSet ds = new DataSet();

                                sda.Fill(ds);
                                if (ds.Tables.Count > 0)
                                {
                                    foreach (DataRow dr in ds.Tables[0].Rows)
                                    {
                                        patching_data patchingData = new patching_data();

                                        string startTm = dr["sched_start_time"].ToString();
                                        if (startTm.Contains(":"))
                                        {
                                            startTm = startTm.Split(':')[0];
                                            startTm = (startTm.Length == 1 ? "0" + startTm : startTm) + ":00";

                                            if (startTm == ((currSchDt.Hour < 10 ? "0" + currSchDt.Hour : "" + currSchDt.Hour) + ":00"))  //"23:00")
                                            {
                                                DayOfWeek dow = currSchDt.DayOfWeek;
                                                //WriteVerbose("DOW: " + currSchDt.DayOfWeek.ToString());

                                                patchingData.server_name = dr["server_name"].ToString();
                                                patchingData.scheduled_dt = DateTime.Parse(currSchDt.ToShortDateString() + " " + startTm);

                                                patchingData.month_code = dr["recurr_code"].ToString();
                                                patchingData.server_os = dr["server_os"].ToString();
                                                patchingData.server_environment = dr["server_environment"].ToString();
                                                patchingData.dow = dow.ToString();
                                                patchingData.sched_start_time = startTm;
                                                patchingData.time_zone = "";

                                                if (patchingData.server_os == "Windows")
                                                {
                                                    sccm_collection_data collData = getCollectionData(startTm, currSchDt.DayOfWeek.ToString());
                                                    if (collData == null)
                                                    {
                                                        WriteVerbose("No Collection Info Found.");
                                                    }
                                                    else
                                                    {
                                                        patchingData.sccm_collection_name = collData.sccm_collection_name;
                                                    }
                                                }

                                                //if server has not been processed then add it
                                                if (!processedServersForHr.Contains(patchingData.server_name))
                                                {
                                                    allPatchingData.Add(patchingData);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                }
                                else
                                {
                                    WriteVerbose("No Data from Service Now");
                                }
                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                WriteVerbose(ex.Message);
                throw ex;
                //MessageBox.Show(recins + " Records processed. Error: " + ex.Message);
            }

            WriteObject(allPatchingData);

            base.ProcessRecord();
        }