コード例 #1
0
        /// <summary>
        /// Retrieves the object for a specific schedule.
        /// </summary>
        /// <param name="scheduleName">Name of the schedule to get.</param>
        /// <returns>Schedule object.</returns>
        public PFSchedule GetScheduleByName(string scheduleName)
        {
            PFList <PFSchedule> scheduleList = null;
            PFSchedule          schedule     = null;

            if (this.ScheduleStorageType == enScheduleStorageType.XMLFiles)
            {
                scheduleList = GetScheduleListXML();
            }
            else if (this.ScheduleStorageType == enScheduleStorageType.Database)
            {
                scheduleList = GetScheduleListDatabase();
            }
            else
            {
                _msg.Length = 0;
                _msg.Append("Invalid or missing ScheduleStorageType: ");
                _msg.Append(this.ScheduleStorageType.ToString());
                throw new System.Exception(_msg.ToString());
            }

            _scheduleList = scheduleList;

            for (int i = 0; i < scheduleList.Count; i++)
            {
                if (scheduleName.ToUpper() == scheduleList[i].Name.ToUpper())
                {
                    schedule = scheduleList[i];
                    break;
                }
            }

            return(schedule);
        }
コード例 #2
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static void LoadMonthlySchedule(MainForm frm, PFSchedule sked)
        {
            LoadDailySchedule(frm, sked);

            if (sked.MonthlyScheduleMonthIdType == enMonthlyScheduleMonthIdType.EveryNumMonths)
            {
                frm.optOccursEveryMonthNum.Checked   = true;
                frm.txtMonthlyOccursIntervalNum.Text = sked.MonthlyOccursEveryNumMonths.ToString();
            }
            else if (sked.MonthlyScheduleMonthIdType == enMonthlyScheduleMonthIdType.OccursDuringMonthName)
            {
                frm.optOccursDuringMonthName.Checked = true;
                frm.chkMonthlyJan.Checked            = sked.MonthlySchedule.Month[1];
                frm.chkMonthlyFeb.Checked            = sked.MonthlySchedule.Month[2];
                frm.chkMonthlyMar.Checked            = sked.MonthlySchedule.Month[3];
                frm.chkMonthlyApr.Checked            = sked.MonthlySchedule.Month[4];
                frm.chkMonthlyMay.Checked            = sked.MonthlySchedule.Month[5];
                frm.chkMonthlyJun.Checked            = sked.MonthlySchedule.Month[6];
                frm.chkMonthlyJul.Checked            = sked.MonthlySchedule.Month[7];
                frm.chkMonthlyAug.Checked            = sked.MonthlySchedule.Month[8];
                frm.chkMonthlySep.Checked            = sked.MonthlySchedule.Month[9];
                frm.chkMonthlyOct.Checked            = sked.MonthlySchedule.Month[10];
                frm.chkMonthlyNov.Checked            = sked.MonthlySchedule.Month[11];
                frm.chkMonthlyDec.Checked            = sked.MonthlySchedule.Month[12];
            }
            else
            {
                frm.optOccursEveryMonthNum.Checked   = true;
                frm.txtMonthlyOccursIntervalNum.Text = "1";
            }

            if (sked.MonthlyScheduleDayIdType == enMonthlyScheduleDayIdType.DayName)
            {
                frm.cboMonthlyDayNameOrdinal.Enabled = true;
                frm.cboMonthlyDayName.Enabled        = true;
                frm.optMonthlyDayName.Checked        = true;
                frm.cboMonthlyDayNameOrdinal.Text    = sked.MonthlyScheduleOrdinal.ToString();
                frm.cboMonthlyDayName.Text           = sked.MonthlyScheduleDay.ToString();
                frm.txtMonthlyDayNumber.Text         = "1";
                frm.txtMonthlyDayNumber.Enabled      = false;
            }
            else if (sked.MonthlyScheduleDayIdType == enMonthlyScheduleDayIdType.DayNumber)
            {
                frm.cboMonthlyDayNameOrdinal.Enabled = false;
                frm.cboMonthlyDayName.Enabled        = false;
                frm.txtMonthlyDayNumber.Enabled      = true;
                frm.optMonthlyDayNumber.Checked      = true;
                frm.txtMonthlyDayNumber.Text         = sked.MonthlyDayNumber.ToString();
            }
            else
            {
                frm.cboMonthlyDayNameOrdinal.Enabled = false;
                frm.cboMonthlyDayName.Enabled        = false;
                frm.txtMonthlyDayNumber.Enabled      = true;
                frm.optMonthlyDayName.Checked        = false;
                frm.optMonthlyDayNumber.Checked      = true;
                frm.txtMonthlyDayNumber.Text         = "1";
            }
        }
