Ejemplo n.º 1
0
        internal static bool IsSearchableProperty(string propertyPath, out KClass kClass, DocumentValidator documentValidator)
        {
            kClass = null;
            var objectPathArray = propertyPath.ToLower().Split('.');

            if (objectPathArray.Length > 1 && documentValidator != null && documentValidator.entities != null && documentValidator.entities.Count > 0)
            {
                var            obClass    = new KClass();
                var            obProperty = new KProperty();
                IList <KClass> allClasses = null;
                if (documentValidator.entities.Keys.Any(x => x == objectPathArray[0].ToLower()))
                {
                    allClasses = documentValidator.entities[objectPathArray[0].ToLower()].Classes;
                }
                else if (documentValidator.entities.First().Value.Classes.Any(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == objectPathArray[0].ToLower()))
                {
                    allClasses = documentValidator.entities.First().Value.Classes;
                }
                if (allClasses != null && allClasses.Any())
                {
                    var dataTypeClasses = Kitsune.Helper.Constants.DataTypeClasses;
                    for (var i = 0; i < objectPathArray.Length; i++)
                    {
                        if (i == 0)
                        {
                            obClass = allClasses.FirstOrDefault(x => x.ClassType == KClassType.BaseClass && x.Name == objectPathArray[i]);
                            if (obClass == null)
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            obProperty = obClass.PropertyList.FirstOrDefault(x => x.Name.ToLower() == objectPathArray[i]);
                            if (obProperty == null)
                            {
                                return(false);
                            }
                            else if ((obProperty.Type == PropertyType.array && !dataTypeClasses.Contains(obProperty.DataType?.Name?.ToLower())) || obProperty.Type == PropertyType.obj)
                            {
                                obClass = allClasses.FirstOrDefault(x => x.ClassType == KClassType.UserDefinedClass && x.Name?.ToLower() == obProperty.DataType?.Name?.ToLower());
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    if (obClass != null)
                    {
                        kClass = obClass;
                        if (obProperty != null && obProperty.Type == PropertyType.array)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        internal KProperty GetProperty(string expression, KEntity entity)
        {
            KProperty kProperty = null;
            KClass    kClass    = null;

            string[] classHierarchyList = expression.Split('.');
            if (entity != null)
            {
                kClass = entity.Classes.Where(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == classHierarchyList[0].ToLower()).FirstOrDefault();
                if (kClass == null)
                {
                    return(null);
                }
                for (int i = 1; i < classHierarchyList.Length - 1; i++)
                {
                    string    propName = classHierarchyList[i].Split('[')[0];
                    KProperty prop     = kClass.PropertyList.Where(x => x.Name.ToLower() == propName.ToLower()).FirstOrDefault();
                    if (prop == null)
                    {
                        return(null);
                    }
                    kClass = entity.Classes.Where(x => x.Name.ToLower() == prop.DataType.Name.ToLower()).FirstOrDefault();
                    if (kClass == null)
                    {
                        return(null);
                    }
                }
                string finalPropName = classHierarchyList[classHierarchyList.Length - 1].Split('[')[0].ToLower();
                kProperty = kClass.PropertyList.Where(x => x.Name == finalPropName).FirstOrDefault();
            }
            return(kProperty);
        }
Ejemplo n.º 3
0
 public Program()
 {
     MyProperty = new KProperty(this);
     MyProperty.Load();
     Runtime.UpdateFrequency    = UpdateFrequency.Update100;
     drawingSurface             = Me.GetSurface(0);
     drawingSurface.ContentType = ContentType.TEXT_AND_IMAGE;
     Search();
 }
        internal static KClass childClasses(dynamic jsonObject, List <KClass> subclasses)
        {
            try
            {
                if (jsonObject != null)
                {
                    var propertyList = jsonObject["PropertyList"];
                    var tempClass    = new KClass()
                    {
                        ClassType   = (KClassType)jsonObject["ClassType"].Value,
                        Name        = jsonObject["Name"].Value,
                        Description = jsonObject["Name"].Value,
                        IsCustom    = true,
                    };
                    var tempPropertyList = new List <KProperty>();
                    foreach (var tempArray in propertyList)
                    {
                        var property   = new KProperty();
                        var typeExists = DynamicFieldExists(tempArray, "Type");
                        if (typeExists)
                        {
                            var propType = tempArray["Type"];
                            property.Type = (PropertyType)tempArray["Type"].Value;
                            property.Name = tempArray["Name"].Value;
                            if (property.Type == PropertyType.array)
                            {
                                var propertyName = tempArray["DataType"];
                                property.DataType = new DataType(propertyName["Name"].Value.ToString());
                            }
                            tempPropertyList.Add(property);
                        }
                        else
                        {
                            property.Name     = tempArray["Name"].Value;
                            property.Type     = PropertyType.obj;
                            property.DataType = new DataType(tempArray["Name"].Value.ToString());
                            tempPropertyList.Add(property);
                            DeeperClasses(tempArray, subclasses);
                        }


                        var tempObject = tempArray;
                    }

                    tempClass.PropertyList = tempPropertyList;

                    return(tempClass);
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Ejemplo n.º 5
0
        private void Init()
        {
            MyProperty = new KProperty(this);
            MyProperty.Load();
            Stage          = 0;
            bottom_pistons = BlockSystem <IMyPistonBase> .SearchByGroup(this, "Foreuse Bottom Pistons");

            bottom_pistons.ForEach(delegate(IMyPistonBase block) {
                block.MinLimit = MyProperty.locker_position_min;
                block.MaxLimit = MyProperty.locker_position_max;
            });
            bottom_mergers = BlockSystem <IMyShipMergeBlock> .SearchByGroup(this, "Foreuse Bottom Mergers");

            top_pistons = BlockSystem <IMyPistonBase> .SearchByGroup(this, "Foreuse Top Pistons");

            top_pistons.ForEach(delegate(IMyPistonBase block) {
                block.MinLimit = MyProperty.locker_position_min;
                block.MaxLimit = MyProperty.locker_position_max;
            });
            top_mergers = BlockSystem <IMyShipMergeBlock> .SearchByGroup(this, "Foreuse Top Mergers");

            connector = BlockSystem <IMyShipConnector> .SearchByName(this, "Foreuse Connector Drills");

            levage_pistons = BlockSystem <IMyPistonBase> .SearchByGroup(this, "Foreuse Levage Pistons");

            levage_pistons.ForEach(delegate(IMyPistonBase block) {
                block.MinLimit = MyProperty.elevator_position_min;
                block.MaxLimit = MyProperty.elevator_position_max;
            });

            grinder_stator = BlockSystem <IMyMotorStator> .SearchByName(this, "Foreuse Grinder Stator");

            grinders = BlockSystem <IMyShipGrinder> .SearchByGroup(this, "Foreuse Grinders");

            welder_stator = BlockSystem <IMyMotorStator> .SearchByName(this, "Foreuse Welder Stator");

            welders = BlockSystem <IMyShipWelder> .SearchByGroup(this, "Foreuse Welders");

            projector = BlockSystem <IMyProjector> .SearchByName(this, "Foreuse Projector Drill");

            light = BlockSystem <IMyLightingBlock> .SearchByGroup(this, "Foreuse Rotating Light");

            drills = BlockSystem <IMyShipDrill> .SearchByGroup(this, "Foreuse Drills");

            control_lcds = BlockSystem <IMyTextPanel> .SearchByName(this, "Foreuse Control LCD");

            control_lcds.ForEach(delegate(IMyTextPanel block)
            {
                block.ContentType = ContentType.TEXT_AND_IMAGE;
            });

            SequenceBlocks = new List <int>()
            {
            };
        }
Ejemplo n.º 6
0
 public Program()
 {
     MyProperty = new KProperty(this);
     MyProperty.Load();
     drawingSurface             = Me.GetSurface(0);
     drawingSurface.ContentType = ContentType.TEXT_AND_IMAGE;
     // Set the continuous update frequency of this script
     Runtime.UpdateFrequency = UpdateFrequency.Update10;
     phase = Phase.None;
     Prepare();
 }
Ejemplo n.º 7
0
        public static bool IsSearchableProperty(string propertyPath, KEntity entity, out KClass kClass)
        {
            kClass = null;
            var objectPathArray = propertyPath.ToLower().Split('.');

            if (objectPathArray.Length > 1)
            {
                var obClass         = new KClass();
                var obProperty      = new KProperty();
                var dataTypeClasses = Kitsune.Helper.Constants.DataTypeClasses;
                for (var i = 0; i < objectPathArray.Length; i++)
                {
                    if (i == 0)
                    {
                        obClass = entity.Classes.FirstOrDefault(x => x.ClassType == KClassType.BaseClass && x.Name == objectPathArray[i]);
                        if (obClass == null)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        obProperty = obClass.PropertyList.FirstOrDefault(x => x.Name.ToLower() == objectPathArray[i]);
                        if (obProperty == null)
                        {
                            return(false);
                        }
                        else if ((obProperty.Type == PropertyType.array && !dataTypeClasses.Contains(obProperty.DataType?.Name?.ToLower())) || obProperty.Type == PropertyType.obj)
                        {
                            obClass = entity.Classes.FirstOrDefault(x => x.ClassType == KClassType.UserDefinedClass && x.Name?.ToLower() == obProperty.DataType?.Name?.ToLower());
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                if (obClass != null)
                {
                    kClass = obClass;
                    if (obProperty != null && obProperty.Type == PropertyType.array)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 8
0
        internal KProperty GetProperty(List <CompilerError> compileErrors, HtmlAttribute dynamicAttribute, DocumentValidator documentValidator, string referenceObject, Dictionary <string, string> classNameAlias)
        {
            KProperty kProperty      = null;
            KClass    kClass         = null;
            string    expression     = referenceObject;
            string    baseExpression = expression.Split('.')[0].Split('[')[0].ToLower();

            while (baseExpression != "kresult" && baseExpression != "search" && classNameAlias.ContainsKey(baseExpression))
            {
                string[] expressionParts = expression.Split('.');
                expressionParts[0] = classNameAlias[baseExpression];
                expression         = String.Join(".", expressionParts);
                baseExpression     = expression.Split('.')[0].Split('[')[0].ToLower();
            }
            string[] classHierarchyList = expression.Split('.');
            KEntity  entity             = documentValidator?.GetKEntityFromEntityName(classHierarchyList[0]) ?? documentValidator?.GetKEntityFromEntityName(documentValidator.defaultEntity);

            if (entity != null)
            {
                kClass = entity.Classes.Where(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == classHierarchyList[0].ToLower()).FirstOrDefault();
                if (kClass == null)
                {
                    compileErrors.Add(CompileResultHelper.GetCompileError(String.Format(ErrorCodeConstants.UnrecognizedType, classHierarchyList[0]), dynamicAttribute.Line, dynamicAttribute.LinePosition));
                    return(null);
                }
                for (int i = 1; i < classHierarchyList.Length - 1; i++)
                {
                    string    propName = classHierarchyList[i].Split('[')[0];
                    KProperty prop     = kClass.PropertyList.Where(x => x.Name.ToLower() == propName.ToLower()).FirstOrDefault();
                    if (prop == null)
                    {
                        compileErrors.Add(CompileResultHelper.GetCompileError(String.Format(ErrorCodeConstants.UnrecognizedProperty, propName), dynamicAttribute.Line, dynamicAttribute.LinePosition));
                        return(null);
                    }
                    kClass = entity.Classes.Where(x => x.Name.ToLower() == prop.DataType.Name.ToLower()).FirstOrDefault();
                    if (kClass == null)
                    {
                        compileErrors.Add(CompileResultHelper.GetCompileError(String.Format(ErrorCodeConstants.UnrecognizedType, prop.DataType.Name), dynamicAttribute.Line, dynamicAttribute.LinePosition));
                        return(null);
                    }
                }
                string finalPropName = classHierarchyList[classHierarchyList.Length - 1].Split('[')[0].ToLower();
                kProperty = kClass.PropertyList.Where(x => x.Name == finalPropName && x.Type == PropertyType.array).FirstOrDefault();
            }
            return(kProperty);
        }
        private dynamic GetDefaultProperty(KEntity entity, string fullExpression)
        {
            KProperty property = GetProperty(fullExpression, entity);

            switch (property.Type)
            {
            case PropertyType.str:
                return("");

            case PropertyType.number:
                return(0);

            case PropertyType.boolean:
                return(false);

            case PropertyType.kstring:
                return("");
            }
            return(null);
        }
Ejemplo n.º 10
0
        public Program()
        {
            MyProperty = new KProperty(this);
            MyProperty.Load();
            drawingSurface             = Me.GetSurface(0);
            drawingSurface.ContentType = ContentType.TEXT_AND_IMAGE;
            Runtime.UpdateFrequency    = UpdateFrequency.Update100;

            lat_stators = BlockSystem <IMyMotorStator> .SearchByName(this, MyProperty.Name);

            if (!lat_stators.IsEmpty)
            {
                lon_stators = BlockSystem <IMyMotorStator> .SearchByGrid(this, lat_stators.First.Top.CubeGrid);

                solar_panels = new BlockSystem <IMySolarPanel>();
                foreach (IMyMotorStator lon_stator in lon_stators.List)
                {
                    solar_panels.Merge(BlockSystem <IMySolarPanel> .SearchByGrid(this, lon_stator.Top.CubeGrid));
                }
            }
        }
        public static List <PropertyPathSegment> ExtractPropertiesFromPath(string propertyPath, KEntity entity)
        {
            List <PropertyPathSegment> kProperties = new List <PropertyPathSegment>();

            var objectPathArray = propertyPath.ToLower().Split('.');
            var obClass         = new KClass();
            var obProperty      = new KProperty();
            var dataTypeClasses = new string[] { "str", "date", "number", "boolean", "kstring" };
            var currentProperty = string.Empty;
            var arrayRegex      = new System.Text.RegularExpressions.Regex(@".*\[(\d+)\]", System.Text.RegularExpressions.RegexOptions.Compiled);
            var functionRegex   = new System.Text.RegularExpressions.Regex(@"(\w+)\((.*)\)", System.Text.RegularExpressions.RegexOptions.Compiled);
            int?arrayIndex      = 0;
            int tempIndex       = 0;

            System.Text.RegularExpressions.Match arrayMatch    = null;
            System.Text.RegularExpressions.Match functionMatch = null;
            for (var i = 0; i < objectPathArray.Length; i++)
            {
                currentProperty = objectPathArray[i];
                arrayMatch      = arrayRegex.Match(currentProperty);
                arrayIndex      = null;
                if (arrayMatch != null && arrayMatch.Success)
                {
                    if (int.TryParse(arrayMatch.Groups[1].Value, out tempIndex))
                    {
                        arrayIndex = tempIndex;
                    }
                    currentProperty = currentProperty.Substring(0, currentProperty.IndexOf('['));
                }

                if (i == 0)
                {
                    obClass = entity.Classes.FirstOrDefault(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == currentProperty);
                    if (obClass != null)
                    {
                        kProperties.Add(new PropertyPathSegment {
                            PropertyDataType = obClass.Name.ToLower(), PropertyName = currentProperty, Type = PropertyType.obj
                        });
                    }
                }
                else
                {
                    obProperty = obClass.PropertyList.FirstOrDefault(x => x.Name.ToLower() == currentProperty);
                    if (obProperty != null)
                    {
                        if ((obProperty.Type == PropertyType.array && !dataTypeClasses.Contains(obProperty.DataType?.Name?.ToLower())) || obProperty.Type == PropertyType.obj || obProperty.Type == PropertyType.kstring || obProperty.Type == PropertyType.phonenumber)
                        {
                            kProperties.Add(new PropertyPathSegment
                            {
                                PropertyName     = obProperty.Name.ToLower(),
                                PropertyDataType = obProperty.DataType.Name.ToLower(),
                                Index            = arrayIndex,
                                Type             = obProperty.Type
                            });

                            obClass = entity.Classes.FirstOrDefault(x => x.Name?.ToLower() == obProperty.DataType?.Name?.ToLower());
                        }
                        else
                        {
                            kProperties.Add(new PropertyPathSegment
                            {
                                PropertyName     = obProperty.Name.ToLower(),
                                PropertyDataType = obProperty.DataType.Name.ToLower(),
                                Index            = arrayIndex,
                                Type             = obProperty.Type
                            });
                        }
                    }
                    else
                    {
                        functionMatch = functionRegex.Match(currentProperty);
                        if (functionMatch.Success)
                        {
                            kProperties.Add(new PropertyPathSegment
                            {
                                PropertyName     = functionMatch.Groups[1].Value,
                                PropertyDataType = "function",
                                Type             = PropertyType.function
                            });
                        }
                    }
                }
            }
            return(kProperties);
        }
Ejemplo n.º 12
0
        public override void ProcessNode(CompileResourceRequest request, List <CompilerError> compileErrors, Dictionary <string, int> customVariables, string rootUrl, string filePath, Dictionary <string, string> classNameAlias, Dictionary <int, string> classNameAliasdepth, int depth, HtmlNode node, HtmlAttribute dynamicAttribute, List <MatchNode> objectNamesToValidate, DocumentValidator documentValidator)
        {
            Node result = LexerGenerator.Parse(dynamicAttribute.Value.Trim('[', ']'));

            if (result?.Token?.Value == ACTIONS.Loop)
            {
                string referenceObject = result.Children[0].Children[0].Token.Value;
                string iterator        = result.Children[2].Children[0].Token.Value;
                //Fix issue with same iterator being used at same depth.
                if (classNameAlias.ContainsKey(iterator) && classNameAliasdepth.ContainsKey(depth) && classNameAliasdepth[depth].Contains(iterator))
                {
                    classNameAlias.Remove(iterator);
                    string oldAliasDepth = classNameAliasdepth[depth];
                    classNameAliasdepth.Remove(depth);
                    oldAliasDepth = oldAliasDepth.Replace(iterator, "").Replace(",,", ",");
                    classNameAliasdepth.Add(depth, oldAliasDepth);
                }
                if (!classNameAlias.ContainsKey(iterator))
                {
                    classNameAlias.Add(iterator, "");
                    if (classNameAliasdepth.ContainsKey(depth))
                    {
                        string oldAliasDepth = classNameAliasdepth[depth];
                        classNameAliasdepth.Remove(depth);
                        classNameAliasdepth.Add(depth, oldAliasDepth + ',' + iterator);
                    }
                    else
                    {
                        classNameAliasdepth.Add(depth, iterator);
                    }
                    objectNamesToValidate.Add(new MatchNode {
                        Value = referenceObject, Line = dynamicAttribute.Line, Column = dynamicAttribute.LinePosition
                    });
                    try
                    {
                        if (result?.Children[4]?.Token?.Value?.ToString() == "ViewProperty" && result?.Children[4]?.Children[1]?.Token?.Value?.ToLower() == "offset")
                        {
                            //Added list type in condition as there might update in the offset and reference object so we have to update the meta also
                            if (request.PageType == Models.Project.KitsunePageType.LIST || request.PageType == Models.Project.KitsunePageType.DEFAULT || request.PageType == Models.Project.KitsunePageType.DETAILS)
                            {
                                request.PageType = Models.Project.KitsunePageType.LIST;
                                request.Offset   = result.Children[6]?.Children[0]?.Token?.Value;
                                request.KObject  = referenceObject;
                            }
                        }
                    }
                    catch { }

                    string[] classHierarchyList = referenceObject.Split('.');
                    if (classHierarchyList[0].StartsWith("kresult", System.StringComparison.InvariantCultureIgnoreCase) || classHierarchyList[0].Equals("search", System.StringComparison.InvariantCultureIgnoreCase))
                    {
                        //pass
                    }
                    else if (classHierarchyList.Length >= 2)
                    {
                        KProperty kProperty = GetProperty(compileErrors, dynamicAttribute, documentValidator, referenceObject, classNameAlias);
                        if (kProperty == null)
                        {
                            compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.KRepeatVariableNotArray, dynamicAttribute.Line, dynamicAttribute.LinePosition));
                        }
                        if (iterator.Split('.').Length > 1)
                        {
                            compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.KRepeatInvalidIterator, dynamicAttribute.Line, dynamicAttribute.LinePosition));
                        }

                        KEntity entity = documentValidator?.GetKEntityFromEntityName(classHierarchyList[0]) ?? documentValidator?.GetKEntityFromEntityName(documentValidator.defaultEntity);
                        if (entity?.Classes?.Where(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == iterator.ToLower()).FirstOrDefault() != null)
                        {
                            compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.BaseClassAsKRepeatIterator, dynamicAttribute.Line, dynamicAttribute.LinePosition));
                        }
                    }
                }
                else
                {
                    compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.KRepeatVariableAlreadyInUse, dynamicAttribute.Line, dynamicAttribute.LinePosition));
                }
            }
            else if (result?.Token?.Value == ACTIONS.InLoop)
            {
                string loopVariable    = result.Children[0].Children[0].Token.Value.ToLower();
                string referenceObject = result.Children[2].Children[0].Token.Value.ToLower() + $"[{GenerateVariableName(5)}]";
                objectNamesToValidate.Add(new MatchNode {
                    Value = referenceObject, Line = dynamicAttribute.Line, Column = dynamicAttribute.LinePosition
                });

                if (classNameAlias.ContainsKey(loopVariable))
                {
                    compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.KRepeatVariableAlreadyInUse, dynamicAttribute.Line, dynamicAttribute.LinePosition));
                    return;
                }
                KEntity entity = documentValidator?.GetKEntityFromEntityName(loopVariable) ?? documentValidator?.GetKEntityFromEntityName(documentValidator.defaultEntity);
                if (entity.Classes.Where(x => x.ClassType == KClassType.BaseClass && x.Name.ToLower() == loopVariable).Any())
                {
                    compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.BaseClassAsKRepeatVariable, dynamicAttribute.Line, dynamicAttribute.LinePosition));
                    return;
                }

                classNameAlias.Add(loopVariable, referenceObject);

                if (classNameAliasdepth.ContainsKey(depth))
                {
                    string oldAliasDepth = classNameAliasdepth[depth];
                    classNameAliasdepth.Remove(depth);
                    classNameAliasdepth.Add(depth, oldAliasDepth + ',' + loopVariable);
                }
                else
                {
                    classNameAliasdepth.Add(depth, loopVariable);
                }
            }
            else
            {
                compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.InvalidKRepeatSyntax, dynamicAttribute.Line, dynamicAttribute.LinePosition));
            }
            dynamicAttribute.Value = "";
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Process nodes with k-object tags.
        /// </summary>
        /// <param name="request">Incoming request</param>
        /// <param name="compileErrors">list of errors during compilation</param>
        /// <param name="kentity">project language</param>
        /// <param name="customVariables">output list to hold custom variables</param>
        /// <param name="rootUrl">root url</param>
        /// <param name="filePath">file path</param>
        /// <param name="classNameAlias">aliases used either with k-repeat or k-object</param>
        /// <param name="classNameAliasdepth">depth based storage of aliases</param>
        /// <param name="depth">depth of the node in DOM</param>
        /// <param name="dynamicAttribute">key-value pair of the k-tag</param>
        public override void ProcessNode(CompileResourceRequest request, List <CompilerError> compileErrors, Dictionary <string, int> customVariables, string rootUrl, string filePath, Dictionary <string, string> classNameAlias, Dictionary <int, string> classNameAliasdepth, int depth, HtmlNode node, HtmlAttribute dynamicAttribute, List <MatchNode> objectNamesToValidate, DocumentValidator documentValidator)
        {
            Node result = LexerGenerator.Parse(dynamicAttribute.Value.Trim('[', ']'));

            if (result?.Children?.Count == 3)
            {
                string referenceNames        = result.Token.Value == ACTIONS.KObject ? result.Children[0].Token.Value : result.Children[0].Children[0].Token.Value.ToLower();
                string referenceObject       = result.Children[2].Children[0].Token.Value.ToLower();
                var    referenceKObjectArray = referenceNames.Split(',');

                KEntity kentity = documentValidator.GetKEntityFromEntityName(documentValidator.defaultEntity);
                var     referenceObjectWithIterator = UpdateIterator(referenceObject, documentValidator);

                var tempRefObj = referenceObjectWithIterator.Trim();
                for (int i = referenceKObjectArray.Length - 1, j = 0; i >= 0; i--, j++)
                {
                    KEntity commEntity = documentValidator.GetKEntityFromEntityName(referenceKObjectArray[i]);
                    if (commEntity != null || (kentity != null && kentity.Classes.Where(x => x.Name?.ToLower() == referenceObject?.Split('.')?[0] && x.ClassType == KClassType.BaseClass).Count() == 0))
                    {
                        compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.BaseClassAsKObjectVariable, dynamicAttribute.Line, dynamicAttribute.LinePosition));
                        return;
                    }
                    else
                    {
                        if (commEntity != null)
                        {
                            kentity = commEntity;
                        }
                        if (j > 0)
                        {
                            tempRefObj = tempRefObj.Substring(0, tempRefObj.LastIndexOf('.'));
                        }
                        KProperty property = GetProperty(compileErrors, dynamicAttribute, documentValidator, tempRefObj, classNameAlias);


                        if (property == null)
                        {
                            compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.InvalidKObjectClass, dynamicAttribute.Line, dynamicAttribute.LinePosition));

                            return;
                        }
                        else if (property.Type == PropertyType.array)
                        {
                            classNameAlias.Add(referenceKObjectArray[i], tempRefObj);
                            objectNamesToValidate.Add(new MatchNode {
                                Value = tempRefObj, Line = dynamicAttribute.Line, Column = dynamicAttribute.LinePosition
                            });
                        }
                        else
                        {
                            classNameAlias.Add(referenceKObjectArray[i], tempRefObj);
                            objectNamesToValidate.Add(new MatchNode {
                                Value = tempRefObj, Line = dynamicAttribute.Line, Column = dynamicAttribute.LinePosition
                            });
                        }
                    }
                }
                request.PageType = Models.Project.KitsunePageType.DETAILS;
                var searchableProperty = IsSearchableProperty(referenceObject, out KClass kobjClass, documentValidator);

                if (referenceObject.StartsWith("webactions.") || kobjClass != null)
                {
                    request.KObject = referenceNames.Trim() + ":" + referenceObject;
                }
                else
                {
                    request.KObject = referenceNames.Trim();
                }
            }
            else
            {
                compileErrors.Add(CompileResultHelper.GetCompileError(ErrorCodeConstants.InvalidKObjectSyntax, dynamicAttribute.Line, dynamicAttribute.LinePosition));
            }
            dynamicAttribute.Value = "";
        }
Ejemplo n.º 14
0
 private void Init()
 {
     MyProperty = new KProperty(this);
     MyProperty.Load();
 }
Ejemplo n.º 15
0
        public IActionResult AddClassProperty([FromRoute] string languageId, [FromRoute] string classname, [FromBody] KProperty kProperty)
        {
            try
            {
                var userId = string.Empty;
                userId = AuthHelper.AuthorizeRequest(Request);

                var tempCommand = new AddPropertyRequestModel()
                {
                    Property   = kProperty,
                    ClassName  = classname,
                    UserId     = userId,
                    LanguageId = languageId
                };

                List <System.ComponentModel.DataAnnotations.ValidationResult> validationResult = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                if (kProperty == null)
                {
                    validationResult.Add(new System.ComponentModel.DataAnnotations.ValidationResult("Property can not be null"));
                }
                else if (string.IsNullOrEmpty(kProperty.Name))
                {
                    validationResult.Add(new System.ComponentModel.DataAnnotations.ValidationResult("Property name can not be null"));
                }

                if (validationResult.Any())
                {
                    return(BadRequest(validationResult));
                }

                return(Ok(MongoConnector.AddPropertyToClass(tempCommand)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }