Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public void SaveTemplate(SystemPattern record)
        {
            FileStream fileStream  = null;
            string     templateDir = Path.Combine(
                this.pluginProperties.ApplicationBaseDir,
                this.pluginProperties.PluginBaseDir,
                this.pluginProperties.PatternSubDir,
                Plugin.Main.Systems.DataTypes.General.PATTERN_DIR_TEMPLATE);
            string fileName = Regex.Replace(record.SystemName, @"[^\d\w\-]", "_", RegexOptions.IgnoreCase);

            fileName += Plugin.Main.Systems.DataTypes.General.PATTERN_FILE_EXTENSION;
            string newPatternFileFullPath = Path.Combine(templateDir, fileName);

            try
            {
                BinaryFormatter formatter = new BinaryFormatter();
                fileStream = new FileStream(newPatternFileFullPath, FileMode.Create);
                formatter.Serialize(fileStream, record);
            }
            catch (Exception)
            {
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BT_Add_Click(object sender, EventArgs e)
        {
            string systemName         = this.tb_SystemName.Text;
            string systemRegex        = this.tb_SystemRegex.Text;
            string patternName        = this.tb_PatternName.Text;
            string patternDescription = this.tb_PatternDescription.Text;

            string repositoryLocalFullpath = Path.Combine(
                this.pluginProperties.ApplicationBaseDir,
                this.pluginProperties.PluginBaseDir,
                this.pluginProperties.PatternSubDir,
                General.PATTERN_DIR_LOCAL);
            string fileName            = Regex.Replace(systemName, @"[^\d\w\-]", "_", RegexOptions.IgnoreCase);
            string patternFileFullPath = Path.Combine(repositoryLocalFullpath, fileName + General.PATTERN_FILE_EXTENSION);

            try
            {
                SystemPattern newPattern = new SystemPattern(systemRegex, systemName, "Local", patternFileFullPath);

                newPattern.IsEnabled = true;
                //newPattern.Config.Name = patternName;
                //newPattern.Config.Description = patternDescription;
                //newPattern.Config.Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                this.taskLayer.AddCustomPatternRecord(newPattern);
                this.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.pluginProperties.HostApplication.LogMessage($"ManageSystems(): {ex.Message}");

                return;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="record"></param>
 public void RemoveTemplate(SystemPattern record)
 {
     if (File.Exists(record.PatternFileFullPath))
     {
         File.Delete(record.PatternFileFullPath);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pRecord"></param>
        public void addRecord(SystemPattern pRecord)
        {
            if (String.IsNullOrEmpty(pRecord.SystemName))
            throw new Exception("You didn't define a system name");
              else if (String.IsNullOrEmpty(pRecord.SystemPatternString))
            throw new Exception("You didn't define a system pattern");

              /*
               * Throw exception if record already exists
               */
              if (cSystemPattern != null)
            foreach (SystemPattern lTmp in cSystemPattern)
              if (lTmp.Equals(pRecord))
            throw new Exception("An entry with this pattern already exists");

              try { Regex.Match("", pRecord.SystemPatternString); }
              catch (ArgumentException)
              {
            throw new Exception("URL pattern is invalid");
              }

              cSystemPattern.Add(pRecord);
              saveSystemRecords();
              notify();
        }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DeleteSystemToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         SystemPattern patternFileObj = (SystemPattern)this.dgv_Systems.SelectedRows[0].DataBoundItem;
         this.taskLayer.RemoveTemplate(patternFileObj);
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Error occurred while deleting pattern file: {ex.Message}", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.pluginProperties.HostApplication.LogMessage($"Presentation.ManageSystem(): {ex.Message}");
     }
 }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="patternFilePath"></param>
        /// <param name="filePattern"></param>
        /// <returns></returns>
        private List <SystemPattern> ParsePatternFiles(string patternFilePath, string filePattern, string source)
        {
            FileStream           fileStream        = null;
            SystemPattern        tmpRecord         = new SystemPattern();
            List <SystemPattern> foundPatternFiles = new List <SystemPattern>();

            string[]        remotePatternFiles;
            BinaryFormatter formatter = new BinaryFormatter();

            if (!Directory.Exists(patternFilePath))
            {
                return(foundPatternFiles);
            }

            remotePatternFiles = Directory.GetFiles(patternFilePath, filePattern);

            foreach (string tmpPatternFile in remotePatternFiles)
            {
                try
                {
                    fileStream = new FileStream(tmpPatternFile, FileMode.Open);
                    tmpRecord  = (SystemPattern)formatter.Deserialize(fileStream);

                    tmpRecord.Source = source;
                    tmpRecord.PatternFileFullPath = tmpPatternFile;

                    foundPatternFiles.Add(tmpRecord);
                }
                catch (Exception ex)
                {
                    // throw new Exception("The data pattern file could not be found");
                    // TODO: Exceptions must be logged in the LogConsole form.  The LocConsole is not
                    //       accessible from here
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                }
            }

            return(foundPatternFiles);
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="record"></param>
        public void SaveNewAccountPatternRecord(SystemPattern record)
        {
            FileStream      fileStream = null;
            BinaryFormatter formatter  = new BinaryFormatter();

            try
            {
                formatter  = new BinaryFormatter();
                fileStream = new FileStream(record.PatternFileFullPath, FileMode.Create);
                formatter.Serialize(fileStream, record);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="record"></param>
        public void AddCustomPatternRecord(SystemPattern record)
        {
            if (string.IsNullOrEmpty(record.SystemName))
            {
                throw new Exception("You didn't define a system name");
            }
            else if (string.IsNullOrEmpty(record.SystemPatternstring))
            {
                throw new Exception("You didn't define a system pattern");
            }

            // Check system pattern regex
            try
            {
                Regex.Match(string.Empty, record.SystemPatternstring);
            }
            catch (ArgumentException)
            {
                throw new Exception("System pattern is invalid");
            }

            this.infrastructureLayer.SaveNewAccountPatternRecord(record);
        }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="newPatterns"></param>
 public void SaveTemplate(SystemPattern newPatterns)
 {
     this.infrastructureLayer.SaveTemplate(newPatterns);
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="record"></param>
 public void RemoveTemplate(SystemPattern record)
 {
     this.infrastructureLayer.RemoveTemplate(record);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pRecord"></param>
 public void removeRecord(SystemPattern pRecord)
 {
     cSystemPattern.Remove(pRecord);
       saveSystemRecords();
       notify();
 }