/*public async Task ChangeAttributes(Dictionary<string, Tuple<ClrType, object>> newAttributeValues,
         *  Guid? aggregateId = null, Guid? aggregateClassId = null,
         *  Guid? entityId = null, Guid? entityClassId = null)
         * {
         *  foreach (var attributeValue in newAttributeValues)
         *  {
         *      // TODO better solution without reflection
         *      var method = this.GetType().GetMethod("ChangeAttribute").MakeGenericMethod(attributeValue.Value.Item1);
         *      Task task = (Task)method.Invoke(this, new object[] { attributeValue.Key, attributeValue.Value.Item2,
         *          aggregateId, aggregateClassId, entityId, entityClassId });
         *      await task;
         *  }
         * }*/

        private async Task <Tuple <T, bool> > FindOldValueAndReplace <T>(Guid?aggregateId, Guid?entityId,
                                                                         string attributeName, T newValue)
        {
            var entityKey = new TrackedEntityKey()
            {
                EntityId = entityId, AggregateId = aggregateId
            };
            EntityAttributeData attributes;

            if (!entityAttributes.TryGetValue(entityKey, out attributes))
            {
                attributes = await crudRepository
                             .FirstOrDefaultAsync <EntityAttributeData>(x => x.AggregateId == aggregateId && x.EntityId == entityId);

                if (attributes == null)
                {
                    attributes = new EntityAttributeData(Guid.NewGuid(), aggregateId, entityId);
                    crudRepository.Add(attributes);
                }

                entityAttributes[entityKey] = attributes;
            }

            T    oldValue    = default(T);
            bool hasOldValue = attributes.TryGetAttributeValue <T>(attributeName, out oldValue);

            attributes.SetAttributeValue(attributeName, newValue);
            return(new Tuple <T, bool>(oldValue, hasOldValue));
        }
示例#2
0
        public List <EntityAttributeData> ParseEntityAttributeData()
        {
            List <EntityAttributeData> list = new List <EntityAttributeData>();

            string[] fileNamess = Directory.GetFiles(rootPath, "entityAttributeMap*.tsv").Select(Path.GetFileName).ToArray();

            List <string> lines = new List <string>();

            foreach (string fileName in fileNamess)
            {
                string content = File.ReadAllText(rootPath + fileName);
                lines.AddRange(content.Split('\n').ToList <string>());
            }

            int seqNo = 1;

            foreach (string line in lines)
            {
                string theLine = line.Trim();

                if (string.IsNullOrWhiteSpace(theLine))
                {
                    continue;
                }

                string[] tmps = theLine.Split('\t');

                if (tmps.Count() != 5)
                {
                    throw new Exception("invalid line in entityAttributeMap.tsv");
                }
                else
                {
                    string intentName     = tmps[0];
                    string entityValue    = tmps[1];
                    string entityType     = tmps[2];
                    string attributeName  = tmps[3];
                    string attributeValue = tmps[4];

                    EntityAttributeData ea = new EntityAttributeData();
                    ea.id             = seqNo.ToString();
                    ea.intentName     = intentName;
                    ea.entityValue    = entityValue;
                    ea.entityType     = entityType;
                    ea.attributeName  = attributeName;
                    ea.attributeValue = attributeValue;

                    list.Add(ea);
                    seqNo += 1;
                }
            }

            return(list);
        }
示例#3
0
 public EntityAttribute(EntityAttributeData entityAttributeData)
 {
     if (entityAttributeData == null)
     {
         throw new ArgumentNullException(nameof(entityAttributeData));
     }
     AttributeId            = entityAttributeData.AttributeId;
     EntityId               = entityAttributeData.AttributeEntityId;
     AttributeValue         = entityAttributeData.AttributeValue;
     AttributeDataType      = entityAttributeData.AttributeDataType;
     AttributeDisplayFormat = entityAttributeData.AttributeDisplayFormat;
     EntityType             = new EntityType(entityAttributeData.AttributeEntityType);
     AttributeType          = new AttributeType(entityAttributeData.AttributeType);
 }
示例#4
0
        public void SetEntityAttribute(EntityAttributeData entityAttributeData)
        {
            if (entityAttributeData == null)
            {
                throw new ArgumentNullException(nameof(entityAttributeData));
            }
            var existingAttribute = CompanyAttributes.FirstOrDefault(a => a.AttributeType.AttributeTypeCode == entityAttributeData.AttributeType.AttributeTypeCode);

            if (existingAttribute != null)
            {
                CompanyAttributes.Remove(existingAttribute);
            }
            CompanyAttributes.Add(new EntityAttribute(entityAttributeData));
        }
示例#5
0
 public EntityAttribute Map(EntityAttributeData ent)
 {
     return(new EntityAttribute(ent));
 }