public List <WorkplanEntity> GetWorkStepDataByStation(string workorder)
        {
            List <WorkplanEntity> entityList = new List <WorkplanEntity>();

            KeyValue[] workplanFilter         = new KeyValue[] { new KeyValue("WORKORDER_NUMBER", workorder), new KeyValue("WORKSTEP_FLAG", "1") };
            string[]   workplanDataResultKeys = new string[] { "CYCLE_TIME_MACHINE", "CYCLE_TIME_USER", "EQUIPMENT_AVAILABLE", "ERP_CHANGE_NUMBER", "ERP_GROUP_DESC", "ERP_GROUP_NUMBER", "MAX_TEST_COUNT", "MDA_DOCUMENT_AVAILABLE",
                                                               "MSL_OFFSET", "MSL_RELEVANT", "MULTIPLE_COUNT", "OBLIGATORY_CONFIRM_FLAG", "PROCESS_LAYER", "SEPARATION_FLAG", "SETUP_FLAG", "SETUP_TIME_MACHINE", "SETUP_TIME_USER", "SKILL_DESC", "SKILL_LEVEL", "STATION_DESC", "STATION_NUMBER",
                                                               "VOUCHER_NUMBER", "WORKSTEP_AG", "WORKSTEP_AVO", "WORKSTEP_DESC", "WORKSTEP_INFO", "WORKSTEP_NUMBER", "WORKSTEP_NUMBER_ALT" };
            string[] workplanDataResultValues = new string[] { };
            LogHelper.Info("begin api mdataGetWorkplanData (Work Order:" + init.currentSettings.workorderNumber + ")");
            int error = imsapi.mdataGetWorkplanData(sessionContext, init.configHandler.StationNumber, workplanFilter, workplanDataResultKeys, out workplanDataResultValues);

            LogHelper.Info("end api mdataGetWorkplanData (result code = " + error + ")");
            if (error != 0)
            {
                view.errorHandler(2, init.lang.ERROR_API_CALL_ERROR + " mdataGetWorkplanData " + error, "");
                return(null);
            }
            view.errorHandler(0, init.lang.ERROR_API_CALL_ERROR + " mdataGetWorkplanData " + error, "");
            if (error == 0)
            {
                int loop  = workplanDataResultKeys.Length;
                int count = workplanDataResultValues.Length;
                for (int i = 0; i < count; i += loop)
                {
                    WorkplanEntity entity = new WorkplanEntity();
                    entity.CYCLE_TIME_MACHINE      = workplanDataResultValues[i];
                    entity.CYCLE_TIME_USER         = workplanDataResultValues[i + 1];
                    entity.EQUIPMENT_AVAILABLE     = workplanDataResultValues[i + 2];
                    entity.ERP_CHANGE_NUMBER       = workplanDataResultValues[i + 3];
                    entity.ERP_GROUP_DESC          = workplanDataResultValues[i + 4];
                    entity.ERP_GROUP_NUMBER        = workplanDataResultValues[i + 5];
                    entity.MAX_TEST_COUNT          = workplanDataResultValues[i + 6];
                    entity.MDA_DOCUMENT_AVAILABLE  = workplanDataResultValues[i + 7];
                    entity.MSL_OFFSET              = workplanDataResultValues[i + 8];
                    entity.MSL_RELEVANT            = workplanDataResultValues[i + 9];
                    entity.MULTIPLE_COUNT          = workplanDataResultValues[i + 10];
                    entity.OBLIGATORY_CONFIRM_FLAG = workplanDataResultValues[i + 11];
                    entity.PROCESS_LAYER           = workplanDataResultValues[i + 12];
                    entity.SEPARATION_FLAG         = workplanDataResultValues[i + 13];
                    entity.SETUP_FLAG              = workplanDataResultValues[i + 14];
                    entity.SETUP_TIME_MACHINE      = workplanDataResultValues[i + 15];
                    entity.SETUP_TIME_USER         = workplanDataResultValues[i + 16];
                    entity.SKILL_DESC              = workplanDataResultValues[i + 17];
                    entity.SKILL_LEVEL             = workplanDataResultValues[i + 18];
                    entity.STATION_DESC            = workplanDataResultValues[i + 19];
                    entity.STATION_NUMBER          = workplanDataResultValues[i + 20];
                    entity.VOUCHER_NUMBER          = workplanDataResultValues[i + 21];
                    entity.WORKSTEP_AG             = workplanDataResultValues[i + 22];
                    entity.WORKSTEP_AVO            = workplanDataResultValues[i + 23];

                    entity.WORKSTEP_DESC       = workplanDataResultValues[i + 24];
                    entity.WORKSTEP_INFO       = workplanDataResultValues[i + 25];
                    entity.WORKSTEP_NUMBER     = workplanDataResultValues[i + 26];
                    entity.WORKSTEP_NUMBER_ALT = workplanDataResultValues[i + 27];
                    entityList.Add(entity);
                }
            }
            return(entityList);
        }
