Esempio n. 1
0
        private int ParseObject(int index, WrapperObject parentNode)
        {
            parentNode.Value = new List <WrapperType>();
            while (this.TokenList[index] != "}")
            {
                string valueName = string.Empty;

                index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index);

                valueName = this.TokenList[index++];

                index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index);
                index = RulesUtility.ValidateToken(this.TokenList[index], ":", "Invalid Token. Need \":\" for divider of value", index);

                index = ParseValue(index, valueName, parentNode);

                if (this.TokenList[index] == ",")
                {
                    index++;
                }
                else if (this.TokenList[index] == "}")
                {
                    // will cancel out
                }
                else
                {
                    throw new Exception("Invalid Token. Need last double quote for name of value");
                }
            }
            return(index);
        }
Esempio n. 2
0
        private int AddHeader(int index)
        {
            var otherHeaders = new WrapperObject("HEADERS");

            while (this.TokenList[index].ToLower() != "namespace")
            {
                if (this.TokenList[index].ToLower() == "using")
                {
                    index++;
                    if (this.TokenList[index].ToLower() == "system")
                    {
                        while (this.TokenList[index] != ";")
                        {
                            index++;
                        }
                    }
                    else
                    {
                        string location = string.Empty;
                        while (this.TokenList[index] != ";")
                        {
                            location += this.TokenList[index++];
                        }
                        otherHeaders.Value.Add(new WrapperString("IMPORT", location));
                    }
                }
                index++;
            }
            this.Structure.Add(otherHeaders);
            return(index);
        }
Esempio n. 3
0
        private int AddClassLikeType(int index, WrapperObject wrapperObject, WrapperObject parentObject, string flag)
        {
            index = RulesUtility.ValidateToken(this.TokenList[index], flag, $"This is not an accurate {flag}.", index);

            while (this.TokenList[index] != "{")
            {
                wrapperObject.WrapperName += this.TokenList[index++];
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This is an invalid class opener.", index);

            switch (flag)
            {
            case "enum":
                index = BuildEnumContent(index, wrapperObject);
                break;

            case "class":
                index = BuildClassContent(index, wrapperObject);
                break;

            default:
                throw new Exception($"Unable to make a enum, struct, or class with this token {flag}.");
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This is an invalid class closer.", index);

            parentObject.Value.Add(wrapperObject);

            return(index);
        }
Esempio n. 4
0
 public void Copy <TType>(WrapperObject <TType> wrapper) where TType : SuperObject
 {
     if (wrapper._justATestField is T tField)
     {
         _justATestField = tField;
     }
 }
Esempio n. 5
0
    public WrapperObject <SuperObject> GetBaseWrapper()
    {
        var baseWrapper = new WrapperObject <SuperObject>();

        baseWrapper.Copy(this);
        return(baseWrapper);
    }
Esempio n. 6
0
        private int BuildClassProperty(int index, WrapperObject contentObject)
        {
            if (this.TokenList[index] == ";")
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index);
                return(index);
            }
            var    type      = (WrapperString)contentObject.GetValue("VALUE_TYPE");
            string statement = $"{type.Value} {contentObject.WrapperName} ";

            while (this.TokenList[index] != ";")
            {
                string lookAhead = this.TokenList[index + 1];
                statement += this.TokenList[index];
                if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" &&
                    this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" &&
                    this.TokenList[index] != "\"" && this.TokenList[index] != "\'")
                {
                    statement += " ";
                }
                index++;
            }
            index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index);
            contentObject.Value.Add(new WrapperString("STATEMENT_1", statement));
            return(index);
        }
Esempio n. 7
0
        private int BuildEnumContent(int index, WrapperObject enumObject)
        {
            int           times       = 0;
            WrapperObject enumContent = new WrapperObject("ENUM_CONTENT");

            while (this.TokenList[index] != "}")
            {
                WrapperString enumEntry = new WrapperString($"ENUM_VALUE_{times++}", string.Empty);

                while (this.TokenList[index] != "}" && this.TokenList[index] != ",")
                {
                    enumEntry.Value += this.TokenList[index++];
                }

                enumContent.Value.Add(enumEntry);

                if (this.TokenList[index] != "}")
                {
                    index = RulesUtility.ValidateToken(this.TokenList[index], ",", $"{enumObject.WrapperName} enum object needs a valid divider.", index);
                }
            }

            enumObject.Value.Add(enumContent);

            return(index);
        }
