本文整理汇总了C#中ProjectItem.Open方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectItem.Open方法的具体用法?C# ProjectItem.Open怎么用?C# ProjectItem.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProjectItem
的用法示例。
在下文中一共展示了ProjectItem.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: PerformReplacesOn
public static void PerformReplacesOn(Project project, String projectName,
String localProjectPath, ProjectItem item)
{
Window codeWindow = item.Open(EnvConstants.vsViewKindTextView);
codeWindow.Activate();
ReplaceToken(codeWindow, "!NAMESPACE!", projectName);
ReplaceToken(codeWindow, "!APPPHYSICALDIR!", localProjectPath);
codeWindow.Close(vsSaveChanges.vsSaveChangesYes);
}
示例4:
vsSaveStatus IVisualStudioService.RemoveReference(ProjectItem projectItem, string reference, int offset)
{
if (!projectItem.IsOpen)
{
projectItem.Open();
}
projectItem.Document.Activate();
var document = _dte.ActiveDocument.Object("TextDocument");
EditPoint start = document.StartPoint.CreateEditPoint();
start.MoveToAbsoluteOffset(offset);
EditPoint end = document.EndPoint.CreateEditPoint();
string pattern = string.Format(@"\<{{script|link}}.+{0}.*{{/\>|script\>}}", reference);//<(script|link)\b(.*?){0}(.*?)(script>|/>)
start.ReplacePattern(end, pattern, " ", (int)vsFindOptions.vsFindOptionsRegularExpression);
var saveResult = this._dte.ActiveDocument.Save();
this._dte.ActiveDocument.Close();
return saveResult;
}
示例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: TryCreateDocument
/// <summary>
/// Tries to open a given project item as a Document which can be used to add or remove headers.
/// </summary>
/// <param name="item">The project item.</param>
/// <param name="document">The document which was created or null if an error occured (see return value).</param>
/// <param name="headers">A dictionary of headers using the file extension as key and the header as value or null if headers should only be removed.</param>
/// <returns>A value indicating the result of the operation. Document will be null unless DocumentCreated is returned.</returns>
public CreateDocumentResult TryCreateDocument(ProjectItem item, out Document document, IDictionary<string, string[]> headers = null)
{
document = null;
if (item.Kind != Constants.vsProjectItemKindPhysicalFile)
return CreateDocumentResult.NoPhyiscalFile;
if (item.Name.EndsWith (LicenseHeader.Extension))
return CreateDocumentResult.LicenseHeaderDocument;
var language = _licenseHeaderExtension.LanguagesPage.Languages
.Where(x => x.Extensions.Any(y => item.Name.EndsWith(y, StringComparison.OrdinalIgnoreCase)))
.FirstOrDefault();
if (language == null)
return CreateDocumentResult.LanguageNotFound;
//try to open the document as a text document
try
{
if (!item.IsOpen[Constants.vsViewKindTextView])
item.Open (Constants.vsViewKindTextView);
}
catch (COMException)
{
return CreateDocumentResult.NoTextDocument;
}
var itemDocument = item.Document;
if (item.Document == null)
return CreateDocumentResult.NoPhyiscalFile;
var textDocument = itemDocument.Object ("TextDocument") as TextDocument;
if (textDocument == null)
return CreateDocumentResult.NoTextDocument;
string[] header = null;
if (headers != null)
{
var extension = headers.Keys
.OrderByDescending (x => x.Length)
.Where (x => item.Name.EndsWith (x, StringComparison.OrdinalIgnoreCase))
.FirstOrDefault();
if (extension == null)
return CreateDocumentResult.NoHeaderFound;
header = headers[extension];
if (header.All (string.IsNullOrEmpty))
return CreateDocumentResult.EmptyHeader;
}
var optionsPage = _licenseHeaderExtension.OptionsPage;
document = new Document (
textDocument,
language,
header,
item,
optionsPage.UseRequiredKeywords
? optionsPage.RequiredKeywords.Split (new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select (k => k.Trim())
: null);
return CreateDocumentResult.DocumentCreated;
}
示例7: OpenProjectItem
public static void OpenProjectItem(ProjectItem pitem)
{
try
{
if (pitem != null)
{
pitem.Open(EnvDTE.Constants.vsViewKindPrimary).Activate();
}
}
catch (Exception)
{
}
}
示例8: GetPackageFromIntegrationServicesProjectItem
/// <summary>
/// If the package designer is already open, then use the package object on it which may have in-memory modifications.
/// If the package designer is not open, then just load the package from disk.
/// </summary>
/// <param name="pi"></param>
/// <returns></returns>
private Package GetPackageFromIntegrationServicesProjectItem(ProjectItem pi)
{
bool bIsOpen = pi.get_IsOpen(BIDSViewKinds.Designer);
if (bIsOpen)
{
Window w = pi.Open(BIDSViewKinds.Designer); //opens the designer
w.Activate();
IDesignerHost designer = w.Object as IDesignerHost;
if (designer == null) return null;
EditorWindow win = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator));
return win.PropertiesLinkComponent as Package;
}
else
{
Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
return app.LoadPackage(pi.get_FileNames(0), null);
}
}
示例9: GetDocumentText
private string GetDocumentText(ProjectItem page)
{
if (!page.IsOpen)
{
page.Open();
}
var document = (TextDocument)page.Document.Object();
var startPoint = document.StartPoint.CreateEditPoint();
var endPoint = document.EndPoint.CreateEditPoint();
return startPoint.GetText(endPoint);
}
示例10: ExecDSV
private void ExecDSV(ProjectItem pi)
{
try
{
//close all project windows
foreach (ProjectItem piTemp in pi.ContainingProject.ProjectItems)
{
bool bIsOpen = piTemp.get_IsOpen(BIDSViewKinds.Designer);
if (bIsOpen)
{
Window win = piTemp.Open(BIDSViewKinds.Designer);
win.Close(vsSaveChanges.vsSaveChangesYes);
}
}
DataSourceView dsv = pi.Object as DataSourceView;
Microsoft.DataWarehouse.Design.DataSourceConnection openedDataSourceConnection = GetOpenedDataSourceConnection(dsv.DataSource);
Program.SQLFlattener = new frmSQLFlattener();
Program.SQLFlattener.txtServer.Text = openedDataSourceConnection.DataSource;
Program.SQLFlattener.cmbDatabase.Items[0] = openedDataSourceConnection.Database;
Program.SQLFlattener.Conn = (System.Data.OleDb.OleDbConnection)openedDataSourceConnection.ConnectionObject;
Program.SQLFlattener.cmbTable.Items[0] = string.Empty;
Program.SQLFlattener.cmbID.Items[0] = string.Empty;
Program.SQLFlattener.cmbPID.Items[0] = string.Empty;
Program.SQLFlattener.dsv = dsv;
Program.SQLFlattener.DataSourceConnection = openedDataSourceConnection;
Program.ASFlattener = null;
if (Program.SQLFlattener.ShowDialog() == DialogResult.OK)
{
Window winDesigner = pi.Open(BIDSViewKinds.Designer);
winDesigner.Activate();
System.ComponentModel.Design.IDesignerHost host = (System.ComponentModel.Design.IDesignerHost)(winDesigner.Object);
Microsoft.AnalysisServices.Design.DataSourceDesigner designer = (Microsoft.AnalysisServices.Design.DataSourceDesigner)host.GetDesigner(dsv);
designer.MakeDesignerDirty();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
}
}
示例11: GetWebDesignerHost
private void GetWebDesignerHost(ProjectItem projItem)
{
#if VS90
//FDesignWindow = projItem.Open("{7651A702-06E5-11D1-8EBD-00A0C90F26EA}");
FDesignWindow = projItem.Open(Constants.vsViewKindDesigner);
FDesignWindow.Activate();
HTMLWindow W = (HTMLWindow)FDesignWindow.Object;
W.CurrentTab = vsHTMLTabs.vsHTMLTabsDesign;
if (W.CurrentTabObject is WebDevPage.DesignerDocument)
{
FDesignerDocument = W.CurrentTabObject as WebDevPage.DesignerDocument;
}
#else
FDesignWindow = projItem.Open("{00000000-0000-0000-0000-000000000000}");
FDesignWindow.Activate();
FDesignWindow = projItem.Open("{7651A702-06E5-11D1-8EBD-00A0C90F26EA}");
FDesignWindow.Activate();
HTMLWindow W = (HTMLWindow)FDesignWindow.Object;
object o = W.CurrentTabObject;
IntPtr pObject;
Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSP = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)o;
Guid sid = typeof(IVSMDDesigner).GUID;
Guid iid = typeof(IVSMDDesigner).GUID;
int hr = oleSP.QueryService(ref sid, ref iid, out pObject);
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(hr);
if (pObject != IntPtr.Zero)
{
try
{
Object TempObj = Marshal.GetObjectForIUnknown(pObject);
if (TempObj is IDesignerHost)
{
FDesignerHost = (IDesignerHost)TempObj;
}
else
{
Object ObjContainer = TempObj.GetType().InvokeMember("ComponentContainer",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.GetProperty, null, TempObj, null);
if (ObjContainer is IDesignerHost)
{
FDesignerHost = (IDesignerHost)ObjContainer;
}
}
FPage = (System.Web.UI.Page)FDesignerHost.RootComponent;
//NotifyRefresh(200);
Application.DoEvents();
}
finally
{
Marshal.Release(pObject);
}
}
#endif
}
示例12: AddHeader
private void AddHeader(string header, int line, ref bool opened, ProjectItem pitem)
{
if (!opened)
{
opened = true;
Window win = pitem.Open(EnvDTE.Constants.vsViewKindCode);
win.Activate();
}
DTE2 dte = (DTE2)this.ServiceProvider.GetService(typeof(DTE));
TextSelection selection = dte.ActiveDocument.Selection as TextSelection;
selection.GotoLine(line, false);
selection.NewLine();
selection.GotoLine(line, false);
selection.Text = "#include " + header;
}
示例13: GetActivatedDocument
/// <summary>
/// Gets an activated document for the specified project item.
/// </summary>
/// <param name="projectItem">The project item.</param>
/// <returns>The document associated with the project item, opened and activated.</returns>
public static Document GetActivatedDocument(ProjectItem projectItem)
{
projectItem.Open(Constants.vsViewKindTextView);
var document = projectItem.Document;
Assert.IsNotNull(projectItem.Document);
document.Activate();
return document;
}
示例14: WriteWebFormTitle
public void WriteWebFormTitle(Window FDesignWindow, ClientParam cParam, ProjectItem projItem)
{
String FileName = FDesignWindow.Document.FullName;
FDesignWindow.Close(vsSaveChanges.vsSaveChangesYes);
//Start Update Process
System.IO.StreamReader SR = new System.IO.StreamReader(FileName, Encoding.Default);
String Context = SR.ReadToEnd();
SR.Close();
//Page Title
Context = Context.Replace("<title>Untitled Page</title>", "<title>" + cParam.FormTitle + "</title>");
System.IO.FileStream Filefs = new System.IO.FileStream(FileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
System.IO.StreamWriter SW = new System.IO.StreamWriter(Filefs, Encoding.UTF8);
SW.Write(Context);
SW.Close();
Filefs.Close();
FDesignWindow = projItem.Open("{7651A702-06E5-11D1-8EBD-00A0C90F26EA}");
FDesignWindow.Activate();
}
示例15: ReplaceStringInProjectItem
private Exception ReplaceStringInProjectItem(ProjectItem item, string oldValue, string newValue)
{
item.Open(EnvDTE.Constants.vsViewKindPrimary);
item.Document.Activate();
if (!ProjectItemContainsString(item, oldValue))
return new Exception(item.Document.Name + " does not contain \"" + oldValue + "\"");
item.Document.ReplaceText(oldValue, newValue, (int)vsFindOptions.vsFindOptionsNone);
/*if (item.Document.Save(item.Document.FullName) == vsSaveStatus.vsSaveCancelled)
{
return new Exception("File Dialog");
}*/
#if !VS2010
System.Threading.Thread.Sleep(7500);
#endif
item.Document.Save(item.Document.FullName);
#if !VS2010
System.Threading.Thread.Sleep(500);
#endif
item.Document.Close(vsSaveChanges.vsSaveChangesNo);
return null;
}