本文整理汇总了C#中ProjectItem.Save方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectItem.Save方法的具体用法?C# ProjectItem.Save怎么用?C# ProjectItem.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProjectItem
的用法示例。
在下文中一共展示了ProjectItem.Save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertGeneratedCode
private void InsertGeneratedCode(ProjectItem projectItem, string generatedContent)
{
projectItem.Open(Constants.vsViewKindCode);
projectItem.Document.ActiveWindow.Activate();
TextDocument textDocument = (TextDocument) projectItem.Document.Object("TextDocument");
EditPoint editPoint = textDocument.StartPoint.CreateEditPoint();
editPoint.Delete(textDocument.EndPoint);
editPoint.Insert(generatedContent);
projectItem.Save(Helper.GetFilePath(projectItem));
}
示例2: InsertGeneratedMethod
private void InsertGeneratedMethod(ProjectItem projectItem, string content)
{
projectItem.Open(Constants.vsViewKindCode);
projectItem.Document.ActiveWindow.Activate();
TextDocument textDocument = (TextDocument) projectItem.Document.Object("TextDocument");
EditPoint editPoint = textDocument.EndPoint.CreateEditPoint();
editPoint.EndOfDocument();
editPoint.StartOfLine();
editPoint.LineUp(1);
editPoint.Insert(content + "\n");
projectItem.Save(Helper.GetFilePath(projectItem));
}
示例3: RenameModule
void RenameModule(Project project, ProjectItem item)
{
var projectName = project.Name;
var moduleName = String.Format("{0}{1}", projectName.Split('.').Last(), "Module");
var className = String.Format("{0}.cs", moduleName);
CodeClass codeClass = GetCodeClass(item.FileCodeModel.CodeElements);
if (codeClass != null)
{
codeClass.Name = moduleName;
item.Save();
item.Name = className;
}
}
示例4: RunFromCodeBehind
private bool RunFromCodeBehind(ProjectItem projectItem, Func<TextDocument, int> lineProvider, bool debug)
{
if (projectItem.IsDirty)
{
projectItem.Save();
}
var codeBehindItem = GetCodeBehindItem(projectItem);
if (codeBehindItem == null)
return false;
bool wasOpen = codeBehindItem.IsOpen;
if (!wasOpen)
{
codeBehindItem.Open();
}
try
{
TextDocument codeBehindTextDocument = (TextDocument)codeBehindItem.Document.Object("TextDocument");
var codeBehindLine = lineProvider(codeBehindTextDocument);
if (codeBehindLine == 0)
{
// could not find the line, run the entire file
codeBehindLine = 1;
}
EditPoint navigatePoint = codeBehindTextDocument.StartPoint.CreateEditPoint();
navigatePoint.MoveToLineAndOffset(codeBehindLine, 1);
navigatePoint.TryToShow();
navigatePoint.Parent.Selection.MoveToPoint(navigatePoint);
return RunInCurrentContext(debug);
}
finally
{
if (!wasOpen && !codeBehindItem.IsDirty)
{
codeBehindItem.Document.Close();
}
projectItem.Document.Activate();
}
}
示例5: BeforeOpeningFile
public void BeforeOpeningFile(ProjectItem projectItem)
{
projectItem.ContainingProject.Save();
string projectPath = projectItem.ContainingProject.Properties.Item("FullPath").Value.ToString();
string fullItemPath = Path.Combine(projectPath, finalProjectItemName);
var existingGeneratedCode = File.ReadAllLines(fullItemPath).Join(Environment.NewLine);
string baseUrl;
if (!currentNativeTypesHandle.TryExtractBaseUrl(existingGeneratedCode, out baseUrl))
{
throw new WizardBackoutException("Failed to read from template base url");
}
string updatedCode = currentNativeTypesHandle.GetUpdatedCode(baseUrl, null);
using (var streamWriter = File.CreateText(fullItemPath))
{
streamWriter.Write(updatedCode);
streamWriter.Flush();
}
projectItem.Open();
projectItem.Save();
}
示例6: DeployAggDesigns
public static void DeployAggDesigns(ProjectItem projItem, DTE2 ApplicationObject)
{
Microsoft.AnalysisServices.Cube oCube = (Microsoft.AnalysisServices.Cube)projItem.Object;
bool bFoundAggDesign = false;
foreach (MeasureGroup mg in oCube.MeasureGroups)
{
if (mg.AggregationDesigns.Count > 0)
{
bFoundAggDesign = true;
break;
}
}
if (!bFoundAggDesign)
{
MessageBox.Show("There are no aggregation designs defined in this cube yet.");
return;
}
if (MessageBox.Show("This command deploys just the aggregation designs in this cube. It does not change which aggregation design is assigned to each partition.\r\n\r\nYou should run a ProcessIndex command from Management Studio on this cube after aggregation designs have been deployed.\r\n\r\nDo you wish to continue?", "BIDS Helper - Deploy Aggregation Designs", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
ApplicationObject.StatusBar.Progress(true, "Deploying Aggregation Designs", 1, 5);
string sPartitionsFileName = projItem.get_FileNames(1);
sPartitionsFileName = sPartitionsFileName.Substring(0, sPartitionsFileName.Length - 5) + ".partitions";
// Check if the file is read-only (and probably checked in to a source control system)
// before attempting to save. (issue: 10327 )
FileAttributes fa = System.IO.File.GetAttributes(sPartitionsFileName);
if ((fa & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
{
//TODO - prompt before saving?
//Save the cube
projItem.Save("");
}
ApplicationObject.StatusBar.Progress(true, "Deploying Aggregation Designs", 2, 5);
// extract deployment information
DeploymentSettings deploySet = new DeploymentSettings(projItem);
// use xlst to create xmla alter command
XslCompiledTransform xslt = new XslCompiledTransform();
XmlReader xsltRdr;
XmlReader xrdr;
// read xslt from embedded resource
xsltRdr = XmlReader.Create(new StringReader(BIDSHelper.Resources.Common.DeployAggDesigns));
using ((xsltRdr))
{
// read content from .partitions file
xrdr = XmlReader.Create(sPartitionsFileName);
using (xrdr)
{
ApplicationObject.StatusBar.Progress(true, "Deploying Aggregation Designs", 3, 5);
// Connect to Analysis Services
Microsoft.AnalysisServices.Server svr = new Microsoft.AnalysisServices.Server();
svr.Connect(deploySet.TargetServer);
ApplicationObject.StatusBar.Progress(true, "Deploying Aggregation Designs", 4, 5);
// execute the xmla
try
{
// Build up the Alter MdxScript command using XSLT against the .partitions file
XslCompiledTransform xslta = new XslCompiledTransform();
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.ConformanceLevel = ConformanceLevel.Fragment;
XmlWriter xwrtr = XmlWriter.Create(sb, xws);
xslta.Load(xsltRdr);
XsltArgumentList xslarg = new XsltArgumentList();
Database targetDB = svr.Databases.FindByName(deploySet.TargetDatabase);
if (targetDB == null)
{
throw new System.Exception(string.Format("A database called {0} could not be found on the {1} server", deploySet.TargetDatabase, deploySet.TargetServer));
}
xslarg.AddParam("TargetDatabase", "", targetDB.ID);
xslarg.AddParam("TargetCubeID", "", oCube.ID);
xslta.Transform(xrdr, xslarg, xwrtr);
Cube oServerCube = targetDB.Cubes.Find(oCube.ID);
if (oServerCube == null)
{
throw new System.Exception(string.Format("The {0} cube is not yet deployed to the {1} server.", oCube.Name, deploySet.TargetServer));
}
// update the agg designs
XmlaResultCollection xmlaRC = svr.Execute(sb.ToString());
StringBuilder sbErr = new StringBuilder();
for (int iRC = 0; iRC < xmlaRC.Count; iRC++)
{
for (int iMsg = 0; iMsg < xmlaRC[iRC].Messages.Count; iMsg++)
//.........这里部分代码省略.........
示例7: MergeNewCodeWithClass
/// <summary>
/// takes the existing feature receiver code, finds the method a puts the new code in there
/// </summary>
/// <param name="existingClassFilename"></param>
private void MergeNewCodeWithClass(ProjectItem existingClassProjectItem, string featureReceiverClassName, string xmlContent)
{
FileCodeModel2 model = (FileCodeModel2)existingClassProjectItem.FileCodeModel;
//ok, Content is xml in the following form
/*
* <FeatureReceiverCode>
<UsingStatement>using Microsoft.SharePoint.Administration;</UsingStatement>
<FeatureActivatedMethod>ActivateTimerJob_<#= TimerJobClass #></FeatureActivatedMethod>
<FeatureActivatedCode>
*/
//this needs to be added;
XmlDocument allCode = new XmlDocument();
allCode.LoadXml(xmlContent);
//placing the using statements in the existing file
XmlNodeList usingNodes = allCode.SelectNodes("/FeatureReceiverCode/UsingStatements/UsingStatement");
foreach (XmlNode usingNode in usingNodes)
{
AddUsingStatement(model, model.CodeElements, usingNode.InnerText);
}
//next we need to add the method call to the existing methods
//FeatureActivatedMethod and add it near the region #region FeatureActivatedGeneratedCode
XmlNode methodNode = allCode.SelectSingleNode("/FeatureReceiverCode/FeatureActivatedMethod");
if (methodNode != null)
{
XmlNode methodCodeNode = allCode.SelectSingleNode("/FeatureReceiverCode/FeatureActivatedCode");
if (methodCodeNode != null)
{
//add the method itself to the class
AddMethodCall(model.CodeElements, featureReceiverClassName, "FeatureActivated", methodNode.InnerText);
//add the call to our method to FeatureActivated
AddMethodToClass(model.CodeElements, featureReceiverClassName, methodCodeNode.InnerText);
}
}
XmlNode methodNode2 = allCode.SelectSingleNode("/FeatureReceiverCode/FeatureDeactivatingMethod");
if (methodNode2 != null)
{
XmlNode methodCodeNode2 = allCode.SelectSingleNode("/FeatureReceiverCode/FeatureDeactivatingCode");
if (methodCodeNode2 != null)
{
//add the method itself to the class
AddMethodCall(model.CodeElements, featureReceiverClassName, "FeatureDeactivating", methodNode2.InnerText);
//add the call to our method to FeatureActivated
AddMethodToClass(model.CodeElements, featureReceiverClassName, methodCodeNode2.InnerText);
}
}
model.Synchronize();
//save automatically during tests
if (model.DTE.SuppressUI)
{
existingClassProjectItem.Save();
}
}
示例8: DeployScript
public static void DeployScript(ProjectItem projItem, DTE2 ApplicationObject)
{
Microsoft.AnalysisServices.Cube oCube = (Microsoft.AnalysisServices.Cube)projItem.Object;
try
{
//validate the script because deploying an invalid script makes cube unusable
Microsoft.AnalysisServices.Design.Scripts script = new Microsoft.AnalysisServices.Design.Scripts(oCube);
}
catch (Microsoft.AnalysisServices.Design.ScriptParsingFailed ex)
{
string throwaway = ex.Message;
MessageBox.Show("MDX Script in " + oCube.Name + " is not valid.", "Problem Deploying MDX Script");
return;
}
if (oCube.MdxScripts.Count == 0)
{
MessageBox.Show("There is no MDX script defined in this cube yet.");
return;
}
try
{
ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
ApplicationObject.StatusBar.Progress(true, "Deploying MdxScript", 1, 5);
// Check if the file is read-only (and probably checked in to a source control system)
// before attempting to save. (issue: 10327 )
FileAttributes fa = System.IO.File.GetAttributes(projItem.get_FileNames(1));
if ((fa & FileAttributes.ReadOnly) != FileAttributes.ReadOnly )
{
//TODO - can I check and maybe prompt before saving?
//Save the cube
projItem.Save("");
}
ApplicationObject.StatusBar.Progress(true, "Deploying MdxScript", 2, 5);
// extract deployment information
DeploymentSettings deploySet = new DeploymentSettings(projItem);
// use xlst to create xmla alter command
XslCompiledTransform xslt = new XslCompiledTransform();
XmlReader xsltRdr;
XmlReader xrdr;
// read xslt from embedded resource
xsltRdr = XmlReader.Create(new StringReader(BIDSHelper.Resources.Common.DeployMdxScript));
using ((xsltRdr))
{
// read content from .cube file
xrdr = XmlReader.Create(projItem.get_FileNames(1));
using (xrdr)
{
ApplicationObject.StatusBar.Progress(true, "Deploying MdxScript", 3, 5);
// Connect to Analysis Services
Microsoft.AnalysisServices.Server svr = new Microsoft.AnalysisServices.Server();
svr.Connect(deploySet.TargetServer);
ApplicationObject.StatusBar.Progress(true, "Deploying MdxScript", 4, 5);
// execute the xmla
try
{
Microsoft.AnalysisServices.Scripter scr = new Microsoft.AnalysisServices.Scripter();
// Build up the Alter MdxScript command using XSLT against the .cube file
XslCompiledTransform xslta = new XslCompiledTransform();
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.ConformanceLevel = ConformanceLevel.Fragment;
XmlWriter xwrtr = XmlWriter.Create(sb, xws);
xslta.Load(xsltRdr);
XsltArgumentList xslarg = new XsltArgumentList();
Database targetDB = svr.Databases.FindByName(deploySet.TargetDatabase);
if (targetDB == null)
{
throw new System.Exception(string.Format("A database called {0} could not be found on the {1} server", deploySet.TargetDatabase, deploySet.TargetServer));
}
string targetDatabaseID = targetDB.ID;
xslarg.AddParam("TargetDatabase", "", targetDatabaseID);
xslta.Transform(xrdr, xslarg, xwrtr);
// Extract the current script from the server and keep a temporary backup copy of it
StringBuilder sbBackup = new StringBuilder();
XmlWriterSettings xwSet = new XmlWriterSettings();
xwSet.ConformanceLevel = ConformanceLevel.Fragment;
xwSet.OmitXmlDeclaration = true;
xwSet.Indent = true;
XmlWriter xwScript = XmlWriter.Create(sbBackup,xwSet);
Cube oServerCube = targetDB.Cubes.Find(oCube.ID);
if (oServerCube == null)
{
throw new System.Exception(string.Format("The {0} cube is not yet deployed to the {1} server.", oCube.Name, deploySet.TargetServer));
}
else if (oServerCube.State == AnalysisState.Unprocessed)
//.........这里部分代码省略.........
示例9: DeployPerspectives
public static void DeployPerspectives(ProjectItem projItem, DTE2 ApplicationObject)
{
Microsoft.AnalysisServices.Cube oCube = (Microsoft.AnalysisServices.Cube)projItem.Object;
if (oCube.Perspectives.Count == 0)
{
MessageBox.Show("There are no perspectives defined in this cube yet.");
return;
}
try
{
ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationDeploy);
ApplicationObject.StatusBar.Progress(true, "Deploying perspectives", 1, 5);
FileAttributes fa = System.IO.File.GetAttributes(projItem.get_FileNames(1));
if ((fa & FileAttributes.ReadOnly) != FileAttributes.ReadOnly )
{
//Save the cube
projItem.Save("");
}
ApplicationObject.StatusBar.Progress(true, "Deploying perspectives", 2, 5);
// extract deployment information
DeploymentSettings deploySet = new DeploymentSettings(projItem);
// use xlst to create xmla alter command
XslCompiledTransform xslt = new XslCompiledTransform();
XmlReader xsltRdr;
XmlReader xrdr;
// read xslt from embedded resource
xsltRdr = XmlReader.Create(new StringReader(BIDSHelper.Resources.Common.DeployPerspectives));
using ((xsltRdr))
{
// read content from .cube file
xrdr = XmlReader.Create(projItem.get_FileNames(1));
using (xrdr)
{
ApplicationObject.StatusBar.Progress(true, "Deploying perspectives", 3, 5);
// Connect to Analysis Services
Microsoft.AnalysisServices.Server svr = new Microsoft.AnalysisServices.Server();
svr.Connect(deploySet.TargetServer);
ApplicationObject.StatusBar.Progress(true, "Deploying perspectives", 4, 5);
// execute the xmla
try
{
// Build up the Alter perspectives command using XSLT against the .cube file
XslCompiledTransform xslta = new XslCompiledTransform();
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.ConformanceLevel = ConformanceLevel.Fragment;
XmlWriter xwrtr = XmlWriter.Create(sb, xws);
xslta.Load(xsltRdr);
XsltArgumentList xslarg = new XsltArgumentList();
Database targetDB = svr.Databases.FindByName(deploySet.TargetDatabase);
if (targetDB == null)
{
throw new System.Exception(string.Format("A database called {0} could not be found on the {1} server", deploySet.TargetDatabase, deploySet.TargetServer));
}
string targetDatabaseID = targetDB.ID;
xslarg.AddParam("TargetDatabase", "", targetDatabaseID);
xslta.Transform(xrdr, xslarg, xwrtr);
Cube oServerCube = targetDB.Cubes.Find(oCube.ID);
if (oServerCube == null)
{
throw new System.Exception(string.Format("The {0} cube is not yet deployed to the {1} server.", oCube.Name, deploySet.TargetServer));
}
//drop any perspectives which don't exist
svr.CaptureXml = true;
for (int i = 0; i < oServerCube.Perspectives.Count; i++)
{
Perspective p = oServerCube.Perspectives[i];
if (!oCube.Perspectives.Contains(p.ID))
{
p.Drop();
i--;
}
}
svr.CaptureXml = false;
try
{
if (svr.CaptureLog.Count > 0)
svr.ExecuteCaptureLog(true, false);
}
catch (System.Exception ex)
{
throw new System.Exception("Error dropping perspective that were deleted in the source code. " + ex.Message);
}
//.........这里部分代码省略.........
示例10: GenerateJsFileFromProjectItem
private ViewModel GenerateJsFileFromProjectItem(ProjectItem item, bool fromCodeSnippet)
{
var fileExtension = Path.GetExtension(item.GetFullPath());
var language = fileExtension.Equals(".cs") ? SupportedLanguage.CSharp : SupportedLanguage.VBNet;
if (!item.Saved)
item.Save();
try
{
JsFile jsFile;
if (fromCodeSnippet)
{
dynamic comObject = item.Document.Selection;
jsFile = _codeGenerator.GetJsFileFromCodeSnippet(comObject.Text, language);
}
else
{
jsFile = _codeGenerator.GetJsFileFromCodeFile(item.GetFullPath(), language);
}
return ViewModelExtensions.MapViewModelFromJsFile(jsFile);
}
catch (Exception)
{
_schell.Toast("Error parsing file");
}
return null;
}