Example #1
0
        public void Create()
        {
            if (PerformedTemplate != null)
            {
                for (int i = 0; i < PerformedTemplateList.Count(); i++)
                {
                    if (PerformedTemplateList[i].Equals(PerformedTemplate.Name))
                    {
                        PerformedTemplate.Id = PerformedTemplateIdList[i];
                        break;
                    }
                }
            }
            if (BaseTemplate != null)
            {
                for (int i = 0; i < BaseTemplateList.Count(); i++)
                {
                    if (BaseTemplateList[i].Equals(BaseTemplate.Name))
                    {
                        BaseTemplate.Id = BaseTemplateIdList[i];
                        break;
                    }
                }

                List <Entity> ps = models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                           .addCondition("TaskTemplateID", "=", BaseTemplate.Id.ToString()), typeof(models.Parameter));
                for (int i = 0; i < PreprocessingParameters.Count(); i++)
                {
                    PreprocessingParameters[i].ParameterId   = ps[i].ID;
                    PreprocessingParameters[i].ParameterName = ((models.Parameter)ps[i]).Name;
                }

                List <Entity> selections = Selection.where (new Query("Selection").addTypeQuery(TypeQuery.select)
                                                            .addCondition("TaskTemplateID", "=", BaseTemplate.Id.ToString()), typeof(Selection));

                int newTaskTemplateId;
                PreprocessingTemplate pp = new PreprocessingTemplate();
                if (IsUsingExitingTemplate)
                {
                    newTaskTemplateId = TemplateId;
                }
                else
                {
                    pp.PreprocessingName = PreprocessingName;
                    pp.BaseTemplate      = BaseTemplate;
                    string templateName = (NewTemplateName == null || NewTemplateName == "") ? "New Preprocessing Template" : NewTemplateName;
                    newTaskTemplateId = new DataHelper().addTaskTemplate(templateName, Task.ID, pp);
                }

                List <PreprocessingParameterViewModel> preprocessingParametersTemp = new List <PreprocessingParameterViewModel>();
                List <string>    types      = new List <string>();
                List <Parameter> parameters = new List <Parameter>();
                List <services.preprocessing.normalization.IParameter> listOfIParameters = new List <services.preprocessing.normalization.IParameter>();
                List <int> paramIds = new List <int>();
                foreach (Entity sel in selections)
                {
                    int newSelectionId = PreprocessingManager.PrepManager.addNewEntitiesForPreprocessing(
                        ((Selection)sel).Name, ((Selection)sel).RowCount, Task.ID, newTaskTemplateId);
                    int oldSelectionId = sel.ID;
                    foreach (PreprocessingParameterViewModel prepParam in PreprocessingParameters)
                    {
                        string prepType   = prepParam.Type;
                        int    oldParamId = prepParam.ParameterId;

                        if ("бинаризация".Equals(prepType))
                        {
                            bool          canCreate     = true;
                            List <Entity> newParameters = models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                                  .addCondition("TaskTemplateID", "=", newTaskTemplateId.ToString()), typeof(models.Parameter));
                            List <Entity> newAddedParameters = new List <Entity>();
                            List <string> classes            = PreprocessingManager.PrepManager.getClasses(oldSelectionId, newTaskTemplateId, oldParamId);
                            foreach (Entity entity in newParameters)
                            {
                                //TypeParameter type = getTypeParameter(prepType, oldParamId);
                                if (classes.Contains(((models.Parameter)entity).Name))
                                //(((models.Parameter)entity).Name.Equals(prepParam.ParameterName)) && ((models.Parameter)entity).Type.Equals(type)) ?????
                                {
                                    newAddedParameters.Add(entity);
                                    canCreate = false;
                                }
                            }
                            if (canCreate)
                            {
                                newParameters = PreprocessingManager.PrepManager.getNewParametersForBinarizationType(oldSelectionId, newTaskTemplateId, oldParamId);
                            }
                            else
                            {
                                newParameters = newAddedParameters;
                            }

                            int i = 0;
                            foreach (Entity entity in newParameters)
                            {
                                PreprocessingParameterViewModel ppVM = new PreprocessingParameterViewModel();
                                ppVM.Position      = i + 1;
                                ppVM.ParameterId   = entity.ID;
                                ppVM.ParameterName = ((models.Parameter)entity).Name;
                                ppVM.Type          = "бинаризация";
                                if (canCreate)
                                {
                                    preprocessingParametersTemp.Add(ppVM);
                                    types.Add("бинаризация");
                                    parameters.Add(new view_models.Parameter(ppVM.ParameterName, ppVM.Type, ((models.Parameter)entity).Comment, entity.ID));
                                }

                                i++;
                                services.preprocessing.normalization.IParameter p = PreprocessingManager.PrepManager.executePreprocessing(newSelectionId, oldSelectionId, oldParamId, prepType, i - 1, entity.ID);
                                continue;
                            }
                        }
                        else
                        {
                            models.Parameter oldParam = ((models.Parameter)services.DatabaseManager.SharedManager.entityById(oldParamId, typeof(models.Parameter)));

                            TypeParameter type          = getTypeParameter(prepType, oldParamId);
                            bool          canCreate     = true;
                            int           newParamId    = -1;
                            List <Entity> newParameters = models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                                  .addCondition("TaskTemplateID", "=", newTaskTemplateId.ToString()), typeof(models.Parameter));
                            foreach (Entity entity in newParameters)
                            {
                                if (((models.Parameter)entity).Name.Equals(prepParam.ParameterName) && ((models.Parameter)entity).Type.Equals(type))
                                {
                                    newParamId = entity.ID;
                                    canCreate  = false;
                                    break;
                                }
                            }
                            if (canCreate)
                            {
                                newParamId = new DataHelper().addOneParameter(prepParam.ParameterName, oldParam.Comment, newTaskTemplateId, prepParam.Position,
                                                                              oldParam.IsOutput, type);
                                PreprocessingParameterViewModel ppVM = new PreprocessingParameterViewModel();
                                ppVM.ParameterName = prepParam.ParameterName;
                                ppVM.Position      = prepParam.Position;
                                ppVM.Type          = prepParam.Type;
                                ppVM.ParameterId   = newParamId;

                                parameters.Add(new view_models.Parameter(prepParam.ParameterName, prepParam.Type, oldParam.Comment, newParamId));
                                types.Add(prepType);
                                preprocessingParametersTemp.Add(ppVM);
                            }

                            services.preprocessing.normalization.IParameter p = PreprocessingManager.PrepManager.executePreprocessing(newSelectionId, oldSelectionId, oldParamId, prepType, prepParam.Position, newParamId);
                            listOfIParameters.Add(p);
                            paramIds.Add(newParamId);
                        }
                    }
                    SerializableList list = new SerializableList();
                    list.selectionId    = newSelectionId;
                    list.parameterIds   = paramIds;
                    list.prepParameters = listOfIParameters;
                    pp.info.Add(list);
                }
                if (parameters != null && types != null)
                {
                    pp.parameters = parameters;
                    pp.types      = types;
                    PreprocessingManager.PrepManager.updateTaskTemplate(newTaskTemplateId, pp);
                }
                if (preprocessingParametersTemp != null)
                {
                    PreprocessingParameters = preprocessingParametersTemp.ToArray();
                }
            }

            OnClose?.Invoke(this, null);
        }