Esempio n. 8
0
        private int FillConditionalStatement(int index, WrapperObject wrapperObject)
        {
            string conditionStatement = string.Empty;
            var    values             = string.Empty;

            index = RulesUtility.ValidateToken(this.TokenList[index], "(", "This needs is a valid \'(\'.", index);
            conditionStatement += "(";
            while (this.TokenList[index] != ")")
            {
                string lookAhead = this.TokenList[index + 1];
                values += this.TokenList[index];
                if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" &&
                    this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" &&
                    this.TokenList[index] != "\"" && this.TokenList[index] != "\'")
                {
                    values += " ";
                }
                index++;
            }
            conditionStatement += values;
            index = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index);
            conditionStatement += ")";
            wrapperObject.Value.Add(new WrapperString("CONDITION_STATEMENT", conditionStatement));

            return(index);
        }
Esempio n. 9
0
        private void ConnectWeighingMachineService()
        {
            grdContainer.BlockUI();
            mBolWeighingMachineLoaded = false;

            try
            {
                mObjWeighingMachineServer = (WeighingMachineServerObject)Activator.GetObject(typeof(WeighingMachineServerObject), "http://localhost:8810/WeighingMachine");
                mObjWrapperObject         = new WrapperObject();

                mObjWeighingMachineServer.DataReceived += new WeighingMachineEventHandler(mObjWrapperObject.WrapperOnDataReceived);
                mObjWrapperObject.WrapperDataReceived  += new WeighingMachineEventHandler(OnDataReceived);

                mObjWeighingMachineConnection = mObjWeighingMachineServer.Connect();
                mBolWeighingMachineLoaded     = true;
            }
            catch (Exception lObjException)
            {
                grdContainer.UnblockUI();
                ShowMessage("Error", lObjException.Message);
                mBolWeighingMachineLoaded = false;
            }
            finally
            {
                grdContainer.UnblockUI();
            }
        }
Esempio n. 10
0
        public void Callsite_ElementBinding_Functions_UniqueIds_ForReplicationOfInnerAndOuterFunction()
        {
            WrapperObject.ResetNextID();
            var ws = Open <HomeWorkspaceModel>(TestDirectory, callsiteDir, "func_nested_replication.dyn");

            BeginRun();
            AssertPreviewValue("22e0f3229b314aa48914e8f6b925872c", Enumerable.Range(1, 3).ToList());
            // this node currently rebinds to its inner callsites so there are repeated values being returned.
            // it's not clear this behavior is correct, but it matches expected results with zeroTouch nodes nested in
            // other zero touch nodes which access trace. This test is created to note the current behavior and to
            // alert us if it changes.
            AssertPreviewValue("74cd0ca6d4964ec2b500fbe96139d28c", new int[][] {
                new int[] { 4 },
                new int[] { 4, 5 },
                new int[] { 4, 5, 6 },
                new int[] { 4, 5, 6, 7 }
            });

            /*
             * AssertPreviewValue("74cd0ca6d4964ec2b500fbe96139d28c", new int[][] {
             * new int[] {4},
             * new int[] {5,6 },
             * new int[]{7,8,9 },
             * new int[]{10,11,12,13 }
             * });
             */
        }
Esempio n. 11
0
        private int FillDoWhile(int index, WrapperObject doObject)
        {
            WrapperObject doContentObject = new WrapperObject("DO_CONTENT");

            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
            index = this.FillFunctionContent(index, doContentObject);
            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);

            WrapperString whileCond = new WrapperString("WHILE_COND", string.Empty);

            index = RulesUtility.ValidateToken(this.TokenList[index], "while", "This needs is a valid \'while\'.", index);
            while (this.TokenList[index] != ")")
            {
                string lookAhead = this.TokenList[index + 1];
                whileCond.Value += this.TokenList[index];
                if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" &&
                    this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" &&
                    this.TokenList[index] != "\"" && this.TokenList[index] != "\'")
                {
                    whileCond.Value += " ";
                }
                index++;
            }

            index            = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index);
            whileCond.Value += ")";

            index            = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index);
            whileCond.Value += ";";

            doObject.Value.Add(doContentObject);
            doObject.Value.Add(whileCond);
            return(index);
        }
