Esempio n. 1
0
        /// <summary>
        /// Performs the validation of the item passed as target
        /// Returns true if the reference is allowed to be executed in the target
        /// that is if the target is a web project and C# project
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns>
        ///     <c>true</c> if [is web C sharp project] [the specified target]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsWebCSharpProject(object target)
        {
            Project project = null;

            if (target is Project)
            {
                project = (Project)target;
            }
            else if (target is ProjectItem)
            {
                project = ((ProjectItem)target).ContainingProject;
            }

            if (project != null &&
                DteHelper.IsWebProject(project) &&
                project.Properties != null)
            {
                try
                {
                    Property property = project.Properties.Item(CurrentWebsiteLanguagePropertyItem);
                    return(property.Value != null &&
                           property.Value.ToString().Equals(CurrentWebsiteLanguagePropertyValue, StringComparison.InvariantCultureIgnoreCase));
                }
                catch (Exception exception)
                {
                    Trace.TraceError(exception.ToString());
                    // Some Project implementations throws this excpetion (i.e.: Analysis services project)
                    // or the CurrentWebsiteLanguagePropertyItem property does not exists.
                    return(false);
                }
            }

            return(false);
        }
Esempio n. 2
0
        private void ButtonRemoveImage_Click(object sender, RoutedEventArgs e)
        {
            var step   = (CrmTypeStep)ListTypeSteps.SelectedItem;
            var images = ListStepImages.SelectedItems.Cast <CrmStepImage>().ToList();

            var isConfirmed = DteHelper.IsConfirmed(
                "Are you sure you want to DELETE image(s):" +
                $" {images.Select(image => image.Name).Aggregate((image1Name, image2Name) => image1Name + ", " + image2Name)}?",
                "Image(s) Deletion");

            if (!isConfirmed)
            {
                return;
            }

            new Thread(() =>
            {
                try
                {
                    images.ForEach(image =>
                    {
                        assemblyRegistration.DeleteStepImage(image.Id);
                        Dispatcher.Invoke(() => step.Children.Remove(image));
                    });
                }
                catch (Exception exception)
                {
                    PopException(exception);
                }
                finally
                {
                    HideBusy();
                }
            }).Start();
        }
Esempio n. 3
0
        private void ButtonRemoveStep_Click(object sender, RoutedEventArgs e)
        {
            var type  = (CrmPluginType)ListPluginTypes.SelectedItem;
            var steps = ListTypeSteps.SelectedItems.Cast <CrmTypeStep>().ToList();

            var isConfirmed = DteHelper.IsConfirmed(
                "Are you sure you want to DELETE steps(s):" +
                $" {steps.Select(step => step.Name).Aggregate((step1Name, step2Name) => step1Name + ", " + step2Name)}?",
                "Step(s) Deletion");

            if (!isConfirmed)
            {
                return;
            }

            new Thread(() =>
            {
                try
                {
                    steps.ForEach(step =>
                    {
                        assemblyRegistration.DeleteTypeStep(step.Id);
                        Dispatcher.Invoke(() => type.Children.Remove(step));
                    });
                }
                catch (Exception exception)
                {
                    PopException(exception);
                }
                finally
                {
                    HideBusy();
                }
            }).Start();
        }
        private Hashtable ReadReferenceState(StateEntry[] initalState)
        {
            Hashtable hashInitialState = null;

            if (initalState != null)
            {
                hashInitialState = new Hashtable();
                foreach (StateEntry entry in initalState)
                {
                    entry.Key   = NormalizeTextNodes(entry.Key);
                    entry.Value = NormalizeTextNodes(entry.Value);

                    object key   = entry.Key;
                    object value = entry.Value;
                    // Both default to string if no other type is provided.
                    if (key is XmlText)
                    {
                    }
                    if (key is string)
                    {
                        key = DteHelper.ReplaceParameters((string)entry.Key, this.ReplacementDictionary);
                    }
                    if (value is string)
                    {
                        value = DteHelper.ReplaceParameters((string)entry.Value, this.ReplacementDictionary);
                    }

                    hashInitialState.Add(key, value);
                }
            }
            return(hashInitialState);
        }
