Exemplo n.º 1
0
        private static void AddAutoCompleteFor(List <string> toFill, CustomVariable customVariable)
        {
            if (CustomVariableCodeGenerator.IsTypeFromCsv(customVariable))
            {
                string fileName = ProjectManager.MakeAbsolute(customVariable.Type, true);

                ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(fileName);

                if (rfs?.IsCsvOrTreatedAsCsv == true)
                {
                    toFill.AddRange(CsvCodeGenerator.GetMemberNamesFrom(rfs));
                }
            }
        }
Exemplo n.º 2
0
        private static void CreateStartingValueVariables(IElement element, List <StateSave> states, ICodeBlock curBlock, Dictionary <InstructionSave, InterpolationCharacteristic> interpolationCharacteristics)
        {
            foreach (StateSave state in states)
            {
                foreach (InstructionSave instructionSave in state.InstructionSaves)
                {
                    string member = instructionSave.Member;

                    if (!ContainsKey(interpolationCharacteristics, member))
                    {
                        CustomVariable customVariable = element.GetCustomVariable(member);

                        NamedObjectSave nos = null;

                        if (customVariable != null)
                        {
                            nos = element.GetNamedObjectRecursively(customVariable.SourceObject);
                        }

                        if (nos == null || nos.IsDisabled == false)
                        {
                            InterpolationCharacteristic interpolationCharacteristic =
                                CustomVariableHelper.GetInterpolationCharacteristic(customVariable, element);

                            interpolationCharacteristics.Add(instructionSave, interpolationCharacteristic);

                            if (interpolationCharacteristic != InterpolationCharacteristic.CantInterpolate)
                            {
                                curBlock.Line("bool set" + instructionSave.Member + " = true;");

                                string defaultStartingValue = "";


                                try
                                {
                                    if (customVariable.GetIsVariableState())
                                    {
                                        IElement stateContainingEntity = null;

                                        if (nos != null)
                                        {
                                            stateContainingEntity = ObjectFinder.Self.GetIElement(nos.SourceClassType);
                                        }
                                        else if (string.IsNullOrEmpty(customVariable.SourceObject))
                                        {
                                            stateContainingEntity = element;
                                        }


                                        if (stateContainingEntity != null)
                                        {
                                            string stateType = "VariableState";
                                            if (customVariable != null && customVariable.Type.ToLower() != "string")
                                            {
                                                stateType = customVariable.Type;
                                            }

                                            defaultStartingValue = StateCodeGenerator.FullyQualifiedDefaultStateValue(stateContainingEntity, stateType);
                                        }
                                    }
                                    else
                                    {
                                        defaultStartingValue = TypeManager.GetDefaultForType(instructionSave.Type);
                                    }
                                }
                                catch
                                {
                                    throw new Exception("Could not get a default value for " + instructionSave.Member + " of type " + instructionSave.Type);
                                }


                                string type = CustomVariableCodeGenerator.GetMemberTypeFor(customVariable, element);

                                curBlock.Line(type + " " + member + FirstValue + "= " + defaultStartingValue + ";");
                                curBlock.Line(type + " " + member + SecondValue + "= " + defaultStartingValue + ";");
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static ICodeBlock CreateClassForStateCategory(ICodeBlock currentBlock, List <StateSave> statesForThisCategory, string categoryClassName, IElement element)
        {
            if (statesForThisCategory.Count != 0)
            {
                string prefix = "public";

                string postfix = null;
                if (IsStateDefinedInBase(element, categoryClassName))
                {
                    postfix = $" : {element.BaseElement.Replace("\\", ".")}.{categoryClassName}";
                }


                currentBlock = currentBlock.Class(prefix, categoryClassName, postfix);

                currentBlock.Line($"public string Name;");

                foreach (var variable in element.CustomVariables)
                {
                    // todo - pass the category here and skip over excluded variables
                    var isExcluded = false;
                    if (!isExcluded)
                    {
                        string type = variable.Type;

                        if (variable.GetIsFile())
                        {
                            type = "string";
                        }
                        else
                        {
                            type = CustomVariableCodeGenerator.GetMemberTypeFor(variable, element);
                        }
                        currentBlock.Line($"public {type} {variable.Name};");
                    }
                }


                for (int i = 0; i < statesForThisCategory.Count; i++)
                {
                    var state = statesForThisCategory[i];

                    currentBlock.Line($"public static {categoryClassName} {state.Name} = new {categoryClassName}()");
                    var variableBlock = currentBlock.Block();

                    variableBlock.Line($"Name = \"{state.Name}\",");

                    foreach (var instruction in state.InstructionSaves)
                    {
                        if (instruction.Value != null)
                        {
                            var rightSide        = GetRightSideAssignmentValueAsString(element, instruction);
                            var matchingVariable = element.GetCustomVariableRecursively(instruction.Member);
                            if (matchingVariable?.GetIsFile() == true)
                            {
                                // If it's a file we are only going to reference the file name here as to not preload the file
                                rightSide = $"\"{rightSide}\"";
                            }

                            variableBlock.Line($"{instruction.Member} = {rightSide},");
                        }
                    }
                    variableBlock.End().Line(";");
                }
                currentBlock = currentBlock.End();
            }
            return(currentBlock);
        }
Exemplo n.º 4
0
        public static string GetRightSideAssignmentValueAsString(IElement element, InstructionSave instruction)
        {
            CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member);

            IElement referencedElement = null;

            #region Determine if the assignment is a file

            bool isFile = false;

            if (customVariable != null)
            {
                referencedElement =
                    BaseElementTreeNode.GetElementIfCustomVariableIsVariableState(customVariable, element);

                isFile = customVariable.GetIsFile();
            }

            #endregion

            string valueAsString = "";

            if (referencedElement == null)
            {
                valueAsString = CodeParser.ParseObjectValue(instruction.Value);

                if (isFile)
                {
                    valueAsString = valueAsString.Replace("\"", "");

                    if (valueAsString == "<NONE>")
                    {
                        valueAsString = "null";
                    }
                }
                else if (CustomVariableCodeGenerator.ShouldAssignToCsv(customVariable, valueAsString))
                {
                    valueAsString = CustomVariableCodeGenerator.GetAssignmentToCsvItem(customVariable, element, valueAsString);
                }
                else if (customVariable != null && customVariable.Type == "Color")
                {
                    valueAsString = "Color." + valueAsString.Replace("\"", "");
                }
                if (customVariable != null && !string.IsNullOrEmpty(customVariable.SourceObject) && !isFile)
                {
                    NamedObjectSave namedObject = element.GetNamedObjectRecursively(customVariable.SourceObject);

                    bool isVariableState = customVariable.GetIsVariableState();

                    IElement objectElement = null;

                    if (namedObject != null)
                    {
                        ObjectFinder.Self.GetIElement(namedObject.SourceClassType);
                    }

                    if (objectElement != null)
                    {
                        if (isVariableState)
                        {
                            string typeName = "VariableState";

                            StateSaveCategory category = objectElement.GetStateCategoryRecursively(customVariable.Type);

                            if (category != null && category.SharesVariablesWithOtherCategories == false)
                            {
                                typeName = category.Name;
                            }
                            valueAsString = objectElement.Name.Replace("/", ".").Replace("\\", ".") + "." + typeName + "." + valueAsString.Replace("\"", "");
                        }
                    }

                    valueAsString = CodeWriter.MakeLocalizedIfNecessary(
                        namedObject,
                        instruction.Member,
                        instruction.Value,
                        valueAsString,
                        customVariable);
                }
            }
            else
            {
                string enumValue = (string)instruction.Value;

                if (!string.IsNullOrEmpty(enumValue) && enumValue != "<NONE>")
                {
                    string variableType = "VariableState";

                    if (customVariable != null && customVariable.Type.ToLower() != "string")
                    {
                        variableType = customVariable.Type;
                    }
                    valueAsString = FullyQualifyStateValue(referencedElement, enumValue, variableType);
                }
            }
            return(valueAsString);
        }