Esempio n. 12
0
        private int FillTryCatch(int index, WrapperObject mainTryObject)
        {
            WrapperObject tryBlockObject = new WrapperObject("TRY_CONTENT");

            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
            index = this.FillFunctionContent(index, tryBlockObject);
            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);

            mainTryObject.Value.Add(tryBlockObject);

            if (this.TokenList[index] == "catch")
            {
                WrapperObject catchBlockObject = new WrapperObject("CATCH_CONTENT");

                index = RulesUtility.ValidateToken(this.TokenList[index], "catch", "This needs is a valid \'catch\'.", index);

                if (this.TokenList[index] == "(")
                {
                    string exStatement = string.Empty;

                    while (this.TokenList[index] != ")")
                    {
                        string lookAhead = this.TokenList[index + 1];
                        exStatement += this.TokenList[index];
                        if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" &&
                            this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" &&
                            this.TokenList[index] != "\"" && this.TokenList[index] != "\'")
                        {
                            exStatement += " ";
                        }
                        index++;
                    }

                    index        = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index);
                    exStatement += ")";

                    catchBlockObject.Value.Add(new WrapperString("CATCH_COND", exStatement));
                }

                index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
                index = this.FillFunctionContent(index, catchBlockObject);
                index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);

                mainTryObject.Value.Add(catchBlockObject);
            }

            if (this.TokenList[index] == "finally")
            {
                WrapperObject finallyObject = new WrapperObject("FINALLY_CONTENT");

                index = RulesUtility.ValidateToken(this.TokenList[index], "finally", "This needs is a valid \'finally\'.", index);
                index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
                index = this.FillFunctionContent(index, finallyObject);
                index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);

                mainTryObject.Value.Add(finallyObject);
            }

            return(index);
        }
Esempio n. 13
0
        public void Callsite_ElementBinding_ShouldReturnUniqueIds()
        {
            WrapperObject.ResetNextID();
            var ws = Open <HomeWorkspaceModel>(TestDirectory, callsiteDir, "nonNestedWorking_replication.dyn");

            BeginRun();
            AssertPreviewValue("a74679f905fc4883bb017851d94ac074", Enumerable.Range(1, 6).ToList());
        }
Esempio n. 14
0
        public void Callsite_ElementBinding_CustomNodes_ShouldReturnUniqueIds()
        {
            WrapperObject.ResetNextID();
            var ws = Open <HomeWorkspaceModel>(TestDirectory, callsiteDir, "element_binding_customNodes_replication.dyn");

            BeginRun();
            AssertPreviewValue("3cab31e7c7e646cfb11f6145edf1d8c3", Enumerable.Range(1, 6).ToList());
        }
Esempio n. 15
0
        private int ParseValue(int index, string valueName, WrapperObject parentNode)
        {
            WrapperType actualValue;

            if (this.TokenList[index].Contains("."))
            {
                var proposedDouble = this.TokenList[index].Split(".");
                if (int.TryParse(proposedDouble[0], out _) && int.TryParse(proposedDouble[1], out _))
                {
                    actualValue = new WrapperDouble(valueName, double.Parse(this.TokenList[index++]));
                }
                else
                {
                    actualValue = new WrapperString(valueName, this.TokenList[index++]);
                }
            }
            else if (int.TryParse(this.TokenList[index], out _))
            {
                actualValue = new WrapperInt(valueName, int.Parse(this.TokenList[index++]));
            }
            else if (this.TokenList[index].ToLower() == "true" || this.TokenList[index].ToLower() == "false")
            {
                bool boolVal = bool.Parse(this.TokenList[index++]);
                actualValue = new WrapperBool(valueName, boolVal);
            }
            else if (this.TokenList[index] == "<")
            {
                if (valueName.ToLower().Contains("array"))
                {
                    actualValue = new WrapperArray(valueName, null);
                    index       = ParseArray(index, actualValue as WrapperArray);
                }
                else
                {
                    actualValue = new WrapperObject(valueName, null);
                    index       = ParseObject(index, actualValue as WrapperObject);
                }
            }
            else
            {
                actualValue = new WrapperString(valueName, this.TokenList[index++]);
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index);
            if (valueName.ToLower().Contains("array"))
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], $"/{valueName.ToLower()}", $"Invalid Token. Need closing name {valueName} for name of value", index);
            }
            else
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], $"/{valueName}", $"Invalid Token. Need closing name {valueName} for name of value", index);
            }
            index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index);

            parentNode.Value.Add(actualValue);
            return(index);
        }
Esempio n. 16
0
        private int FillBracketStatement(int index, WrapperObject wrapperObject)
        {
            index = this.FillConditionalStatement(index, wrapperObject);

            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
            index = this.FillFunctionContent(index, wrapperObject);
            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);

            return(index);
        }