Esempio n. 5
0
        /// <summary>
        /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            DynamicTypeService typeService = (DynamicTypeService)context.GetService(typeof(DynamicTypeService));

            Debug.Assert(typeService != null, "No dynamic type service registered.");

            IVsHierarchy hier = DteHelper.GetCurrentSelection(context);

            Debug.Assert(hier != null, "No active hierarchy is selected.");

            ITypeDiscoveryService typeDiscovery = typeService.GetTypeDiscoveryService(hier);

            if (typeDiscovery != null)
            {
                List <string> types = new List <string>();
                foreach (Type type in typeDiscovery.GetTypes(typeof(object), false))
                {
                    if (ShouldInclude(type))
                    {
                        types.Add(type.FullName);
                    }
                }

                types.Sort(StringComparer.CurrentCulture);

                return(new StandardValuesCollection(types));
            }
            else
            {
                return(new StandardValuesCollection(new List <string>()));
            }
        }
        private void AddItemTemplate(Project rootproject)
        {
            DTE    dte         = (DTE)GetService(typeof(DTE));
            string projectPath = DteHelper.BuildPath(rootproject);
            string folderPath  = projectPath;

            if (!string.IsNullOrEmpty(this.Path))
            {
                folderPath = System.IO.Path.Combine(folderPath, this.Path);
            }
            ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, folderPath);

            if (prItem != null)
            {
                this.NewItem = prItem.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
            else
            {
                Project project = DteHelper.FindProjectByPath(dte.Solution, folderPath);
                if (project != null)
                {
                    project.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
                }
                else
                {
                    throw new InvalidOperationException(
                              String.Format(CultureInfo.CurrentUICulture, Resources.InsertionPointException, folderPath));
                }
            }
        }
Esempio n. 7
0
        public bool Test()
        {
            try
            {
                EnvDTE.DTE             dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
                IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
                object item = DteHelper.GetTarget(dte);
                //MessageBox.Show("Coneccion exitosa.- a " + _Server.Information.Product.ToString(),  Fwk.GuidPk.Properties.Resources.ProductTitle);


                //templateFilename = new Uri(templateFilename).LocalPath;
                StringBuilder items = new StringBuilder();
                //VsBoundReference vsTarget = null;
                if (item is Project)
                {
                    foreach (ProjectItem i in ((Project)item).ProjectItems)
                    {
                        items.AppendLine(i.Name);
                    }
                    //vsTarget = new ProjectReference(templateFilename, (Project)item);
                }

                MessageBox.Show(items.ToString(), Fwk.GuidPk.Properties.Resources.ProductTitle);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Fwk.CodeGenerator.HelperFunctions.GetAllMessageException(ex), Fwk.GuidPk.Properties.Resources.ProductTitle);
                return(false);
            }
            return(true);
        }
Esempio n. 8
0
        private void RegisterModifyPlugin(Project project)
        {
            DteHelper.SetCurrentProject(project);
            var regWindow = new Login(GetService(typeof(SDTE)) as DTE2);

            regWindow.ShowModal();
        }