Esempio n. 2
0
        public WorkplanEntity GetWorkStepDataByStation(string workorder, string stationNumber)
        {
            WorkplanEntity entity = null;

            KeyValue[] workplanFilter           = new KeyValue[] { new KeyValue("WORKORDER_NUMBER", workorder), new KeyValue("WORKSTEP_FLAG", "1") };
            string[]   workplanDataResultKeys   = new string[] { "PROCESS_LAYER", "WORKSTEP_NUMBER", "WORKPLAN_ID" };
            string[]   workplanDataResultValues = new string[] { };
            LogHelper.Info("begin api mdataGetWorkplanData (Work Order:" + workorder + ")");
            int error = imsapi.mdataGetWorkplanData(sessionContext, stationNumber, workplanFilter, workplanDataResultKeys, out workplanDataResultValues);

            LogHelper.Info("end api mdataGetWorkplanData (result code = " + error + ")");
            if (error != 0)
            {
                view.errorHandler(2, init.lang.ERROR_API_CALL_ERROR + " mdataGetWorkplanData " + error, "");
                return(null);
            }
            if (error == 0)
            {
                entity = new WorkplanEntity();
                entity.PROCESS_LAYER   = workplanDataResultValues[0];
                entity.WORKSTEP_NUMBER = workplanDataResultValues[1];
                //entity.WORKPLAN_ID = workplanDataResultValues[2];
            }
            return(entity);
        }
        /// <summary>
        /// Remove all unused connectors AFTER the new linking was applied
        /// </summary>
        private static void RemoveUnusedConnectors(IUnitOfWork uow, WorkplanEntity workplanEntity, Workplan workplan)
        {
            var connectorRepo = uow.GetRepository <IConnectorEntityRepository>();

            // Remove connectors, that are now longer part of the workplan
            var removedConnectors = workplanEntity.Connectors.Where(ce => workplan.Connectors.All(c => c.Id != ce.ConnectorId));

            connectorRepo.RemoveRange(removedConnectors);
        }
 /// <summary>
 /// Load connectors and return them as a map EntityId => IConnector instance
 /// </summary>
 private static Dictionary <long, IConnector> LoadConnectors(WorkplanEntity workplan)
 {
     return(workplan.Connectors.ToDictionary(
                connector => connector.Id,
                connector => (IConnector) new Connector
     {
         Id = connector.ConnectorId,
         Name = connector.Name,
         Classification = (NodeClassification)connector.Classification
     }));
 }
        /// <summary>
        /// Restore <see cref="IWorkplanStep"/> instances from entities
        /// </summary>
        private static List <IWorkplanStep> LoadSteps(WorkplanEntity workplan, IDictionary <long, IConnector> connectors)
        {
            var steps = new List <IWorkplanStep>();

            foreach (var stepEntity in workplan.Steps)
            {
                var fullName = $"{stepEntity.NameSpace}.{stepEntity.Classname}, {stepEntity.Assembly}";
                var type     = Type.GetType(fullName, true, true);
                // Create instance using public and private constructors
                var step = (WorkplanStepBase)Activator.CreateInstance(type, true);
                step.Id = stepEntity.StepId;

                // Restore output descriptions
                step.OutputDescriptions = new OutputDescription[stepEntity.OutputDescriptions.Count];
                for (int index = 0; index < step.OutputDescriptions.Length; index++)
                {
                    var descriptionEntity = stepEntity.OutputDescriptions.First(ode => ode.Index == index);
                    var description       = new OutputDescription
                    {
                        OutputType   = (OutputType)descriptionEntity.OutputType,
                        Name         = descriptionEntity.Name,
                        MappingValue = descriptionEntity.MappingValue
                    };
                    step.OutputDescriptions[index] = description;
                }

                // Restore parameters from JSON
                if (step is ITaskStep <IParameters> taskStep)
                {
                    JsonConvert.PopulateObject(stepEntity.Parameters, taskStep.Parameters);
                }

                // Restore Subworkplan if necessary
                if (step is ISubworkplanStep subworkplanStep)
                {
                    subworkplanStep.Workplan = LoadWorkplan(stepEntity.SubWorkplan);
                }

                // Restore step name
                if (step is INamedTaskStep namedTaskStep && !string.IsNullOrEmpty(stepEntity.Name))
                {
                    namedTaskStep.Name = stepEntity.Name;
                }

                // Link inputs and outputs
                step.Inputs  = RestoreReferences(stepEntity, ConnectorRole.Input, connectors);
                step.Outputs = RestoreReferences(stepEntity, ConnectorRole.Output, connectors);

                steps.Add(step);
            }

            return(steps);
        }
        /// <summary>
        /// Convert a workplan entity to a <see cref="Workplan"/> instance
        /// </summary>
        private static Workplan LoadWorkplan(WorkplanEntity workplanEntity)
        {
            // Load connectors and steps
            var connectors = LoadConnectors(workplanEntity);
            var steps      = LoadSteps(workplanEntity, connectors);

            // Restore workplan and its properties
            var workplan = Workplan.Restore(connectors.Values.ToList(), steps);

            workplan.Id           = workplanEntity.Id;
            workplan.Name         = workplanEntity.Name;
            workplan.Version      = workplanEntity.Version;
            workplan.State        = (WorkplanState)workplanEntity.State;
            workplan.MaxElementId = workplanEntity.MaxElementId;

            return(workplan);
        }
        /// <summary>
        /// Save or update steps of the workplan and return a map of StepId => Entity
        /// </summary>
        private static IDictionary <long, StepEntity> SaveSteps(IUnitOfWork uow, WorkplanEntity workplanEntity, Workplan workplan)
        {
            var stepRepo        = uow.GetRepository <IStepEntityRepository>();
            var descriptionRepo = uow.GetRepository <IOutputDescriptionEntityRepository>();
            var referenceRepo   = uow.GetRepository <IConnectorReferenceRepository>();

            // Remove connectors, that are now longer used. We only use Created/Updated columns
            // and do not want the entities flagged as deleted
            var removedSteps = workplanEntity.Steps.Where(se => workplan.Steps.All(s => s.Id != se.StepId));

            foreach (var removedStep in removedSteps.ToList())
            {
                descriptionRepo.RemoveRange(removedStep.OutputDescriptions);
                referenceRepo.RemoveRange(removedStep.Connectors);
                stepRepo.Remove(removedStep);
            }

            var stepEntities = new Dictionary <long, StepEntity>();

            foreach (var step in workplan.Steps)
            {
                // Get or create entity
                var stepEntity = workplanEntity.Steps.FirstOrDefault(se => se.StepId == step.Id);
                if (stepEntity == null)
                {
                    var stepType     = step.GetType();
                    var assemblyName = stepType.Assembly.GetName().Name;
                    stepEntity = stepRepo.Create(step.Id, step.Name, assemblyName, stepType.Namespace, stepType.Name);
                    workplanEntity.Steps.Add(stepEntity);
                }
                else
                {
                    stepEntity.Name = step.Name;
                }

                // Update all output descriptions
                for (int index = 0; index < step.OutputDescriptions.Length; index++)
                {
                    var description       = step.OutputDescriptions[index];
                    var descriptionEntity = stepEntity.OutputDescriptions.FirstOrDefault(ode => ode.Index == index);
                    if (descriptionEntity == null)
                    {
                        descriptionEntity = descriptionRepo.Create(index, (int)description.OutputType, description.MappingValue);
                        stepEntity.OutputDescriptions.Add(descriptionEntity);
                    }
                    else
                    {
                        descriptionEntity.OutputType   = (int)description.OutputType;
                        descriptionEntity.MappingValue = description.MappingValue;
                    }
                    descriptionEntity.Name = description.Name;
                }

                // Task steps need parameters
                if (step is ITaskStep <IParameters> taskStep)
                {
                    stepEntity.Parameters = JsonConvert.SerializeObject(taskStep.Parameters);
                }

                // Subworkplan steps and need a reference to the workplan
                if (step is ISubworkplanStep subworkPlanStep)
                {
                    stepEntity.SubWorkplanId = subworkPlanStep.WorkplanId;
                }

                stepEntities[step.Id] = stepEntity;
            }

            return(stepEntities);
        }
        /// <summary>
        /// Save or update connectors of the workplan and return a map of StepId => Entity
        /// </summary>
        private static IDictionary <long, ConnectorEntity> SaveConnectors(IUnitOfWork uow, WorkplanEntity workplanEntity, Workplan workplan)
        {
            var connectorRepo = uow.GetRepository <IConnectorEntityRepository>();

            var connectorEntities = new Dictionary <long, ConnectorEntity>();

            foreach (var connector in workplan.Connectors)
            {
                var connectorEntity = workplanEntity.Connectors.FirstOrDefault(ce => ce.ConnectorId == connector.Id);
                if (connectorEntity == null)
                {
                    connectorEntity = connectorRepo.Create(connector.Id, (int)connector.Classification);
                    workplanEntity.Connectors.Add(connectorEntity);
                }
                connectorEntity.Name            = connector.Name;
                connectorEntities[connector.Id] = connectorEntity;
            }

            return(connectorEntities);
        }