protected virtual string TweekDerivedType(DerivedAttribute attribute, string type) { var domain = attribute.Domain; if (domain is AggregationType aggr) { //drill down while (aggr != null) { domain = aggr.ElementType; aggr = domain as AggregationType; } } if (!(domain is EntityDefinition)) { return(type); } // ReSharper disable once LoopCanBeConvertedToQuery foreach (var kvp in SpecialDerivesDictionary) { type = type.Replace(kvp.Key, kvp.Value); } return(type); }
protected string GetDerivedAttributePlacement(DerivedAttribute attribute) { var type = attribute.ParentEntity; if (Settings.IgnoreDerivedAttributes == null || !Settings.IgnoreDerivedAttributes.Any()) { return($"I{attribute.ParentEntity.Name}"); } var select = type.IsInAllSelects.FirstOrDefault(s => Settings.IgnoreDerivedAttributes.Any(i => string.Compare(i.EntityName, s.Name, StringComparison.InvariantCultureIgnoreCase) == 0 && string.Compare(i.Name, attribute.Name, StringComparison.InvariantCultureIgnoreCase) == 0)); if (select != null) { var baseNamespace = Settings.CrossAccessNamespace.Replace("." + Settings.SchemaInterfacesNamespace, ""); var ns = GetFullNamespace(select, baseNamespace, Settings.CrossAccessStructure); ns = TrimNamespace(ns); return($"{ns}.{@select.Name}"); } var entity = type.AllSupertypes.FirstOrDefault(s => Settings.IgnoreDerivedAttributes.Any(i => string.Compare(i.EntityName, s.Name, StringComparison.InvariantCultureIgnoreCase) == 0 && string.Compare(i.Name, attribute.Name, StringComparison.InvariantCultureIgnoreCase) == 0)); if (entity != null) { return($"I{entity.Name}"); } return($"I{attribute.ParentEntity.Name}"); }
public ResourceComponent(DerivedAttribute resource, int value = 0) { ComponentType = AbilityComponentType.Resource; Resource = resource; Value = value; Setup(); }
public ResourceComponent() { ComponentType = AbilityComponentType.Resource; Resource = DerivedAttribute.None; Value = 0; Setup(); }
protected string GetInterfaceCSTypeFull(DerivedAttribute attribute) { var baseNamespace = Settings.CrossAccessNamespace.Replace("." + Settings.SchemaInterfacesNamespace, ""); var fullName = TypeHelper.GetCSType(attribute.Domain, Settings, true, true, GetFullNamespace(attribute.Domain, baseNamespace, Settings.CrossAccessStructure)); fullName = TweekDerivedType(attribute, fullName); //fullName = fullName.Replace("List<", "IEnumerable<"); return(TrimNamespace(fullName)); }
public static void Run() { Console.WriteLine(nameof(TestAttributeInheritance)); DerivedAttribute attr = typeof(TestType).GetCustomAttribute <DerivedAttribute>(); if (attr.Field != "Hello" || attr.Property != 100) { throw new Exception(); } }
protected string GetDerivedAccess(DerivedAttribute attribute) { if (attribute.AccessCandidates == null || !attribute.AccessCandidates.Any()) { return(null); } if (string.IsNullOrWhiteSpace(attribute.AccessFunction)) { return("return " + string.Join(" ?? ", attribute.AccessCandidates.Select(c => string.Join(".", c))) + ";"); } var singleAccess = string.Join(".", attribute.AccessCandidates.First()); return($"return {attribute.AccessFunction}({singleAccess});"); }
protected string GetDerivedKeyword(DerivedAttribute attribute) { var overrides = Type.AllSupertypes.Any(s => s.DerivedAttributes.Any(d => d.Name == attribute.Name)); if (overrides) { return("override "); } var virt = Type.AllSubTypes.Any(s => s.DerivedAttributes.Any(d => d.Name == attribute.Name)); if (virt) { return("virtual "); } return(""); }
protected bool IsIgnored(DerivedAttribute attribute) { var type = attribute.ParentEntity; if (Settings.IgnoreDerivedAttributes == null || !Settings.IgnoreDerivedAttributes.Any()) { return(false); } if (type.IsInAllSelects.Any(s => Settings.IgnoreDerivedAttributes.Any(i => string.Compare(i.EntityName, s.Name, StringComparison.InvariantCultureIgnoreCase) == 0 && string.Compare(i.Name, attribute.Name, StringComparison.InvariantCultureIgnoreCase) == 0))) { return(true); } return(type.AllSupertypes.Any(s => Settings.IgnoreDerivedAttributes.Any(i => string.Compare(i.EntityName, s.Name, StringComparison.InvariantCultureIgnoreCase) == 0 && string.Compare(i.Name, attribute.Name, StringComparison.InvariantCultureIgnoreCase) == 0))); }
protected bool IsDirectDerived(DerivedAttribute attribute) { var domain = attribute.Domain; var aggr = domain as AggregationType; while (aggr != null) { domain = aggr.ElementType; aggr = domain as AggregationType; } if (domain is SimpleType) { return(true); } var named = domain as EntityDefinition; if (named == null) { return(false); } return(SpecialDerivesDictionary.Keys.Any(s => string.Compare(s, named.Name, StringComparison.InvariantCultureIgnoreCase) == 0)); }
//TODO: Add try catch public override void Run() { try { using (CurrentDbContext = new AryaDbDataContext(CurrentProjectId, ImportRequestedBy)) { List <DerivedAttributeInterchangeRecord> allData = ImportData.DerivedAttributes; //read all the data into a list<T>, change this as its not very efficient and scalable. //CsvConfiguration conf = GetCurrentConfiguration(); ////char delimiterChar = (char)FieldDelimiter.GetDisplayTextAndDbValue().DbValue; //using (var csvReader = new CsvReader(File.OpenText(InputFilePath), conf)) //{ // allData = csvReader.GetRecordsWithNulls<DerivedAttributeInterchangeRecord>().Distinct(new DerivedAttributeInterchangeRecordComparer()).ToList(); //} var invalidRecords = allData.GetInvalidRecords(); var derivedAttributeInterchangeRecords = invalidRecords as IList <DerivedAttributeInterchangeRecord> ?? invalidRecords.ToList(); derivedAttributeInterchangeRecords.ToList().ForEach(ir => _warnings.Add(new WorkerWarning { LineData = ir.ToString(), ErrorMessage = Properties.Resources.RequiredValueNullWarningMessage })); var validImportRecords = allData.Except(derivedAttributeInterchangeRecords.ToList()).ToList(); int insertCount = 0; int updateCount = 0; int ignoreCount = 0; // load a dictionary with taxonomy string / id pairs (taken from TaxonomyImport) var taxDict = CurrentDbContext.ExecuteQuery <TaxonomyPathAndId>( @"SELECT TaxonomyPath, TaxonomyID FROM V_Taxonomy WHERE TaxonomyPath <> '' AND ProjectId = {0}", CurrentProjectId). ToDictionary(key => key.TaxonomyPath, value => value.TaxonomyId, StringComparer.OrdinalIgnoreCase); // iterate through the input records. foreach (var csvRecord in validImportRecords) { var currentRecord = csvRecord; // check for AttributeName - pull Id var attIds = from a in CurrentDbContext.Attributes where a.AttributeName == currentRecord.DerivedAttributeName && a.AttributeType == AttributeTypeEnum.Derived.ToString() // AttributeTypeEnum.Derived.ToString() select a.ID; if (!attIds.Any()) { _warnings.Add(new WorkerWarning() { LineData = currentRecord.ToString(), ErrorMessage = Properties.Resources.AttributeDoesNotExistWarningMessage }); continue; } if (taxDict.ContainsKey(currentRecord.TaxonomyPath)) { Guid taxId = taxDict[currentRecord.TaxonomyPath]; var dAtt = from d in CurrentDbContext.DerivedAttributes where d.TaxonomyID == taxId && d.AttributeID == attIds.First() select d; // if derived attribute exists, update it, otherwise insert a new one. if (dAtt.Any()) { var updatedAttribute = dAtt.First(); if (SameValue(updatedAttribute, currentRecord)) { ignoreCount++; continue; } updatedAttribute.Expression = csvRecord.DerivedAttributeExpression.Trim(); updatedAttribute.MaxResultLength = csvRecord.MaxResultLength; updateCount++; } else { var newAttribute = new DerivedAttribute { ID = Guid.NewGuid(), TaxonomyID = taxId, AttributeID = attIds.First(), Expression = csvRecord.DerivedAttributeExpression, MaxResultLength = csvRecord.MaxResultLength }; CurrentDbContext.DerivedAttributes.InsertOnSubmit(newAttribute); insertCount++; } } else//its a global derived attribute record { var existingGlobalDerivedAttribute = CurrentDbContext.DerivedAttributes.FirstOrDefault(da => da.AttributeID == attIds.First() && da.TaxonomyID == null); // if derived attribute exists, update it, otherwise insert a new one. if (existingGlobalDerivedAttribute != null) { // var updatedAttribute = existingGlobalDerivedAttribute.First(); if (SameValue(existingGlobalDerivedAttribute, currentRecord)) { ignoreCount++; continue; } existingGlobalDerivedAttribute.Expression = currentRecord.DerivedAttributeExpression.Trim(); existingGlobalDerivedAttribute.MaxResultLength = currentRecord.MaxResultLength; updateCount++; } else { var newAttribute = new DerivedAttribute { ID = Guid.NewGuid(), TaxonomyID = null, AttributeID = attIds.First(), Expression = csvRecord.DerivedAttributeExpression, MaxResultLength = csvRecord.MaxResultLength }; CurrentDbContext.DerivedAttributes.InsertOnSubmit(newAttribute); insertCount++; } } } SaveDataChanges(); ProcessSummaryReport(insertCount, updateCount, ignoreCount); } } catch (IndexOutOfRangeException ex) { var newException = new Exception(Properties.Resources.InvalidRowInInputFileMessage, ex); Summary.SetError(newException); } catch (Exception ex) { Summary.SetError(ex);//.SummaryError = _derivedAttributeImportWorkerError; } }
private bool SameValue(DerivedAttribute existingGlobalDerivedAttribute, DerivedAttributeInterchangeRecord currentRecord) { return(String.Compare(existingGlobalDerivedAttribute.Expression, currentRecord.DerivedAttributeExpression) == 0 && existingGlobalDerivedAttribute.MaxResultLength == currentRecord.MaxResultLength); }
protected bool IsOverwritting(DerivedAttribute attribute) { return(attribute.ParentEntity.AllSupertypes.Any(s => s.DerivedAttributes.Any(d => d.Name == attribute.Name))); }