public TemplateViewModel(int templateId, int var = 0)
        {
            TemplateName = ((dms.models.TaskTemplate)dms.services.DatabaseManager.SharedManager.entityById(templateId, typeof(dms.models.TaskTemplate))).Name;;

            List <Entity> parameters = dms.models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                   .addCondition("TaskTemplateID", "=", templateId.ToString()), typeof(dms.models.Parameter));

            List <Parameter> input  = new List <Parameter>();
            List <Parameter> output = new List <Parameter>();

            foreach (Entity param in parameters)
            {
                dms.models.Parameter p = (dms.models.Parameter)param;
                if (p.IsOutput == 0)
                {
                    input.Add(new Parameter(p.Name, p.Type.ToString(), p.Comment, param.ID));
                }
                else
                {
                    output.Add(new Parameter(p.Name, p.Type.ToString(), p.Comment, param.ID));
                }
            }
            InputParameters  = input.ToArray();
            OutputParameters = output.ToArray();
        }
Example #2
0
        private void addParameters(string filePath, char delimiter, ParameterCreationViewModel[] parameters,
                                   int selectionId, int taskTemplateId, bool isUsingExitingTemplate)
        {
            using (StreamReader sr = new StreamReader(filePath))
            {
                DataHelper helper  = new DataHelper();
                int        rowStep = 0;
                string     line    = sr.ReadLine();
                if (line != "" && HasHeader)
                {
                    line = sr.ReadLine();
                }
                int paramCount = parameters.Length;

                List <Entity>         listSelRow    = new List <Entity>(countRows);
                List <Entity>         listParams    = new List <Entity>(paramCount * countRows);
                List <ValueParameter> listValParams = new List <ValueParameter>(paramCount * countRows);
                while (line != "" && line != null)
                {
                    rowStep++;
                    SelectionRow entity = helper.addSelectionRow(selectionId, rowStep);
                    listSelRow.Add(entity);

                    string[] values = line.Split(delimiter);

                    int index = -1;
                    foreach (string value in values)
                    {
                        index++;
                        string        parameterName = parameters[index].Name;
                        string        comment       = parameters[index].Comment == null ? "" : parameters[index].Comment;
                        int           isOutput      = getIsOutput(parameters[index].KindOfParameter);
                        TypeParameter type          = getTypeParameter(parameters[index].Type);

                        if (rowStep == 1)
                        {
                            dms.models.Parameter parameter = helper.addParameter(parameterName, comment, taskTemplateId, index, isOutput, type);
                            listParams.Add(parameter);
                        }
                        listValParams.Add(helper.addValueParameter(entity.ID, -1 /*parameter.ID*/, value));
                    }

                    line = sr.ReadLine();
                }

                DatabaseManager.SharedManager.insertMultipleEntities(listSelRow);
                if (!isUsingExitingTemplate)
                {
                    DatabaseManager.SharedManager.insertMultipleEntities(listParams);
                }
                else
                {
                    listParams = dms.models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                             .addCondition("TaskTemplateID", "=", taskTemplateId.ToString()), typeof(dms.models.Parameter));
                }

                List <Entity> list     = new List <Entity>(countRows * paramCount);
                int           selRowId = 0;
                for (int i = 0; i < paramCount * countRows; i++)
                {
                    if (i % paramCount == 0)
                    {
                        selRowId = i == 0 ? listSelRow[0].ID : listSelRow[i / paramCount].ID;
                    }
                    int paramId = listParams[i % paramCount].ID;

                    ValueParameter param = listValParams[i];
                    param.ParameterID    = paramId;
                    param.SelectionRowID = selRowId;
                    list.Add(param);
                }
                DatabaseManager.SharedManager.insertMultipleEntities(list);
            }
        }