Esempio n. 9
0
 private void DeletePluginCallback(object sender, EventArgs args)
 {
     try
     {
         if (DteHelper.IsConfirmed("Are you sure you want to UNregister this plugin?" +
                                   " This means that the plugin and all its steps will be deleted!", "Unregistration"))
         {
             Status.Update(">>>>> Starting new session <<<<<");
             DeletePlugin();
         }
     }
     catch (UserException e)
     {
         VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING,
                                         OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
     }
     catch (Exception e)
     {
         var error1 = "[ERROR] " + e.Message
                      + (e.InnerException != null ? "\n" + "[ERROR] " + e.InnerException.Message : "");
         Status.Update(error1);
         Status.Update(e.StackTrace);
         Status.Update("Unable to delete assembly, see error above.");
         var error2 = e.Message + "\n" + e.StackTrace;
         MessageBox.Show(error2, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     finally
     {
         Status.Update(">>>>> DONE! <<<<<");
     }
 }
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            DTE vs = GetService <DTE>(true);
            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
            object item = DteHelper.GetTarget(vs);

            if (item == null)
            {
                throw new InvalidOperationException("There is no valid target to reference the template.");
            }

            if (item is Project)
            {
                addedReference = new ProjectReference(recipeName, (Project)item);
            }
            else if (item is Solution)
            {
                addedReference = new SolutionReference(recipeName, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                addedReference = new ProjectItemReference(recipeName, (ProjectItem)item);
            }
            else
            {
                throw new NotSupportedException("Current selection is unsupported.");
            }

            referenceService.Add(addedReference);

            MessageBox.Show("The new reference was successfully added.", "New Reference",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
 /// <summary>
 /// Creates the new launch condition with the given values
 /// </summary>
 public override void Execute()
 {
     try
     {
         IVsdDeployable            deployable            = (IVsdDeployable)SetupProject.Object;
         IVsdCollectionSubset      plugins               = deployable.GetPlugIns();
         IVsdLaunchConditionPlugIn launchConditionPlugin = plugins.Item("LaunchCondition") as IVsdLaunchConditionPlugIn;
         if (launchConditionPlugin != null)
         {
             vsdLaunchCondition =
                 (IVsdLaunchCondition)DteHelper.CoCreateInstance(
                     this.Site,
                     typeof(VsdLaunchConditionClass),
                     typeof(IVsdLaunchCondition));
             vsdLaunchCondition.Name       = this.LaunchConditionName;
             vsdLaunchCondition.Condition  = this.Condition;
             vsdLaunchCondition.Message    = this.Message;
             vsdLaunchCondition.InstallUrl = this.InstallUrl;
             launchConditionPlugin.Items.Add(vsdLaunchCondition);
         }
     }
     catch (Exception)
     {
         vsdLaunchCondition = null;
         throw;
     }
 }
        // Methods
        private void AddItemTemplate(Project rootproject)
        {
            DTE    service = (DTE)this.GetService(typeof(DTE));
            string str2    = DteHelper.BuildPath(rootproject);

            if (!string.IsNullOrEmpty(this.Path))
            {
                str2 = System.IO.Path.Combine(str2, this.Path);
            }
            ProjectItem item = DteHelper.FindItemByPath(service.Solution, str2);

            if (item != null)
            {
                this.NewItem = item.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
            else
            {
                Project project = DteHelper.FindProjectByPath(service.Solution, str2);
                if (project == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "InsertionPointException", new object[] { str2 }));
                }
                project.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="para">自定义参数</param>
        /// <result></result>
        public override CommandResult Process(object para)
        {
            CommandResult result = new CommandResult();

            result.ErrCode = CommandExecStatus.Succeed;
            result.ErrMsg  = para.ToString();
            if (vsWindowType.vsWindowTypeDocument == DteHelper.Dte2.ActiveWindow.Type)
            {
                _currentCodePoint    = DteHelper.GetCurrentActivePoint();
                _currentCodeDocument = DteHelper.Dte2.ActiveDocument;
                List <CodeDomCodeElement <CodeElement> > listElement = DteHelper.FetchCodeElementByPoint(_currentCodeDocument.ProjectItem.FileCodeModel, _currentCodePoint);
                this.CurrentCodeElement = DteHelper.FindPointElement(listElement, _currentCodePoint);
            }
            else if (vsWindowType.vsWindowTypeSolutionExplorer == DteHelper.Dte2.ActiveWindow.Type && CurrentCodeElement != null)
            {
                //取得所有选中文件
                IList <ProjectItem> listItem = DteHelper.GetSelectedItem(Constant.CSharpFileExtension);

                List <CodeDomCodeElement <CodeElement> > listElement = DteHelper.FetchCodeElementByPoint(_currentCodeDocument.ProjectItem.FileCodeModel, _currentCodePoint);
                CodeDomCodeElement <CodeElement>         codeElement = DteHelper.FindPointElement(listElement, _currentCodePoint);

                foreach (var projectItem in listItem)
                {
                    foreach (var codeClass in DteHelper.GetClassFromFile(projectItem.FileCodeModel))
                    {//重构元素
                        DteHelper.RefactorElement(this.CurrentCodeElement, codeElement, codeClass);
                    }
                }
            }
            return(result);
        }
        // Methods
        public override void Execute()
        {
            DTE dte = base.GetService <DTE>();

            string solutionDirectory = Path.GetDirectoryName((string)dte.Solution.Properties.Item("Path").Value);
            string targetPath        = Path.Combine(solutionDirectory, this.RelativePath);
            string targetDir         = Path.GetDirectoryName(targetPath);

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }
            using (StreamWriter writer = new StreamWriter(targetPath, false, new UTF8Encoding(true, true)))
            {
                writer.WriteLine(this.content);
            }

            SolutionFolder sf = DteHelper.FindSolutionFolderByPath(dte.Solution, Path.GetDirectoryName(this.RelativePath));

            if (null != sf)
            {
                sf.Parent.ProjectItems.AddFromFile(targetPath);
            }
            else
            {
                DteHelper.SelectSolution(dte);
                ProjectItem pi = dte.ItemOperations.AddExistingItem(targetPath);
            }
            dte.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
        }
        /// <summary>
        /// Searchs the fol configuration files and nest them.
        ///From Radim: http://stackoverflow.com/questions/19427333/how-to-find-a-projectitem-by-the-file-name
        /// </summary>
        /// <param name="projectItems">The project items.</param>
        private static void SearchFolConfigFilesAndNestThem(ProjectItems projectItems)
        {
            foreach (ProjectItem projectItem in projectItems)
            {
                string transFileName;

                if (projectItem.TryGetPropertyValue(ProjectItemExt.FullPathProperty, out transFileName))
                {
                    transFileName = Path.GetFileName(transFileName);
                    string configFileName;
                    if (TransformationProvider.CheckTransformationFileAndGetSourceFileFromIt(transFileName,
                                                                                             Options.Options.TransfomationFileNameRegexp, Options.Options.SourceFileRegexpMatchIndex,
                                                                                             out configFileName))
                    {
                        var configItem     = DteHelper.FindItemByName(projectItems, configFileName, true);
                        var itemToBeNested = DteHelper.FindItemByName(projectItems, transFileName, true);

                        if (configItem == null || itemToBeNested == null)
                        {
                            continue;
                        }

                        // ReSharper disable once UnusedVariable
                        var    pitn = configItem.ProjectItems.AddFromFile(itemToBeNested.GetFullPath());
                        string itemType;
                        if (itemToBeNested.TryGetPropertyValue(ProjectItemExt.ItemTypeProperty, out itemType))
                        {
                            pitn.TrySetPropertyValue(ProjectItemExt.ItemTypeProperty, itemType);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Ensures Physical Folder existence
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE vs = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
            path = "";

            // TODO: this code should be in DteHelper
            // In some case vs.Solution.FullName == ""
            if (vs.Solution.FullName != "")
            {
                path = DteHelper.GetPathFull(vs, DteHelper.BuildPath(solutionFolder));
            }
            else
            {
                Property property = vs.Solution.Properties.Item("Path");
                path = System.IO.Path.GetDirectoryName(property.Value.ToString());

                path = System.IO.Path.Combine(path, DteHelper.BuildPath(solutionFolder));
            }

            if (!string.IsNullOrEmpty(path))
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            else
            {
                // throw an exception.
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Adds the new folder to the setup project
 /// with the given parameters
 /// </summary>
 public override void Execute()
 {
     try
     {
         IVsdDeployable       deployable   = (IVsdDeployable)SetupProject.Object;
         IVsdCollectionSubset plugins      = deployable.GetPlugIns();
         IVsdFolderPlugIn     folderPlugin = plugins.Item("Folder") as IVsdFolderPlugIn;
         if (folderPlugin != null)
         {
             vsdFolder =
                 (IVsdCustomFolder)DteHelper.CoCreateInstance(
                     this.Site,
                     typeof(VsdCustomFolderClass),
                     typeof(IVsdCustomFolder));
             vsdFolder.Name            = FolderName;
             vsdFolder.Property_2      = this.Property;
             vsdFolder.DefaultLocation = this.DefaultLocation;
             folderPlugin.Items.Add(vsdFolder);
         }
     }
     catch (Exception)
     {
         vsdFolder = null;
         throw;
     }
 }
 private void ExecuteSearch(CompletionContext context, string searchTerm)
 {
     ThreadPool.QueueUserWorkItem(state =>
     {
         DteHelper.ExecuteCommand("Edit.CompleteWord");
     });
 }
Esempio n. 19
0
        private void AddItemTemplate(Project rootproject)
        {
            DTE    dte         = (DTE)GetService(typeof(DTE));
            string projectPath = DteHelper.BuildPath(rootproject);
            string folderPath  = projectPath;

            if (!string.IsNullOrEmpty(this.Path))
            {
                folderPath += "\\" + this.Path;
            }
            ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, folderPath);

            if (prItem != null)
            {
                this.NewItem =
                    prItem.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
            else
            {
                Project project = DteHelper.FindProjectByPath(dte.Solution, folderPath);
                if (project != null)
                {
                    this.NewItem =
                        project.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
                }
                else
                {
                    throw new InvalidOperationException(
                              String.Format("Cannot find insertion point {0}", folderPath));
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:CustomTypeProvider"/> class.
        /// </summary>
        /// <param name="provider">The provider.</param>
        public CustomTypeProvider(IServiceProvider provider, List <Project> additionalProjects, bool useProjectItemWrapper)
        {
            this.useProjectItemWrapper = useProjectItemWrapper;
            DynamicTypeService typeService = (DynamicTypeService)provider.GetService(typeof(DynamicTypeService));

            Debug.Assert(typeService != null, "No dynamic type service registered.");

            availableTypes = new Dictionary <string, Type>();

            if (additionalProjects != null && additionalProjects.Count > 0)
            {
                foreach (Project project in additionalProjects)
                {
                    IVsHierarchy          additionalHierarchy = DteHelper.GetVsHierarchy(provider, project);
                    ITypeDiscoveryService additionalDiscovery = typeService.GetTypeDiscoveryService(additionalHierarchy);
                    AddTypes(additionalDiscovery, project);
                }
            }
            else
            {
                IVsHierarchy hier = DteHelper.GetCurrentSelection(provider);
                Debug.Assert(hier != null, "No active hierarchy is selected.");

                ITypeDiscoveryService discovery = typeService.GetTypeDiscoveryService(hier);
                Project dteProject = VSHelper.ToDteProject(hier);

                AddTypes(discovery, dteProject);
            }

            if (availableTypes.Count > 0 && TypesChanged != null)
            {
                TypesChanged(this, new EventArgs());
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Uses <see cref="DteHelper.FindItemByName"/> to search for the item specified by the "Name" attributte
        /// </summary>
        /// <param name="currentValue"></param>
        /// <param name="newValue"></param>
        /// <returns></returns>
        /// <seealso cref="ValueProvider.OnBeginRecipe"/>
        /// <seealso cref="DteHelper.FindItemByName"/>
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            if (currentValue == null)
            {
                IDictionaryService dictservice = (IDictionaryService)
                                                 ServiceHelper.GetService(this, typeof(IDictionaryService));

                string itemFullName = ArgumentsHelper.ReplaceToken(itemFullNameExpression, dictservice);

                Project project = dictservice.GetValue(projectArgumentName) as Project;

                if (project != null)
                {
                    try
                    {
                        newValue = DteHelper.FindItemByName(project.ProjectItems, itemFullName, true);
                    }
                    catch
                    {
                        //With Web projects without any subfolder this method throws an exception
                        newValue = DteHelper.FindItemByName(project.ProjectItems, itemFullName, false);
                    }

                    if (newValue != null)
                    {
                        return(true);
                    }
                }
            }

            newValue = currentValue;
            return(false);
        }
Esempio n. 22
0
        /// <summary>
        /// It sets all the items with the appropiate values
        /// </summary>
        public override void Execute()
        {
            if (MessageBox.Show(Properties.Resources.Actions_ItemsBuildProps_Confirmation,
                                Properties.Resources.Actions_ItemsBuildProps_Title, MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            DTE         vs   = (DTE)GetService(typeof(DTE));
            ProjectItem item = (ProjectItem)DteHelper.GetTarget(vs);

            vs.StatusBar.Highlight(true);
            if (item.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
            {
                SetPropertiesOfFolder(item);
            }
            if (applied)
            {
                Trace.TraceInformation(Properties.Resources.Actions_ItemsBuildProps_Success);
                vs.StatusBar.Text = Properties.Resources.Actions_ItemsBuildProps_Success;
            }
            else
            {
                Trace.TraceInformation(Properties.Resources.Actions_ItemsBuildProps_Fail);
                vs.StatusBar.Text = Properties.Resources.Actions_ItemsBuildProps_Fail;
            }
            vs.StatusBar.Highlight(false);
        }
        public void ExecuteLazyCommand()
        {
            DTE dte   = Package.GetGlobalService(typeof(DTE)) as DTE;
            int?index = DteHelper.GetDocumentIndex(dte.ActiveDocument.FullName);

            if (index == null)
            {
                return;
            }
            if (index == 1)
            {
                index = dte.Documents.Count + 1;
            }

            for (int i = (index ?? 0) - 1; i >= 1; i--)
            {
                try
                {
                    dte.Documents.Item(i).Activate();
                    break;
                }
                catch { }
            }
            //dte.ExecuteCommand("View.NavigateForward", "");
        }
        private Guid _CreateAssembly(byte[] assemblyData, bool sandbox)
        {
            UpdateStatus("Creating assembly ... ", 1);

            var assemblyInfo = AssemblyHelper.GetAssemblyInfo(typeof(IPlugin).FullName);

            var assembly = new PluginAssembly
            {
                Name          = DteHelper.GetProjectName(),
                IsolationMode = (sandbox
                                                                        ? PluginAssembly.Enums.IsolationMode.Sandbox
                                                                        : PluginAssembly.Enums.IsolationMode.None).ToOptionSetValue(),
                Content    = Convert.ToBase64String(assemblyData),
                SourceType = PluginAssembly.Enums.SourceType.Database.ToOptionSetValue(),
                Culture    = assemblyInfo.CultureInfo.LCID == CultureInfo.InvariantCulture.LCID
                                                                 ? "neutral"
                                                                 : assemblyInfo.CultureInfo.Name
            };

            Context.AddObject(assembly);
            UpdateStatus("Saving new assembly to CRM ...");
            Context.SaveChanges();
            Id = assembly.Id;

            AddNewTypes(GetExistingTypeNames());

            //UpdateStatus("Saving new types to CRM ...");
            //Context.SaveChanges();

            UpdateStatus("Finished creating assembly. ID => " + Id, -1);

            OnRegActionTaken(RegistrationEvent.Create);

            return(Id);
        }
Esempio n. 25
0
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            var service = base.GetService <DTE>(true);

            newValue = string.Empty;
            string selectedFolderPath = DteHelper.GetFilePathRelative((ProjectItem)DteHelper.GetTarget(service));

            string[] pathParts =
                selectedFolderPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
                                         StringSplitOptions.RemoveEmptyEntries);
            if (pathParts.Length > 3)
            {
                if (pathParts[1] == TemplateConfiguration.GetConfiguration().ExtRootFolderName&&
                    (pathParts[2].Equals(ExtJsClassType.Model.ToString(), StringComparison.InvariantCultureIgnoreCase) ||
                     pathParts[2].Equals(ExtJsClassType.View.ToString(), StringComparison.InvariantCultureIgnoreCase) ||
                     pathParts[2].Equals(ExtJsClassType.Store.ToString(), StringComparison.InvariantCultureIgnoreCase) ||
                     pathParts[2].Equals(ExtJsClassType.Controller.ToString(), StringComparison.InvariantCultureIgnoreCase)))
                {
                    for (var i = 3; i < pathParts.Length; i++)
                    {
                        newValue += pathParts[i] + ".";
                    }
                }
            }
            return(true);
        }
        private void DeleteObsoleteTypes()
        {
            var pluginClasses = AssemblyHelper.GetClasses <IPlugin>();
            var wfClasses     = AssemblyHelper.GetClasses <CodeActivity>();

            var existingTypes = CrmAssemblyHelper.GetCrmTypes(Id, Context);

            var nonExistentTypes = existingTypes
                                   .Where(pluginType => !pluginClasses.Contains(pluginType.TypeName) &&
                                          !wfClasses.Contains(pluginType.TypeName)).ToList();

            // delete non-existing types
            if (nonExistentTypes.Any())
            {
                if (DteHelper.IsConfirmed("Please confirm that you want to DELETE non-existent types in this assembly." +
                                          " This means that all its steps will be deleted!", "Type deletion"))
                {
                    UpdateStatus("Deleting non-existent types ... ", 1);

                    nonExistentTypes.ForEach(pluginType => DeleteTree(pluginType.Id,
                                                                      Dependency.Enums.RequiredComponentType.PluginType));

                    UpdateStatus("Finished deleting non-existent types.", -1);
                }
                else
                {
                    throw new Exception("Can't update assembly with obsolete types in the system.");
                }
            }
        }
Esempio n. 27
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            // can't fetch assembly without an ID
            if (assemblyRegistration.Id == Guid.Empty)
            {
                DteHelper.ShowInfo("Can't delete a non-existent assembly.", "Non-existent assembly!");
                return;
            }

            if (DteHelper.IsConfirmed("Are you sure you want to UNregister this plugin?" +
                                      " This means that the plugin and all its steps will be deleted!", "Unregistration"))
            {
                new Thread(() =>
                {
                    try
                    {
                        assemblyRegistration.DeleteAssembly(assemblyRegistration.Id);
                        crmAssembly.Clear();
                    }
                    catch (Exception exception)
                    {
                        PopException(exception);
                    }
                    finally
                    {
                        UpdateStatus("", false);
                    }
                }).Start();
            }
        }
        /// <summary>
        /// Finds the project item in project.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="name">The name.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <returns>ProjectItem instance of set name or null if not found</returns>
        public static ProjectItem FindProjectItemInProject(Project project, string name, bool recursive)
        {
            ProjectItem projectItem = null;

            if (project.Kind != EnvDTE.Constants.vsProjectKindSolutionItems)
            {
                if (project.ProjectItems != null && project.ProjectItems.Count > 0)
                {
                    projectItem = DteHelper.FindItemByName(project.ProjectItems, name, recursive);
                }
            }
            else
            {
                // if solution folder, one of its ProjectItems might be a real project
                foreach (ProjectItem item in project.ProjectItems)
                {
                    var realProject = item.Object as Project;

                    if (realProject != null)
                    {
                        projectItem = FindProjectItemInProject(realProject, name, recursive);

                        if (projectItem != null)
                        {
                            break;
                        }
                    }
                }
            }

            return(projectItem);
        }
Esempio n. 29
0
        /// <summary>
        /// Delete ProjectItems content filtering by the input kind guid
        /// </summary>
        public override void Execute()
        {
            if (projectItems != null)
            {
                foreach (ProjectItem projectItem in projectItems)
                {
                    if (string.IsNullOrEmpty(kind) ||
                        projectItem.Kind.Equals(kind, StringComparison.InvariantCultureIgnoreCase))
                    {
                        DTE vs = (DTE)GetService(typeof(DTE));
                        if (string.Compare(projectItem.Name, "properties", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            DeleteItem(projectItem, vs);
                        }
                    }
                }
            }
            else if (this.projectItem != null)
            {
                DTE vs = (DTE)GetService(typeof(DTE));
                DeleteItem(projectItem, vs);
            }
            else if (project != null && !string.IsNullOrEmpty(itemName))
            {
                DTE vs = (DTE)GetService(typeof(DTE));

                this.projectItem = DteHelper.FindItemByName(project.ProjectItems, itemName, true);

                if (this.projectItem != null)
                {
                    DeleteItem(projectItem, vs);
                }
            }
        }
Esempio n. 30
0
 /// <summary>
 /// Creates the new registry locator
 /// </summary>
 public override void Execute()
 {
     try
     {
         IVsdDeployable       deployable    = (IVsdDeployable)SetupProject.Object;
         IVsdCollectionSubset plugins       = deployable.GetPlugIns();
         IVsdLocatorPlugIn    locatorPlugin = plugins.Item("Locator") as IVsdLocatorPlugIn;
         if (locatorPlugin != null)
         {
             vsdLocator =
                 (IVsdRegistryKeyLocator)DteHelper.CoCreateInstance(
                     this.Site,
                     typeof(VsdRegistryKeyLocatorClass),
                     typeof(IVsdRegistryKeyLocator));
             vsdLocator.Name     = this.LocatorName;
             vsdLocator.Property = this.Property;
             vsdLocator.RegKey   = this.RegistryKey;
             vsdLocator.Root     = vsdRegistryRoot.vsdrrHKLM;
             vsdLocator.Value    = this.Value;
             locatorPlugin.Items.Add(vsdLocator);
         }
     }
     catch (Exception)
     {
         vsdLocator = null;
         throw;
     }
 }