public void LoadApplicationDw(ProcTypes procType)
        {
            logger.LogVerbose("LoadApplicationDW Called");

            try
            {
                using (var dataContext = this.pddModelDataContext ?? new PDDModelDataContext())
                {
                    var measure = dataContext.ReadMeasures().FirstOrDefault(m => m.MeasureID == (int)procType);

                    // Process only if the frequency is greater than 0
                    if (measure.Frequency > 0)
                    {
                        //If the Last Data value is null, look back 7 days from now, so that data can be back-filled
                        if (measure.LastDataLoadDateTime == null)
                        {
                            measure.LastDataLoadDateTime = measure.LastDataLoadDateTime.GetValueOrDefault(DateTime.UtcNow.AddDays(Defaults.BackfillDays - 1));
                        }

                        while (measure.LastDataLoadDateTime.Value <= DateTime.UtcNow)
                        {
                            switch (procType)
                            {
                            case ProcTypes.LoadErrorHealthDwData:
                                logger.LogVerbose($"LoadErrorHealthDWData for {measure.LastDataLoadDateTime}",
                                                  this.GetType().Name);
                                sqlRepo.PerformanceSummaryRepository.LoadErrorHealthDwData(measure.LastDataLoadDateTime.Value);
                                break;

                            case ProcTypes.LoadUserHealthDwData:
                                logger.LogVerbose($"LoadUserHealthDWData for {measure.LastDataLoadDateTime}",
                                                  this.GetType().Name);
                                sqlRepo.PerformanceSummaryRepository.LoadUserHealthDwData(measure.LastDataLoadDateTime.Value);
                                break;
                            }

                            measure.LastDataLoadDateTime = measure.LastDataLoadDateTime.Value.AddMinutes((double)measure.Frequency);
                            dataContext.SubmitChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var message = ex.GetExceptionDetails();
                logger.LogError($"LoadApplicationDW: {message}");
            }

            logger.LogVerbose("LoadApplicationDW Called - Success");
        }
Beispiel #2
0
 private void PopulateProcTypeCombo(int tid)
 {
     try
     {
         using (ProcTypes procType = new ProcTypes())
         {
             cmbProcType.DataSource    = procType.ProcTypesCombo(tid);
             cmbProcType.ValueMember   = "Value";
             cmbProcType.DisplayMember = "Display";
         }
     }
     catch (Exception ex)
     {
         CommonLogger.Info(ex.ToString());
     }
 }
		/// <summary>
		/// Initializes an automatically generated procedure.
		/// </summary>
		/// <param name="installer">The installer to use when modifying the procedure.</param>
		/// <param name="name">The name of the procedure, in in the format of the AutoProcRegex.</param>
		/// <param name="objects">The list of objects that are in the schema. Used for change detection.</param>
		public AutoProc(string name, IColumnDefinitionProvider columnProvider, IEnumerable<SchemaObject> objects)
		{
			// initialize dependencies
			_columnProvider = columnProvider;

			// break up the name into its components
			var match = new Regex(AutoProcRegexString, RegexOptions.IgnoreCase).Match(name);
			_type = (ProcTypes)Enum.Parse(typeof(ProcTypes), match.Groups["type"].Value);
			_tableName = new SqlName(match.Groups["tablename"].Value, 2);

			// generate the singular table name
			if (!String.IsNullOrWhiteSpace(match.Groups["single"].Value))
				_singularTableName = match.Groups["single"].Value;
			else
				_singularTableName = Singularizer.Singularize(_tableName.Table);

			// generate the plural table name
			if (!String.IsNullOrWhiteSpace(match.Groups["plural"].Value))
				_pluralTableName = match.Groups["plural"].Value;
			else
			{
				_pluralTableName = _tableName.Table;
				if (String.Compare(_pluralTableName, _singularTableName, StringComparison.OrdinalIgnoreCase) == 0)
					_pluralTableName = _tableName.Table + "s";
			}

			// get the specified name
			string procName = match.Groups["name"].Value;
			if (!String.IsNullOrWhiteSpace(procName))
			{
				if (MoreThanOneBitIsSet((int)_type))
					throw new ArgumentException("Can only rename an autoproc if generating one at a time.");
				Name = SqlParser.FormatSqlName(procName);
			}

			//  check the exec as owner flag
			if (!String.IsNullOrWhiteSpace(match.Groups["tvp"].Value))
				_tvpName = match.Groups["tvp"].Value;
			if (!String.IsNullOrWhiteSpace(match.Groups["idtvp"].Value))
				_idtvpName = match.Groups["idtvp"].Value;

			//  check the exec as owner flag
			if (!String.IsNullOrWhiteSpace(match.Groups["execasowner"].Value))
				_executeAsOwner = Boolean.Parse(match.Groups["execasowner"].Value);

			// if we received a set of objects, then we can calculate a signature
			if (objects != null)
			{
				Regex optionalSqlName = new Regex(@"([\[\]])");
				string escapedWildcardedName = optionalSqlName.Replace(Regex.Escape(_tableName.Table), @"$1?");
				Regex regex = new Regex(String.Format(CultureInfo.InvariantCulture, @"(CREATE\s+TABLE\s+.*{0}[\]\s]\s*\()|(ALTER\s+TABLE\s+.*{0}.*PRIMARY\s+KEY)", escapedWildcardedName));

				// calculate the signature based upon the TABLE definition, plus any PRIMARY KEY definition for the table
				string sql = String.Join(" ", objects.Where(o => regex.Match(o.Sql).Success)
					.Select(o => o.Sql)
					.OrderBy(s => s));

				// add a version signature so we can force updates if we need to
				sql += VersionSignature;

				Signature = SchemaObject.CalculateSignature(sql);
			}
			else
			{
				// we don't know what the schema is, so assume that the proc has changed
				Signature = Guid.NewGuid().ToString();
			}
		}