Exemple #1
0
        public SCenter()
        {
            try
            {
                DateTime now                 = DateTime.Now;
                string   fileLog             = "sCenter_" + now.Year.ToString() + now.Month.ToString() + now.Day.ToString() + this.ExtensioLog;
                string   completePathFileLog = System.IO.Path.Combine(_logPathSettings, fileLog);

                // prepare the setting folders
                FileCenter.CheckPath(_settingsPath);
                FileCenter.CheckPath(_tskPathSettings);
                FileCenter.CheckPath(_logPathSettings);

                _allFilesInTskPath = new System.Collections.Generic.List <FileCenter>();
                _allTheTaskers     = new System.Collections.Generic.List <Tasker>();
                _filesToExecute    = new System.Collections.Generic.List <string>();
                _filesName         = new System.Collections.Generic.List <string>();
                _fileLog           = new FileCenter(completePathFileLog);
            }
            catch (System.IO.DirectoryNotFoundException ex) { throw new System.IO.IOException(ex.ToString() + " - Constructor SCenter"); }
            catch (System.IO.PathTooLongException ex) { throw new System.IO.PathTooLongException(ex.ToString() + " - Constructor SCenter"); }
            catch (System.IO.IOException ex) { throw new System.IO.IOException(ex.ToString() + " - Constructor SCenter"); }
            catch (UnauthorizedAccessException ex) { throw new UnauthorizedAccessException(ex.ToString() + " - Constructor SCenter"); }
            catch (ArgumentNullException ex) { throw new ArgumentNullException(ex.ToString() + " - Constructor SCenter"); }
            catch (NotSupportedException ex) { throw new NotSupportedException(ex.ToString() + " - Constructor SCenter"); }
        }
Exemple #2
0
        public FileCenter(string filename)
        {
            string path = System.IO.Path.GetDirectoryName(filename);

            try
            {
                FileCenter.CheckPath(path);
                FileCenter.CheckFile(filename);

                _pathFile = new System.IO.DirectoryInfo(path);
                _fileName = new System.IO.FileInfo(filename);

                _extension            = _fileName.Extension;
                _extensionUsedToWrite = new System.Collections.Generic.List <string> {
                    ".txt", ".log"
                };
            }
            catch (System.IO.DirectoryNotFoundException ex) { throw new System.IO.IOException(ex.Message + " - FileCenter"); }
            catch (System.IO.PathTooLongException ex) { throw new System.IO.PathTooLongException(ex.Message + " - FileCenter"); }
            catch (System.IO.IOException ex) { throw new System.IO.IOException(ex.Message + " - FileCenter"); }
            catch (UnauthorizedAccessException ex) { throw new UnauthorizedAccessException(ex.Message + " - FileCenter"); }
            catch (ArgumentNullException ex) { throw new ArgumentNullException(ex.Message + " - FileCenter"); }
            catch (ArgumentException ex) { throw new ArgumentException(ex.Message + " - FileCenter"); }
            catch (NotSupportedException ex) { throw new NotSupportedException(ex.Message + " - FileCenter"); }
            catch (System.Security.SecurityException ex) { throw new System.Security.SecurityException(ex.Message + " - FileCenter"); }
        }
Exemple #3
0
        /*
         * <summary>
         *  method use to control the input
         *  prepar the timer and file to execute
         *  <parameters>
         *      <param type="string">the task to do with the type
         *          <format>[min]\t[hour]\t[day]\t[month]\t[week]\t[your task]</format>
         *      </param>
         *  </parameters>
         *  <bug>
         *      It's not active the week control
         *  </bug>
         * </summary>
         */
        private void TaskController(string theTask)
        {
            if (String.IsNullOrEmpty(theTask))
            {
                throw new ArgumentNullException("There aren't a schedulated task. Insert a task with this format: [min]\t[hour]\t[day]\t[month]\t[week]\t[your task]. Remember to use tab and not withe space.");
            }

            try
            {
                string[] tasker = new string[6];

                tasker = theTask.Split('\t');

                _configurationValues["min"]   = tasker[0];
                _configurationValues["hour"]  = tasker[1];
                _configurationValues["day"]   = tasker[2];
                _configurationValues["month"] = tasker[3];
                _configurationValues["week"]  = tasker[4];
                _configurationValues["task"]  = tasker[5];

                this.SetElapse(_configurationValues["min"], _configurationValues["hour"], _configurationValues["day"], _configurationValues["month"], _configurationValues["week"]);
                _taskFile = new FileCenter(_configurationValues["task"]);
            }
            catch (FormatException ex) { throw new FormatException(ex.Message + " - TaskController"); }
            catch (OverflowException ex) { throw new FormatException(ex.Message + " - TaskController"); }
            catch (Exception ex) { throw new Exception(ex.Message + " - TaskController"); }
        }
Exemple #4
0
        /*
         * <summary>
         *  read inside the task files and get the time and the file to execute
         *  <parameters>
         *      <param type="FileCenter" name="fileToRead">the file to read</param>
         *  </parameters>
         * </summary>
         */
        private System.Collections.Generic.List <string> GetTaskFromAFile(FileCenter fileToRead)
        {
            System.Text.StringBuilder text = fileToRead.ReadFile();
            System.Collections.Generic.List <string> tasks = new System.Collections.Generic.List <string>();

            // read all the line and ignore the comment (#)
            foreach (var line in text.ToString().Split('\n'))
            {
                if (line.IndexOf(_commentChar) >= 0 || String.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                tasks.Add(line);
            }

            text.Clear();

            return(tasks);
        }