Esempio n. 17
0
        private int BuildFunction(int index, WrapperObject functionObject, bool isStruct)
        {
            int           holderValue = 1;
            WrapperObject parameters  = new WrapperObject("PARAMETERS");

            index = RulesUtility.ValidateToken(this.TokenList[index], "(", "This needs is a valid \'(\'.", index);

            while (this.TokenList[index] != ")")
            {
                WrapperObject parameter = new WrapperObject($"PARAMETER_{holderValue++}");
                if (RulesUtility.IsValidType(this.ProgramTypeLanguage, this.TokenList[index]))
                {
                    string valueName = this.TokenList[index++];
                    if (this.TokenList[index] == "[")
                    {
                        valueName += "[]";
                        index     += 2;
                    }
                    parameter.Value.Add(new WrapperString("VALUE_TYPE", valueName));
                    parameter.Value.Add(new WrapperString("PARAM_NAME", this.TokenList[index++]));
                    if (this.TokenList[index] == ")")
                    {
                        parameters.Value.Add(parameter);
                        break;
                    }
                    index = RulesUtility.ValidateToken(this.TokenList[index], ",", "This needs is a valid \',\'.", index);
                }
                else
                {
                    throw new Exception("This is an invalid parameter type.");
                }
                parameters.Value.Add(parameter);
            }

            if (isStruct && parameters.Value.Count < 0)
            {
                throw new Exception("You cannot have a default constructor for a struct object.");
            }
            else if (parameters.Value.Count > 0)
            {
                functionObject.Value.Add(parameters);
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index);
            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
            WrapperObject functionContent = new WrapperObject("FUNCTION_CONTENT");

            index = this.FillFunctionContent(index, functionContent);

            functionObject.Value.Add(functionContent);

            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);

            return(index);
        }
Esempio n. 18
0
        private int BuildAutoProperty(int index, WrapperObject contentObject, WrapperObject parentObject)
        {
            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index);
            WrapperObject setObject = new WrapperObject("SET");
            WrapperObject getObject = new WrapperObject("GET");

            contentObject.CopyData(getObject);
            contentObject.CopyData(setObject);

            string compVariableName = "_" + char.ToLower(contentObject.WrapperName[0]).ToString() + contentObject.WrapperName.Substring(1);
            string holdOlderName    = contentObject.WrapperName;

            if (!parentObject.GetKeys().Contains(compVariableName))
            {
                contentObject.WrapperName = compVariableName;
                contentObject.UpdateStringValue("ACCESS_MOD", "private");
                parentObject.Value.Add(contentObject);
            }

            WrapperString valueType  = setObject.GetValue("VALUE_TYPE") as WrapperString;
            WrapperObject parameters = new WrapperObject("PARAMETERS");
            WrapperObject parameter  = new WrapperObject($"PARAMETER_1");

            parameter.Value.Add(new WrapperString("VALUE_TYPE", valueType.Value));
            parameter.Value.Add(new WrapperString("PARAM_NAME", "value"));
            setObject.UpdateStringValue("VALUE_TYPE", "void");
            parameters.Value.Add(parameter);
            setObject.Value.Add(parameters);

            if (this.TokenList[index] == "get")
            {
                index = this.BuildAuxMethod(index, getObject, compVariableName);
                index = this.BuildAuxMethod(index, setObject, compVariableName);
            }
            else if (this.TokenList[index] == "set")
            {
                index = this.BuildAuxMethod(index, setObject, compVariableName);
                index = this.BuildAuxMethod(index, getObject, compVariableName);
            }
            else
            {
                throw new Exception("This auto property needs an explicet get and set keywords.");
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index);
            getObject.WrapperName = $"Get{holdOlderName}";
            setObject.WrapperName = $"Set{holdOlderName}";
            parentObject.Value.Add(getObject);
            parentObject.Value.Add(setObject);
            this._autoPropertyList.Add(holdOlderName);
            this._autoPropertyList.Add($"this.{holdOlderName}");

            return(index);
        }
