Пример #1
0
        /// <summary>
        ///		Ejecuta el contenido de un bucle for
        /// </summary>
        private async Task ExecuteForLoopAsync(SentenceFor sentence, VariableModel start, VariableModel end, VariableModel step, CancellationToken cancellationToken)
        {
            VariableModel index          = new VariableModel(sentence.Variable.Name, ConvertSymbolType(sentence.Variable.Type));
            bool          isPositiveStep = step.IsGreaterThan(0);

            // Asigna el valor inicial a la variable de índice
            index.Value = start.Value;
            // Abre un nuevo contexto
            Context.Add();
            // Añade la variable al contexto
            Context.Actual.VariablesTable.Add(index);
            // Ejecuta las sentencias
            while (!IsEndForLoop(index, end, isPositiveStep) && !Stopped)
            {
                // Ejecuta las sentencias
                await ExecuteAsync(sentence.Sentences, cancellationToken);

                // Incrementa / decrementa el valor al índice (el step debería ser -x si es negativo, por tanto, siempre se suma)
                index.Sum(step);
                // y lo ajusta en el contexto
                Context.Actual.VariablesTable.Add(index);
            }
            // Elimina el contexto
            Context.Pop();
        }
Пример #2
0
        /// <summary>
        /// Check if a variable with the given values exists.
        /// </summary>
        /// <param name="container">{Blockly.Workspace|Blockly.VariableMap}</param>
        public static void CheckVariableValues(object container, string name, string type, string id)
        {
            VariableMap variableMap = container as VariableMap;

            if (variableMap == null)
            {
                Workspace workspace = container as Workspace;
                if (workspace != null)
                {
                    variableMap = workspace.VariableMap;
                }
            }

            if (variableMap == null)
            {
                throw new Exception("calls TestHelper.CheckVariableValues, argument container must be Worspace or VariableMap");
            }

            VariableModel variable = variableMap.GetVariableById(id);

            Assert.NotNull(variable);
            Assert.AreEqual(name, variable.Name);
            Assert.AreEqual(type, variable.Type);
            Assert.AreEqual(id, variable.ID);
        }
