public bool SaveBindings(string configPath, string bindingsXml)
        {
            string bindingPath = ConfigurationParser.GetConfigFilePath(configPath, true) ?? configPath + ".bindings";
            var    config      = new ConfigurationParser(bindingPath);

            try
            {
                ProjectHelpers.CheckFileOutOfSourceControl(bindingPath);

                if (bindingsXml == "<binding />" && File.Exists(bindingPath))
                {
                    config.RemoveBindings();
                }
                else
                {
                    config.SaveBinding(TaskBinding.FromXml(bindingsXml));
                    ProjectHelpers.AddNestedFile(configPath, bindingPath);
                }

                IVsPersistDocData persistDocData;
                if (!CakePackage.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);
            }
        }
예제 #2
0
        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 (!CakePackage.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);
            }
        }