コード例 #3
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        public static void CreateScreenInputFromSchedule(MainForm frm, PFSchedule sked)
        {
            try
            {
                _msg.Length = 0;
                _msg.Append("CreateScreenInputFromSchedule started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                frm.InitializeForm();

                frm.cboScheduleFrequency.Text  = sked.ScheduleFrequency.ToString();
                frm.txtScheduleName.Text       = sked.Name;
                frm.txtRunWindowInMinutes.Text = sked.RunWindow.TotalMinutes.ToString();
                frm.txtScheduleStart.Text      = sked.ScheduleStartDate.ToString("MM/dd/yyyy HH:mm:ss");
                frm.txtScheduleEnd.Text        = sked.ScheduleEndDate.ToString("MM/dd/yyyy HH:mm:ss");

                frm.txtCurrDateTime.Text       = sked.TestCurrDateTime.ToString("MM/dd/yyyy HH:mm:ss");
                frm.cboExpectedTestResult.Text = sked.ExpectedTestResult.ToString();

                switch (sked.ScheduleFrequency)
                {
                case enScheduleFrequency.OneTime:
                    LoadRunOneTimeSchedule(frm, sked);
                    break;

                case enScheduleFrequency.Daily:
                    LoadDailySchedule(frm, sked);
                    break;

                case enScheduleFrequency.Weekly:
                    LoadWeeklySchedule(frm, sked);
                    break;

                case enScheduleFrequency.Monthly:
                    LoadMonthlySchedule(frm, sked);
                    break;

                default:
                    _msg.Length = 0;
                    _msg.Append("Unexpected or invalid schedule frequency: ");
                    _msg.Append(frm.txtScheduleName.Text.Trim());
                    throw new System.Exception(_msg.ToString());
                    //break;
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... CreateScreenInputFromSchedule finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #4
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        public static PFSchedule CreateScheduleFromScreenInput(MainForm frm)
        {
            PFSchedule sked = new PFSchedule(frm.txtScheduleName.Text.Trim());

            try
            {
                _msg.Length = 0;
                _msg.Append("CreateScheduleFromScreenInput started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                enScheduleFrequency skedFreq = PFScheduler.GetScheduleFrequency(frm.cboScheduleFrequency.Text.Trim());

                if (frm.txtCurrDateTime.Text.Trim().Length == 0)
                {
                    frm.txtCurrDateTime.Text = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
                }

                switch (skedFreq)
                {
                case enScheduleFrequency.OneTime:
                    CreateRunOneTimeSchedule(frm, sked);
                    break;

                case enScheduleFrequency.Daily:
                    CreateDailySchedule(frm, sked);
                    break;

                case enScheduleFrequency.Weekly:
                    CreateWeeklySchedule(frm, sked);
                    break;

                case enScheduleFrequency.Monthly:
                    CreateMonthlySchedule(frm, sked);
                    break;

                default:
                    _msg.Length = 0;
                    _msg.Append("Unexpected or invalid schedule frequency: ");
                    _msg.Append(frm.txtScheduleName.Text.Trim());
                    throw new System.Exception(_msg.ToString());
                    //break;
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... CreateScheduleFromScreenInput finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }

            return(sked);
        }
コード例 #5
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static void LoadWeeklySchedule(MainForm frm, PFSchedule sked)
        {
            LoadDailySchedule(frm, sked);

            frm.txtWeeklyRecursEveryNumDays.Text = sked.WeeklyOccursEveryNumWeeks.ToString();
            frm.chkWeeklyMonday.Checked          = sked.WeeklySchedule.Day[0];
            frm.chkWeeklyTuesday.Checked         = sked.WeeklySchedule.Day[1];
            frm.chkWeeklyWednesday.Checked       = sked.WeeklySchedule.Day[2];
            frm.chkWeeklyThursday.Checked        = sked.WeeklySchedule.Day[3];
            frm.chkWeeklyFriday.Checked          = sked.WeeklySchedule.Day[4];
            frm.chkWeeklySaturday.Checked        = sked.WeeklySchedule.Day[5];
            frm.chkWeeklySunday.Checked          = sked.WeeklySchedule.Day[6];
        }
コード例 #6
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static void CreateMonthlySchedule(MainForm frm, PFSchedule sked)
        {
            CreateDailySchedule(frm, sked);

            sked.ScheduleFrequency = enScheduleFrequency.Monthly;

            sked.ScheduleOccursEveryNumDays = 1;

            if (frm.optOccursEveryMonthNum.Checked)
            {
                sked.MonthlyScheduleMonthIdType  = enMonthlyScheduleMonthIdType.EveryNumMonths;
                sked.MonthlyOccursEveryNumMonths = Convert.ToInt32(frm.txtMonthlyOccursIntervalNum.Text.Trim());
            }
            else if (frm.optOccursDuringMonthName.Checked)
            {
                sked.MonthlyScheduleMonthIdType = enMonthlyScheduleMonthIdType.OccursDuringMonthName;
                sked.MonthlySchedule.Month[1]   = frm.chkMonthlyJan.Checked;
                sked.MonthlySchedule.Month[2]   = frm.chkMonthlyFeb.Checked;
                sked.MonthlySchedule.Month[3]   = frm.chkMonthlyMar.Checked;
                sked.MonthlySchedule.Month[4]   = frm.chkMonthlyApr.Checked;
                sked.MonthlySchedule.Month[5]   = frm.chkMonthlyMay.Checked;
                sked.MonthlySchedule.Month[6]   = frm.chkMonthlyJun.Checked;
                sked.MonthlySchedule.Month[7]   = frm.chkMonthlyJul.Checked;
                sked.MonthlySchedule.Month[8]   = frm.chkMonthlyAug.Checked;
                sked.MonthlySchedule.Month[9]   = frm.chkMonthlySep.Checked;
                sked.MonthlySchedule.Month[10]  = frm.chkMonthlyOct.Checked;
                sked.MonthlySchedule.Month[11]  = frm.chkMonthlyNov.Checked;
                sked.MonthlySchedule.Month[12]  = frm.chkMonthlyDec.Checked;
            }
            else
            {
                sked.MonthlyScheduleMonthIdType = enMonthlyScheduleMonthIdType.Unknown;
            }

            if (frm.optMonthlyDayName.Checked)
            {
                sked.MonthlyScheduleDayIdType = enMonthlyScheduleDayIdType.DayName;
                sked.MonthlyScheduleOrdinal   = PFScheduler.GetMonthlyScheduleOrdinal(frm.cboMonthlyDayNameOrdinal.Text.Trim());
                sked.MonthlyScheduleDay       = PFScheduler.GetScheduleDay(frm.cboMonthlyDayName.Text.Trim());
            }
            else if (frm.optMonthlyDayNumber.Checked)
            {
                sked.MonthlyScheduleDayIdType = enMonthlyScheduleDayIdType.DayNumber;
                sked.MonthlyDayNumber         = Convert.ToInt32(frm.txtMonthlyDayNumber.Text.Trim());
            }
            else
            {
                sked.MonthlyScheduleDayIdType = enMonthlyScheduleDayIdType.Unknown;
            }
        }
コード例 #7
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static void CreateRunOneTimeSchedule(MainForm frm, PFSchedule sked)
        {
            sked.ScheduleFrequency = enScheduleFrequency.OneTime;
            sked.RunAt             = Convert.ToDateTime(frm.txtRunOnceAt.Text.Trim());
            TimeSpan runWindow = new TimeSpan(0, Convert.ToInt32(frm.txtRunWindowInMinutes.Text.Trim()), 0);

            sked.RunWindow                  = runWindow;
            sked.ScheduleStartDate          = Convert.ToDateTime(frm.txtRunOnceAt.Text.Trim());
            sked.ScheduleEndDate            = Convert.ToDateTime(frm.txtRunOnceAt.Text.Trim()).Add(sked.RunWindow);
            frm.txtScheduleStart.Text       = sked.ScheduleStartDate.ToString("MM/dd/yyyy HH:mm:ss");
            frm.txtScheduleEnd.Text         = sked.ScheduleEndDate.ToString("MM/dd/yyyy HH:mm:ss");
            sked.ScheduleOccursEveryNumDays = 1;
            sked.TestCurrDateTime           = Convert.ToDateTime(frm.txtCurrDateTime.Text.Trim());
            sked.ExpectedTestResult         = PFScheduler.GetScheduleLookupResult(frm.cboExpectedTestResult.Text);
        }
コード例 #8
0
        public static void ShowScheduleDetailXml(MainForm frm)
        {
            PFSchedule sked                      = null;
            string     connectionString          = string.Empty;
            string     scheduleDefinitionsFolder = string.Empty;
            string     scheduleFileName          = string.Empty;

            try
            {
                _msg.Length = 0;
                _msg.Append("ShowScheduleDetail started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                if (frm.txtTaskSchedule.Text.Trim().Length == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify the name of the schedule for ShowScheduleDetail.");
                    throw new System.Exception(_msg.ToString());
                }

                InitFolderPaths();

                scheduleDefinitionsFolder = _scheduleDefinitionsFolder;
                scheduleFileName          = Path.GetFileNameWithoutExtension(frm.txtTaskSchedule.Text) + ".xml";

                connectionString = Path.Combine(scheduleDefinitionsFolder, scheduleFileName);

                sked = PFSchedule.LoadFromXmlFile(connectionString);

                _msg.Length = 0;
                _msg.Append(sked.ToXmlString());
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... ShowScheduleDetail finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: mcondon013/pfcodelibrary
        private void SaveScheduleToFile()
        {
            if (this.chkEraseOutputBeforeEachTest.Checked)
            {
                Program._messageLog.Clear();
            }

            try
            {
                string filename    = string.Empty;
                string configValue = AppConfig.GetStringValueFromConfigFile("ScheduleFilesFolder", string.Empty);
                if (configValue.Trim().Length > 0)
                {
                    _saveSelectionsFolder = configValue;
                }
                if (this.txtScheduleName.Text.Trim().Length == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify a name for the schedule.");
                    throw new System.Exception(_msg.ToString());
                }
                _saveSelectionsFile = this.txtScheduleName.Text + ".xml";
                DialogResult res = ShowSaveFileDialog();
                if (res == DialogResult.OK)
                {
                    filename = _saveSelectionsFile;
                    PFSchedule sked = Tests.CreateScheduleFromScreenInput(this);
                    sked.SaveToXmlFile(filename);
                    if (this.txtScheduleName.Text.Trim().Length == 0)
                    {
                        this.txtScheduleName.Text = Path.GetFileNameWithoutExtension(filename);
                    }
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        }
コード例 #10
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static void CreateWeeklySchedule(MainForm frm, PFSchedule sked)
        {
            CreateDailySchedule(frm, sked);

            sked.ScheduleFrequency = enScheduleFrequency.Weekly;

            sked.ScheduleOccursEveryNumDays = 1;

            sked.WeeklyOccursEveryNumWeeks = Convert.ToInt32(frm.txtWeeklyRecursEveryNumDays.Text.Trim());
            sked.WeeklySchedule.Day[0]     = frm.chkWeeklyMonday.Checked;
            sked.WeeklySchedule.Day[1]     = frm.chkWeeklyTuesday.Checked;
            sked.WeeklySchedule.Day[2]     = frm.chkWeeklyWednesday.Checked;
            sked.WeeklySchedule.Day[3]     = frm.chkWeeklyThursday.Checked;
            sked.WeeklySchedule.Day[4]     = frm.chkWeeklyFriday.Checked;
            sked.WeeklySchedule.Day[5]     = frm.chkWeeklySaturday.Checked;
            sked.WeeklySchedule.Day[6]     = frm.chkWeeklySunday.Checked;
        }
コード例 #11
0
 private static void PrintResult(PFSchedule sked, DateTime currTime, bool result, bool expectedResult)
 {
     _msg.Length = 0;
     _msg.Append(sked.DailyFrequency.ToString());
     _msg.Append(": ");
     _msg.Append(currTime.ToString());
     if (result == expectedResult)
     {
         _msg.Append(" matches expected result. ");
     }
     else
     {
         _msg.Append(" DOES NOT MATCH expected result. ");
     }
     _msg.Append(sked.ScheduleLookupResult.ToString());
     Program._messageLog.WriteLine(_msg.ToString());
 }
コード例 #12
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static void CreateDailySchedule(MainForm frm, PFSchedule sked)
        {
            sked.ScheduleFrequency = enScheduleFrequency.Daily;
            TimeSpan runWindow = new TimeSpan(0, Convert.ToInt32(frm.txtRunWindowInMinutes.Text.Trim()), 0);

            sked.RunWindow         = runWindow;
            sked.ScheduleStartDate = Convert.ToDateTime(frm.txtScheduleStart.Text.Trim());
            sked.ScheduleEndDate   = Convert.ToDateTime(frm.txtScheduleEnd.Text.Trim());

            sked.TestCurrDateTime   = Convert.ToDateTime(frm.txtCurrDateTime.Text.Trim());
            sked.ExpectedTestResult = PFScheduler.GetScheduleLookupResult(frm.cboExpectedTestResult.Text);


            if (frm.optDailyRunOnce.Checked)
            {
                sked.DailyFrequency = enDailyFrequency.OneTime;
            }
            else if (frm.optDailyRecurring.Checked)
            {
                sked.DailyFrequency = enDailyFrequency.Recurring;
            }
            else
            {
                sked.DailyFrequency = enDailyFrequency.Unknown;
            }

            if (sked.DailyFrequency == enDailyFrequency.OneTime)
            {
                sked.OccursOnceAtTime           = PFScheduler.GetTimeSpan(frm.txtDailyRunOnceAt.Text);
                sked.ScheduleOccursEveryNumDays = Convert.ToInt32(frm.txtScheduleRunsEveryNumDays.Text.Trim());
            }
            else if (sked.DailyFrequency == enDailyFrequency.Recurring)
            {
                sked.ScheduleOccursEveryNumDays   = Convert.ToInt32(frm.txtScheduleRunsEveryNumDays.Text.Trim());
                sked.DailyOccursEveryTimeInterval = Convert.ToInt32(frm.txtDailyOccursEveryIntervalNum.Text.Trim());
                sked.DailyOccursTimeInterval      = PFScheduler.GetDailyOccursInterval(frm.cboDailyOccursInterval.Text);
                sked.DailyOccursStartTime         = PFScheduler.GetTimeSpan(frm.txtOccursStartingAt.Text.Trim());
                sked.DailyOccursEndTime           = PFScheduler.GetTimeSpan(frm.txtOccursEndsAt.Text.Trim());
            }
            else
            {
                sked.DailyFrequency = enDailyFrequency.Unknown;
            }
        }
コード例 #13
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static void RunOneTimeTest(MainForm frm)
        {
            PFSchedule             sked         = new PFSchedule(frm.txtScheduleName.Text.Trim());
            bool                   isScheduled  = false;
            enScheduleLookupResult lookupResult = enScheduleLookupResult.Unknown;

            CreateRunOneTimeSchedule(frm, sked);

            isScheduled  = sked.DateIsScheduled(sked.TestCurrDateTime);
            lookupResult = sked.ScheduleLookupResult;


            _msg.Length = 0;
            _msg.Append("Schedule type:        ");
            _msg.Append(sked.ScheduleFrequency.ToString());
            _msg.Append("\r\n");
            _msg.Append("Schedule Name:        ");
            _msg.Append(sked.Name);
            _msg.Append("\r\n");
            _msg.Append("RunAt date:           ");
            _msg.Append(sked.RunAt.ToString("MM/dd/yyyy HH:mm:ss"));
            _msg.Append("\r\n");
            _msg.Append("Test date:            ");
            _msg.Append(sked.TestCurrDateTime.ToString("MM/dd/yyyy HH:mm:ss"));
            _msg.Append("\r\n");
            _msg.Append("Actual result:        ");
            _msg.Append(lookupResult.ToString());
            _msg.Append("\r\n");
            _msg.Append("Expected test result: ");
            _msg.Append(sked.ExpectedTestResult.ToString());
            _msg.Append("\r\n");
            _msg.Append("Success/Failure:      ");
            if (sked.ExpectedTestResult == lookupResult)
            {
                _msg.Append("SUCCESS");
            }
            else
            {
                _msg.Append("FAIL");
            }
            _msg.Append("\r\n");
            Program._messageLog.WriteLine(_msg.ToString());
        }
コード例 #14
0
        private PFList <PFSchedule> GetScheduleListXML()
        {
            PFList <PFSchedule> scheduleList = new PFList <PFSchedule>();

            string[] scheduleFiles = null;


            scheduleFiles = Directory.GetFiles(this.ConnectionString, "*.xml", SearchOption.TopDirectoryOnly);

            if (scheduleFiles != null)
            {
                for (int i = 0; i < scheduleFiles.Length; i++)
                {
                    PFSchedule schedule = PFSchedule.LoadFromXmlFile(scheduleFiles[i]);
                    scheduleList.Add(schedule);
                }
            }

            return(scheduleList);
        }
コード例 #15
0
ファイル: MainForm.cs プロジェクト: mcondon013/pfcodelibrary
        private void SaveScheduleToDatabase()
        {
            string connectionString = _taskDefsDbConnectionString;

            if (this.chkEraseOutputBeforeEachTest.Checked)
            {
                Program._messageLog.Clear();
            }



            try
            {
                if (this.txtScheduleName.Text.Trim().Length == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify a name for the schedule.");
                    throw new System.Exception(_msg.ToString());
                }

                PFSchedule sked = Tests.CreateScheduleFromScreenInput(this);
                sked.SaveToDatabase(connectionString);

                _msg.Length = 0;
                _msg.Append("\r\nSchedule saved to ");
                _msg.Append(connectionString);
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        }
コード例 #16
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static string GetScheduledMonthDaysList(PFSchedule sked)
        {
            StringBuilder scheduledMonths    = new StringBuilder();
            int           numMonthsScheduled = 0;

            for (int i = 0; i < sked.MonthlySchedule.Month.Length; i++)
            {
                if (sked.MonthlySchedule.Month[i] == true)
                {
                    numMonthsScheduled++;
                    enScheduleMonth mo = (enScheduleMonth)i;

                    if (numMonthsScheduled > 1)
                    {
                        scheduledMonths.Append(", ");
                    }
                    scheduledMonths.Append(mo.ToString());
                }
            }

            return(scheduledMonths.ToString());
        }
コード例 #17
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        private static string GetScheduledDaysList(PFSchedule sked)
        {
            StringBuilder scheduledDays    = new StringBuilder();
            int           numDaysScheduled = 0;

            for (int i = 0; i < sked.WeeklySchedule.Day.Length; i++)
            {
                if (sked.WeeklySchedule.Day[i] == true)
                {
                    numDaysScheduled++;
                    enScheduleDay day = (enScheduleDay)i;

                    if (numDaysScheduled > 1)
                    {
                        scheduledDays.Append(", ");
                    }
                    scheduledDays.Append(day.ToString());
                }
            }

            return(scheduledDays.ToString());
        }
コード例 #18
0
        private PFList <PFSchedule> GetScheduleListDatabase()
        {
            PFList <PFSchedule> scheduleList = new PFList <PFSchedule>();
            PFDatabase          db           = null;

            try
            {
                db = new PFDatabase(DatabasePlatform.SQLServerCE35);
                db.ConnectionString = this.ConnectionString;
                db.OpenConnection();

                DbDataReader rdr = db.RunQueryDataReader(_scheduleDefinitionsSelectAllSQL, System.Data.CommandType.Text);

                while (rdr.Read())
                {
                    string     str      = rdr["ScheduleObject"].ToString();
                    PFSchedule schedule = PFSchedule.LoadFromXmlString(str);
                    scheduleList.Add(schedule);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
            }



            return(scheduleList);
        }
コード例 #19
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
 private static void LoadDailySchedule(MainForm frm, PFSchedule sked)
 {
     if (sked.DailyFrequency == enDailyFrequency.OneTime)
     {
         frm.optDailyRunOnce.Checked          = true;
         frm.txtDailyRunOnceAt.Text           = PFScheduler.FormatTimeSpan(sked.OccursOnceAtTime);
         frm.txtScheduleRunsEveryNumDays.Text = sked.ScheduleOccursEveryNumDays.ToString();
     }
     else if (sked.DailyFrequency == enDailyFrequency.Recurring)
     {
         frm.optDailyRecurring.Checked           = true;
         frm.txtScheduleRunsEveryNumDays.Text    = sked.ScheduleOccursEveryNumDays.ToString();
         frm.txtDailyOccursEveryIntervalNum.Text = sked.DailyOccursEveryTimeInterval.ToString();
         frm.cboDailyOccursInterval.Text         = sked.DailyOccursTimeInterval.ToString();
         frm.txtOccursStartingAt.Text            = PFScheduler.FormatTimeSpan(sked.DailyOccursStartTime);
         frm.txtOccursEndsAt.Text = PFScheduler.FormatTimeSpan(sked.DailyOccursEndTime);
     }
     else
     {
         frm.optDailyRunOnce.Checked   = false;
         frm.optDailyRecurring.Checked = false;
     }
 }
コード例 #20
0
ファイル: MainForm.cs プロジェクト: mcondon013/pfcodelibrary
        private void LoadScheduleFromFile()
        {
            if (this.chkEraseOutputBeforeEachTest.Checked)
            {
                Program._messageLog.Clear();
            }

            string filename    = string.Empty;
            string configValue = AppConfig.GetStringValueFromConfigFile("ScheduleFilesFolder", string.Empty);

            if (configValue.Trim().Length > 0)
            {
                _saveSelectionsFolder = configValue;
            }
            DialogResult res = ShowOpenFileDialog();

            if (res == DialogResult.OK)
            {
                filename = _saveSelectionsFile;
                PFSchedule sked = PFSchedule.LoadFromXmlFile(filename);
                Tests.CreateScreenInputFromSchedule(this, sked);
                ProcessScheduleFrequencyChange();
            }
        }
コード例 #21
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        public static void ShowAllScheduledDates(MainForm frm)
        {
            List <DateTime> scheduledDates;
            PFSchedule      sked              = null;
            DateTime        prevDateTime      = DateTime.MinValue;
            DateTime        searchEndDateTime = DateTime.MaxValue;
            DateTime        scheduleEndDate   = Convert.ToDateTime(frm.txtScheduleEnd.Text.Trim());
            Stopwatch       sw = new Stopwatch();

            try
            {
                _msg.Length = 0;
                _msg.Append("ShowAllScheduledDates started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                sw.Start();

                sked = CreateScheduleFromScreenInput(frm);

                prevDateTime      = Convert.ToDateTime(frm.txtCurrDateTime.Text);
                searchEndDateTime = Convert.ToDateTime(frm.txtScheduleEnd.Text);
                if (scheduleEndDate < searchEndDateTime)
                {
                    searchEndDateTime = scheduleEndDate;
                }

                scheduledDates = sked.GetListOfScheduledDates(prevDateTime, searchEndDateTime);

                _msg.Length = 0;
                _msg.Append("\r\n");
                _msg.Append("Total # of scheduled dates: ");
                _msg.Append(scheduledDates.Count.ToString("#,##0"));
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                for (int inx = 0; inx < scheduledDates.Count; inx++)
                {
                    _msg.Length = 0;
                    _msg.Append(scheduledDates[inx].ToString("MM/dd/yyyy HH:mm:ss"));
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                sw.Stop();
                _msg.Length = 0;
                _msg.Append("\r\n");
                _msg.Append("Elapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... ShowAllScheduledDates finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #22
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
 private static void LoadRunOneTimeSchedule(MainForm frm, PFSchedule sked)
 {
     frm.txtRunOnceAt.Text = sked.RunAt.ToString("MM/dd/yyyy HH:mm:ss");
 }
コード例 #23
0
ファイル: MainForm.cs プロジェクト: mcondon013/pfcodelibrary
        private void LoadScheduleFromDatabase()
        {
            string connectionString      = _taskDefsDbConnectionString;
            string scheduleName          = this.txtScheduleName.Text.Trim();
            PFList <PFSchedule> skedList = null;
            PFSchedule          sked     = null;
            PFScheduleManager   skedMgr  = new PFScheduleManager(enScheduleStorageType.Database, connectionString);
            string inputFileName         = string.Empty;

            if (this.chkEraseOutputBeforeEachTest.Checked)
            {
                Program._messageLog.Clear();
            }

            try
            {
                skedList = skedMgr.GetScheduleList();
                NameListPrompt namesPrompt = new NameListPrompt();
                namesPrompt.lblSelect.Text = "Select the name from list below:";
                for (int i = 0; i < skedList.Count; i++)
                {
                    namesPrompt.lstNames.Items.Add(skedList[i].Name);
                }
                if (skedList.Count > 0)
                {
                    namesPrompt.lstNames.SelectedIndex = 0;
                }
                DialogResult res = namesPrompt.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (namesPrompt.lstNames.SelectedIndex == -1)
                    {
                        _msg.Length = 0;
                        _msg.Append("You did not select any schedule to load");
                        throw new System.Exception(_msg.ToString());
                    }
                    this.InitializeForm();
                    scheduleName = namesPrompt.lstNames.SelectedItem.ToString();
                    if (scheduleName.Length == 0)
                    {
                        _msg.Length = 0;
                        _msg.Append("You must specify a sked name");
                        throw new System.Exception(_msg.ToString());
                    }

                    sked = skedMgr.GetScheduleByName(scheduleName);

                    if (sked == null)
                    {
                        _msg.Length = 0;
                        _msg.Append("Unable to find schedule ");
                        _msg.Append(scheduleName);
                        _msg.Append(" in the database at ");
                        _msg.Append(_taskDefsDbConnectionString);
                        throw new System.Exception(_msg.ToString());
                    }

                    Tests.CreateScreenInputFromSchedule(this, sked);
                    ProcessScheduleFrequencyChange();
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        }
コード例 #24
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        public static void GetNextScheduleDateTest(MainForm frm)
        {
            PFSchedule sked                    = null;
            DateTime   prevDateTime            = DateTime.MinValue;
            DateTime   currDateTime            = DateTime.MinValue;
            DateTime   searchEndDateTime       = DateTime.MaxValue;
            DateTime   nextScheduleDateTime    = DateTime.MaxValue;
            DateTime   currentScheduleDateTime = DateTime.MaxValue;
            DateTime   scheduleEndDate         = Convert.ToDateTime(frm.txtScheduleEnd.Text.Trim());
            Stopwatch  sw = new Stopwatch();

            try
            {
                _msg.Length = 0;
                _msg.Append("GetNextScheduleDateTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                sw.Start();

                sked = CreateScheduleFromScreenInput(frm);

                currDateTime            = Convert.ToDateTime(frm.txtCurrDateTime.Text);
                currentScheduleDateTime = sked.GetCurrentScheduledDateTime(currDateTime, searchEndDateTime);

                prevDateTime      = Convert.ToDateTime(frm.txtCurrDateTime.Text);
                searchEndDateTime = prevDateTime.Add(new TimeSpan(366, 0, 0, 0));
                if (scheduleEndDate < searchEndDateTime)
                {
                    searchEndDateTime = scheduleEndDate;
                }

                nextScheduleDateTime = sked.GetNextScheduledDateTime(prevDateTime, searchEndDateTime);

                _msg.Length = 0;
                _msg.Append("Curr scheduled date/time: ");
                _msg.Append(currentScheduleDateTime.ToString("MM/dd/yyyy HH:mm:ss"));
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Next scheduled date/time: ");
                _msg.Append(nextScheduleDateTime.ToString("MM/dd/yyyy HH:mm:ss"));
                Program._messageLog.WriteLine(_msg.ToString());

                sw.Stop();
                _msg.Length = 0;
                _msg.Append("\r\n");
                _msg.Append("Elapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... GetNextScheduleDateTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #25
0
        public void RunTask()
        {
            PFTask             task = new PFTask();
            PFTaskHistoryEntry the  = new PFTaskHistoryEntry();

            PFTimers.Stopwatch sw = new PFTimers.Stopwatch();
            string             connectionString = string.Empty;
            string             scheduleFolder   = string.Empty;
            string             scheduleName     = string.Empty;

            try
            {
                if (_frm.chkEraseOutputBeforeEachTest.Checked)
                {
                    Program._messageLog.Clear();
                }

                if (_frm.txtTaskName.Text.Trim().Length == 0 ||
                    _frm.txtFileToRun.Text.Trim().Length == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify a the name and a file to run for RunTest");
                    throw new System.Exception(_msg.ToString());
                }

                sw.Start();

                _msg.Length = 0;
                _msg.Append("Before taskProcessor.Start");
                Program._messageLog.WriteLine(_msg.ToString());

                System.Diagnostics.Process p = Process.GetCurrentProcess();
                foreach (ProcessThread th in p.Threads)
                {
                    _msg.Length = 0;
                    _msg.Append("Thread ID: ");
                    _msg.Append(th.Id.ToString());
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                scheduleFolder = _scheduleDefinitionsFolder;
                scheduleName   = Path.GetFileNameWithoutExtension(_frm.txtTaskSchedule.Text.Trim()) + ".xml";
                if (_frm.optUseXmlFiles.Checked)
                {
                    connectionString = Path.Combine(scheduleFolder, scheduleName);
                }
                else if (_frm.optUseDatabase.Checked)
                {
                    connectionString = _taskDefsDbConnectionString;
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("You must select storage type: XML Files or Database.");
                    throw new System.Exception(_msg.ToString());
                }


                task.TaskName              = _frm.txtTaskName.Text;
                task.TaskDescription       = _frm.txtTaskDescription.Text;
                task.TaskType              = PFAppUtils.PFEnumProcessor.StringToEnum <enTaskType>(_frm.cboTaskType.Text);
                task.MaxTaskHistoryEntries = Convert.ToInt32(_frm.txtMaxHistoryEntries.Text);
                if (_frm.optUseXmlFiles.Checked)
                {
                    task.Schedule = PFSchedule.LoadFromXmlFile(connectionString);
                }
                else
                {
                    task.Schedule = PFSchedule.LoadFromDatabase(connectionString, _frm.txtTaskSchedule.Text.Trim());
                }
                task.FileToRun        = _frm.txtFileToRun.Text;
                task.WorkingDirectory = _frm.txtWorkingDirectory.Text;
                string[] lines = _frm.txtArguments.Lines;
                task.Arguments              = lines;
                task.WindowStyle            = PFAppUtils.PFEnumProcessor.StringToEnum <enWindowStyle>(_frm.cboWindowStyle.Text);
                task.CreateNoWindow         = _frm.chkCreateNoWindow.Checked;
                task.UseShellExecute        = _frm.chkUseShellExecute.Checked;
                task.RedirectStandardOutput = _frm.chkRedirectStandardOutput.Checked;
                task.RedirectStandardError  = _frm.chkRedirectStandardError.Checked;

                the.TaskID             = task.ID;
                the.TaskName           = task.TaskName;
                the.ScheduledStartTime = task.Schedule.GetCurrentScheduledDateTime(DateTime.Now, DateTime.Now.AddHours(1));

                PFTaskProcessor taskProcessor = new PFTaskProcessor(task);
                taskProcessor.Start();

                _msg.Length = 0;
                _msg.Append("After taskProcessor.Start");
                Program._messageLog.WriteLine(_msg.ToString());

                System.Diagnostics.Process p1 = Process.GetCurrentProcess();
                foreach (ProcessThread th in p1.Threads)
                {
                    _msg.Length = 0;
                    _msg.Append("Thread ID: ");
                    _msg.Append(th.Id.ToString());
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                _msg.Length = 0;
                _msg.Append("Main thread id:    ");
                _msg.Append(System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
                _msg.Length = 0;
                _msg.Append("Spawned thread id: ");
                _msg.Append(taskProcessor.ThreadID.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                while (taskProcessor.HasFinished == false)
                {
                    System.Threading.Thread.Sleep(1000);
                    System.Threading.Thread.Yield();
                }


                sw.Stop();

                _msg.Length = 0;
                _msg.Append("Elapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\nTaskProcessor property values: \r\n");
                _msg.Append("Curr Directory:  ");
                _msg.Append(task.WorkingDirectory);
                _msg.Append("\r\n");
                _msg.Append("Command Line:    ");
                _msg.Append(task.FileToRun);
                _msg.Append(" ");
                _msg.Append(PFTextProcessor.ConvertStringArrayToString(task.Arguments));
                _msg.Append("\r\n");
                _msg.Append("StartTime:       ");
                _msg.Append(taskProcessor.StartTime.ToString("MM/dd/yyyy HH:mm:ss"));
                _msg.Append("\r\n");
                _msg.Append("FinishTime       ");
                _msg.Append(taskProcessor.FinishTime.ToString("MM/dd/yyyy HH:mm:ss"));
                _msg.Append("\r\n");
                _msg.Append("Elapsed Time:    ");
                _msg.Append(taskProcessor.ElapsedTimeFormatted);
                _msg.Append("\r\n");
                _msg.Append("Exit Code:       ");
                _msg.Append(taskProcessor.ProcessExitCode.ToString());
                _msg.Append("\r\n");
                _msg.Append("OutputMessages:  ");
                _msg.Append(taskProcessor.OutputMessages);
                _msg.Append("\r\n");
                _msg.Append("ErrorMessages:   ");
                _msg.Append(taskProcessor.ErrorMessages);
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                //fill up and save the history entry
                the.ActualStartTime    = taskProcessor.StartTime;
                the.ActualEndTime      = taskProcessor.FinishTime;
                the.TaskOutputMessages = taskProcessor.OutputMessages;
                the.TaskErrorMessages  = taskProcessor.ErrorMessages;
                the.TaskReturnCode     = taskProcessor.ProcessExitCode;
                if (taskProcessor.ProcessExitCode == 0)
                {
                    the.TaskRunResult = enTaskRunResult.Success;
                }
                else
                {
                    the.TaskRunResult = enTaskRunResult.Failure;
                }
                if (_frm.optUseXmlFiles.Checked)
                {
                    string theFilename = _taskHistoryFolder + the.TaskName + "_" + the.ActualEndTime.ToString("_yyyyMMdd_HHmmss") + ".xml";
                    if (File.Exists(theFilename))
                    {
                        File.Delete(theFilename);
                    }
                    the.SaveToXmlFile(theFilename);
                }
                else if (_frm.optUseDatabase.Checked)
                {
                    the.SaveToDatabase(_taskDefsDbConnectionString);
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify whether to store the history in XML files or Database.");
                    throw new System.Exception(_msg.ToString());
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        }
コード例 #26
0
        public static void DailyScheduleTest(MainForm frm)
        {
            try
            {
                _msg.Length = 0;
                _msg.Append("DailyScheduleTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                PFSchedule sked = new PFSchedule();
                sked.Name = "DailyOneTimeSchedule001";
                sked.ScheduleFrequency          = enScheduleFrequency.Daily;
                sked.ScheduleOccursEveryNumDays = 1;   //occurs every day
                sked.DailyFrequency             = enDailyFrequency.OneTime;
                sked.RunWindow = new TimeSpan(0, 10, 0);

                sked.OccursOnceAtTime  = new TimeSpan(17, 15, 0);
                sked.ScheduleStartDate = Convert.ToDateTime("7/11/2013");
                sked.ScheduleEndDate   = Convert.ToDateTime("12/31/2013");

                _msg.Length = 0;
                _msg.Append("Schedule Name::  ");
                _msg.Append(sked.Name.ToString());
                _msg.Append("\r\n");
                _msg.Append("DailyFrequency:  ");
                _msg.Append(sked.DailyFrequency.ToString());
                _msg.Append("\r\n");
                _msg.Append("RunWindow:  ");
                _msg.Append(sked.RunWindow.ToString());
                _msg.Append("\r\n");
                _msg.Append("OccursEvery:     ");
                _msg.Append(sked.ScheduleOccursEveryNumDays.ToString());
                _msg.Append(" day(s)");
                _msg.Append("\r\n");
                _msg.Append("OccursOnceAtTime:  ");
                _msg.Append(sked.OccursOnceAtTime.ToString());
                _msg.Append("\r\n");
                _msg.Append("DurationStart:   ");
                _msg.Append(sked.ScheduleStartDate.ToString());
                _msg.Append("\r\n");
                _msg.Append("DurationEnd:     ");
                _msg.Append(sked.ScheduleEndDate.ToString());
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                sked.Name = "DailyRecurringSchedule001";
                sked.ScheduleOccursEveryNumDays = 1;   //occurs every day
                sked.DailyFrequency             = enDailyFrequency.Recurring;
                sked.RunWindow = new TimeSpan(0, 15, 0);
                sked.DailyOccursEveryTimeInterval = 5;
                sked.DailyOccursTimeInterval      = enDailyOccursInterval.Minutes; //recurs every 5 minutes
                sked.DailyOccursStartTime         = new TimeSpan(0, 3, 15, 0, 0);
                sked.DailyOccursEndTime           = new TimeSpan(0, 22, 45, 0, 0);
                sked.ScheduleStartDate            = Convert.ToDateTime("7/11/2013");
                sked.ScheduleEndDate = Convert.ToDateTime("12/31/2013");

                _msg.Length = 0;
                _msg.Append("Schedule Name::  ");
                _msg.Append(sked.Name.ToString());
                _msg.Append("\r\n");
                _msg.Append("DailyFrequency:  ");
                _msg.Append(sked.DailyFrequency.ToString());
                _msg.Append("\r\n");
                _msg.Append("RunWindow:       ");
                _msg.Append(sked.RunWindow.ToString());
                _msg.Append("\r\n");
                _msg.Append("OccursEvery:     ");
                _msg.Append(sked.DailyOccursEveryTimeInterval.ToString());
                _msg.Append(" ");
                _msg.Append(sked.DailyOccursTimeInterval.ToString());
                _msg.Append("\r\n");
                _msg.Append("DailyOccursStartTime: ");
                _msg.Append(sked.DailyOccursStartTime.ToString());
                _msg.Append("\r\n");
                _msg.Append("DailyOccursEndTime:   ");
                _msg.Append(sked.DailyOccursEndTime.ToString());
                _msg.Append("\r\n");
                _msg.Append("DurationStart:   ");
                _msg.Append(sked.ScheduleStartDate.ToString());
                _msg.Append("\r\n");
                _msg.Append("DurationEnd:     ");
                _msg.Append(sked.ScheduleEndDate.ToString());
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... DailyScheduleTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #27
0
        //tests
        public static void OneTimeScheduleTest(MainForm frm)
        {
            try
            {
                _msg.Length = 0;
                _msg.Append("OneTimeScheduleTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                PFSchedule sked = new PFSchedule();
                sked.ScheduleFrequency = enScheduleFrequency.OneTime;
                sked.RunAt             = Convert.ToDateTime("07/23/2013 16:05:00");
                sked.RunWindow         = new TimeSpan(0, 10, 0);

                DateTime currDate = DateTime.Now;

                _msg.Length = 0;
                _msg.Append("CurrDate: ");
                _msg.Append(currDate.ToString("MMMM d, yyyy HH:mm:ss"));
                _msg.Append(" ");

                if (sked.DateIsScheduled(currDate))
                {
                    _msg.Append("is match");
                }
                else
                {
                    _msg.Append("NOT a match");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                DateTime nextDate = DateTime.Now.Add(new TimeSpan(0, 0, 15));

                _msg.Length = 0;
                _msg.Append("NextDate: ");
                _msg.Append(nextDate.ToString("MMMM d, yyyy HH:mm:ss"));
                _msg.Append(" ");

                if (sked.DateIsScheduled(nextDate))
                {
                    _msg.Append("is match");
                }
                else
                {
                    _msg.Append("NOT a match");
                }
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... OneTimeScheduleTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #28
0
        public static void VerifyDailyScheduleTimesTest(MainForm frm)
        {
            bool     expectedResult = false;
            bool     result         = false;
            DateTime currTime       = DateTime.Now;

            try
            {
                _msg.Length = 0;
                _msg.Append("VerifyDailyScheduleTimesTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                PFSchedule sked = new PFSchedule("TestSchedule");
                sked.ScheduleFrequency = enScheduleFrequency.Daily;
                TimeSpan skedTime = new TimeSpan(12, 25, 00);
                sked.SetDailyOneTimeSchedule(2, 10, skedTime, Convert.ToDateTime("7/13/2013 11:00:00"), Convert.ToDateTime("7/31/2013 23:22:59"));

                expectedResult = true;
                currTime       = Convert.ToDateTime("7/13/2013 12:27:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);

                expectedResult = false;
                currTime       = Convert.ToDateTime("7/13/2013 12:47:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);

                expectedResult = true;
                currTime       = Convert.ToDateTime("7/15/2013 12:27:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);

                expectedResult = false;
                currTime       = Convert.ToDateTime("7/14/2013 12:27:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);

                sked = null;
                sked = new PFSchedule("TestRecurringSchedule");

                sked.ScheduleFrequency = enScheduleFrequency.Daily;
                //skedTime = new TimeSpan(15, 35, 00);
                sked.SetDailyRecurringSchedule(3, 10, 3, enDailyOccursInterval.Hours, new TimeSpan(1, 0, 0), new TimeSpan(21, 59, 59), Convert.ToDateTime("7/13/2013 00:00:00"), Convert.ToDateTime("7/31/2013 23:59:59"));

                expectedResult = true;
                currTime       = Convert.ToDateTime("7/13/2013 10:05:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);

                expectedResult = false;
                currTime       = Convert.ToDateTime("7/13/2013 11:05:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);

                expectedResult = true;
                currTime       = Convert.ToDateTime("7/13/2013 13:05:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);

                expectedResult = false;
                currTime       = Convert.ToDateTime("7/13/2014 11:05:00");
                result         = sked.DateIsScheduled(currTime);
                PrintResult(sked, currTime, result, expectedResult);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... VerifyDailyScheduleTimesTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #29
0
        public void GetScheduleDatabase()
        {
            string scheduleName = _frm.txtTaskSchedule.Text.Trim();
            PFList <PFSchedule> scheduleList = null;
            PFSchedule          sked         = null;
            PFScheduleManager   skedMgr      = new PFScheduleManager(enScheduleStorageType.Database, _taskDefsDbConnectionString);

            try
            {
                if (_frm.chkEraseOutputBeforeEachTest.Checked)
                {
                    Program._messageLog.Clear();
                }

                scheduleList = skedMgr.GetScheduleList();
                if (scheduleList.Count == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("No schedules found in database: ");
                    _msg.Append(_taskDefsDbConnectionString);
                    throw new System.Exception(_msg.ToString());
                }
                NameListPrompt namesPrompt = new NameListPrompt();
                namesPrompt.lblSelect.Text = "Select the name from list below:";
                for (int i = 0; i < scheduleList.Count; i++)
                {
                    namesPrompt.lstNames.Items.Add(scheduleList[i].Name);
                }
                if (scheduleList.Count > 0)
                {
                    namesPrompt.lstNames.SelectedIndex = 0;
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("No schedules found in database: ");
                    _msg.Append(_taskDefsDbConnectionString);
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                DialogResult res = namesPrompt.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (namesPrompt.lstNames.SelectedIndex == -1)
                    {
                        _msg.Length = 0;
                        _msg.Append("You did not select any schedule.");
                        throw new System.Exception(_msg.ToString());
                    }
                    scheduleName = namesPrompt.lstNames.SelectedItem.ToString();
                    if (scheduleName.Length == 0)
                    {
                        _msg.Length = 0;
                        _msg.Append("You must specify a the name");
                        throw new System.Exception(_msg.ToString());
                    }

                    sked = skedMgr.GetScheduleByName(scheduleName);

                    if (sked == null)
                    {
                        _msg.Length = 0;
                        _msg.Append("Unable to find the ");
                        _msg.Append(scheduleName);
                        _msg.Append(" in the database at ");
                        _msg.Append(_taskDefsDbConnectionString);
                        throw new System.Exception(_msg.ToString());
                    }

                    _frm.txtTaskSchedule.Text = sked.Name;
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        }
コード例 #30
0
ファイル: Tests.cs プロジェクト: mcondon013/pfcodelibrary
        public static void InitTaskProcessorTest(MainForm frm)
        {
            PFTask             task = new PFTask();
            PFTaskHistoryEntry the  = new PFTaskHistoryEntry();

            PFTimers.Stopwatch sw = new PFTimers.Stopwatch();

            try
            {
                _msg.Length = 0;
                _msg.Append("InitTaskProcessorTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());


                sw.Start();

                _msg.Length = 0;
                _msg.Append("Before taskProcessor.Start");
                Program._messageLog.WriteLine(_msg.ToString());

                System.Diagnostics.Process p = Process.GetCurrentProcess();
                foreach (ProcessThread th in p.Threads)
                {
                    _msg.Length = 0;
                    _msg.Append("Thread ID: ");
                    _msg.Append(th.Id.ToString());
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                task.TaskName              = "TestTask01";
                task.TaskDescription       = "Test the task for Testprog";
                task.TaskType              = enTaskType.WindowsExecutable;
                task.FileToRun             = @"C:\Temp\TestAppFolders\FilesToRun\testbat01.bat";
                task.WorkingDirectory      = @"C:\Temp\TestAppFolders\FilesToRun";
                task.MaxTaskHistoryEntries = 15;
                task.Schedule              = PFSchedule.LoadFromXmlFile(@"C:\ProFast\Projects\ScheduleFiles\TestWeeklyOccurs.xml");

                the.TaskID             = task.ID;
                the.TaskName           = task.TaskName;
                the.ScheduledStartTime = task.Schedule.GetCurrentScheduledDateTime(DateTime.Now, DateTime.Now.AddHours(1));

                PFTaskProcessor taskProcessor = new PFTaskProcessor(task);
                taskProcessor.Start();

                _msg.Length = 0;
                _msg.Append("After taskProcessor.Start");
                Program._messageLog.WriteLine(_msg.ToString());

                System.Diagnostics.Process p1 = Process.GetCurrentProcess();
                foreach (ProcessThread th in p1.Threads)
                {
                    _msg.Length = 0;
                    _msg.Append("Thread ID: ");
                    _msg.Append(th.Id.ToString());
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                _msg.Length = 0;
                _msg.Append("Main thread id:    ");
                _msg.Append(System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
                _msg.Length = 0;
                _msg.Append("Spawned thread id: ");
                _msg.Append(taskProcessor.ThreadID.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                while (taskProcessor.HasFinished == false)
                {
                    System.Threading.Thread.Sleep(1000);
                    System.Threading.Thread.Yield();
                }


                sw.Stop();

                _msg.Length = 0;
                _msg.Append("Elapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\nTaskProcessor property values: \r\n");
                _msg.Append("StartTime:       ");
                _msg.Append(taskProcessor.StartTime.ToString("MM/dd/yyyy HH:mm:ss"));
                _msg.Append("\r\n");
                _msg.Append("FinishTime       ");
                _msg.Append(taskProcessor.FinishTime.ToString("MM/dd/yyyy HH:mm:ss"));
                _msg.Append("\r\n");
                _msg.Append("Elapsed Time:    ");
                _msg.Append(taskProcessor.ElapsedTimeFormatted);
                _msg.Append("\r\n");
                _msg.Append("Exit Code:       ");
                _msg.Append(taskProcessor.ProcessExitCode.ToString());
                _msg.Append("\r\n");
                _msg.Append("OutputMessages:  ");
                _msg.Append(taskProcessor.OutputMessages);
                _msg.Append("\r\n");
                _msg.Append("ErrorMessages:   ");
                _msg.Append(taskProcessor.ErrorMessages);
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                //fill up and save the history entry
                the.ActualStartTime    = taskProcessor.StartTime;
                the.ActualEndTime      = taskProcessor.FinishTime;
                the.TaskOutputMessages = taskProcessor.OutputMessages;
                the.TaskErrorMessages  = taskProcessor.ErrorMessages;
                the.TaskReturnCode     = taskProcessor.ProcessExitCode;
                if (taskProcessor.ProcessExitCode == 0)
                {
                    the.TaskRunResult = enTaskRunResult.Success;
                }
                else
                {
                    the.TaskRunResult = enTaskRunResult.Failure;
                }
                //string theFilename = @"c:\tempObjectInstance\" + the.TaskName + "_" + the.TaskID.ToString() + "_" + the.ActualEndTime.ToString("_yyyyMMdd_HHmmss") + ".txt";
                string theFilename = @"c:\tempObjectInstance\" + the.TaskName + "_" + the.ActualEndTime.ToString("_yyyyMMdd_HHmmss") + ".txt";
                if (File.Exists(theFilename))
                {
                    File.Delete(theFilename);
                }
                the.SaveToXmlFile(theFilename);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... InitTaskProcessorTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }