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)
            {
                InitializeItemData(result.ItemType, result.ItemId);

                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());
                }
            }
        }
        private void SelectedIdentityCommandClick()
        {
            string itemTypeName          = "Identity";
            string itemTypeSingularLabel = "Identity";

            List <PropertyInfo> predefinedSearchItems;

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

            var searchArguments = new ItemSearchPresenterArgs()
            {
                Title = "Search dialog",
                PredefinedPropertyValues = predefinedSearchItems
            };

            ItemSearchPresenter presenter = dialogFactory.GetItemSearchPresenter(itemTypeName, itemTypeSingularLabel);
            var result = presenter.Run(searchArguments);

            if (result.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                // TODO : should be replaced by better approach
                dynamic item = authManager.InnovatorInstance.newItem(itemTypeName, "get");
                item.setID(result.ItemId);
                item.setAttribute("select", "keyed_name");
                item = item.apply();

                this.SelectedIdentityKeyedName = item.getProperty("keyed_name");
                this.selectedIdentityId        = result.ItemId;

                if (projectConfigurationManager.CurrentProjectConfiguraiton.LastSavedSearch.ContainsKey(result.ItemType))
                {
                    projectConfigurationManager.CurrentProjectConfiguraiton.LastSavedSearch[result.ItemType] = result.LastSavedSearch;
                }
                else
                {
                    projectConfigurationManager.CurrentProjectConfiguraiton.LastSavedSearch.Add(result.ItemType, result.LastSavedSearch);
                }
            }
        }
        private void SearchMethodDialogCommandClicked(object window)
        {
            string itemTypeName          = "Method";
            string itemTypeSingularLabel = "Method";

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

            List <PropertyInfo> predefinedSearchItems;

            if (!projectConfiguration.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 PropertyInfo()
                {
                    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);
                }
                catch (Exception ex) { }

                this.Package = packageName;

                // TODO : duplicated with OpenFromPackageView
                TemplateInfo template = null;
                string       methodTemplatePattern   = @"//MethodTemplateName\s*=\s*(?<templatename>[^\W]*)\s*";
                Match        methodTemplateNameMatch = Regex.Match(methodCode, methodTemplatePattern);
                if (methodTemplateNameMatch.Success)
                {
                    string templateName = methodTemplateNameMatch.Groups["templatename"].Value;
                    template = templateLoader.Templates.Where(t => t.TemplateLanguage == methodLanguage && t.TemplateName == templateName).FirstOrDefault();

                    if (template == null)
                    {
                        var messageWindow = new MessageBoxWindow();
                        messageWindow.ShowDialog(window as Window,
                                                 $"The template {templateName} from selected method not found. Default template will be used.",
                                                 "Open method from Aras Innovator",
                                                 MessageButtons.OK,
                                                 MessageIcon.Information);
                    }
                }
                if (template == null)
                {
                    template = templateLoader.Templates.Where(t => t.TemplateLanguage == methodLanguage && t.IsSupported).FirstOrDefault();
                }

                this.SelectedTemplate = template;

                if (projectConfiguration.LastSavedSearch.ContainsKey(result.ItemType))
                {
                    projectConfiguration.LastSavedSearch[result.ItemType] = result.LastSavedSearch;
                }
                else
                {
                    projectConfiguration.LastSavedSearch.Add(result.ItemType, result.LastSavedSearch);
                }
            }
        }
        private void SearchMethodDialogCommandClicked(object window)
        {
            string itemTypeName          = "Method";
            string itemTypeSingularLabel = "Method";

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

            List <PropertyInfo> predefinedSearchItems;

            if (!projectConfiguration.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 PropertyInfo()
                {
                    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);
                }
                catch (Exception ex) { }

                this.Package = packageName;

                this.SelectedTemplate = templateLoader.GetTemplateFromCodeString(methodCode, methodLanguage, "Open method from Aras Innovator");

                if (projectConfiguration.LastSavedSearch.ContainsKey(result.ItemType))
                {
                    projectConfiguration.LastSavedSearch[result.ItemType] = result.LastSavedSearch;
                }
                else
                {
                    projectConfiguration.LastSavedSearch.Add(result.ItemType, result.LastSavedSearch);
                }
            }
        }