/// <summary>
        /// Updates an attribute value, or appends a new attribute, in an NGSIv2 entity
        /// </summary>
        /// <param name="id">ID of the entity in the NGSIv2 endpoint</param>
        /// <param name="attributeName">Name of the attribute that should be updated</param>
        /// <param name="attributeUpdate">New attribute object according to NGSIv2 spec</param>
        public void UpdateOrAppend(string id, string attributeName, Dictionary <string, object> attributeUpdate)
        {
            Entity fivesEntity  = new Entity();
            bool   entityExists = true;

            try
            {
                fivesEntity = World.Instance.First(entity => entity.ContainsComponent("ngsi") && entity["ngsi"]["id"].Value.Equals(id));
            }
            catch
            {
                entityExists = false;
            }
            if (entityExists)
            {
                var entityComponent = fivesEntity[attributeName];
                var attributeValue  = attributeUpdate["value"];
                foreach (KeyValuePair <string, object> attr in (Dictionary <string, object>)attributeValue)
                {
                    entityComponent[attr.Key].Suggest(attr.Value);
                }
            }

            AttributeObject update = new AttributeObject();

            update.value = attributeUpdate["value"];
            ngsiClient.AttributeContext.UpdateAttribute(id, attributeName, update, r => { });
        }
示例#2
0
    public AttributeObject HardCoding()
    {
        AttributeObject attribute = attributeDatabse.attributeObjects[Random.Range(0, attributeDatabse.attributeObjects.Length)];


        return(attribute);
    }
        private object HandleWildcard(string wildcard, EntityObject entityObject, AttributeObject attributeObject, EntityPropertyItem entityPropertyItem, UIHierarchyNodeObject appHierarchyNodeObject)
        {
            IEnumerable <EntityPropertyItem> hierarchy;
            EntityPropertyItem parent;

            if (attributeObject != null)
            {
                hierarchy = entityPropertyItem.GetAncestorProperties(attributeObject);
                parent    = hierarchy.First();
            }
            else
            {
                hierarchy = entityPropertyItem.GetAncestorProperties(entityObject);
                parent    = hierarchy.First();
            }

            if (entityPropertyItem.PropertyName == "UIHierarchyPath")
            {
                switch (parent.PropertyName)
                {
                case "IdentityField":
                case "UI":
                {
                    var uiPath = appHierarchyNodeObject.GetUIPath();
                }

                break;
                }
            }

            return(null);
        }
        private AttributeObject LoadAttribute(AttributeObject curObject, string NameOFAttribute, string SizeOFAttribute)
        {
            curObject.Name = NameOFAttribute;
            curObject.Size = Int32.Parse(SizeOFAttribute);

            return curObject;
        }
