public override bool Apply(CachedRoutine routine) { if (string.IsNullOrWhiteSpace(this.Match)) { return(false); } //var reg = new RegExp(this.Match.Replace("\\", "\\\\"), RegexOptions.None); var reg = new Regex(this.Match.Replace("\\", "\\\\"), RegexOptions.None); return(reg.Match(routine.Routine).Success); }
public static RoutineIncludeExcludeInstruction Create(CachedRoutine routine, List <BaseRule> appRules, DefaultRuleMode defaultRuleMode, List <BaseRule> fileRules = null) { var instruction = new RoutineIncludeExcludeInstruction(); // apply Metadata first if (routine.jsDALMetadata != null && routine.jsDALMetadata.jsDAL != null) { if (routine.jsDALMetadata.jsDAL != null) { if (routine.jsDALMetadata.jsDAL.exclude ?? false) { instruction.Source = RoutineIncludeExcludeInstructionSource.DatabaseMetadata; instruction.Excluded = routine.jsDALMetadata.jsDAL.exclude; if (instruction.Excluded ?? false) { instruction.Reason = "T-SQL metadata"; } } else if (!routine.jsDALMetadata.jsDAL.include ?? false) { instruction.Source = RoutineIncludeExcludeInstructionSource.DatabaseMetadata; instruction.Included = routine.jsDALMetadata.jsDAL.include; if (instruction.Included ?? false) { instruction.Reason = "T-SQL metadata"; } } } } if (instruction.Reason != null) { return(instruction); } // always apply APP-level rules first foreach (var rule in appRules) { if (rule.Apply(routine)) { if (defaultRuleMode == DefaultRuleMode.ExcludeAll) { instruction.Included = true; instruction.Reason = rule.ToString(); } else if (defaultRuleMode == DefaultRuleMode.IncludeAll) { instruction.Excluded = true; instruction.Reason = rule.ToString(); } else { throw new Exception("Unsupported DefaultRuleMode: " + defaultRuleMode.ToString()); } instruction.Rule = rule; instruction.Source = RoutineIncludeExcludeInstructionSource.DbSourceLevel; return(instruction); } } ; if (instruction.Rule != null) { return(instruction); } // apply JSFile level if (fileRules != null) { foreach (var fileRule in fileRules) { if (fileRule == null) { continue; } if (fileRule.Apply(routine)) { if (defaultRuleMode == DefaultRuleMode.ExcludeAll) { instruction.Included = true; instruction.Reason = fileRule.ToString(); // TODO: Consider recording a more substantial reference to the rule } else if (defaultRuleMode == DefaultRuleMode.IncludeAll) { instruction.Excluded = true; instruction.Reason = fileRule.ToString(); } else { throw new Exception("Unsupported DefaultRuleMode: " + defaultRuleMode.ToString()); } instruction.Rule = fileRule; instruction.Source = RoutineIncludeExcludeInstructionSource.JsFileLevel; return(instruction); } } ; } if (defaultRuleMode == DefaultRuleMode.ExcludeAll) { instruction.Excluded = true; } else { instruction.Included = true; } instruction.Rule = null; instruction.Source = RoutineIncludeExcludeInstructionSource.DbSourceLevel; instruction.Reason = "Default"; return(instruction); }
// public int RoughSizeInBytes() // { // var s= Schema.ByteSize() + Routine.ByteSize() + Type.ByteSize() + ParametersHash.ByteSize() // + sizeof(long/*RowVer*/) + sizeof(long/*ResultSetRowver*/) + ResultSetHash.ByteSize() + ResultSetError.ByteSize() // + TypescriptParameterTypeDefinition.ByteSize() + TypescriptOutputParameterTypeDefinition.ByteSize() // + TypescriptResultSetDefinitions.ByteSize() + TypescriptMethodStub.ByteSize() + sizeof(bool/*IsDeleted*/); // /* // public bool IsDeleted; // public List<RoutineParameterV2> Parameters; // public Dictionary<string, List < ResultSetFieldMetadata >> ResultSetMetadata; // public jsDALMetadata jsDALMetadata; // */ // } public bool Equals(CachedRoutine r) { return(this.Schema.Equals(r.Schema, StringComparison.OrdinalIgnoreCase) && this.Routine.Equals(r.Routine, StringComparison.OrdinalIgnoreCase)); }
public override bool Apply(CachedRoutine routine) { return(routine.Schema.Equals(this.Schema, StringComparison.OrdinalIgnoreCase) && routine.Routine.Equals(this.Routine, StringComparison.OrdinalIgnoreCase) ); }
public void AddToCache(long maxRowDate, CachedRoutine newCachedRoutine, string lastUpdateByHostName, out ChangeDescriptor changeDescriptor) { changeDescriptor = null; if (this.Id == null) { this.Id = ShortId.Generate(); } if (this.CachedRoutineList == null) { this.CachedRoutineList = new List <CachedRoutine>(); } lock (CachedRoutineList) { // look for an existing item var existing = this.CachedRoutineList.Where(e => newCachedRoutine.Equals(e)).FirstOrDefault(); if (existing != null) { // if existing is not deleted but the update IS if (!existing.IsDeleted && newCachedRoutine.IsDeleted) { changeDescriptor = ChangeDescriptor.Create(lastUpdateByHostName, $"{newCachedRoutine.FullName} DROPPED"); this.CachedRoutineList.Remove(existing); // will be added again below } else if (existing.IsDeleted && newCachedRoutine.IsDeleted) // still deleted then nothing to do { return; } else if (existing.IsDeleted && !newCachedRoutine.IsDeleted) { // "undeleted" changeDescriptor = ChangeDescriptor.Create(lastUpdateByHostName, $"{newCachedRoutine.FullName} (RE)ADDED"); this.CachedRoutineList.Remove(existing); // will be added again below } else if (!newCachedRoutine.IsDeleted) { bool parametersUpdated = newCachedRoutine.ParametersHash != existing.ParametersHash; bool resultSetsUpdated = newCachedRoutine.ResultSetHash != existing.ResultSetHash; bool jsDALMetadataUpdated = false; if (existing.jsDALMetadata == null && newCachedRoutine.jsDALMetadata != null) { jsDALMetadataUpdated = true; } else if (existing.jsDALMetadata != null && newCachedRoutine.jsDALMetadata == null) { jsDALMetadataUpdated = true; } else if (newCachedRoutine.jsDALMetadata != null) { var newMatchesExisting = newCachedRoutine.jsDALMetadata.Equals(existing.jsDALMetadata); jsDALMetadataUpdated = newCachedRoutine.jsDALMetadata != null && !newMatchesExisting; } // no metadata related change if (!parametersUpdated && !resultSetsUpdated && !jsDALMetadataUpdated) { return; } this.CachedRoutineList.Remove(existing); // will be added again below var applicableChanges = new List <string>(); if (parametersUpdated) { applicableChanges.Add("PARAMETERS"); } if (resultSetsUpdated) { applicableChanges.Add("RESULT SETS"); } if (jsDALMetadataUpdated) { applicableChanges.Add("jsDAL metadata"); } changeDescriptor = ChangeDescriptor.Create(lastUpdateByHostName, $"{newCachedRoutine.FullName} UPDATED {string.Join(", ", applicableChanges.ToArray())}"); } } else { changeDescriptor = ChangeDescriptor.Create(lastUpdateByHostName, $"{newCachedRoutine.FullName} ADDED"); } this.CachedRoutineList.Add(newCachedRoutine); } }
public virtual bool Apply(CachedRoutine routine) { throw new NotImplementedException(); }