示例#1
0
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            var project = projectManager.SelectedProject;

            EnvDTE.Configuration config = project.ConfigurationManager.ActiveConfiguration;
            EnvDTE.Properties    props  = config.Properties;

            var outputPath         = props.Item("OutputPath");
            var dllFullPath        = Path.Combine(project.Properties.Item("FullPath").Value.ToString(), outputPath.Value.ToString(), project.Properties.Item("OutputFileName").Value.ToString());
            var selectedMethodName = projectManager.MethodName;

            string projectConfigPath = projectManager.ProjectConfigPath;

            MethodInfo methodInformation = projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName);

            string selectedMethodPath = projectManager.MethodPath;
            string sourceCode         = File.ReadAllText(selectedMethodPath, new UTF8Encoding(true));

            var        tree   = CSharpSyntaxTree.ParseText(sourceCode);
            SyntaxNode root   = tree.GetRoot();
            var        member = root.DescendantNodes()
                                .OfType <NamespaceDeclarationSyntax>()
                                .FirstOrDefault();
            var className  = GetFullClassName(member);
            var methodName = GetMethodName(member);

            //(me as IdentifierNameSyntax).Identifier.ValueText

            //var selectedClassName =
            //ProjectConfiguraiton projectConfiguration = projectConfigurationManager.Load(projectConfigPath);
            projectManager.ExecuteCommand("Build.BuildSolution");

            var currentDllPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var directoryPath  = Path.GetDirectoryName(currentDllPath);
            var launcherPath   = Path.Combine(directoryPath, "MethodLauncher", "MethodLauncher.exe");

            string        packageMethodFolderPath = this.projectConfigurationManager.CurrentProjectConfiguraiton.UseCommonProjectStructure ? methodInformation.Package.MethodFolderPath : string.Empty;
            string        methodWorkingFolder     = Path.Combine(projectManager.ServerMethodFolderPath, packageMethodFolderPath, methodInformation.MethodName);
            ICodeProvider codeProvider            = codeProviderFactory.GetCodeProvider(projectManager.Language);

            string methodCode = codeProvider.LoadMethodCode(methodWorkingFolder, sourceCode);

            var debugMethodView       = dialogFactory.GetDebugMethodView(projectConfigurationManager, methodInformation, methodCode, projectConfigPath, project.Name, project.FullName);
            var debugMethodViewResult = debugMethodView.ShowDialog();

            if (debugMethodViewResult?.DialogOperationResult != true)
            {
                return;
            }

            string projectDirectoryPath = Path.GetDirectoryName(projectManager.SelectedProject.FileName);
            string launcherConfigPath   = Path.Combine(projectDirectoryPath, "LauncherConfig.xml");

            CreateLauncherConfigFile(dllFullPath, className, methodName, debugMethodViewResult, launcherConfigPath,
                                     CommonData.EventSpecificDataTypeList.FirstOrDefault(ev => ev.EventSpecificData.ToString() == methodInformation.EventData.ToString()).EventDataClass, methodInformation.TemplateName);

            ProcessStartInfo startInfo = new ProcessStartInfo(launcherPath);

            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.Arguments   = launcherConfigPath + " " + authManager.InnovatorUser.passwordHash;

            Process process = Process.Start(startInfo);

            projectManager.AttachToProcess(process);
        }
