Esempio n. 1
0
        private void InitOperationAttributes(int operationId)
        {
            if (operationId == 0)
            {
                operationAttributes1.InitializeControl(null);
                return;
            }

            _viewShedulerStepModel.nameVis = cbOperation.Text;

            string fileName = OperationTools.GetOperationFileNameById(operationId);

            if (string.IsNullOrEmpty(fileName))
            {
                operationAttributes1.InitializeControl(null);
                return;
            }

            Type   attrType     = null;
            string operName     = OperationTools.GetOperationNameEnById(operationId);
            string operFileName = OperationTools.GetOperationFileNameById(operationId);
            string operFileMd5  = OperationTools.GetOperationFileMd5ById(operationId);

            if (!string.IsNullOrEmpty(operName) && !string.IsNullOrEmpty(operFileName) && !string.IsNullOrEmpty(operFileMd5))
            {
                attrType = PluginOperationAdapter.GetPluginOperationAttributesType(
                    operName
                    , operFileName
                    , operFileMd5);
            }

            if (attrType != null)
            {
                IOperationAttributes operationAttributesInstance = (IOperationAttributes)Activator.CreateInstance(attrType);

                //Ищем сохраненные атрибуты
                JObject savedModel = NewtonJson.GetModelFromJson(_viewShedulerStepModel.OperationAttributes) as JObject;
                JToken  token      = null;
                if (savedModel != null && savedModel.HasValues)
                {
                    foreach (var prop in operationAttributesInstance.GetType().GetProperties())
                    {
                        savedModel.TryGetValue(prop.Name, out token);
                        if (token != null)
                        {
                            object propValue = ExtTools.ConvertStringToType(token.ToString(), prop.PropertyType);
                            if (propValue != null)
                            {
                                prop.SetValue(operationAttributesInstance, propValue);
                            }
                        }
                    }
                }

                operationAttributes1.InitializeControl(operationAttributesInstance, operationId);
            }
            else
            {
                operationAttributes1.InitializeControl(null);
            }
        }