Esempio n. 19
0
        private void BuildObject(WrapperObject mainNode, string tabs)
        {
            if (mainNode.WrapperName != string.Empty)
            {
                this.Results += $"{tabs}\"{mainNode.WrapperName}\": {{\n";
            }
            for (int index = 0; index < mainNode.Value.Count; index++)
            {
                var node = mainNode.Value[index];
                switch (node)
                {
                case WrapperArray wrapperArray:
                    BuildArray(wrapperArray, tabs + "\t");
                    break;

                case WrapperObject wrapperObject:
                    BuildObject(wrapperObject, tabs + "\t");
                    break;

                case WrapperBool wrapperBool:
                    this.Results += $"{tabs + "\t"}\"{wrapperBool.WrapperName}\": {wrapperBool.Value.ToString().ToLower()}";
                    break;

                case WrapperDouble wrapperDouble:
                    this.Results += $"{tabs + "\t"}\"{wrapperDouble.WrapperName}\": {wrapperDouble.Value}";
                    break;

                case WrapperInt wrapperInt:
                    this.Results += $"{tabs + "\t"}\"{wrapperInt.WrapperName}\": {wrapperInt.Value}";
                    break;

                case WrapperString wrapperString:
                    this.Results += $"{tabs + "\t"}\"{wrapperString.WrapperName}\": \"{wrapperString.Value}\"";
                    break;

                default:
                    throw new Exception("This type is invalid for build the file.");
                }
                if (index != mainNode.Value.Count - 1)
                {
                    this.Results += ",\n";
                }
                else
                {
                    this.Results += "\n";
                }
            }
            if (mainNode.WrapperName != string.Empty)
            {
                this.Results += $"{tabs}}}";
            }
        }
Esempio n. 20
0
        private int ParseValue(int index, string valueName, WrapperObject parentNode)
        {
            WrapperType actualValue = null;

            if (this.TokenList[index].Contains("\""))
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index);

                actualValue = new WrapperString(valueName, this.TokenList[index++]);

                index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index);
            }
            else if (this.TokenList[index].Contains("."))
            {
                var proposedDouble = this.TokenList[index].Split(".");
                if (int.TryParse(proposedDouble[0], out _) && int.TryParse(proposedDouble[1], out _))
                {
                    actualValue = new WrapperDouble(valueName, double.Parse(this.TokenList[index++]));
                }
                else
                {
                    throw new Exception("This is an invlid Double Value");
                }
            }
            else if (int.TryParse(this.TokenList[index], out _))
            {
                actualValue = new WrapperInt(valueName, int.Parse(this.TokenList[index++]));
            }
            else if (this.TokenList[index] == "true" || this.TokenList[index] == "false")
            {
                bool boolVal = bool.Parse(this.TokenList[index++]);
                actualValue = new WrapperBool(valueName, boolVal);
            }
            else if (this.TokenList[index] == "{")
            {
                index++;
                actualValue = new WrapperObject(valueName, null);
                index       = ParseObject(index, actualValue as WrapperObject);
                index++;
            }
            else if (this.TokenList[index] == "[")
            {
                index++;
                actualValue = new WrapperArray(valueName, null);
                index       = ParseArray(index, actualValue as WrapperArray);
                index++;
            }

            parentNode.Value.Add(actualValue);
            return(index);
        }
Esempio n. 21
0
        private int Start(int index)
        {
            WrapperObject wholeFile = new WrapperObject("WHOLE_FILE");

            while (index < this.TokenList.Count)
            {
                WrapperObject potentialObject = new WrapperObject();

                if (RulesUtility.ValidAccessModifiers(this.ProgramTypeLanguage, this.TokenList[index]))
                {
                    potentialObject.Value.Add(new WrapperString("ACCESS_MOD", this.TokenList[index++].ToLower()));
                }
                else
                {
                    potentialObject.Value.Add(new WrapperString("ACCESS_MOD", "public"));
                }

                if (this.TokenList[index].ToLower() == "static")
                {
                    potentialObject.Value.Add(new WrapperBool("IS_STATIC", true));
                    index++;
                }
                else if (this.TokenList[index].ToLower() == "enum")
                {
                    index = this.AddClassLikeType(index, potentialObject, wholeFile, "enum");
                    continue;
                }
                else
                {
                    potentialObject.Value.Add(new WrapperBool("IS_STATIC", false));
                }

                if (this._isOneClass)
                {
                    throw new Exception("Java does not allow multiple classes. Please seperate classes into individual files.");
                }
                else
                {
                    this._isOneClass = true;
                }

                index = this.AddClassLikeType(index, potentialObject, wholeFile, "class");
            }

            this.Structure.Add(wholeFile);

            this._isOneClass = false;

            return(index);
        }