Example #2
0
        public PreprocessingViewModel(models.Task task, int templateId)
        {
            Task = task;
            List <Entity> taskTemplates = TaskTemplate.where (new Query("TaskTemplate").addTypeQuery(TypeQuery.select)
                                                              .addCondition("TaskID", "=", task.ID.ToString()), typeof(TaskTemplate));

            BaseTemplateList   = new string[taskTemplates.Count];
            BaseTemplateIdList = new int[taskTemplates.Count];

            bool canCreate = false;

            if (taskTemplates.Count != 0)
            {
                int index = 0;
                canCreate = true;
                foreach (Entity entity in taskTemplates)
                {
                    BaseTemplateIdList[index] = entity.ID;
                    BaseTemplateList[index]   = ((TaskTemplate)entity).Name;
                    index++;
                }
                PerformedTemplateList   = BaseTemplateList;
                PerformedTemplateIdList = BaseTemplateIdList;

                IsUsingExitingTemplate = false;
                Random r = new Random();
                PreprocessingName = "Преобразование " + r.Next(1, 1000);
                NewTemplateName   = "New Template";
                TaskTemplate template = null;
                Pair         pair     = new Pair();
                if (templateId == -1)
                {
                    TemplateId        = taskTemplates[0].ID;
                    pair.Id           = PerformedTemplateIdList[0];
                    pair.Name         = PerformedTemplateList[0];
                    PerformedTemplate = pair;
                }
                else
                {
                    TemplateId        = templateId;
                    template          = ((TaskTemplate)services.DatabaseManager.SharedManager.entityById(templateId, typeof(TaskTemplate)));
                    pair.Id           = templateId;
                    pair.Name         = template.Name;
                    PerformedTemplate = pair;
                }

                TaskTemplate          template_temp = ((TaskTemplate)services.DatabaseManager.SharedManager.entityById(TemplateId, typeof(TaskTemplate)));
                PreprocessingTemplate pt            = (PreprocessingTemplate)template_temp.PreprocessingParameters;

                if (pt == null)
                {
                    Pair pair_2 = new Pair();
                    pair_2.Id    = BaseTemplateIdList[0];
                    pair_2.Name  = BaseTemplateList[0];
                    BaseTemplate = pair_2;
                }
                else
                {
                    BaseTemplate = pt.BaseTemplate;
                }


                List <Entity> parameters = models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                   .addCondition("TaskTemplateID", "=", TemplateId.ToString()), typeof(models.Parameter));
                PreprocessingParameters = new PreprocessingParameterViewModel[parameters.Count];
                index = 0;
                foreach (Entity entity in parameters)
                {
                    PreprocessingParameters[index]               = new PreprocessingParameterViewModel();
                    PreprocessingParameters[index].ParameterId   = entity.ID;
                    PreprocessingParameters[index].ParameterName = ((models.Parameter)entity).Name;
                    PreprocessingParameters[index].Position      = ((models.Parameter)entity).Index;
                    if (template == null)
                    {
                        PreprocessingParameters[index].Type = "без предобработки";
                    }
                    else
                    {
                        PreprocessingTemplate pp    = (PreprocessingTemplate)template.PreprocessingParameters;
                        List <Parameter>      list  = pp.parameters;
                        List <string>         types = pp.types;
                        PreprocessingParameters[index].Type = types[index];
                    }
                    index++;
                }
            }

            cancelHandler          = new ActionHandler(Cancel, o => true);
            createHandler          = new ActionHandler(Create, o => canCreate && CanUseExitingTemplate && CanCreateTemplate);
            CanUseExitingTemplate  = CanCreateTemplate = true;
            IsUsingExitingTemplate = false;
        }