示例#2
0
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            var project = projectManager.SelectedProject;

            var projectConfigPath = projectManager.ProjectConfigPath;
            var methodConfigPath  = projectManager.MethodConfigPath;

            var projectConfiguration = projectConfigurationManager.Load(projectConfigPath);

            string selectedMethodPath = projectManager.MethodPath;
            string sourceCode         = File.ReadAllText(selectedMethodPath, new UTF8Encoding(true));
            string selectedMethodName = Path.GetFileNameWithoutExtension(selectedMethodPath);

            MethodInfo methodInformation = projectConfiguration.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName);

            if (methodInformation == null)
            {
                throw new Exception();
            }

            ICodeProvider codeProvider = codeProviderFactory.GetCodeProvider(project.CodeModel.Language, projectConfiguration);
            string        methodCode   = codeProvider.LoadMethodCode(sourceCode, methodInformation, projectManager.ServerMethodFolderPath);

            var packageManager = new PackageManager(authManager);
            var saveView       = dialogFactory.GetSaveToArasView(projectConfigurationManager, projectConfiguration, packageManager, methodInformation, methodCode, projectConfigPath, project.Name, project.FullName);
            var saveViewResult = saveView.ShowDialog();

            if (saveViewResult?.DialogOperationResult != true)
            {
                return;
            }

            var templateLoader = new TemplateLoader(this.dialogFactory);

            templateLoader.Load(methodConfigPath);

            dynamic currentMethodItem = saveViewResult.MethodItem;

            if (!currentMethodItem.isError())
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);

                var action = GetUpdateAction(currentMethodItem.getLockStatus());
                currentMethodItem = currentMethodItem.apply(action);
            }
            else
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem = authManager.InnovatorInstance.newItem("Method", "add");
                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);
                currentMethodItem = currentMethodItem.apply();
            }

            if (currentMethodItem.isError())
            {
                throw new Exception(currentMethodItem.getErrorString());
            }

            var newId = currentMethodItem.getID();

            if (string.IsNullOrEmpty(saveViewResult.CurrentMethodPackage))
            {
                packageManager.AddPackageElementToPackageDefinition(newId, saveViewResult.MethodName, saveViewResult.SelectedPackage);
            }
            else
            {
                if (!string.Equals(saveViewResult.CurrentMethodPackage, saveViewResult.SelectedPackage))
                {
                    packageManager.DeletePackageElementByNameFromPackageDefinition(saveViewResult.MethodName);
                    packageManager.AddPackageElementToPackageDefinition(newId, saveViewResult.MethodName, saveViewResult.SelectedPackage);
                }
            }

            if (methodInformation.MethodName == saveViewResult.MethodName)
            {
                methodInformation.InnovatorMethodConfigId     = currentMethodItem.getProperty("config_id");
                methodInformation.InnovatorMethodId           = newId;
                methodInformation.PackageName                 = saveViewResult.SelectedPackage;
                methodInformation.ExecutionAllowedToKeyedName = saveViewResult.SelectedIdentityKeyedName;
                methodInformation.ExecutionAllowedToId        = saveViewResult.SelectedIdentityId;
                methodInformation.MethodComment               = saveViewResult.MethodComment;

                projectConfigurationManager.Save(projectConfigPath, projectConfiguration);
            }

            string message          = string.Format("Method \"{0}\" saved", saveViewResult.MethodName);
            var    messageBoxWindow = dialogFactory.GetMessageBoxWindow();

            messageBoxWindow.ShowDialog(message,
                                        string.Empty,
                                        MessageButtons.OK,
                                        MessageIcon.Information);
        }
        public SaveToPackageViewModel(
            IAuthenticationManager authManager,
            IDialogFactory dialogFactory,
            IProjectConfiguraiton projectConfiguration,
            TemplateLoader templateLoader,
            PackageManager packageManager,
            ICodeProvider codeProvider,
            IProjectManager projectManager,
            IArasDataProvider arasDataProvider,
            MethodInfo methodInformation,
            string pathToFileForSave)
        {
            if (authManager == null)
            {
                throw new ArgumentNullException(nameof(authManager));
            }
            if (dialogFactory == null)
            {
                throw new ArgumentNullException(nameof(dialogFactory));
            }
            if (projectConfiguration == null)
            {
                throw new ArgumentNullException(nameof(projectConfiguration));
            }
            if (templateLoader == null)
            {
                throw new ArgumentNullException(nameof(templateLoader));
            }
            if (packageManager == null)
            {
                throw new ArgumentNullException(nameof(packageManager));
            }
            if (codeProvider == null)
            {
                throw new ArgumentNullException(nameof(codeProvider));
            }
            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }
            if (arasDataProvider == null)
            {
                throw new ArgumentNullException(nameof(arasDataProvider));
            }
            if (methodInformation == null)
            {
                throw new ArgumentNullException(nameof(methodInformation));
            }

            this.authManager          = authManager;
            this.dialogFactory        = dialogFactory;
            this.projectConfiguration = projectConfiguration;
            this.templateLoader       = templateLoader;
            this.packageManager       = packageManager;
            this.projectManager       = projectManager;
            this.arasDataProvider     = arasDataProvider;
            this.MethodInformation    = methodInformation;

            this.folderBrowserCommand    = new RelayCommand <object>(OnFolderBrowserClick);
            this.okCommand               = new RelayCommand <object>(OkCommandClick, IsEnabledOkButton);
            this.closeCommand            = new RelayCommand <object>(OnCloseCliked);
            this.selectedIdentityCommand = new RelayCommand(SelectedIdentityCommandClick);

            string sourceCode = File.ReadAllText(pathToFileForSave, new UTF8Encoding(true));

            this.methodItemTypeInfo     = arasDataProvider.GetMethodItemTypeInfo();
            this.MethodNameMaxLength    = methodItemTypeInfo.NameStoredLength;
            this.MethodCommentMaxLength = methodItemTypeInfo.CommentsStoredLength;

            MethodComment             = MethodInformation.MethodComment;
            PackagePath               = projectConfiguration.LastSelectedDir;
            MethodName                = MethodInformation.MethodName;
            MethodCode                = codeProvider.LoadMethodCode(sourceCode, MethodInformation, projectManager.ServerMethodFolderPath);
            SelectedPackage           = MethodInformation.PackageName;
            selectedIdentityKeyedName = MethodInformation.ExecutionAllowedToKeyedName;
            selectedIdentityId        = MethodInformation.ExecutionAllowedToId;
        }
        public override void ExecuteCommandImpl(object sender, EventArgs args)
        {
            var project = projectManager.SelectedProject;

            string selectedMethodPath = projectManager.MethodPath;
            string sourceCode         = File.ReadAllText(selectedMethodPath, new UTF8Encoding(true));
            string selectedMethodName = Path.GetFileNameWithoutExtension(selectedMethodPath);

            string projectConfigPath = projectManager.ProjectConfigPath;

            MethodInfo methodInformation = projectConfigurationManager.CurrentProjectConfiguraiton.MethodInfos.FirstOrDefault(m => m.MethodName == selectedMethodName);

            if (methodInformation == null)
            {
                throw new Exception();
            }

            string packageMethodFolderPath = this.projectConfigurationManager.CurrentProjectConfiguraiton.UseCommonProjectStructure ? methodInformation.Package.MethodFolderPath : string.Empty;
            string methodWorkingFolder     = Path.Combine(projectManager.ServerMethodFolderPath, packageMethodFolderPath, methodInformation.MethodName);

            ICodeProvider codeProvider = codeProviderFactory.GetCodeProvider(projectManager.Language);

            CodeInfo codeItemInfo = codeProvider.UpdateSourceCodeToInsertExternalItems(methodWorkingFolder, sourceCode, methodInformation, projectConfigurationManager.CurrentProjectConfiguraiton.UseVSFormatting);

            if (codeItemInfo != null)
            {
                var dialogResult = dialogFactory.GetMessageBoxWindow().ShowDialog(messageManager.GetMessage("CouldNotInsertExternalItemsInsideOfMethodCodeSection"),
                                                                                  messageManager.GetMessage("ArasVSMethodPlugin"),
                                                                                  MessageButtons.OKCancel,
                                                                                  MessageIcon.Question);
                if (dialogResult == MessageDialogResult.Cancel)
                {
                    return;
                }

                projectManager.AddItemTemplateToProjectNew(codeItemInfo, packageMethodFolderPath, true, 0);
                sourceCode = codeItemInfo.Code;
            }

            string methodCode = codeProvider.LoadMethodCode(methodWorkingFolder, sourceCode);

            var packageManager = new PackageManager(authManager, this.messageManager);
            var saveView       = dialogFactory.GetSaveToArasView(projectConfigurationManager, packageManager, methodInformation, methodCode, projectConfigPath, project.Name, project.FullName);
            var saveViewResult = saveView.ShowDialog();

            if (saveViewResult?.DialogOperationResult != true)
            {
                return;
            }

            TemplateLoader templateLoader = new TemplateLoader();

            templateLoader.Load(projectManager.MethodConfigPath);

            dynamic currentMethodItem = saveViewResult.MethodItem;

            if (!currentMethodItem.isError())
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);

                var action = GetUpdateAction(currentMethodItem.getLockStatus());
                currentMethodItem = currentMethodItem.apply(action);
            }
            else
            {
                methodCode = saveViewResult.MethodCode;
                var template = templateLoader.Templates.FirstOrDefault(t => t.TemplateName == saveViewResult.TemplateName);
                if (template != null && !template.IsSupported)
                {
                    methodCode = methodCode.Insert(0, string.Format("//MethodTemplateName={0}\r\n", template.TemplateName));
                }

                currentMethodItem = authManager.InnovatorInstance.newItem("Method", "add");
                currentMethodItem.setProperty("comments", saveViewResult.MethodComment);
                currentMethodItem.setProperty("method_code", methodCode);
                currentMethodItem.setProperty("name", saveViewResult.MethodName);
                currentMethodItem.setProperty("method_type", saveViewResult.MethodLanguage);
                currentMethodItem.setProperty("execution_allowed_to", saveViewResult.SelectedIdentityId);
                currentMethodItem = currentMethodItem.apply();
            }

            if (currentMethodItem.isError())
            {
                throw new Exception(currentMethodItem.getErrorString());
            }

            string newId    = currentMethodItem.getID();
            string configId = currentMethodItem.getProperty("config_id");

            if (string.IsNullOrEmpty(saveViewResult.CurrentMethodPackage))
            {
                packageManager.AddPackageElementToPackageDefinition(configId, saveViewResult.MethodName, saveViewResult.SelectedPackageInfo.Name);
            }
            else
            {
                if (!string.Equals(saveViewResult.CurrentMethodPackage, saveViewResult.SelectedPackageInfo.ToString()))
                {
                    packageManager.DeletePackageByElementIdFromPackageDefinition(configId);
                    packageManager.AddPackageElementToPackageDefinition(configId, saveViewResult.MethodName, saveViewResult.SelectedPackageInfo.Name);
                }
            }

            if (methodInformation.MethodName == saveViewResult.MethodName &&
                methodInformation.Package.Name == saveViewResult.SelectedPackageInfo.Name)
            {
                methodInformation.InnovatorMethodConfigId = configId;
                methodInformation.InnovatorMethodId       = newId;
                methodInformation.Package = saveViewResult.SelectedPackageInfo;
                methodInformation.ExecutionAllowedToKeyedName = saveViewResult.SelectedIdentityKeyedName;
                methodInformation.ExecutionAllowedToId        = saveViewResult.SelectedIdentityId;
                methodInformation.MethodComment = saveViewResult.MethodComment;

                projectConfigurationManager.Save(projectConfigPath);
            }

            var messageBoxWindow = dialogFactory.GetMessageBoxWindow();

            messageBoxWindow.ShowDialog(this.messageManager.GetMessage("MethodSaved", saveViewResult.MethodName),
                                        string.Empty,
                                        MessageButtons.OK,
                                        MessageIcon.Information);
        }