Esempio n. 22
0
        public void Callsite_ElementBinding_CustomNodes2dReplication_ShouldReturnUniqueIds()
        {
            WrapperObject.ResetNextID();
            var ws = Open <HomeWorkspaceModel>(TestDirectory, callsiteDir, "element_binding_customNodes_replication2d.dyn");

            BeginRun();
            AssertPreviewValue("3cab31e7c7e646cfb11f6145edf1d8c3", new int[][] {
                new int[] { 1 },
                new int[] { 2, 3 },
                new int[] { 4, 5, 6 },
                new int[] { 7, 8, 9, 10 },
                new int[] { 11, 12, 13, 14, 15 },
                new int[] { 16, 17, 18, 19, 20, 21 }
            });
        }
    public void OnResultExecuting(ResultExecutingContext context)
    {
        var result = context.Result;

        if (result is ObjectResult)
        {
            // wrap the inner object
            var newValue = new WrapperObject(result.Value);
            // replace the result
            context.Result = new ObjectResult(newValue)
            {
                // copy the status code
                StatusCode = result.StatusCode,
            };
        }
    }
Esempio n. 24
0
        private int ParseArray(int index, WrapperArray parentNode)
        {
            parentNode.Value = new List <WrapperObject>();
            int id = 0;

            while (this.TokenList[index] != "]")
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], "{", "Need object for arrays", index);

                var actualValue = new WrapperObject(string.Format("ID-", id++), null);
                index = ParseObject(index, actualValue);
                index++;

                bool hasNoId = true;
                foreach (var new_id in actualValue.Value)
                {
                    if (new_id.WrapperName.ToLower() == "id")
                    {
                        var tempNode = new_id as WrapperInt;
                        actualValue.WrapperName = tempNode.WrapperName + "-" + tempNode.Value;
                        hasNoId = false;
                        break;
                    }
                }

                if (hasNoId)
                {
                    throw new Exception("Array entry has no valid id. Please place id value in Json.");
                }

                parentNode.Value.Add(actualValue);

                if (this.TokenList[index] == ",")
                {
                    index++;
                }
                else if (this.TokenList[index] == "]")
                {
                    // will cancel out
                }
                else
                {
                    throw new Exception("Invalid Token. Need last double quote for name of value");
                }
            }
            return(index);
        }
Esempio n. 25
0
        private int ParseObject(int index, WrapperObject parentNode)
        {
            parentNode.Value = new List <WrapperType>();
            while (index < this.TokenList.Count)
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index);
                if (this.TokenList[index] == $"/{parentNode.WrapperName}")
                {
                    break;
                }
                string valueName = this.TokenList[index++];
                index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index);

                index = ParseValue(index, valueName, parentNode);
            }
            return(index - 1);
        }
Esempio n. 26
0
        private int AddHeader(int index)
        {
            var otherHeaders = new WrapperObject("HEADERS");

            // TODO: make sure to implement this while multi file task
            while ((this.TokenList[index].ToLower() != "class" && this.TokenList[index].ToLower() != "enum") &&
                   !RulesUtility.ValidAccessModifiers(this.ProgramTypeLanguage, this.TokenList[index]))
            {
                if (this.TokenList[index].ToLower() == "import")
                {
                    index++;
                    if (this.TokenList[index].ToLower() == "java")
                    {
                        while (this.TokenList[index] != ";")
                        {
                            index++;
                        }
                    }
                    else
                    {
                        string location = string.Empty;
                        while (this.TokenList[index] != ";")
                        {
                            location += this.TokenList[index++];
                        }
                        otherHeaders.Value.Add(new WrapperString("IMPORT", location));
                    }
                }
                else if (this.TokenList[index].ToLower() == "package")
                {
                    index = RulesUtility.ValidateToken(this.TokenList[index], "package", "This is not an accurate package.", index);
                    string packageName = string.Empty;
                    while (this.TokenList[index] != ";")
                    {
                        packageName += this.TokenList[index++];
                    }
                    otherHeaders.Value.Add(new WrapperString("PACKAGE", packageName));
                }
                index++;
            }

            this.Structure.Add(otherHeaders);

            return(index);
        }
        public string Serialize(IEnumerable <Suggestion> suggestions)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(WrapperObject));

            using (MemoryStream ms = new MemoryStream())
            {
                WrapperObject wrapperObject = new WrapperObject
                {
                    Suggestions = suggestions
                };

                serializer.WriteObject(ms, wrapperObject);

                ms.Position = 0;
                using (StreamReader sr = new StreamReader(ms))
                {
                    return(sr.ReadToEnd());
                }
            }
        }
Esempio n. 28
0
        public override void ParseFile()
        {
            Log.Info("Starting to Parse XML file.");
            WrapperType mainNode;
            int         index = 0;

            index = VerifyHeader(index);
            if (this.TokenList[index] == "<")
            {
                index++;
                if (this.TokenList[index].Contains("Array"))
                {
                    mainNode = new WrapperArray(this.TokenList[index++], null);

                    index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need first double quote for name of value", index);

                    index = ParseArray(index, mainNode as WrapperArray);

                    index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index);
                    index = RulesUtility.ValidateToken(this.TokenList[index], $"/{mainNode.WrapperName + "Array"}", $"Invalid Token. Need closing name {mainNode.WrapperName} for name of value", index);
                    index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index);
                }
                else
                {
                    mainNode = new WrapperObject(this.TokenList[index++], null);
                    index    = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need first double quote for name of value", index);
                    index    = ParseObject(index, mainNode as WrapperObject);

                    index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index);
                    index = RulesUtility.ValidateToken(this.TokenList[index], $"/{mainNode.WrapperName}", $"Invalid Token. Need closing name {mainNode.WrapperName} for name of value", index);
                    index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index);
                }
            }
            else
            {
                throw new Exception("Invalid start to XML Parsing.");
            }

            this.Structure.Add(mainNode);
            Log.Success("XML Parse Successfully Completed.");
        }
Esempio n. 29
0
        private void BuildObject(WrapperObject mainNode, string tabs)
        {
            this.Results += $"{tabs}<{mainNode.WrapperName}>\n";
            foreach (var node in mainNode.Value)
            {
                if (node.WrapperName.ToLower() == "id")
                {
                    continue;
                }
                switch (node)
                {
                case WrapperArray wrapperArray:
                    BuildArray(wrapperArray, tabs + "  ");
                    break;

                case WrapperObject wrapperObject:
                    BuildObject(wrapperObject, tabs + "  ");
                    break;

                case WrapperBool wrapperBool:
                    this.Results += $"{tabs + "  "}<{wrapperBool.WrapperName}>{wrapperBool.Value}</{wrapperBool.WrapperName}>\n";
                    break;

                case WrapperDouble wrapperDouble:
                    this.Results += $"{tabs + "  "}<{wrapperDouble.WrapperName}>{wrapperDouble.Value}</{wrapperDouble.WrapperName}>\n";
                    break;

                case WrapperInt wrapperInt:
                    this.Results += $"{tabs + "  "}<{wrapperInt.WrapperName}>{wrapperInt.Value}</{wrapperInt.WrapperName}>\n";
                    break;

                case WrapperString wrapperString:
                    this.Results += $"{tabs + "  "}<{wrapperString.WrapperName}>{wrapperString.Value}</{wrapperString.WrapperName}>\n";
                    break;

                default:
                    throw new Exception("This type is invalid for build the file.");
                }
            }
            this.Results += $"{tabs}</{mainNode.WrapperName}>\n";
        }
Esempio n. 30
0
        public void Callsite_ElementBinding_CustomNodes_MultipleRunsShouldResetInvocationCount()
        {
            WrapperObject.ResetNextID();
            var ws = Open <HomeWorkspaceModel>(TestDirectory, callsiteDir, "element_binding_customNodes_replication.dyn");

            BeginRun();
            AssertPreviewValue("3cab31e7c7e646cfb11f6145edf1d8c3", Enumerable.Range(1, 6).ToList());

            //grab the inner callsite inside the custom node
            var callsite = this.CurrentDynamoModel.EngineController.LiveRunnerRuntimeCore.RuntimeData.CallsiteCache.
                           Where(kv => kv.Key.Contains("WrapperObject")).FirstOrDefault().Value;

            //should have executed 6 times
            Assert.AreEqual(callsite.invokeCount, 6);

            //force a re execution and if binding succeeds then data should be unchanged.
            ws.Nodes.OfType <CodeBlockNodeModel>().First().SetCodeContent("5..10", ws.ElementResolver);
            AssertPreviewValue("3cab31e7c7e646cfb11f6145edf1d8c3", Enumerable.Range(1, 6).ToList());
            //count should have been reset and invoked 6 more times
            Assert.AreEqual(callsite.invokeCount, 6);
        }
