Esempio n. 1
0
        private void UpdateMethodView(Window view)
        {
            dynamic methodItem = authManager.InnovatorInstance.newItem("Method", "get");

            methodItem.setProperty("name", methodName);
            methodItem = methodItem.apply();

            if (methodItem.isError())
            {
                var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                messageWindow.ShowDialog(messageManager.GetMessage("MethodIsNotFoundInTheCurrentConnection", methodName),
                                         messageManager.GetMessage("UpdateMethodFromArasInnovator"),
                                         MessageButtons.OK,
                                         MessageIcon.Information);

                methodConfigId             = string.Empty;
                methodId                   = string.Empty;
                methodLanguage             = string.Empty;
                methodCode                 = string.Empty;
                executionIdentityKeyedName = string.Empty;
                executionIdentityId        = string.Empty;
                methodType                 = string.Empty;
                methodComment              = string.Empty;
                this.selectedTemplate      = null;
                package = null;
            }
            else
            {
                methodConfigId             = methodItem.getProperty("config_id", string.Empty);
                methodId                   = methodItem.getProperty("id", string.Empty);
                methodLanguage             = methodItem.getProperty("method_type", string.Empty);
                methodCode                 = methodItem.getProperty("method_code", string.Empty);
                executionIdentityKeyedName = methodItem.getPropertyAttribute("execution_allowed_to", "keyed_name", string.Empty);
                executionIdentityId        = methodItem.getProperty("execution_allowed_to", string.Empty);
                methodComment              = methodItem.getProperty("comments", string.Empty);

                if (methodLanguage == "C#" || methodLanguage == "VB")
                {
                    methodType = "server";
                }
                else
                {
                    methodType = "client";
                }

                TemplateInfo template;
                string       templateName = templateLoader.GetMethodTemplateName(methodCode);
                if (string.IsNullOrEmpty(templateName))
                {
                    template = templateLoader.GetDefaultTemplate(methodLanguage);
                }
                else
                {
                    template = templateLoader.GetTemplateFromCodeString(templateName, methodLanguage);
                    if (template == null)
                    {
                        var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                        messageWindow.ShowDialog(messageManager.GetMessage("TheTemplateFromSelectedMethodNotFoundDefaultTemplateWillBeUsed", templateName),
                                                 "Update method from Aras Innovator",
                                                 MessageButtons.OK,
                                                 MessageIcon.Information);

                        template = templateLoader.GetDefaultTemplate(methodLanguage);
                    }
                }

                this.SelectedTemplate = template;

                try
                {
                    this.package = packageManager.GetPackageDefinitionByElementId(methodConfigId);
                }
                catch (Exception ex)
                {
                    this.package = null;
                }
            }

            RaisePropertyChanged(string.Empty);
        }
        private void InitializeItemData(string itemType, string id)
        {
            dynamic item = authenticationManager.InnovatorInstance.newItem(itemType, "get");

            item.setID(id);
            item = item.apply();
            if (item.isError())
            {
                return;
            }

            this.MethodName        = item.getProperty("name", string.Empty);
            this.MethodId          = item.getProperty("id", string.Empty);
            this.MethodConfigId    = item.getProperty("config_id", string.Empty);
            this.MethodLanguage    = item.getProperty("method_type", string.Empty);
            this.IdentityKeyedName = item.getPropertyAttribute("execution_allowed_to", "keyed_name", string.Empty);
            this.IdentityId        = item.getProperty("execution_allowed_to", string.Empty);
            this.MethodComment     = item.getProperty("comments", string.Empty);

            var methodCode = item.getProperty("method_code", string.Empty);

            this.MethodCode = Regex.Replace(methodCode, @"//MethodTemplateName=[\S]+\r\n", "");

            if (methodLanguage == "C#" || methodLanguage == "VB")
            {
                this.MethodType = "server";
            }
            else
            {
                this.MethodType = "client";
            }

            var packageName = string.Empty;

            try
            {
                packageName = packageManager.GetPackageDefinitionByElementId(MethodConfigId).Name;
            }
            catch (Exception ex) { }

            this.Package = packageName;

            TemplateInfo template;
            string       templateName = templateLoader.GetMethodTemplateName(methodCode);

            if (string.IsNullOrEmpty(templateName))
            {
                template = templateLoader.GetDefaultTemplate(methodLanguage);
            }
            else
            {
                template = templateLoader.GetTemplateFromCodeString(templateName, methodLanguage);
                if (template == null)
                {
                    var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                    messageWindow.ShowDialog(messageManager.GetMessage("TheTemplateFromSelectedMethodNotFoundDefaultTemplateWillBeUsed", templateName),
                                             "Open method from Aras Innovator",
                                             MessageButtons.OK,
                                             MessageIcon.Information);

                    template = templateLoader.GetDefaultTemplate(methodLanguage);
                }
            }

            this.SelectedTemplate = template;
        }
        private void SearchMethodDialogCommandClicked(object window)
        {
            string itemTypeName          = "Method";
            string itemTypeSingularLabel = "Method";

            List <PropertyInfo> predefinedPropertyValues = new List <PropertyInfo> {
                new PropertyInfo()
                {
                    PropertyName = "method_type", PropertyValue = projectLanguage, IsReadonly = true
                }
            };

            List <PropertyInfo> predefinedSearchItems;

            if (!configurationManager.CurrentProjectConfiguraiton.LastSavedSearch.TryGetValue(itemTypeName, out predefinedSearchItems))
            {
                predefinedSearchItems = new List <PropertyInfo>();
            }

            foreach (var searchItem in predefinedSearchItems)
            {
                if (predefinedPropertyValues.Any(x => x.PropertyName == searchItem.PropertyName))
                {
                    continue;
                }

                predefinedPropertyValues.Add(new ItemSearchPropertyInfo()
                {
                    PropertyName = searchItem.PropertyName, PropertyValue = searchItem.PropertyValue
                });
            }

            var presenter       = dialogFactory.GetItemSearchPresenter(itemTypeName, itemTypeSingularLabel);
            var searchArguments = new ItemSearchPresenterArgs()
            {
                Title = "Search dialog",
                PredefinedPropertyValues = predefinedPropertyValues
            };

            var result = presenter.Run(searchArguments);

            if (result.DialogResult == DialogResult.OK)
            {
                dynamic item = authenticationManager.InnovatorInstance.newItem(result.ItemType, "get");
                item.setID(result.ItemId);
                item = item.apply();

                this.MethodName        = item.getProperty("name", string.Empty);
                this.MethodId          = item.getProperty("id", string.Empty);
                this.MethodConfigId    = item.getProperty("config_id", string.Empty);
                this.MethodLanguage    = item.getProperty("method_type", string.Empty);
                this.IdentityKeyedName = item.getPropertyAttribute("execution_allowed_to", "keyed_name", string.Empty);
                this.IdentityId        = item.getProperty("execution_allowed_to", string.Empty);
                this.MethodComment     = item.getProperty("comments", string.Empty);

                var methodCode = item.getProperty("method_code", string.Empty);
                this.MethodCode = Regex.Replace(methodCode, @"//MethodTemplateName=[\S]+\r\n", "");

                if (methodLanguage == "C#" || methodLanguage == "VB")
                {
                    this.MethodType = "server";
                }
                else
                {
                    this.MethodType = "client";
                }

                var packageName = string.Empty;

                try
                {
                    packageName = packageManager.GetPackageDefinitionByElementName(methodName).Name;
                }
                catch (Exception ex) { }

                this.Package = packageName;

                TemplateInfo template;
                string       templateName = templateLoader.GetMethodTemplateName(methodCode);
                if (string.IsNullOrEmpty(templateName))
                {
                    template = templateLoader.GetDefaultTemplate(methodLanguage);
                }
                else
                {
                    template = templateLoader.GetTemplateFromCodeString(templateName, methodLanguage);
                    if (template == null)
                    {
                        var messageWindow = this.dialogFactory.GetMessageBoxWindow();
                        messageWindow.ShowDialog(messageManager.GetMessage("TheTemplateFromSelectedMethodNotFoundDefaultTemplateWillBeUsed", templateName),
                                                 "Open method from Aras Innovator",
                                                 MessageButtons.OK,
                                                 MessageIcon.Information);

                        template = templateLoader.GetDefaultTemplate(methodLanguage);
                    }
                }

                this.SelectedTemplate = template;

                if (configurationManager.CurrentProjectConfiguraiton.LastSavedSearch.ContainsKey(result.ItemType))
                {
                    configurationManager.CurrentProjectConfiguraiton.LastSavedSearch[result.ItemType] = result.LastSavedSearch.Cast <PropertyInfo>().ToList();
                }
                else
                {
                    configurationManager.CurrentProjectConfiguraiton.LastSavedSearch.Add(result.ItemType, result.LastSavedSearch.Cast <PropertyInfo>().ToList());
                }
            }
        }