示例#5
0
        public SaveToPackageViewModel(
            IAuthenticationManager authManager,
            IDialogFactory dialogFactory,
            IProjectConfiguraiton projectConfiguration,
            TemplateLoader templateLoader,
            PackageManager packageManager,
            ICodeProvider codeProvider,
            IProjectManager projectManager,
            IArasDataProvider arasDataProvider,
            IIOWrapper iOWrapper,
            MessageManager messageManager,
            MethodInfo methodInformation,
            string sourceCode)
        {
            if (authManager == null)
            {
                throw new ArgumentNullException(nameof(authManager));
            }
            if (dialogFactory == null)
            {
                throw new ArgumentNullException(nameof(dialogFactory));
            }
            if (projectConfiguration == null)
            {
                throw new ArgumentNullException(nameof(projectConfiguration));
            }
            if (templateLoader == null)
            {
                throw new ArgumentNullException(nameof(templateLoader));
            }
            if (packageManager == null)
            {
                throw new ArgumentNullException(nameof(packageManager));
            }
            if (codeProvider == null)
            {
                throw new ArgumentNullException(nameof(codeProvider));
            }
            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }
            if (arasDataProvider == null)
            {
                throw new ArgumentNullException(nameof(arasDataProvider));
            }
            if (iOWrapper == null)
            {
                throw new ArgumentNullException(nameof(iOWrapper));
            }
            if (messageManager == null)
            {
                throw new ArgumentNullException(nameof(messageManager));
            }
            if (methodInformation == null)
            {
                throw new ArgumentNullException(nameof(methodInformation));
            }

            this.authManager          = authManager;
            this.dialogFactory        = dialogFactory;
            this.projectConfiguration = projectConfiguration;
            this.templateLoader       = templateLoader;
            this.packageManager       = packageManager;
            this.projectManager       = projectManager;
            this.arasDataProvider     = arasDataProvider;
            this.iOWrapper            = iOWrapper;
            this.messageManager       = messageManager;
            this.MethodInformation    = methodInformation;

            this.folderBrowserCommand    = new RelayCommand <object>(OnFolderBrowserClick);
            this.okCommand               = new RelayCommand <object>(OkCommandClick, IsEnabledOkButton);
            this.closeCommand            = new RelayCommand <object>(OnCloseCliked);
            this.selectedIdentityCommand = new RelayCommand(SelectedIdentityCommandClick);

            this.methodItemTypeInfo     = arasDataProvider.GetMethodItemTypeInfo();
            this.MethodNameMaxLength    = methodItemTypeInfo.NameStoredLength;
            this.MethodCommentMaxLength = methodItemTypeInfo.CommentsStoredLength;

            MethodComment = MethodInformation.MethodComment;
            PackagePath   = projectConfiguration.LastSelectedDir;
            MethodName    = MethodInformation.MethodName;

            string packageMethodFolderPath = projectConfiguration.UseCommonProjectStructure ? methodInformation.Package.MethodFolderPath : string.Empty;
            string methodWorkingFolder     = Path.Combine(projectManager.ServerMethodFolderPath, packageMethodFolderPath, methodInformation.MethodName);

            MethodCode                = codeProvider.LoadMethodCode(methodWorkingFolder, sourceCode);
            SelectedPackage           = MethodInformation.Package.Name;
            selectedIdentityKeyedName = MethodInformation.ExecutionAllowedToKeyedName;
            selectedIdentityId        = MethodInformation.ExecutionAllowedToId;
        }