public void OpenFile(string filename, int lineNumber) { if (dte == null) { dte = GetDTE(); } if (dte == null) { throw new InvalidOperationException("Unable to obtain DTE for " + description); } // Register the IOleMessageFilter to handle any threading errors. MessageFilter.Register(); // Display the Visual Studio IDE. dte.MainWindow.Activate(); dte.UserControl = true; Window window = dte.ItemOperations.OpenFile(filename, Constants.vsViewKindTextView); window.SetFocus(); if (lineNumber != -1) { ((TextSelection)dte.ActiveDocument.Selection).GotoLine(lineNumber, true); } // Turn off the filter MessageFilter.Revoke(); }
public void AppendGenericCover(bool firstSlide, Presentation destinationPresentation = null) { var presentationTemplatePath = MasterWizardManager.Instance.SelectedWizard.GetGenericCoverFile(); try { var thread = new Thread(delegate() { MessageFilter.Register(); var presentation = PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); var selectedTheme = SettingsManager.Instance.GetSelectedTheme(SlideType.Cover); if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } AppendSlide(presentation, -1, destinationPresentation, firstSlide); presentation.Close(); }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }
/// <summary> /// Called when the add-in is loaded, after all the initialization code in the assembly has run. /// </summary> private void ThisAddIn_Startup(object sender, EventArgs e) { //TraceLevel level = (TraceLevel)Settings.Default.EnableDebugging; //SyncServiceTrace.DebugLevel.Level = level; //SettingsModel.Level = level; SyncServiceTrace.I(Resources.LogService_Startup); // Register custom message filter for COM calls. See http://msdn.microsoft.com/en-us/library/ms228772%28v=vs.90%29.aspx if (!MessageFilter.Register()) { SyncServiceTrace.W("Failed to register message handler."); } // Initialize all assemblies. AssemblyInit.Instance.Init(); AIT.TFS.SyncService.Adapter.TFS2012.AssemblyInit.Instance.Init(); AIT.TFS.SyncService.Adapter.Word2007.AssemblyInit.Instance.Init(); InitializeAddIn(); // if you enable / diable the addin, _ribbon is not set if (_ribbon != null) { _ribbon.RegisterToServices(); } SyncServiceTrace.I(Resources.LogService_StartupComplete); }
static void Main(string[] args) { MessageFilter.Register(); //Your code here //... MessageFilter.Revoke(); }
private void createEach(List <ResultItem> allValue, string townName) { ReportFromTemplate report = new ReportFromTemplate(); string templateFile = templateText.Text;; report.CreateNewDucument(templateFile); int number = 2; int picIndex = 1; foreach (ResultItem s in allValue) { int m_iErrCnt = 0; while (s.RegionID.Contains(townName) && s.Figure.Contains("-02") && (s.Category.Contains("建筑垃圾") || s.Category.Contains("生活垃圾"))) { try { MessageFilter.Register(); report.CopyTable(); if (report.InsertInfo(ref number, s, ref picIndex, insitu.Text, sShot.Text)) { number++; } MessageFilter.Revoke(); break; } catch (SystemException err) { m_iErrCnt++; if (m_iErrCnt < 3) { System.Threading.Thread.Sleep(1000); } else { break; } } } //if (number > 20) break; } report.deletePage(1); string[] contents = new string[2]; contents[0] = "青浦区" + townName + "2019" + "02" + "期"; contents[1] = "固体废弃物第三方测评报告"; report.insertFirstPage(contents); string townDirectory = outputPath.Text + @"\" + townName + "-201902期"; if (!Directory.Exists(townDirectory)) { Directory.CreateDirectory(townDirectory); } report.SaveDocument(townDirectory + @"\青浦区" + townName + "201902期" + "固体废弃物第三方测评报告" + ".docx"); }
private static DTE GetDTE(int processId, Version version) { MessageFilter.Register(); var process = Process.GetProcessById(processId); string progIdName = "VisualStudio"; switch (process.MainModule.ModuleName.ToLowerInvariant()) { case "wdexpress.exe": progIdName = "WDExpress"; break; case "vwdexpress.exe": progIdName = "VWDExpress"; break; } string progId = string.Format("!{0}.DTE.{1}:{2}", progIdName, version, processId); object runningObject = null; IBindCtx bindCtx = null; IRunningObjectTable rot = null; IEnumMoniker enumMonikers = null; Marshal.ThrowExceptionForHR(CreateBindCtx(reserved: 0, ppbc: out bindCtx)); bindCtx.GetRunningObjectTable(out rot); rot.EnumRunning(out enumMonikers); IMoniker[] moniker = new IMoniker[1]; uint numberFetched = 0; while (enumMonikers.Next(1, moniker, out numberFetched) == 0) { IMoniker runningObjectMoniker = moniker[0]; string name = null; try { if (runningObjectMoniker != null) { runningObjectMoniker.GetDisplayName(bindCtx, null, out name); } } catch (UnauthorizedAccessException) { // Do nothing, there is something in the ROT that we do not have access to. } if (!string.IsNullOrEmpty(name) && string.Equals(name, progId, StringComparison.Ordinal)) { rot.GetObject(runningObjectMoniker, out runningObject); break; } } return((DTE)runningObject); }
private void createAllFuhe(List <ResultItem> allValue) { ReportFromTemplate report = new ReportFromTemplate(); string templateFile = @"D:\青浦区垃圾巡查\0301.docx"; report.CreateNewDucument(templateFile); int number = 2; int picIndex = 1; foreach (ResultItem s in allValue) { int m_iErrCnt = 0; while (!s.Figure.Contains(flag) && (s.Category.Contains("建筑垃圾") || s.Category.Contains("生活垃圾"))) { try { MessageFilter.Register(); report.CopyTable(); if (report.InsertInfo(ref number, s, ref picIndex, insituText.Text, dstPath + @"\截图")) { number++; } MessageFilter.Revoke(); break; } catch (SystemException err) { m_iErrCnt++; if (m_iErrCnt < 3) { System.Threading.Thread.Sleep(1000); } else { break; } } } //if (number > 20) break; } report.deletePage(1); string[] contents = new string[2]; contents[0] = "青浦区" + phase.Text + "期"; contents[1] = "固体废弃物第三方测评报告"; report.insertFirstPage(contents); string townDirectory = dstPath + @"\报告\"; if (!Directory.Exists(townDirectory)) { Directory.CreateDirectory(townDirectory); } report.SaveDocument(townDirectory + @"青浦区" + phase.Text + "期" + "固体废弃物复核点位报告" + ".docx"); }
private void ThreadTestAll() { ReportFromTemplate report = new ReportFromTemplate(); string templateFile = templateText.Text; report.CreateNewDucument(templateFile); getAllshp(shpPathText.Text); Invoke(new MethodInvoker(() => { progWorkQP.Maximum = allValue.Count; progWorkQP.Value = 0; })); int number = 2; int picIndex = 1; foreach (ResultItem s in allValue) { int m_iErrCnt = 0; while (true) { try { MessageFilter.Register(); report.CopyTable(); if (report.InsertInfo(ref number, s, ref picIndex, insitu.Text, sShot.Text)) { number++; Invoke(new MethodInvoker(() => { progWorkQP.Value = number - 2; })); } MessageFilter.Revoke(); break; } catch (SystemException err) { m_iErrCnt++; if (m_iErrCnt < 3) { System.Threading.Thread.Sleep(1000); } else { break; } } } //if (number > 20) break; } report.deletePage(1); report.SaveDocument(outputPath.Text + @"\" + "垃圾监测总报告.docx"); MessageBox.Show("完成!"); }
static void AttachDebugger(Process proc) { try { MessageFilter.Register(); var dte = GetVisualStudioReference(); // didn't get a visual studio reference if (dte == null) { return; } var vsProcs = RetryOnVisualStudioBusy(() => dte.Debugger.LocalProcesses); int total = RetryOnVisualStudioBusy(() => vsProcs.Count); dynamic target = null; for (var i = 0; i < total; i++) { try { var vsProc = RetryOnVisualStudioBusy(() => vsProcs.Item(i)); int vsProcId = RetryOnVisualStudioBusy(() => vsProc.ProcessID); if (vsProcId == proc.Id) { target = vsProc; break; } } catch { /* whelp */ } } if (target != null) { RetryOnVisualStudioBusy(() => { target.Attach(); return(null); }); } try { MessageFilter.Revoke(); } catch { /* don't care */ } } catch { throw; } }
static void Main(string[] args) { System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0", true); DTE2 dte = (EnvDTE80.DTE2)System.Activator.CreateInstance(t, true); // See http://msdn.microsoft.com/en-us/library/ms228772.aspx for the // code for MessageFilter - just paste it into the so_sln namespace. MessageFilter.Register(); dte.Solution.Open(@"C:\path\to\my.sln"); foreach (Project project in dte.Solution.Projects) { Console.WriteLine(project.Name); } }
private static void AttachProcess() { var localByName = System.Diagnostics.Process.GetProcessesByName(_appName); MessageFilter.Register(); var process = GetProcess(localByName[0].Id); if (process != null) { process.Attach(); Console.WriteLine($"Attached to {process.Name}"); } MessageFilter.Revoke(); }
/// <summary> /// Enables the ability for that project to be able to use NHibernate Repo migrations, automatic or manual. /// </summary> public void EnableMigrations(EnableMigrationsCriteria criteria) { MessageFilter.Register(); var repoInfo = TypeHandler.FindSingleRepo(criteria.ProjectPath, criteria.RepoName); //if it is null something is wrong so drop out. if (repoInfo == null) { return; } AssertRepoHasEmptyConstructor(repoInfo.RepoType); EnsureDbAndMigrationTableExists(criteria.ProjectPath, repoInfo.RepoType, criteria.ConfigFilePath); var repoBase = TypeHandler.CreateRepoBase(repoInfo.Assembly.Location, repoInfo.RepoType); //create migration log table, if it doesn't exist. var updater = CreateSchemaUpdater(criteria.ProjectPath, typeof(MigrationRepo), criteria.ConfigFilePath, repoBase.ConnectionStringOrName); updater.Execute(true, true); bool multipleFound = false; var configType = TypeHandler.FindSingleConfiguration(criteria.ProjectPath, repoInfo.RepoType, out multipleFound); //this should not happen. should only ever have one config per repo type. if (multipleFound) { return; } if (configType == null) { LoggerBase.Log("Adding migration configuration"); var filePath = new ConfigurationFileHandler().CreateConfigurationFile(criteria.ProjectPath, repoInfo.RepoType.Name, "Migrations", MigrationToUse.Manual); new ProjectDteHelper().AddFile(criteria.ProjectPath, "Migrations", filePath, showFile: true); } else { LoggerBase.Log("System is already configured for migrations, see class: " + configType.Name); } //clean up ProjectEvalutionHelper.FinishedWithProject(criteria.ProjectPath); MessageFilter.Revoke(); }
private void createAll(List <ResultItem> all, string directory, string d) { ReportFromTemplate report = new ReportFromTemplate(); report.CreateNewDucument(directory); int number = 2; int picIndex = 1; foreach (ResultItem s in allValue) { int m_iErrCnt = 0; while (s.District == d) { try { MessageFilter.Register(); report.CopyTable(); if (report.InsertInfo(ref number, s, ref picIndex, dstPath + @"\截图")) { number++; } MessageFilter.Revoke(); break; } catch (SystemException err) { m_iErrCnt++; if (m_iErrCnt < 3) { System.Threading.Thread.Sleep(1000); } else { break; } } } //if (number > 20) break; } report.deletePage(1); string output = @"D:\三个区\" + d + ".docx"; report.SaveDocument(output); }
private void Run() { object application = GetAcadApplication(process); using (MessageFilter.Register(Stopwatch.StartNew())) { try { SendCommand(application, command); result.Complete(null); } catch (Exception e) { result.Complete(e); } } }
private static int BuildSolution(string fileName, bool convertToX86) { //Separate name of Solution string solutionName = FlatRedBall.IO.FileManager.RemovePath(fileName); //Register MessageFilter to prevent failed RPC messages MessageFilter.Register(); mInstance.Solution.Open(fileName); mInstance.Solution.SolutionBuild.SolutionConfigurations.Item("Debug").Activate(); object o = mInstance.Solution.SolutionBuild.ActiveConfiguration; if (convertToX86) { foreach (EnvDTE.Project proj in mInstance.Solution.Projects) { if (proj.ConfigurationManager == null) { continue; } System.Diagnostics.Trace.WriteLine(proj.Name); EnvDTE.Configuration config = proj.ConfigurationManager.ActiveConfiguration; EnvDTE.Property prop = config.Properties.Item("PlatformTarget"); prop.Value = "x86"; } } mInstance.Solution.SolutionBuild.Build(true); if (mInstance.Solution.SolutionBuild.LastBuildInfo == 0) { // instanceHandle.Quit(); // MessageFilter.Revoke(); return(0); } else { mInstance.MainWindow.Activate(); MessageFilter.Revoke(); return(mInstance.Solution.SolutionBuild.LastBuildInfo); } }
public void TestReleaseBuildIsAnyCPU() { MessageFilter.Register(); DTE2 dte2 = GetCurrent(); Assert.IsNotNull(dte2); foreach (SolutionConfiguration2 config in dte2.Solution.SolutionBuild.SolutionConfigurations) { if (config.PlatformName.Contains("Mixed Platforms") || config.PlatformName.Contains("Any CPU")) { foreach (SolutionContext context in config.SolutionContexts) { Assert.AreEqual("Any CPU", context.PlatformName, string.Format("{0} is configured {1} in {2}/{3}", context.ProjectName, context.PlatformName, config.PlatformName, config.Name)); } } } MessageFilter.Revoke(); }
protected void when_executing_vs2010(bool waitOnPlugins = false) { CreateProjectFiles(); BuildOpenWrapPackage(); CopyPackageDependencies(); InitializeServices(); ExecuteCommands(); Type t = Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true); object app = Activator.CreateInstance(t, true); Dte = (DTE2)app; MessageFilter.Register(); Dte.Solution.Open(SlnFile.Path); while (Dte.Solution.IsOpen == false) { Thread.Sleep(TimeSpan.FromSeconds(1)); } foreach (var action in _dteActions) { action(Dte); } if (waitOnPlugins) { Dte.Windows.Output("OpenWrap").WaitForMessage(StartSolutionPlugin.SOLUTION_PLUGINS_STARTED); } ReadErrors(); ReadOpenWrapOutput(); foreach (var error in Errors) { Console.WriteLine("Error: " + error.Description); } }
static void Main(string[] args) { Random r = new Random(); Excel.Workbook myWb = MyExcel.GetWorkBook(System.AppDomain.CurrentDomain.BaseDirectory + "demo.xlsx"); try { MessageFilter.Register(); #region 写excel myWb.Application.ScreenUpdating = true; //控制excel刷新暂停,false之后等到true才刷新,不暂停将会导致写一个格刷新一次 //这里写入excel Excel.Worksheet ws = (Excel.Worksheet)myWb.Sheets["Sheet1"]; //想要搞的workbook的名字 string sample = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD"; string[] samples = sample.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in samples) { for (int i = 1; i < 10; i++) { ws.GetCell(item, i).Value = r.Next(1, 100); } } myWb.Save(); myWb.Application.ScreenUpdating = true; #endregion MessageFilter.Revoke(); } catch (Exception ex) { throw ex; } finally { myWb.Application.Quit(); } }
/// <summary> /// Client side - see ConnectDebugger description. /// Server side - starts ipc channel / monitors for newly attaching ipc connections. /// </summary> /// <param name="csScript">C# script</param> public static void ScriptServer_ConnectDebugger( Object _mainArg = null, CodeType codetype = CodeType.Managed, IEnumerable <String> csScripts = null, String hostExePath = null, String additionCommandLineArguments = "") { mainArg = _mainArg; //--------------------------------------------------------------- // Detect Visual studio, which is debugging us. //--------------------------------------------------------------- Process currentProcess = Process.GetCurrentProcess(); Process debuggerProcess = null; debuggerProcess = GetParentProcess(currentProcess); // // Visual studio is either debug process by itself, or it starts msvsmon.exe, when we locate // parent of parent approach. // if (debuggerProcess != null && debuggerProcess.ProcessName.ToLower() == "msvsmon") { debuggerProcess = GetParentProcess(debuggerProcess); } if (debuggerProcess != null && debuggerProcess.ProcessName.ToLower() != "devenv") { debuggerProcess = null; // Not a visual studio, e.g. cmd } DTE2 dte = null; if (debuggerProcess != null) { MessageFilter.Register(); dte = GetDTE(debuggerProcess.Id); } string[] args = Environment.GetCommandLineArgs(); if (args.Contains(serverSwitch)) { // Breakpoint here will not work, Debugger is not yet attached. for (int i = 0; i < 100; i++) { if (Debugger.IsAttached) { break; } Thread.Sleep(50); } // Breakpoint will start to work after this point. System.Threading.Tasks.Task.Run(() => { IpcServerLoop(); }); if (dte != null) { MessageFilter.Revoke(); } return; } //--------------------------------------------------------------- // Self hosting if not embedded in application //--------------------------------------------------------------- if (hostExePath == null) { hostExePath = Assembly.GetExecutingAssembly().Location; } if (dte != null) { MessageFilter.Register(); if (dte.Debugger.DebuggedProcesses.Count > 1) { // If starting debug with two processes, then wait a little for second to start so 3-rd process won't start Thread.Sleep(500); } bool bAttached = false; String debuggerTypes = "Managed (v4.6, v4.5, v4.0)"; switch (codetype) { case CodeType.Managed: debuggerTypes = "Managed (v4.6, v4.5, v4.0)"; break; case CodeType.Mixed: debuggerTypes = "Managed (v4.6, v4.5, v4.0)|Native"; // Application will terminate when detached from debugger. break; case CodeType.Native: debuggerTypes = "Native"; break; } Debugger2 debugger2 = (Debugger2)dte.Debugger; Transport transport = debugger2.Transports.Item(1 /* Default transport */); String[] debTypes = debuggerTypes.Split('|').ToArray(); Engine[] engines = new Engine[debTypes.Length]; for (int i = 0; i < engines.Length; i++) { engines[i] = transport.Engines.Item(debTypes[i]); } for (int iTry = 0; iTry < 2; iTry++) { var processes = dte.Debugger.LocalProcesses.Cast <Process2>().ToArray(); var exeNames = processes.Select(x => x.Name).ToArray(); for (int i = 0; i < exeNames.Length; i++) { var process = processes[i]; if (exeNames[i] == hostExePath) { var processId = process.ProcessID; String cmdArgs = GetProcessCommandLine(processId); if (cmdArgs == null || !cmdArgs.Contains(serverSwitch)) { continue; } // No need to attach if debugging multiple processes if (dte != null && dte.Debugger.DebuggedProcesses.Count <= 1) { process.Attach2(engines); } foreach (String csScript in csScripts) { new IpcChannel(process.ProcessID).Send(csScript); } bAttached = true; break; } } if (bAttached) { break; } ProcessStartInfo procStartInfo = new ProcessStartInfo(); procStartInfo.Arguments = serverSwitch + " " + additionCommandLineArguments; procStartInfo.CreateNoWindow = true; procStartInfo.FileName = hostExePath; procStartInfo.WorkingDirectory = Environment.CurrentDirectory; Process.Start(procStartInfo); Console.WriteLine("Starting process '" + hostExePath + "'"); //System.Threading.Thread.Sleep(1000); } //for } if (dte != null) { MessageFilter.Revoke(); } Environment.Exit(0); }
public void AppendBasicOverviewSummary(BasicOverviewSummaryControl basicOverviewSummary, Presentation destinationPresentation = null) { try { var thread = new Thread(delegate() { MessageFilter.Register(); var slidesCount = basicOverviewSummary.OutputReplacementsLists.Count; for (var k = 0; k < slidesCount; k++) { var presentationTemplatePath = MasterWizardManager.Instance.SelectedWizard.GetBasicOverviewSummaryFile(); if (!File.Exists(presentationTemplatePath)) { continue; } var presentation = PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { if (shape.HasTable != MsoTriState.msoTrue) { continue; } var table = shape.Table; var tableRowsCount = table.Rows.Count; var tableColumnsCount = table.Columns.Count; for (var i = 1; i <= tableRowsCount; i++) { for (var j = 1; j <= tableColumnsCount; j++) { var tableShape = table.Cell(i, j).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); if (!basicOverviewSummary.OutputReplacementsLists[k].ContainsKey(cellText)) { continue; } tableShape.TextFrame.TextRange.Text = basicOverviewSummary.OutputReplacementsLists[k][cellText]; basicOverviewSummary.OutputReplacementsLists[k].Remove(cellText); } } var deletedRows = 0; for (var i = 1; i <= tableRowsCount; i++) { var tableShape = table.Cell(i - deletedRows, 1).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); if (!cellText.Equals("DeleteRow")) { continue; } table.Rows[i - deletedRows].Delete(); deletedRows++; } } } var selectedTheme = basicOverviewSummary.SelectedTheme; if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } AppendSlide(presentation, -1, destinationPresentation); presentation.Close(); } }); thread.Start(); while (thread.IsAlive) { System.Windows.Forms.Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }
public void AppendCover(bool firstSlide, Presentation destinationPresentation = null) { var presentationTemplatePath = MasterWizardManager.Instance.SelectedWizard.GetCoverFile(); try { var thread = new Thread(delegate() { MessageFilter.Register(); var presentation = PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { for (int i = 1; i <= shape.Tags.Count; i++) { switch (shape.Tags.Name(i)) { case "DATE_DATA0": shape.TextFrame.TextRange.Text = TabHomeMainPage.Instance.SlideCover.PresentationDate; break; case "TITLE": shape.TextFrame.TextRange.Text = TabHomeMainPage.Instance.SlideCover.Title; break; case "BUSINESS_NAME": shape.TextFrame.TextRange.Text = TabHomeMainPage.Instance.SlideCover.DecisionMaker; break; case "DECISION_MAKER": shape.TextFrame.TextRange.Text = TabHomeMainPage.Instance.SlideCover.Advertiser; break; case "QUOTE": shape.TextFrame.TextRange.Text = TabHomeMainPage.Instance.SlideCover.Quote; break; case "SALESPERSON_NAME": shape.TextFrame.TextRange.Text = TabHomeMainPage.Instance.SlideCover.SalesRep; break; } } } } var selectedTheme = SettingsManager.Instance.GetSelectedTheme(SlideType.Cover); if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } AppendSlide(presentation, -1, destinationPresentation, firstSlide); presentation.Close(); }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }
public static void AddProjectsToSolution(string solutionFileName, List <string> projectFileNames) { Project newProject = null; //Register MessageFilter to prevent failed RPC messages MessageFilter.Register(); BusyAction(() => mInstance.Solution.Open(solutionFileName)); BusyAction(() => { if (!mInstance.Solution.IsOpen) { throw new Exception(solutionFileName + " did not open!"); } }); foreach (var projectFileName in projectFileNames) { var exists = false; var name = projectFileName; foreach (Project project in mInstance.Solution.Projects) { if (project.FileName.ToLower() == name.ToLower()) { exists = true; newProject = project; break; } } if (!exists) { newProject = mInstance.Solution.AddFromFile(projectFileName); } //Add dependency for projects that reference it's dll foreach (Project project in mInstance.Solution.Projects) { var proj = project.Object as VSProject; if (proj != null) { foreach (Reference reference in proj.References) { Reference reference1 = reference; Project project1 = newProject; BusyAction(() => { if (reference1.Name == project1.Name) { mInstance.Solution.SolutionBuild.BuildDependencies.Item( project1.UniqueName).AddProject(project1.UniqueName); } }); } } } } BusyAction(() => mInstance.Solution.Close(true)); }
public static void AppendDashboardTargetCustomers(this PowerPointProcessor target, ITargetCustomersOutputData outputData, Presentation destinationPresentation = null) { var presentationTemplatePath = MasterWizardManager.Instance.SelectedWizard.GetTargetCustomersFile(String.Format(MasterWizardManager.TargetCustomersSlideTemplate, 1)); if (!File.Exists(presentationTemplatePath)) { return; } try { var thread = new Thread(delegate() { MessageFilter.Register(); var presentation = target.PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { for (int i = 1; i <= shape.Tags.Count; i++) { switch (shape.Tags.Name(i)) { case "HEADER": shape.TextFrame.TextRange.Text = outputData.Title; break; case "TEXTBOX0": shape.TextFrame.TextRange.Text = outputData.TargetDemo; break; case "TEXTBOX1": shape.TextFrame.TextRange.Text = outputData.HHI; break; case "TEXTBOX2": shape.TextFrame.TextRange.Text = outputData.Geography; break; } } } } var selectedTheme = outputData.SelectedTheme; if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } target.AppendSlide(presentation, -1, destinationPresentation); presentation.Close(); }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }
public void AppendDetailedGridGridBased(PublicationDetailedGridControl[] outputControls, Presentation destinationPresentation = null) { try { var thread = new Thread(delegate() { foreach (var outputControl in outputControls) { MessageFilter.Register(); var slidesCount = outputControl.OutputReplacementsLists.Count; var rowsCount = slidesCount > 0 ? outputControl.Grid[0].GetLength(0) : 0; for (int k = 0; k < slidesCount; k++) { var presentationTemplatePath = MasterWizardManager.Instance.SelectedWizard.GetDetailedGridFile( Controller.Instance.Grids.DetailedGrid.SelectedColumnsCount, rowsCount, Controller.Instance.Grids.DetailedGrid.ShowCommentsHeader); var currentSlideRowsCount = outputControl.Grid[k].GetLength(0); if (!File.Exists(presentationTemplatePath)) { continue; } var presentation = PowerPointObject.Presentations.Open(FileName: presentationTemplatePath, WithWindow: MsoTriState.msoFalse); bool hideAdSpecsOnSlide = ((k + 1) < slidesCount && outputControl.ShowAdSpecsOnlyOnLastSlide) || outputControl.DoNotShowAdSpecs; foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { for (int i = 1; i <= shape.Tags.Count; i++) { switch (shape.Tags.Name(i)) { case "PLOGO": if (!string.IsNullOrEmpty(outputControl.LogoFile)) { slide.Shapes.AddPicture(FileName: outputControl.LogoFile, LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue, Left: shape.Left, Top: shape.Top, Width: shape.Width, Height: shape.Height); } shape.Visible = MsoTriState.msoFalse; break; case "HEADER": shape.TextFrame.TextRange.Text = outputControl.Header; break; case "SIGLINE": if (!outputControl.ShowSignatureLine || hideAdSpecsOnSlide) { shape.Visible = MsoTriState.msoFalse; } break; case "SIGAPPROVAL": if (!outputControl.ShowSignatureLine || hideAdSpecsOnSlide) { shape.Visible = MsoTriState.msoFalse; } break; } } if (shape.HasTable != MsoTriState.msoTrue) { continue; } var table = shape.Table; var tableRowsCount = table.Rows.Count; var tableColumnsCount = table.Columns.Count; for (var i = 1; i <= tableRowsCount; i++) { for (var j = 1; j <= tableColumnsCount; j++) { var tableShape = table.Cell(i, j).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellKey = tableShape.TextFrame.TextRange.Text.Trim(); if (!outputControl.OutputReplacementsLists[k].Keys.Contains(cellKey)) { continue; } var cellText = outputControl.OutputReplacementsLists[k][cellKey]; if (!cellText.Equals("Merge")) { tableShape.TextFrame.TextRange.Text = cellText; outputControl.OutputReplacementsLists[k].Remove(cellKey); } else { tableShape.TextFrame.TextRange.Text = String.Empty; var nextColumnIndex = j - 1; if (nextColumnIndex >= tableColumnsCount) { continue; } table.Cell(i, j).Merge(table.Cell(i, nextColumnIndex)); table.Cell(i, j).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = PpParagraphAlignment.ppAlignLeft; } } } var deletedRows = 0; var dataStart = 4 + currentSlideRowsCount * (Controller.Instance.Grids.DetailedGrid.ShowCommentsHeader ? 2 : 1); var dataEnd = tableRowsCount - 1; for (var i = dataStart; i <= dataEnd; i++) { table.Rows[i - deletedRows].Delete(); deletedRows++; } tableRowsCount = table.Rows.Count; deletedRows = 0; for (var i = 1; i <= tableRowsCount; i++) { var tableShape = table.Cell(i - deletedRows, 1).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); if (!cellText.Equals("MergeComment")) { continue; } table.Rows[i - deletedRows].Delete(); deletedRows++; } } } var selectedTheme = outputControl.SelectedTheme; if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } AppendSlide(presentation, -1, destinationPresentation); presentation.Close(); } } }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }
public static void AppendOptions(this PowerPointProcessor target, IEnumerable <IOptionsSlideData> pages, Theme selectedTheme, bool pasteToSlideMaster, Presentation destinationPresentation = null) { try { var thread = new Thread(delegate() { MessageFilter.Register(); foreach (var page in pages) { var slideNumber = 0; foreach (var pageDictionary in page.ReplacementsList) { var copyOfReplacementList = new Dictionary <string, string>(pageDictionary); var presentationTemplatePath = page.TemplateFilePath; if (!File.Exists(presentationTemplatePath)) { return; } var presentation = target.PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); var taggedSlide = presentation.Slides.Count > 0 ? presentation.Slides[1] : null; var logoShapes = new List <Shape>(); if (page.Logos != null && slideNumber < page.Logos.Length) { var slideLogos = page.Logos[slideNumber]; foreach (var shape in taggedSlide.Shapes.OfType <Shape>().Where(s => s.HasTable != MsoTriState.msoTrue)) { for (var i = 1; i <= shape.Tags.Count; i++) { var shapeTagName = shape.Tags.Name(i); for (var j = 0; j < slideLogos.Length; j++) { if (!shapeTagName.Equals(string.Format("STATIONLOGO{0}", j + 1))) { continue; } string fileName = slideLogos[j]; if (!String.IsNullOrEmpty(fileName) && File.Exists(fileName)) { var newShape = taggedSlide.Shapes.AddPicture(fileName, MsoTriState.msoFalse, MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height); newShape.Top = shape.Top; newShape.Left = shape.Left; newShape.Width = shape.Width; newShape.Height = shape.Height; logoShapes.Add(newShape); } shape.Visible = MsoTriState.msoFalse; } } } } var tableContainer = taggedSlide.Shapes.OfType <Shape>().FirstOrDefault(s => s.HasTable == MsoTriState.msoTrue); if (tableContainer == null) { return; } var tableWidth = tableContainer.Width; var table = tableContainer.Table; var tableRowsCount = table.Rows.Count; for (var i = 1; i <= tableRowsCount; i++) { for (var j = 1; j <= table.Columns.Count; j++) { var tableShape = table.Cell(i, j).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); var key = copyOfReplacementList.Keys.FirstOrDefault(k => k.Trim().ToLower().Equals(cellText.ToLower())); if (String.IsNullOrEmpty(key)) { continue; } tableShape.TextFrame.TextRange.Text = copyOfReplacementList[key]; copyOfReplacementList.Remove(key); } } tableRowsCount = table.Rows.Count; for (var i = tableRowsCount; i >= 1; i--) { for (var j = 1; j < 3; j++) { var tableShape = table.Cell(i, j).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); if (!cellText.Equals("Delete Row")) { continue; } table.Rows[i].Delete(); break; } } tableRowsCount = table.Rows.Count; for (var i = 1; i <= tableRowsCount; i++) { for (var j = table.Columns.Count; j >= 1; j--) { var tableShape = table.Cell(i, j).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); while (cellText == "Merge") { var prevColumnIndex = j - 1; tableShape.TextFrame.TextRange.Text = String.Empty; if (prevColumnIndex >= table.Columns.Count) { break; } table.Cell(i, prevColumnIndex).Merge(table.Cell(i, j)); tableShape = table.Cell(i, prevColumnIndex).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { break; } tableShape.TextFrame.TextRange.ParagraphFormat.Alignment = PpParagraphAlignment.ppAlignLeft; cellText = tableShape.TextFrame.TextRange.Text.Trim(); if (cellText == "Merge") { j--; } } } } var tableColumnsCount = table.Columns.Count; if (page.ColumnWidths != null) { for (var i = 0; i < page.ColumnWidths.Length; i++) { if ((i + 2) <= tableColumnsCount) { table.Columns[i + 2].Width = page.ColumnWidths[i] * 72.27f; } } } tableColumnsCount = table.Columns.Count; for (var i = tableColumnsCount - 1; i >= 0; i--) { var tableShape = table.Cell(4, i + 1).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); if (cellText.Equals("Delete Column")) { table.Columns[i + 1].Delete(); } } tableContainer.Width = tableWidth; if (pasteToSlideMaster) { var newSlide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank); Design design; if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); design = presentation.Designs[presentation.Designs.Count]; design.Name = DateTime.Now.ToString("MMddyy-hhmmsstt"); } else { design = presentation.Designs.Add(DateTime.Now.ToString("MMddyy-hhmmsstt")); } tableContainer.Copy(); design.SlideMaster.Shapes.Paste(); foreach (var logoShape in logoShapes) { logoShape.Copy(); design.SlideMaster.Shapes.Paste(); } if (page.ContractSettings.IsConfigured) { target.FillContractInfo(design, page.ContractSettings, BusinessObjects.Instance.OutputManager.ContractTemplateFolder); } newSlide.Design = design; } else { if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } if (page.ContractSettings.IsConfigured) { target.FillContractInfo(taggedSlide, page.ContractSettings, BusinessObjects.Instance.OutputManager.ContractTemplateFolder); } } target.AppendSlide(presentation, 1, destinationPresentation); presentation.Close(); slideNumber++; } } }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }
public static void AppendCalendar(this PowerPointProcessor target, CalendarOutputData monthOutputData, Presentation destinationPresentation = null) { var presentationTemplatePath = BusinessObjects.Instance.OutputManager.GetCalendarFile(monthOutputData.ShowLogo, monthOutputData.DayOutput.Length); if (String.IsNullOrEmpty(presentationTemplatePath) || !File.Exists(presentationTemplatePath)) { return; } try { var thread = new Thread(delegate() { monthOutputData.PrepareDayLogoPaths(); var daysCount = monthOutputData.DayOutput.Length; MessageFilter.Register(); var presentation = target.PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { if (shape.HasTextFrame == MsoTriState.msoTrue) { shape.TextFrame.TextRange.Font.Color.RGB = monthOutputData.SlideRGB; shape.TextFrame.TextRange.Paragraphs().Font.Color.RGB = monthOutputData.SlideRGB; } for (int i = 1; i <= shape.Tags.Count; i++) { var shapeName = shape.Tags.Name(i).Trim(); switch (shapeName) { case "LOGO": if (!string.IsNullOrEmpty(monthOutputData.LogoFile)) { var logoShape = slide.Shapes.AddPicture(monthOutputData.LogoFile, MsoTriState.msoFalse, MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height); logoShape.Top = shape.Top; logoShape.Left = shape.Left; logoShape.Width = shape.Width; logoShape.Height = shape.Height; if (SlideSettingsManager.Instance.SlideSettings.SlideSize.Orientation == SlideOrientationEnum.Portrait) { logoShape.Rotation = 90; } } shape.Visible = MsoTriState.msoFalse; break; case "HEADERTAG": shape.TextFrame.TextRange.Text = monthOutputData.SlideTitle; break; case "PREPAREDFOR": if (string.IsNullOrEmpty(monthOutputData.BusinessName) && string.IsNullOrEmpty(monthOutputData.DecisionMaker)) { shape.Visible = MsoTriState.msoFalse; } else { shape.Visible = MsoTriState.msoCTrue; } break; case "ADVORDEC1": if (string.IsNullOrEmpty(monthOutputData.BusinessName) && string.IsNullOrEmpty(monthOutputData.DecisionMaker)) { shape.Visible = MsoTriState.msoFalse; } else { shape.Visible = MsoTriState.msoCTrue; if (string.IsNullOrEmpty(monthOutputData.BusinessName)) { shape.TextFrame.TextRange.Text = monthOutputData.DecisionMaker; } else { shape.TextFrame.TextRange.Text = monthOutputData.BusinessName; } } break; case "DECNAME2": if (string.IsNullOrEmpty(monthOutputData.DecisionMaker)) { shape.Visible = MsoTriState.msoFalse; } else { shape.Visible = MsoTriState.msoCTrue; shape.TextFrame.TextRange.Text = monthOutputData.DecisionMaker; } break; case "MONTHYEAR": shape.TextFrame.TextRange.Text = monthOutputData.MonthText; break; case "COMMENTS": shape.TextFrame.TextRange.Text = monthOutputData.Comments; break; case "TAGA": shape.TextFrame.TextRange.Text = monthOutputData.TagA; break; case "TAGB": shape.TextFrame.TextRange.Text = monthOutputData.TagB; break; case "TAGC": shape.TextFrame.TextRange.Text = monthOutputData.TagC; break; case "TAGD": shape.TextFrame.TextRange.Text = monthOutputData.TagD; break; case "DAY1": case "1-1": if (daysCount > 0) { SetDayRecordTagValue(monthOutputData, slide, shape, 1); } break; case "DAY2": case "2-1": if (daysCount > 1) { SetDayRecordTagValue(monthOutputData, slide, shape, 2); } break; case "DAY3": case "3-1": if (daysCount > 2) { SetDayRecordTagValue(monthOutputData, slide, shape, 3); } break; case "DAY4": case "4-1": if (daysCount > 3) { SetDayRecordTagValue(monthOutputData, slide, shape, 4); } break; case "DAY5": case "5-1": if (daysCount > 4) { SetDayRecordTagValue(monthOutputData, slide, shape, 5); } break; case "DAY6": case "6-1": if (daysCount > 5) { SetDayRecordTagValue(monthOutputData, slide, shape, 6); } break; case "DAY7": case "7-1": if (daysCount > 6) { SetDayRecordTagValue(monthOutputData, slide, shape, 7); } break; case "DAY8": case "8-1": if (daysCount > 7) { SetDayRecordTagValue(monthOutputData, slide, shape, 8); } break; case "DAY9": case "9-1": if (daysCount > 8) { SetDayRecordTagValue(monthOutputData, slide, shape, 9); } break; case "DAY10": case "10-1": if (daysCount > 9) { SetDayRecordTagValue(monthOutputData, slide, shape, 10); } break; case "DAY11": case "11-1": if (daysCount > 10) { SetDayRecordTagValue(monthOutputData, slide, shape, 11); } break; case "DAY12": case "12-1": if (daysCount > 11) { SetDayRecordTagValue(monthOutputData, slide, shape, 12); } break; case "DAY13": case "13-1": if (daysCount > 12) { SetDayRecordTagValue(monthOutputData, slide, shape, 13); } break; case "DAY14": case "14-1": if (daysCount > 13) { SetDayRecordTagValue(monthOutputData, slide, shape, 14); } break; case "DAY15": case "15-1": if (daysCount > 14) { SetDayRecordTagValue(monthOutputData, slide, shape, 15); } break; case "DAY16": case "16-1": if (daysCount > 15) { SetDayRecordTagValue(monthOutputData, slide, shape, 16); } break; case "DAY17": case "17-1": if (daysCount > 16) { SetDayRecordTagValue(monthOutputData, slide, shape, 17); } break; case "DAY18": case "18-1": if (daysCount > 17) { SetDayRecordTagValue(monthOutputData, slide, shape, 18); } break; case "DAY19": case "19-1": if (daysCount > 18) { SetDayRecordTagValue(monthOutputData, slide, shape, 19); } break; case "DAY20": case "20-1": if (daysCount > 19) { SetDayRecordTagValue(monthOutputData, slide, shape, 20); } break; case "DAY21": case "21-1": if (daysCount > 20) { SetDayRecordTagValue(monthOutputData, slide, shape, 21); } break; case "DAY22": case "22-1": if (daysCount > 21) { SetDayRecordTagValue(monthOutputData, slide, shape, 22); } break; case "DAY23": case "23-1": if (daysCount > 22) { SetDayRecordTagValue(monthOutputData, slide, shape, 23); } break; case "DAY24": case "24-1": if (daysCount > 23) { SetDayRecordTagValue(monthOutputData, slide, shape, 24); } break; case "DAY25": case "25-1": if (daysCount > 24) { SetDayRecordTagValue(monthOutputData, slide, shape, 25); } break; case "DAY26": case "26-1": if (daysCount > 25) { SetDayRecordTagValue(monthOutputData, slide, shape, 26); } break; case "DAY27": case "27-1": if (daysCount > 26) { SetDayRecordTagValue(monthOutputData, slide, shape, 27); } break; case "DAY28": case "28-1": if (daysCount > 27) { SetDayRecordTagValue(monthOutputData, slide, shape, 28); } break; case "DAY29": case "29-1": if (daysCount > 28) { SetDayRecordTagValue(monthOutputData, slide, shape, 29); } break; case "DAY30": case "30-1": if (daysCount > 29) { SetDayRecordTagValue(monthOutputData, slide, shape, 30); } break; case "DAY31": case "31-1": if (daysCount > 30) { SetDayRecordTagValue(monthOutputData, slide, shape, 31); } break; case "DAY32": if (daysCount > 31) { SetDayRecordTagValue(monthOutputData, slide, shape, 32); } break; case "DAY33": if (daysCount > 32) { SetDayRecordTagValue(monthOutputData, slide, shape, 33); } break; case "DAY34": if (daysCount > 33) { SetDayRecordTagValue(monthOutputData, slide, shape, 34); } break; case "DAY35": if (daysCount > 34) { SetDayRecordTagValue(monthOutputData, slide, shape, 35); } break; } } } foreach (var note in monthOutputData.Notes) { Shape noteShape = null; if (SlideSettingsManager.Instance.SlideSettings.SlideSize.Orientation == SlideOrientationEnum.Portrait) { noteShape = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationVertical, note.Left, note.Top, note.StaticWidth, note.Bottom - note.Top); } else { noteShape = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, note.Left, note.Top, note.Right - note.Left, note.StaticHeight); } noteShape.Fill.Visible = MsoTriState.msoTrue; noteShape.Fill.Solid(); noteShape.Fill.ForeColor.RGB = Information.RGB(note.BackgroundColor.R, note.BackgroundColor.G, note.BackgroundColor.B); noteShape.Fill.Transparency = 0; noteShape.Line.Visible = MsoTriState.msoTrue; noteShape.Line.ForeColor.SchemeColor = PpColorSchemeIndex.ppForeground; noteShape.Line.BackColor.RGB = Information.RGB(0, 0, 0); noteShape.Shadow.Visible = MsoTriState.msoTrue; noteShape.Shadow.Type = MsoShadowType.msoShadow14; noteShape.TextFrame.TextRange.Font.Color.RGB = Information.RGB(note.ForeColor.R, note.ForeColor.G, note.ForeColor.B); noteShape.TextFrame.TextRange.Font.Name = "Calibri"; noteShape.TextFrame.TextRange.Font.Size = 8; note.Note.AddTextRange(noteShape.TextFrame.TextRange); } } var backgroundFilePath = BusinessObjects.Instance.OutputManager.GetCalendarBackgroundFile(monthOutputData.SlideColor, monthOutputData.Parent.Date, monthOutputData.ShowBigDate); if (!String.IsNullOrEmpty(backgroundFilePath) && File.Exists(backgroundFilePath)) { var backgroundShape = presentation.SlideMaster.Shapes.AddPicture(backgroundFilePath, MsoTriState.msoFalse, MsoTriState.msoCTrue, 0, 0); if (SlideSettingsManager.Instance.SlideSettings.SlideSize.Orientation == SlideOrientationEnum.Portrait) { backgroundShape.Height = presentation.SlideMaster.Width; backgroundShape.Width = presentation.SlideMaster.Height; backgroundShape.Top = (presentation.SlideMaster.Height - backgroundShape.Height) / 2; backgroundShape.Left = (presentation.SlideMaster.Width - backgroundShape.Width) / 2;; backgroundShape.Rotation = 90; } else { backgroundShape.Top = (presentation.SlideMaster.Height - backgroundShape.Height) / 2; backgroundShape.Left = (presentation.SlideMaster.Width - backgroundShape.Width) / 2; } } presentation.SlideMaster.Design.Name = GetSlideMasterName(monthOutputData); target.AppendSlide(presentation, -1, destinationPresentation); presentation.Close(); }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } finally { MessageFilter.Revoke(); } }
public void Init() { MessageFilter.Register(); }
private static int Main(string[] args) { if (args.Length == 0 || args[0] == "--help" || args[0] == "-h") { ShowHelp(); return(0); } string solutionFile = NormalizePath(args[0]); var dte = FindInstanceEditingSolution(solutionFile); if (dte == null) { // Open a new instance dte = TryVisualStudioLaunch("VisualStudio.DTE.17.0"); if (dte == null) { // Launch of VS 2022 failed, fallback to 2019 dte = TryVisualStudioLaunch("VisualStudio.DTE.16.0"); } dte.UserControl = true; try { dte.Solution.Open(solutionFile); } catch (ArgumentException) { Console.Error.WriteLine("Solution.Open: Invalid path or file not found"); return(1); } dte.MainWindow.Visible = true; } MessageFilter.Register(); try { // Open files for (int i = 1; i < args.Length; i++) { // Both the line number and the column begin at one string[] fileArgumentParts = args[i].Split(';'); string filePath = NormalizePath(fileArgumentParts[0]); try { dte.ItemOperations.OpenFile(filePath); } catch (ArgumentException) { Console.Error.WriteLine("ItemOperations.OpenFile: Invalid path or file not found"); return(1); } if (fileArgumentParts.Length > 1) { if (int.TryParse(fileArgumentParts[1], out int line)) { var textSelection = (TextSelection)dte.ActiveDocument.Selection; if (fileArgumentParts.Length > 2) { if (int.TryParse(fileArgumentParts[2], out int column)) { textSelection.MoveToLineAndOffset(line, column); } else { Console.Error.WriteLine("The column part of the argument must be a valid integer"); return(1); } } else { textSelection.GotoLine(line, Select: true); } } else { Console.Error.WriteLine("The line part of the argument must be a valid integer"); return(1); } } } } finally { var mainWindow = dte.MainWindow; mainWindow.Activate(); SetForegroundWindow(new IntPtr(mainWindow.HWnd)); MessageFilter.Revoke(); } return(0); }
static int Main(string[] args) { if (args.Length == 0 || args[0] == "--help" || args[0] == "-h") { ShowHelp(); return(0); } string solutionFile = NormalizePath(args[0]); string solutionDir = Path.GetDirectoryName(solutionFile); DTE dte = FindInstanceEditingSolution(solutionFile); if (dte == null) { // Open a new instance Type visualStudioDTEType = Type.GetTypeFromProgID("VisualStudio.DTE.15.0"); dte = Activator.CreateInstance(visualStudioDTEType) as DTE; dte.UserControl = true; try { dte.Solution.Open(solutionFile); } catch (ArgumentException) { Console.Error.WriteLine("Solution.Open: Invalid path or file not found"); return(1); } dte.MainWindow.Visible = true; } MessageFilter.Register(); try { // Open files for (int i = 1; i < args.Length; i++) { // Both the line number and the column begin at one string[] fileArgumentParts = args[i].Split(new char[] { ':' }); string filePath = NormalizePath(fileArgumentParts[0]); try { dte.ItemOperations.OpenFile(filePath); } catch (ArgumentException) { Console.Error.WriteLine("ItemOperations.OpenFile: Invalid path or file not found"); return(1); } if (fileArgumentParts.Length > 1) { if (int.TryParse(fileArgumentParts[1], out int line)) { var textSelection = (TextSelection)dte.ActiveDocument.Selection; if (fileArgumentParts.Length > 2) { if (int.TryParse(fileArgumentParts[2], out int column)) { textSelection.MoveToLineAndOffset(line, column); } else { Console.Error.WriteLine("The column part of the argument must be a valid integer"); return(1); } } else { textSelection.GotoLine(line, Select: true); } } else { Console.Error.WriteLine("The line part of the argument must be a valid integer"); return(1); } } } var mainWindow = dte.MainWindow; mainWindow.Activate(); SetForegroundWindow(new IntPtr(mainWindow.HWnd)); } finally { MessageFilter.Revoke(); } return(0); }
public static void AppendSolutionCommonSlide(this PowerPointProcessor target, OutputDataPackage dataPackage, Presentation destinationPresentation = null) { var presentationTemplatePath = dataPackage.TemplateName; try { var thread = new Thread(delegate() { MessageFilter.Register(); var presentation = target.PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); foreach (Slide slide in presentation.Slides) { var backgroundClipartShapes = new List <Shape>(); foreach (Shape shape in slide.Shapes) { for (var i = 1; i <= shape.Tags.Count; i++) { var tagName = shape.Tags.Name(i); if (tagName.ToUpper().Contains("CLIPART")) { if (dataPackage.ClipartItems.ContainsKey(tagName.ToUpper())) { var clipartObject = dataPackage.ClipartItems[tagName.ToUpper()]; var newShape = slide.Shapes.AddClipartObject(clipartObject, shape); if (newShape != null && clipartObject.OutputBackground) { backgroundClipartShapes.Add(newShape); } } shape.Visible = MsoTriState.msoFalse; } else if (tagName.ToUpper().Contains("CHART")) { if (dataPackage.ChartItems.ContainsKey(tagName.ToUpper())) { shape.UpdateChartData(dataPackage.ChartItems[tagName.ToUpper()]); } } else if (shape.TextFrame.HasText != MsoTriState.msoFalse) { if (dataPackage.TextItems.ContainsKey(tagName.ToUpper())) { shape.TextFrame.TextRange.Text = dataPackage.TextItems[tagName.ToUpper()] ?? String.Empty; } else { shape.Visible = MsoTriState.msoFalse; } } } } var tableContainer = slide.Shapes.OfType <Shape>().FirstOrDefault(s => s.HasTable == MsoTriState.msoTrue); tableContainer?.UpdateTableData(dataPackage.TableItems, dataPackage.TableWithHeader); if (!String.IsNullOrEmpty(dataPackage.LayoutName)) { foreach (CustomLayout customLayout in slide.Design.SlideMaster.CustomLayouts) { if (!String.Equals(dataPackage.LayoutName, customLayout.Name, StringComparison.OrdinalIgnoreCase)) { continue; } slide.CustomLayout = customLayout; break; } } foreach (var clipartShape in backgroundClipartShapes) { clipartShape.ZOrder(MsoZOrderCmd.msoSendToBack); } } var selectedTheme = dataPackage.Theme; if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } target.AppendSlide(presentation, -1, destinationPresentation, dataPackage.AddAsFirtsPage); presentation.Close(); }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }