コード例 #1
0
        /// <summary>
        /// Validates the file, using the <see cref="OutputMonitorConfig"/> provided.
        /// </summary>
        /// <param name="options">The validation options.</param>
        /// <returns></returns>
        public ValidationResult Validate(OutputMonitorConfig options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Perform basic validation on the file
            FileValidationResult fileValidation = _analyzer.Validate();
            ValidationResult     result         = new ValidationResult(fileValidation.Success, fileValidation.Message);

            if (!result.Succeeded)
            {
                return(result);
            }

            // If requested, ensure that there is an associated metadata file
            if (options.LookForMetadataFile)
            {
                string metadataFile = Path.ChangeExtension(_analyzer.File.FullName, options.MetadataFileExtension);
                if (!File.Exists(metadataFile))
                {
                    return(new ValidationResult(false, "Metadata file not found: {0}".FormatWith(Path.GetFileName(metadataFile))));
                }
            }

            // If we reach this point, the file validated successfully
            return(new ValidationResult(true));
        }
コード例 #2
0
        /// <summary>
        /// Retrieves a collection of output monitor destinations of the specified type.
        /// </summary>
        /// <param name="monitorType">The type of output monitor destinations to retrieve.</param>
        /// <returns>A collection of output monitor destinations.</returns>
        public IEnumerable <string> GetOutputMonitorDestinations(string monitorType)
        {
            STFMonitorType      stfMonitorType = (STFMonitorType)Enum.Parse(typeof(STFMonitorType), monitorType);
            Collection <string> result         = new Collection <string>();

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                foreach (MonitorConfig monitorConfig in context.MonitorConfigs.Where(m => m.MonitorType == monitorType))
                {
                    if (monitorConfig.Configuration.StartsWith("<OutputMonitorConfig"))
                    {
                        OutputMonitorConfig outputConfig = LegacySerializer.DeserializeXml <OutputMonitorConfig>(monitorConfig.Configuration);

                        if (stfMonitorType.Equals(STFMonitorType.OutputEmail) || stfMonitorType.Equals(STFMonitorType.DigitalSendNotification))
                        {
                            result.Add(outputConfig.MonitorLocation);
                        }
                        else
                        {
                            result.Add($@"\\{monitorConfig.ServerHostName}\{outputConfig.MonitorLocation}");
                        }
                    }
                }
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Applies the retention policy from the specified <see cref="OutputMonitorConfig"/> to the file.
        /// </summary>
        /// <param name="options">The validation/retention options.</param>
        /// <param name="isFileValid">if set to <c>true</c> the file should be considered valid.</param>
        public void ApplyRetention(OutputMonitorConfig options, bool isFileValid = true)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // If the retention option is DoNothing, quit now
            if (options.Retention == RetentionOption.DoNothing)
            {
                return;
            }

            // Determine the "real" name for the file
            string file       = _analyzer.File.FullName;
            string filePrefix = options.RetentionFileName ?? Path.GetFileNameWithoutExtension(file);

            // Determine whether we should retain or delete the output file(s)
            bool retain = options.Retention == RetentionOption.AlwaysRetain ||
                          (options.Retention == RetentionOption.RetainIfCorrupt && isFileValid == false);

            // Apply the retention option for the file
            string retentionDirectory = string.Empty;

            if (retain)
            {
                string session = ScanFilePrefix.Parse(filePrefix).SessionId;
                retentionDirectory = options.RetentionLocation.Replace("{SESSION}", session);
                System.IO.Directory.CreateDirectory(retentionDirectory);
                CopyFile(file, retentionDirectory, filePrefix, Path.GetExtension(file));
            }
            File.Delete(file);

            // If we were expecting a metadata file, apply the retention options there as well
            if (options.LookForMetadataFile)
            {
                string metadataFile = Path.ChangeExtension(file, options.MetadataFileExtension);
                if (Retry.UntilTrue(() => File.Exists(metadataFile), 5, TimeSpan.FromSeconds(1)))
                {
                    if (retain)
                    {
                        CopyFile(metadataFile, retentionDirectory, filePrefix, options.MetadataFileExtension);
                    }
                    File.Delete(metadataFile);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OutputMonitorConfigControl"/> form.
        /// </summary>
        /// <param name="monitorConfig">The configuration data for an output monitor.</param>
        public OutputMonitorConfigControl(MonitorConfig monitorConfig)
        {
            InitializeComponent();

            // Populate combo boxes
            retention_ComboBox.DataSource    = EnumUtil.GetDescriptions <RetentionOption>().ToArray();
            retention_ComboBox.SelectedIndex = -1;

            //groupBox_Validation.Enabled = IsEnterpriseEnabled();
            _errorProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink;

            _outputMonitorConfig = (OutputMonitorConfig)StfMonitorConfigFactory.Create(monitorConfig.MonitorType, monitorConfig.Configuration);

            // Populate the controls
            _serverHostName = monitorConfig.ServerHostName;
            _monitorType    = EnumUtil.Parse <STFMonitorType>(monitorConfig.MonitorType);
            InitializeMonitorType();
            destination_TextBox.Text         = _outputMonitorConfig.MonitorLocation;
            retention_ComboBox.SelectedItem  = EnumUtil.GetDescription(_outputMonitorConfig.Retention);
            retentionLocation_TextBox.Text   = _outputMonitorConfig.RetentionLocation;
            lookForMetadata_CheckBox.Checked = _outputMonitorConfig.LookForMetadataFile;
            metadataExtension_TextBox.Text   = _outputMonitorConfig.MetadataFileExtension;
        }
コード例 #5
0
 /// <summary>
 /// Refreshes monitor configuration for this instance.
 /// </summary>
 public override void RefreshConfig(MonitorConfig monitorConfig)
 {
     Configuration = LegacySerializer.DeserializeXml <OutputMonitorConfig>(monitorConfig.Configuration);
 }