示例#5
0
    public bool FindAvailabeGroupAndType(AttributeObject attribute, ItemObject item)
    {
        bool group = false;
        bool type  = false;

        for (int i = 0; i < attribute.availableGroups.Length; i++)
        {
            if (item.group == attribute.availableGroups[i])
            {
                group = true;
                break;
            }
        }

        for (int i = 0; i < attribute.availableTypes.Length; i++)
        {
            if (item.type == attribute.availableTypes[i])
            {
                type = true;
                break;
            }
        }
        if (group == true && type == true)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
        /// <summary>
        /// Updates an attribute of an entity along with its metadata
        /// </summary>
        /// <param name="entityId">Id of the entity of which the attribute should be updated</param>
        /// <param name="attributeName">Name of the attribute that should be updated</param>
        /// <param name="newAttribute">New attribute data</param>
        /// <param name="callback">Callback that should be invoked when the request returned</param>
        public void UpdateAttribute
            (string entityId, string attributeName, AttributeObject newAttribute, Action <RequestResponse> callback)
        {
            string      path    = EntitiesResource + "/" + entityId + "/attrs/" + attributeName;
            RestRequest request = new RestRequest(path, Method.PUT);

            request.AddHeader("Content-Type", "application/json");
            request.AddJsonBody(newAttribute);
            Client.SendRequest(request, callback);
        }
        internal AttributeObject CreateNumAttribute(string NameOfAttribute, string SizeOfAttribute)
        {
            AttributeObject curObject = new AttributeObject();

            curObject.Type = AttributeConstants.NUM;

            curObject = LoadAttribute(curObject, NameOfAttribute, SizeOfAttribute);

            return curObject;
        }
        /// <summary>   Process this.  </summary>
        ///
        /// <remarks>   Ken, 10/5/2020. </remarks>
        ///
        /// <param name="entityObject">             The entity object. </param>
        /// <param name="attributeObject">          The attribute object. </param>
        /// <param name="entityPropertyItem">       The entity property item. </param>
        /// <param name="annotationType"></param>
        /// <param name="propertyBuilder">          The property builder. </param>
        /// <param name="appHierarchyNodeObject">   The application hierarchy node object. </param>
        /// <param name="generatorConfiguration">   The generator configuration. </param>
        ///
        /// <returns>   True if it succeeds, false if it fails. </returns>

        public bool Process(EntityObject entityObject, AttributeObject attributeObject, EntityPropertyItem entityPropertyItem, Type annotationType, PropertyBuilder propertyBuilder, AppUIHierarchyNodeObject appHierarchyNodeObject, IGeneratorConfiguration generatorConfiguration)
        {
            if (annotationType != null)
            {
                return(Process(entityObject, attributeObject, entityPropertyItem, appHierarchyNodeObject, annotationType, (c) => propertyBuilder.SetCustomAttribute(c)));
            }
            else
            {
                throw new Exception($"Cannot find Attribute type or custom handler to process property '{ entityPropertyItem.PropertyName }");
            }
        }
示例#9
0
    public void DebugTest()
    {
        Debug.Log(attributeDatabse.attributeObjects.Length);
        int             attributeID = Random.Range(0, attributeDatabse.attributeObjects.Length);
        AttributeObject attribute   = attributeDatabse.attributeObjects[attributeID];

        ItemObject itemObject = itemDatabase.ItemObjects[Random.Range(0, itemDatabase.ItemObjects.Length)];

        Debug.Log(attribute.name);
        Debug.Log(itemObject.name);

        Debug.Log(FindAvailabeGroupAndType(attribute, itemObject));
    }
示例#10
0
    public AttributeObject[] ItemSet(ItemObject item)
    {
        int attributeCount = AttributeCount(item.data.itemRank);

        AttributeObject[] attributes = new AttributeObject[attributeCount];


        for (int i = 0; i < attributeCount; i++)
        {
            for (int j = 0; j < 10000; j++)
            {
                int             attributeID = Random.Range(0, attributeDatabse.attributeObjects.Length);
                AttributeObject attribute   = attributeDatabse.attributeObjects[attributeID];


                if (attribute.isSelected == false)
                {
                    if (FindAvailabeGroupAndType(attribute, item) == true)
                    {
                        if (item.level >= attribute.requiredLevel)
                        {
                            attributes[i] = attribute;

                            //for (int k = 0; k < attributeDatabse.attributeObjects.Length; k++)
                            //{
                            //    if (attributeDatabse.attributeObjects[k].attributeType == attribute.attributeType)
                            //    {
                            //        attributeDatabse.attributeObjects[k].isSelected = true;
                            //    }
                            //}
                            break;
                        }
                    }
                }

                if (j == 9000)
                {
                    Debug.Log("Break Point");
                    break;
                }
            }
        }


        for (int i = 0; i < attributeDatabse.attributeObjects.Length; i++)
        {
            attributeDatabse.attributeObjects[i].isSelected = false;
        }
        return(attributes);
    }
示例#11
0
        private async void cmdBurnEdge_Click(object sender, EventArgs e)
        {
            // Edge cannot go below 1.
            if (await AttributeObject.ValueAsync <= 0)
            {
                Program.ShowMessageBox(await LanguageManager.GetStringAsync("Message_CannotBurnEdge"), await LanguageManager.GetStringAsync("MessageTitle_CannotBurnEdge"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Verify that the user wants to Burn a point of Edge.
            if (Program.ShowMessageBox(await LanguageManager.GetStringAsync("Message_BurnEdge"), await LanguageManager.GetStringAsync("MessageTitle_BurnEdge"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            AttributeObject.Degrade(1);
            ValueChanged?.Invoke(this, e);
        }
        internal AttributeObject Create(string NameOfAttribute, string TypeOfAttribute, string SizeOfAttribute)
        {
            AttributeObject currentAttribute = new AttributeObject();

            switch(TypeOfAttribute)
            {
                case AllSpecialSymbols.CHAR:
                    currentAttribute = AttributeService.CreateCharAttribute(NameOfAttribute, SizeOfAttribute);
                    break;
                case AllSpecialSymbols.NUM:
                    currentAttribute = AttributeService.CreateNumAttribute(NameOfAttribute, SizeOfAttribute);
                    break;
                default:
                    ErrorHandlerSURLY.AttributeErrors.UnrecoginizedType(TypeOfAttribute);
                    break;
            }

            return currentAttribute;
        }
示例#13
0
        /// <summary>   Parse file. </summary>
        ///
        /// <remarks>   Ken, 10/1/2020. </remarks>
        ///
        /// <param name="path">             Full pathname of the file. </param>
        /// <param name="textReplacements"> The text replacements. </param>
        ///
        /// <returns>   A List&lt;TRecord&gt; </returns>

        public override List <EntityDomainRecord> ParseFile(string path, Dictionary <string, string> textReplacements)
        {
            var          records    = base.ParseFile(path, textReplacements);
            EntityObject lastEntity = null;

            this.Entities = new List <EntityObject>();

            foreach (var record in records)
            {
                if (record.EntityName != null)
                {
                    var entity = new EntityObject(record.EntityName, record.ParentDataItem);

                    if (record.Properties != null)
                    {
                        entity.Properties.AddRange(record.Properties);
                    }

                    this.Entities.Add(entity);

                    lastEntity = entity;
                }
                else if (record.AttributeName != null)
                {
                    var attribute = new AttributeObject(record.AttributeName, record.AttributeType);

                    if (record.Properties != null)
                    {
                        attribute.Properties.AddRange(record.Properties);
                    }

                    lastEntity.Attributes.Add(attribute);
                }
                else
                {
                    DebugUtils.Break();
                }
            }

            return(records);
        }
示例#14
0
        private void cmdImproveATT_Click(object sender, EventArgs e)
        {
            int intUpgradeKarmaCost = AttributeObject.UpgradeKarmaCost;

            if (intUpgradeKarmaCost == -1)
            {
                return;                            //TODO: more descriptive
            }
            if (intUpgradeKarmaCost > _objCharacter.Karma)
            {
                Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_NotEnoughKarma"), LanguageManager.GetString("MessageTitle_NotEnoughKarma"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string confirmstring = string.Format(GlobalSettings.CultureInfo, LanguageManager.GetString("Message_ConfirmKarmaExpense"), AttributeObject.DisplayNameFormatted, AttributeObject.Value + 1, intUpgradeKarmaCost);

            if (!CommonFunctions.ConfirmKarmaExpense(confirmstring))
            {
                return;
            }

            AttributeObject.Upgrade();
            ValueChanged?.Invoke(this, e);
        }
        private string GetAllAttributesOfARelationThatTheUserRequested(RelationObject relationObjectToGrabAttributesFrom, IList<AttributeObject> attributesRequestedByUser)
        {
            EnsureObjectContainsAttributes(relationObjectToGrabAttributesFrom);

            string curSymbol = QueryParser.FindNextSymbol();

            while(!AllSpecialSymbols.GetListOfAllSymbols().Contains(curSymbol))
            {
                AttributeObject attributeToAddToAttributesRequestedByUser = new AttributeObject();

                EnsureAttributeExistInObject(curSymbol, relationObjectToGrabAttributesFrom);
                attributeToAddToAttributesRequestedByUser = GetAttributeObjectFromRelationObject(curSymbol, relationObjectToGrabAttributesFrom);

                attributesRequestedByUser.Add(attributeToAddToAttributesRequestedByUser);

                curSymbol = QueryParser.FindNextSymbol();
            }

            return curSymbol;
        }
 internal void RenewObjects()
 {
     relationToCreate = new RelationObject();
     attributesForRelationToCreate = new List<AttributeObject>();
     currentAttribute = new AttributeObject();
     currentSymbol = string.Empty;
     RelationNamesToDestroy = new List<String>();
     RelationNameToDelete = string.Empty;
     reading = false;
     RelationCRUDService = new RelationCRUDServices(this);
     RelationService = new RelationServices();
     QueryService = new QueryServices();
 }
 public TupleCellObject()
 {
     Value = string.Empty;
     AttributeAssociatedWithCell = new AttributeObject();
 }
        private bool Process(EntityObject entityObject, AttributeObject attributeObject, EntityPropertyItem entityPropertyItem, UIHierarchyNodeObject appHierarchyNodeObject, Type annotationType, Action <CustomAttributeBuilder> builderAction)
        {
            var argValues       = new List <object>();
            var namedFields     = new List <FieldInfo>();
            var fieldValues     = new List <object>();
            var namedProperties = new List <PropertyInfo>();
            var propertyValues  = new List <object>();

            var constructor = annotationType.GetConstructors().FirstOrDefault(c =>
            {
                var hasParmsFieldsOrProperties = false;
                var hasParm     = false;
                var hasField    = false;
                var hasProperty = false;
                var parameters  = c.GetParameters();
                var x           = 0;

                if (entityPropertyItem.ChildProperties == null)
                {
                    if (parameters.Length == 1 && !entityPropertyItem.PropertyValue.IsNullOrEmpty())
                    {
                        var parm = parameters.FirstOrDefault();

                        if (parm == parameters.ElementAt(x))
                        {
                            var value = this.GetValue(parm.ParameterType, entityPropertyItem, (w) => HandleWildcard(w, entityObject, attributeObject, entityPropertyItem, appHierarchyNodeObject));
                            argValues.Add(value);
                            hasParmsFieldsOrProperties = true;
                            x++;
                        }
                    }
                }
                else
                {
                    foreach (var childProperty in entityPropertyItem.ChildProperties)
                    {
                        var propertyName          = childProperty.PropertyName;
                        var propertyNameCamelCase = propertyName.ToCamelCase();
                        object value;

                        if (propertyName.StartsWith("UI"))
                        {
                            propertyNameCamelCase = "ui" + propertyName.RemoveStartIfMatches("UI");
                        }

                        hasParm = parameters.Any(p => p.Name.IsOneOf(propertyName, propertyNameCamelCase));

                        if (hasParm)
                        {
                            var parm = parameters.Single(p => p.Name.IsOneOf(propertyName, propertyNameCamelCase));

                            if (parm == parameters.ElementAt(x))
                            {
                                value = this.GetValue(parm.ParameterType, childProperty, (w) => HandleWildcard(w, entityObject, attributeObject, childProperty, appHierarchyNodeObject));
                                argValues.Add(value);
                                hasParmsFieldsOrProperties = true;
                                x++;
                            }

                            continue;
                        }

                        hasField = annotationType.GetFields().Any(f => f.Name.IsOneOf(propertyName, propertyNameCamelCase));

                        if (hasField)
                        {
                            var field = annotationType.GetFields().Single(f => f.Name.IsOneOf(propertyName, propertyNameCamelCase));

                            value = this.GetValue(field.FieldType, childProperty, (w) => HandleWildcard(w, entityObject, attributeObject, childProperty, appHierarchyNodeObject));
                            argValues.Add(value);
                            namedFields.Add(field);
                            hasParmsFieldsOrProperties = true;

                            continue;
                        }

                        hasProperty = annotationType.GetProperties().Any(p => p.Name.IsOneOf(propertyName, propertyNameCamelCase));

                        if (hasProperty)
                        {
                            var property = annotationType.GetProperties().Single(p => p.Name.IsOneOf(propertyName, propertyNameCamelCase));

                            value = this.GetValue(property.PropertyType, childProperty, (w) => HandleWildcard(w, entityObject, attributeObject, childProperty, appHierarchyNodeObject));
                            argValues.Add(value);
                            namedProperties.Add(property);
                            hasParmsFieldsOrProperties = true;

                            continue;
                        }

                        if (!hasParmsFieldsOrProperties)
                        {
                            break;
                        }
                    }
                }

                if (x != parameters.Length)
                {
                    var remainingParms = parameters.Skip(x).ToArray();

                    if (remainingParms.Length == 0)
                    {
                        return(false);
                    }
                    else
                    {
                        foreach (var remainingParm in remainingParms)
                        {
                            if (remainingParm.HasDefaultValue)
                            {
                                argValues.Add(remainingParm.DefaultValue);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }

                return(hasParmsFieldsOrProperties);
            });

            if (constructor != null)
            {
                builderAction(new CustomAttributeBuilder(constructor, argValues.ToArray(), namedProperties.ToArray(), propertyValues.ToArray(), namedFields.ToArray(), fieldValues.ToArray()));

                return(true);
            }
            else
            {
                throw new Exception($"Cannot find appropriate constructor for annotation type '{ annotationType.AsDisplayText() }' matching property '{ entityPropertyItem.PropertyName }");
            }
        }
        private string CropValueToSize(AttributeObject attr, string curSymbol)
        {
            string convertedSizeOfCurSymbol = string.Empty;

            switch (attr.Type)
            {
                case AttributeConstants.CHAR:
                    convertedSizeOfCurSymbol = CropRightmostCharacters(attr, curSymbol);
                    break;
                case AttributeConstants.NUM:
                    convertedSizeOfCurSymbol = CropLeftmostCharacters(attr, curSymbol);
                    break;
                default:
                    ErrorHandlerSURLY.TupleErrors.InvalidType(attr.Type);
                    break;
            }

            return convertedSizeOfCurSymbol;
        }
        private string CropRightmostCharacters(AttributeObject attr, string curSymbol)
        {
            string convertedSizeOfCurSymbol = curSymbol;

            if (curSymbol.Length > attr.Size)
            {
                convertedSizeOfCurSymbol = curSymbol.Remove(attr.Size);
            }

            return convertedSizeOfCurSymbol;
        }
 private void ConfirmTupleValueMatchesAttributeType(AttributeObject attr, string curSymbol)
 {
     switch(attr.Type)
     {
         case AttributeConstants.CHAR:
             // Already string
             break;
         case AttributeConstants.NUM:
             ConfirmTypleIsANumber(curSymbol);
             break;
         default:
             ErrorHandlerSURLY.TupleErrors.InvalidType(attr.Type);
             break;
     }
 }