protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            _dte = await GetServiceAsync(typeof(DTE)) as DTE2;

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            _instance = this;

            _dispatcher = Dispatcher.CurrentDispatcher;
            Package     = this;
            Options     = (Options)GetDialogPage(typeof(Options));

            Logger.Initialize(this, Vsix.Name);

            Events2 events = _dte.Events as Events2;

            _solutionEvents = events.SolutionEvents;

            _solutionEvents.AfterClosing   += () => { ErrorList.CleanAllErrors(); };
            _solutionEvents.ProjectRemoved += (project) => { ErrorList.CleanAllErrors(); };

            CreateBundle.Initialize(this);
            UpdateBundle.Initialize(this);
            UpdateAllFiles.Initialize(this);
            BundleOnBuild.Initialize(this);
            RemoveBundle.Initialize(this);
            ClearOutputFiles.Initialize(this);
            ToggleProduceOutput.Initialize(this);
            OpenSettings.Initialize(this);
            ProjectEventCommand.Initialize(this);
            ConvertToGulp.Initialize(this);
        }
Exemple #2
0
        public static void AddHierarchyItem(ErrorTask task, EnvDTE.Project project)
        {
            IVsHierarchy hierarchyItem = null;
            IVsSolution  solution      = BundlerMinifierPackage.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if (solution != null && project != null)
            {
                int flag = -1;

                try
                {
                    flag = solution.GetProjectOfUniqueName(project.FullName, out hierarchyItem);
                }
                catch (COMException ex)
                {
                    if ((uint)ex.ErrorCode != DISP_E_MEMBERNOTFOUND)
                    {
                        throw;
                    }
                }

                if (0 == flag)
                {
                    task.HierarchyItem = hierarchyItem;
                }
            }
        }
        protected override void Initialize()
        {
            _instance   = this;
            _dte        = GetService(typeof(DTE)) as DTE2;
            _dispatcher = Dispatcher.CurrentDispatcher;
            Package     = this;
            Options     = (Options)GetDialogPage(typeof(Options));

            Logger.Initialize(this, Vsix.Name);

            Events2 events = _dte.Events as Events2;

            _solutionEvents = events.SolutionEvents;

            _solutionEvents.AfterClosing   += () => { ErrorList.CleanAllErrors(); };
            _solutionEvents.ProjectRemoved += (project) => { ErrorList.CleanAllErrors(); };

            CreateBundle.Initialize(this);
            UpdateBundle.Initialize(this);
            UpdateAllFiles.Initialize(this);
            BundleOnBuild.Initialize(this);
            RemoveBundle.Initialize(this);
            ClearOutputFiles.Initialize(this);
            ToggleProduceOutput.Initialize(this);
            OpenSettings.Initialize(this);
            ProjectEventCommand.Initialize(this);
            ConvertToGulp.Initialize(this);

            base.Initialize();
        }
        public bool SaveBindings(string configPath, string bindingsXml)
        {
            string bindingPath = configPath + ".bindings";

            try
            {
                var sb = new StringBuilder();

                if (File.Exists(bindingPath))
                {
                    var lines = File.ReadAllLines(bindingPath);

                    foreach (var line in lines)
                    {
                        if (!line.TrimStart().StartsWith("///<binding", StringComparison.OrdinalIgnoreCase))
                        {
                            sb.AppendLine(line);
                        }
                    }
                }

                if (bindingsXml != "<binding />")
                {
                    sb.Insert(0, "///" + bindingsXml);
                }

                ProjectHelpers.CheckFileOutOfSourceControl(bindingPath);

                if (sb.Length == 0)
                {
                    ProjectHelpers.DeleteFileFromProject(bindingPath);
                }
                else
                {
                    File.WriteAllText(bindingPath, sb.ToString(), Encoding.UTF8);
                    ProjectHelpers.AddNestedFile(configPath, bindingPath);
                }

                IVsPersistDocData persistDocData;
                if (!BundlerMinifierPackage.IsDocumentDirty(configPath, out persistDocData) && persistDocData != null)
                {
                    int    cancelled;
                    string newName;
                    persistDocData.SaveDocData(VSSAVEFLAGS.VSSAVE_SilentSave, out newName, out cancelled);
                }
                else if (persistDocData == null)
                {
                    new FileInfo(configPath).LastWriteTime = DateTime.Now;
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                return(false);
            }
        }
        public bool SaveBindings(string configPath, string bindingsXml)
        {
            string bindingPath = configPath + ".bindings";

            try
            {
                ProjectHelpers.CheckFileOutOfSourceControl(bindingPath);

                if (bindingsXml == "<binding />" && File.Exists(bindingPath))
                {
                    ProjectHelpers.DeleteFileFromProject(bindingPath);
                }
                else
                {
                    File.WriteAllText(bindingPath, "///" + bindingsXml, Encoding.UTF8);
                    ProjectHelpers.AddNestedFile(configPath, bindingPath);
                }

                IVsPersistDocData persistDocData;
                if (!BundlerMinifierPackage.IsDocumentDirty(configPath, out persistDocData) && persistDocData != null)
                {
                    int    cancelled;
                    string newName;
                    persistDocData.SaveDocData(VSSAVEFLAGS.VSSAVE_SilentSave, out newName, out cancelled);
                }
                else if (persistDocData == null)
                {
                    new FileInfo(configPath).LastWriteTime = DateTime.Now;
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                return(false);
            }
        }