Esempio n. 31
0
 public bool IsUsed(WrapperObject container)
 {
     return NativeMethods.cgIsParameterUsed(this.Handle, container.Handle);
 }
        public virtual WrapperObject ConvertToWraperObject(XmlDocument item)
        {
            WrapperObject obj = new WrapperObject(null);
            obj.MappingSettings = this.PipeSettings.Mappings;
            obj.Language = this.PipeSettings.LanguageIds.FirstOrDefault();

            obj.AddProperty(PublishingConstants.FieldTitle, item.Title);
            obj.AddProperty(PublishingConstants.FieldContent, item.Content);
            obj.AddProperty(PublishingConstants.FieldItemHash, GenerateItemHash(item));
            obj.AddProperty(PublishingConstants.FieldLink, item.Image);
            obj.AddProperty(PublishingConstants.FieldPublicationDate, item.Date);
            obj.AddProperty(PublishingConstants.FieldIdentifier, item.Id);
            obj.AddProperty(PublishingConstants.FieldCategories, item.Categories); //list of categories (Category.Name) separated by comma
            //obj.AddProperty(PublishingConstants.FieldCategories, "News");
            return obj;
        }
        protected override void SetPropertiesThroughPropertyDescriptor(IContent item, WrapperObject wrapperObj)
        {
            var properties = TypeDescriptor.GetProperties(wrapperObj);
            TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
            foreach (PropertyDescriptor propertyValue in properties)
            {
                if (propertyValue.Name.Equals("Categories")) {
                    //var Category = taxonomyManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Taxonomy.Name == "Categories").FirstOrDefault();
                    //try
                    //{
                    //   (item as Telerik.Sitefinity.GenericContent.Model.Content).Organizer.AddTaxa("Category", Category.Id);
                    //}
                    //catch (Exception e){
                    //}
                    var tagName = propertyValue.GetValue(wrapperObj).ToString();
                    var newtagname = tagName.Replace(" ", "").Replace("&", "");
                    var tagList = taxonomyManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == newtagname);
                    if (tagList.Any())
                    {
                      (item as Telerik.Sitefinity.GenericContent.Model.Content).Organizer.AddTaxa("Category", tagList.FirstOrDefault().Id);
                    }
                    else {
                        var catTaxonomy = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == "Categories").SingleOrDefault();
                       var parentTaxonomy = taxonomyManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == "News").Single();
                       var newCat = taxonomyManager.CreateTaxon<HierarchicalTaxon>();
                        newCat.Name = newtagname;
                        newCat.Title = tagName;
                        newCat.Description = "";
                        newCat.UrlName = newtagname;
                        newCat.Taxonomy = catTaxonomy;
                        parentTaxonomy.Subtaxa.Add(newCat);
                        //taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == "news").First().Taxa.Add(newCat);
                        taxonomyManager.SaveChanges();
                        tagList = taxonomyManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == newtagname);
                        (item as Telerik.Sitefinity.GenericContent.Model.Content).Organizer.AddTaxa("Category", tagList.FirstOrDefault().Id);
                    }
                    try
                    {

                    }
                    catch (Exception e)
                    {
                    }
                }
                else
                {
                    var propertyDescriptor = this.ContentItemTypeDescriptros.Find(propertyValue.Name, false);

                    if (propertyDescriptor == null) continue;

                    if (propertyDescriptor is LstringPropertyDescriptor)
                    {
                        // HACK - the property value can be Lstring, TextSyndicationContent or string in this case.
                        var value = "";
                        if (propertyValue.GetValue(wrapperObj) is Lstring)
                        {
                            value = ((Lstring)propertyValue.GetValue(wrapperObj)).Value;
                        }
                        else
                        {
                            if (propertyValue.GetValue(wrapperObj) is TextSyndicationContent)
                            {
                                value = ((TextSyndicationContent)propertyValue.GetValue(wrapperObj)).Text;
                            }
                            else
                            {
                                value = (string)propertyValue.GetValue(wrapperObj);
                            }
                        }
                        ((LstringPropertyDescriptor)propertyDescriptor).SetString(item, value, this.GetWrapperObjectCulture(wrapperObj));
                        continue;
                    }

                    if (!propertyDescriptor.IsReadOnly)
                    {
                        if (!propertyDescriptor.PropertyType.IsList() && !propertyDescriptor.PropertyType.IsCollection() &&
                            !propertyDescriptor.PropertyType.IsDictionary())
                        {
                            (item as IDynamicFieldsContainer).SetValue(propertyValue.Name, propertyValue.GetValue(wrapperObj));
                        }
                    }
                }
            }
        }