Пример #3
0
        /// <summary>
        ///		Ejecuta una sentencia de declaración
        /// </summary>
        private async Task ExecuteDeclareAsync(SentenceDeclare sentence, CancellationToken cancellationToken)
        {
            VariableModel variable = new VariableModel(sentence.Variable.Name, ConvertSymbolType(sentence.Variable.Type));

            // Si es un tipo conocido, añade la variable al contexto
            if (variable.Type == VariableModel.VariableType.Unknown)
            {
                AddError($"Unknown variable type: {sentence.Variable.Name} - {sentence.Variable.Type}");
            }
            else
            {
                // Ejecuta la expresión
                if (sentence.Expressions.Count != 0)
                {
                    variable.Value = (await ExecuteExpressionAsync(sentence.Expressions, cancellationToken)).Value;
                }
                else
                {
                    variable.AssignDefault();
                }
                // Si no hay errores, añade la variable a la colección
                if (!Stopped)
                {
                    // Ejecuta la sentencia
                    Context.Actual.VariablesTable.Add(variable);
                    // Debug
                    AddDebug($"Declare {sentence.Variable.Name} = " + variable.GetStringValue());
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Save a Variable
 /// </summary>
 public void Save(VariableModel variableModel, params QueryModel[] queryModel)
 {
     this.DataManageHelperService.SaveIntoDataBase(variableModel, queryModel?.ToList());
     if (this.CodeBaseShared.ListSetVariable.Any(c => c.Name == variableModel.Name))
     {
         this.CodeBaseShared.ListSetVariable.Remove(this.CodeBaseShared.ListSetVariable.FirstOrDefault(c => c.Name == variableModel.Name));
     }
 }
Пример #5
0
        public ActionResult EditVariable(VariableModel model)
        {
            var result = model.Id > 0
                ? _variableService.UpdateLookupVariable(model)
                : _variableService.CreateLookupVariable(model.Name, model.Type);

            return(RedirectToAction("Index", new { tabIndex = 2 }));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="propertyValue"></param>
        private void NewResponseVariableChangedReceived(string variableName, string variableValue)
        {
            VariableModel variable = VariableHelper.Variables[variableName];

            VariableHelper.SetVariableValue(variable, variableValue);

            VariableChanged?.Invoke(this, variable);
        }
Пример #7
0
 public ActionResult Edit(VariableModel model)
 {
     if (model.Edit())
     {
         return(Json(new JavaScriptSerializer().Serialize(model)));
     }
     return(View());
 }
        public TransformationModel XmlToObject(string xmlPath)
        {
            XDocument doc = XDocument.Load(xmlPath);

            var ChainObj          = new TransformationModel(XmlEnum.Transformation);
            var processingStepObj = new ProcessingStepsModel(XmlEnum.ProcessingSteps);

            var processingSteps = doc.Descendants("Map");

            foreach (var step in processingSteps)
            {
                var MapObj       = new MapModel(XmlEnum.Map);
                var BasObj       = new CodeModulePathModel(XmlEnum.CodeModulePath);
                var BasesObj     = new CodeModulesModel(XmlEnum.CodeModules);
                var VariableObj  = new VariableModel(XmlEnum.TransformationVariables);
                var VariablesObj = new TransformationVariablesModel(XmlEnum.TransformationVariables);

                var Bas = step.Descendants("CodeModules");
                foreach (var b in Bas)
                {
                    BasObj.AddCodeModulePathModel(XmlEnum.CodeModulePath,
                                                  b.Element("CodeModulePath").Attribute("Location").Value);
                    BasesObj.AddCodeModule(BasObj);
                }

                var TransformationVariables = step.Descendants("TransformationVariables").Elements("Variable");
                foreach (var v in TransformationVariables)
                {
                    VariableObj.AddVariable(XmlEnum.Variable,
                                            v.Attribute("Value").Value,
                                            v.Attribute("IsPublic").Value,
                                            v.Attribute("InitialValue").Value);
                    VariablesObj.AddVariable(VariableObj);
                }

                MapObj.AddMap(XmlEnum.Map,
                              step.Attribute("Sequence").Value,
                              step.Attribute("Name").Value,
                              step.Element("MapFilePath").Attribute("Location").Value,
                              step.Element("SourceFilePath").Attribute("Location").Value,
                              step.Element("TargetFilePath").Attribute("Location").Value,
                              BasesObj,
                              VariablesObj);

                processingStepObj.AddMap(MapObj);
            }

            var Chain = doc.Descendants("Transformation");

            foreach (var t in Chain)
            {
                ChainObj.AddTransformationModel(XmlEnum.Transformation,
                                                t.Attribute("createdon").Value,
                                                t.Attribute("createdby").Value,
                                                processingStepObj);
            }
            return(ChainObj);
        }
Пример #9
0
        public static VariableEditorViewModel GetModelFromFile(ManagedFile file)
        {
            var logger = LogManager.GetLogger("FileToVariableEditorMapper");

            logger.Debug("Entering GetModelFromFile()");

            var model = new VariableEditorViewModel(file);

            // Get the DDI PhysicalInstance that corresponds to this ManagedFile.
            logger.Debug("Getting PhysicalInstance");
            var physicalInstance = GetPhysicalInstance(file, file.CatalogRecord.Organization.AgencyID);

            logger.Debug("Got PhysicalInstance");

            // Make the list of variables.
            if (physicalInstance == null)
            {
                logger.Debug("Got null PhysicalInstance");
                return(model);
            }

            // Populate what is needed to get the list of variables.
            logger.Debug("Populating PhysicalInstance");
            var client = RepositoryHelper.GetClient();

            foreach (var dr in physicalInstance.DataRelationships)
            {
                client.PopulateItem(dr, false, Algenta.Colectica.Model.Repository.ChildReferenceProcessing.PopulateLatest);
            }
            logger.Debug("Populated PhysicalInstance");

            var allVariables = physicalInstance.DataRelationships
                               .SelectMany(x => x.LogicalRecords)
                               .SelectMany(x => x.VariablesInRecord);

            foreach (var variable in allVariables)
            {
                var variableModel = new VariableModel()
                {
                    Id          = variable.Identifier.ToString(),
                    Agency      = variable.AgencyId,
                    Name        = variable.ItemName.Current,
                    Label       = variable.Label.Current,
                    Version     = variable.Version,
                    LastUpdated = variable.VersionDate.ToShortDateString()
                };
                model.Variables.Add(variableModel);
            }

            model.VariablesJson = Newtonsoft.Json.JsonConvert.SerializeObject(model.Variables, Newtonsoft.Json.Formatting.None);

            model.IsUserCurator  = false;
            model.IsUserApprover = false;

            logger.Debug("Leaving GetModelFromFile()");
            return(model);
        }
Пример #10
0
        internal static DomainValue GetVariableBand(VariableModel theVariable)
        {
            Debug.Assert(!theVariable.DomainExpression.IsEmpty);

            var variableDomainExpressionRoot = theVariable.DomainExpression.Node;
            var evaluatorContext             = new VariableDomainExpressionEvaluatorContext(variableDomainExpressionRoot, theVariable.Parent.Workspace);

            return(VariableDomainExpressionEvaluator.Evaluate(evaluatorContext));
        }
Пример #11
0
        /// <summary>
        /// 脚本执行完成, 将生成的csv文件合并成XLS文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CurrentWorker_RunComplete(object sender, EventArgs e)
        {
            if (FileType != InOut.FileType.XLS)
            {
                return;
            }
            Workbook workbook = new Workbook();

            foreach (string variable in filePaths.Keys)
            {
                Worksheet worksheet = new Worksheet(variable);
                using (var csv = new CsvReader(new StreamReader(filePaths[variable], Encoding.UTF8)))
                {
                    csv.Configuration.Delimiter       = ",";
                    csv.Configuration.HasHeaderRecord = false;
                    int rowindex = 0;
                    while (csv.Read())
                    {
                        string[] records = csv.CurrentRecord;

                        for (int i = 0; i < records.Length; i++)
                        {
                            worksheet.Cells[rowindex, i] = new Cell(records[i]);
                        }
                        rowindex++;
                    }
                }
                workbook.Worksheets.Add(worksheet);
            }

            FileStream stream = null;

            try
            {
                string path       = Path.Combine(AppSettings.Instance.CurrentExecutePath, "data");
                string file       = VariableModel.Parse(FileName);
                string outputFile = Path.Combine(path, file.IndexOf(".") == -1 ? (file + ".xls") : (file.Substring(0, file.IndexOf(".")) + ".xls"));
                stream = new FileStream(outputFile, FileMode.Create);
                workbook.SaveToStream(stream);
            }
            finally
            {
                foreach (string file in filePaths.Values)
                {
                    try
                    {
                        File.Delete(file);
                    }
                    catch { }
                }
                Reset();
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
        private IntVar ProcessVariable(VariableModel variable)
        {
            var variableBand  = VariableBandEvaluator.GetVariableBand(variable);
            var variableRange = variableBand.GetRange();
            var orVariable    = solver.MakeIntVar(variableRange.Lower, variableRange.Upper, variable.Name.Text);

            this.cache.AddVariable(orVariable);

            return(orVariable);
        }
Пример #13
0
        private void AddNewVariableCommandAction()
        {
            var model = new VariableModel
            {
                VariableName  = VariableName.Replace(" ", "_"),
                VariableValue = VariableValue,
                UserDefined   = true
            };

            Variables.Add(model);
        }
Пример #14
0
 /// <summary>
 ///		Comprueba si se ha terminado un bucle for
 /// </summary>
 private bool IsEndForLoop(VariableModel index, VariableModel end, bool isPositiveStep)
 {
     if (isPositiveStep)
     {
         return(index.IsGreaterThan(end));
     }
     else
     {
         return(index.IsLessThan(end));
     }
 }
Пример #15
0
        /// <summary>
        ///		Obtiene el valor de una variable
        /// </summary>
        private async Task <VariableModel> GetVariableValueAsync(string name, ExpressionsCollection expressions, CancellationToken cancellationToken)
        {
            VariableModel variable = new VariableModel(name, VariableModel.VariableType.Unknown);

            // Asigna el valor
            if (expressions.Count > 0)
            {
                variable.Value = await ExecuteExpressionAsync(expressions, cancellationToken);
            }
            // Devuelve la variable
            return(variable);
        }
Пример #16
0
        public virtual void GoToURL()
        {
            string bindVal = Eval(BindName);

            if (!string.IsNullOrEmpty(bindVal))
            {
                URL = bindVal;
            }
            string url = VariableModel.Parse(URL);

            Goto(url);
        }
        public T GetValueByBinding <T>(string BindTrace, List <QueryModel> listFormQueryModel = null)
        {
            VariableModel variableModel = this.GetEntityByBinding(BindTrace, listFormQueryModel);

            if (variableModel != null)
            {
                return(variableModel.GetValue <T>(BindTrace.Split('.').LastOrDefault()));
            }
            else
            {
                return(default(T));
            }
        }
        public object GetValueByBinding(string BindTrace, List <QueryModel> listFormQueryModel = null)
        {
            VariableModel variableModel = this.GetEntityByBinding(BindTrace, listFormQueryModel);

            if (variableModel != null)
            {
                return(variableModel[BindTrace.Split('.').LastOrDefault()]);
            }
            else
            {
                return(null);
            }
        }
Пример #19
0
        public override void Perform()
        {
            Element element = GetElement();

            if (!element.Exists)
            {
                ActionArrayVariable arr = VariableModel.Find <ActionArrayVariable>(ObjectName);
                if (arr == null)
                {
                    throw new ApplicationException("变量" + ObjectName + "未找到");
                }
                arr.AddItemToArray("");
            }
        }
Пример #20
0
        public async Task <VariableModel> GetSpecificPipeLineVariable(string projectname, int definitionid, string variablekey)
        {
            VariableModel variableModel = new VariableModel();

            try
            {
                variableModel = await buildManager.GetSpecificPipeLineVariable(projectname, definitionid, variablekey);
            }
            catch (Exception)
            {
            }

            return(variableModel);
        }
Пример #21
0
        public override void Perform()
        {
            List <string> list = GetMutiContent();

            if (list.Count > 0)
            {
                ActionArrayVariable var = VariableModel.Find <ActionArrayVariable>(ObjectName);
                if (var == null)
                {
                    throw new ApplicationException("变量" + ObjectName + "未找到,请确定变量" + ObjectName + "是否定义");
                }
                var.AddItemsToList(list);
            }
        }
        public override void Perform()
        {
            string value = GetValue(GetElement());

            if (!(string.IsNullOrEmpty(value) && FliterEmptyString))
            {
                ActionStringVariable arr = VariableModel.Find <ActionStringVariable>(ObjectName);
                if (arr == null)
                {
                    throw new ApplicationException("变量" + ObjectName + "未找到");
                }
                arr.Data = value;
            }
        }
 public static void AddVariableToProfileModel(this VariableModel model, ProfileTypeDefinitionModel profileItem, IDALContext dalContext)
 {
     if (model is PropertyModel property)
     {
         property.AddVariableToProfileModel(profileItem, dalContext);
     }
     else if (model is DataVariableModel variable)
     {
         variable.AddVariableToProfileModel(profileItem, dalContext);
     }
     else
     {
         throw new Exception($"Unexpected variable type {model.GetType()}");
     }
 }
Пример #24
0
        /// <summary>
        ///		Ejecuta una sentencia de impresión
        /// </summary>
        private VariableModel ExecutePrint(ImplicitFunctionModel function)
        {
            VariableModel result = Context.Actual.VariablesTable[function.Arguments[0].Name];

            // Imprime el resultado
            if (result == null)
            {
                AddError($"Method Print: Cant find value for argument {function.Arguments[0].Name}");
            }
            else
            {
                Interpreter.DbScriptExecutor.ConsoleWriteLine(result.GetStringValue());
            }
            // Devuelve el resultado
            return(result);
        }
Пример #25
0
        public override void Perform()
        {
            string _fileName = VariableModel.Parse(FileName);

            AutoRobo.Core.IO.DataTableReader reader = new AutoRobo.Core.IO.DataTableReader(FileType, _fileName, HasHeaderRecord);
            var varObj = ActionModel.VariableActionModel.Find <ActionTableVariable>(VariableName);

            try
            {
                varObj.Data = reader.Read();
            }
            catch (Exception ex) {
                LogWrite(string.Format("读文件{0}失败", _fileName));
                LogWrite(ex.Message);
            }
        }
Пример #26
0
        /// <summary>
        ///		Calcula una operación de cadena
        /// </summary>
        private VariableModel ComputeString(ExpressionOperatorBase expression, VariableModel first, VariableModel second, out string error)
        {
            string firstValue  = first.Value.ToString();
            string secondValue = second.Value.ToString();

            // Inicializa los argumentos de salida
            error = string.Empty;
            // Ejecuta la operación
            switch (expression)
            {
            case ExpressionOperatorMath operation:
                if (operation.Type == ExpressionOperatorMath.MathType.Sum)
                {
                    return(new VariableModel("Result", firstValue + secondValue));
                }
                break;

            case ExpressionOperatorLogical operation:
                int compare = NormalizeString(firstValue).CompareTo(NormalizeString(secondValue));

                switch (operation.Type)
                {
                case ExpressionOperatorLogical.LogicalType.Distinct:
                    return(new VariableModel("Result", compare != 0));

                case ExpressionOperatorLogical.LogicalType.Equal:
                    return(new VariableModel("Result", compare == 0));

                case ExpressionOperatorLogical.LogicalType.Greater:
                    return(new VariableModel("Result", compare > 0));

                case ExpressionOperatorLogical.LogicalType.GreaterOrEqual:
                    return(new VariableModel("Result", compare >= 0));

                case ExpressionOperatorLogical.LogicalType.Less:
                    return(new VariableModel("Result", compare < 0));

                case ExpressionOperatorLogical.LogicalType.LessOrEqual:
                    return(new VariableModel("Result", compare <= 0));
                }
                break;
            }
            // Si ha llegado hasta aquí es porque no se puede ejecutar la operación
            error = "Cant execute this operation with a string";
            return(null);
        }
Пример #27
0
        /// <summary>
        /// Receive an event that signifies a variable was changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="variable"></param>
        private void Event_VariableChanged(object sender, VariableModel variable)
        {
            LogHelper.LogInfo(string.Format("Variable: {0}. New Value: {1}", variable.PropertyName, variable.PropertyValue));

            PropertyInfo property = this.GetType().GetProperty(variable.PropertyName);

            if (property == null)
            {
                return;
            }
            property.SetValue(this, variable.PropertyValue);

            if (IsPanelDebugVisible)
            {
                WriteListVariable();
            }
        }
Пример #28
0
        public bool UpdateLookupVariable(VariableModel model)
        {
            using (var db = new LicenseDbEntities())
            {
                var variable = db.lu_LicenseVariables.FirstOrDefault(x => x.Id == model.Id);
                if (variable == null)
                {
                    return(false);
                }

                variable.Name = model.Name;
                variable.Type = model.Type;
                db.SaveChanges();
            }

            return(true);
        }
Пример #29
0
        private void InitializeFilePath()
        {
            if (filePaths.Count > 0)
            {
                return;
            }
            string _fileName = VariableModel.Parse(FileName);
            string path      = Path.Combine(AppSettings.Instance.CurrentExecutePath, "data");

            _fileName = Path.Combine(path, GetFileName(_fileName));

            string[] vars = VariableName.Split(",".ToCharArray());
            foreach (string v in vars)
            {
                filePaths.Add(v, _fileName.Insert(_fileName.IndexOf("."), "_" + v));
            }
        }
Пример #30
0
        /// <summary>
        ///		Ejecuta la sentencia para devolver el resultado de una función
        /// </summary>
        private async Task ExecuteFunctionReturnAsync(SentenceReturn sentence, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(Context.Actual.ScopeFuntionResultVariable))
            {
                AddError("Cant execute a return because there is not function block");
            }
            else
            {
                VariableModel result = await ExecuteExpressionAsync(sentence.Expression, cancellationToken);

                // Si no hay error, añade el resultado al contexto
                if (result != null)
                {
                    Context.Actual.VariablesTable.Add(Context.Actual.ScopeFuntionResultVariable, result.Type, result.Value);
                }
            }
        }