public void Run() { /* * NetOffice provides features to compare 2 proxies directly on server. * * 2 proxies may different instances but pointing to the same instance on the com server(the office application) * * This is a showstopper to demonstrate a deep comparison. * * ------------------------------------------------------- * Former NetOffice versions spend operator overloads here. * This is impossible in NetOffice 2.0 and above because * NetOffice 2.0 use interfaces instead of classes. * */ using (var application = COMObject.Create <Excel.Application>()) { application.DisplayAlerts = false; Excel.Workbook book = application.Workbooks.Add(); bool isEqual = false; // determine active workbook is the same as book1 on the server isEqual = application.ActiveWorkbook.EqualsOnServer(book); // another static version to do the same isEqual = COMObject.EqualsOnServer(application.ActiveWorkbook, book); application.Quit(); } HostApplication.ShowFinishDialog(); }
public void Run() { // Replace Excel.Workbook with MyWorkbook NetOffice.Core.Default.ObjectActivator.CreateInstance += delegate(Core sender, NetOffice.CoreServices.OnCreateInstanceEventArgs args) { if (args.RequestedFrom.ContractType == typeof(Excel.Workbook)) { args.Replace = new MyWorkbook(); } }; Excel.Application application = new Excel.ApplicationClass(); application.DisplayAlerts = false; // add and cast book to MyWorkbook MyWorkbook book = application.Workbooks.Add() as MyWorkbook; if (book.Has3Sheets) { Console.WriteLine("Book has 3 sheets."); } application.Quit(); application.Dispose(); HostApplication.ShowFinishDialog(); }
public void Run() { // NetOffice Core supports so-called managed C# dynamic // with proxy management services. No need for additional NetOffice Api assemblies. // NetOffice want convert a proxy to COMDynamicObject each time if its failed to resolve // a corresponding wrapper type. // Note: Reference to Microsoft.CSharp is required. dynamic application = new COMDynamicObject("Excel.Application"); application.DisplayAlerts = false; var book = application.Workbooks.Add(); foreach (var sheet in book.Sheets) { Console.WriteLine(sheet); } // quit and dispose all open proxies application.Quit(); application.Dispose(); // -- no proxies open anymore -- HostApplication.ShowFinishDialog(); }
public void SetProxyEntryToSettings(Guid networkId, ProxyEntry proxy) { string nwId = networkId.ToString(); this.Settings.Remove(nwId + "_Url_" + ProxyScheme.All.ToString()); this.Settings.Remove(nwId + "_Port_" + ProxyScheme.All.ToString()); foreach (var key in proxy.Url.Keys) { this.Settings[nwId + "_Url_" + key.ToString()] = proxy.Url[key]; this.Settings[nwId + "_Port_" + key.ToString()] = proxy.Port[key].ToString(); } //remove old storage system this.Settings.Remove(nwId + "_Url"); this.Settings.Remove(nwId + "_Port"); this.Settings[nwId + "_IsAutoConf"] = proxy.IsAutoConf.ToString(); this.Settings[nwId + "_IsAutoDetect"] = proxy.IsAutoDetect.ToString(); this.Settings[nwId + "_ByPassLocal"] = proxy.ByPassLocal.ToString(); this.Settings[nwId + "_Exceptions"] = proxy.Exceptions; this.Settings[nwId + "_RequiresAuthentication"] = proxy.RequiresAuthentication.ToString(); this.Settings[nwId + "_AuthenticationUsername"] = proxy.AuthenticationUsername; this.Settings[nwId + "_AuthenticationPassword"] = Encrypt(proxy.AuthenticationPassword); OnSettingsChanged(); if (HostApplication != null) { HostApplication.SetStatusText(this, ActionResources.Saved_Status); } }
public void RunExample() { // start excel and turn off msg boxes Excel.Application excelApplication = new Excel.Application(); excelApplication.DisplayAlerts = false; // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(excelApplication); // add a new workbook Excel.Workbook workBook = excelApplication.Workbooks.Add(); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1]; // we need some data to display Excel.Range dataRange = PutSampleData(workSheet); // create a nice diagram Excel.ChartObject chart = ((Excel.ChartObjects)workSheet.ChartObjects()).Add(70, 100, 375, 225); chart.Chart.SetSourceData(dataRange); // save the book string workbookFile = utils.File.Combine(HostApplication.RootDirectory, "Example05", Excel.Tools.DocumentFormat.Normal); workBook.SaveAs(workbookFile); // close excel and dispose reference excelApplication.Quit(); excelApplication.Dispose(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, workbookFile); }
private string GetItName(object element) { if (element == null) { return(string.Empty); } ModelElement mel = element as ModelElement; if (mel != null) { if (!string.IsNullOrWhiteSpace(this.MessageTemplate)) { ServiceContractModel scModel = DomainModelHelper.GetElement <ServiceContractModel>(mel.Store); if (scModel != null && scModel.ImplementationTechnology != null) { return(scModel.ImplementationTechnology.Name); } // try with Host HostApplication hApp = DomainModelHelper.GetElement <HostApplication>(mel.Store); if (hApp != null && hApp.ImplementationTechnology != null) { return(hApp.ImplementationTechnology.Name); } } } return(string.Empty); }
private bool IsValidVersion(string product, Version version) { if (version.Name.Equals("Current")) { return(true); } if (product.Equals("Promob") || product.Equals("Catalog")) { HostApplication hostApplication = this.BetaData.Parent.PluginData.HostApplications["Promob"]; if ((version.MajorVersion >= hostApplication.MajorVersion && version.MinorVersion > hostApplication.MinorVersion) || (version.MinorVersion == hostApplication.MinorVersion && version.BuildNumber >= hostApplication.BuildNumber)) { return(true); } } else { if ((version.MajorVersion >= this.BetaData.Parent.MajorVersion && version.MinorVersion > this.BetaData.Parent.MinorVersion) || (version.MinorVersion == this.BetaData.Parent.MinorVersion && version.BuildNumber >= this.BetaData.Parent.BuildNumber)) { return(true); } } return(false); }
public void Run() { // NetOffice instances implements the IClonable interface // and deal with underlying proxies as well Excel.Application application = new Excel.ApplicationClass(); application.DisplayAlerts = false; Excel.Workbook book = application.Workbooks.Add(); // clone the book Excel.Workbook cloneBook = book.Clone() as Excel.Workbook; // dispose the origin book keep the underlying proxy alive // until the clone is disposed book.Dispose(); // alive and works even the origin book is disposed foreach (Excel.Worksheet sheet in cloneBook.Sheets) { Console.WriteLine(sheet); } application.Quit(); application.Dispose(); HostApplication.ShowFinishDialog(); }
public void Run() { // this examples shows how to use variant types(object in NetOffice) at runtime // the reason for the most variant definitions in office is a more flexible value set.(95%) // here is some code to demonstrate this // start application Excel.Application application = new Excel.ApplicationClass(); application.DisplayAlerts = false; // create new Workbook and a new named style Excel.Workbook book = application.Workbooks.Add(); Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets[1]; Excel.Range range = sheet.Cells[1, 1]; Excel.Style myStyle = book.Styles.Add("myUniqueStyle"); // Range.Style is defined as Variant in Excel and as object in NetOffice // You got always an Excel.Style instance if you ask for Excel.Style style = (Excel.Style)range.Style; // and here comes the magic. both sets are valid because the variants was very flexible in the setter range.Style = "myUniqueStyle"; range.Style = myStyle; // Name, Bold, Size are string, bool and double but defined as Variant style.Font.Name = "Arial"; style.Font.Bold = true; // you can also set "true" and it works. variants makes it possible style.Font.Size = 14; // quit & dipose application.Quit(); application.Dispose(); HostApplication.ShowFinishDialog(); }
public void Run() { // this examples shows a special method to ask at runtime for a particular method oder property // morevover you can enable the option NetOffice.Settings.EnableSafeMode. // NetOffice checks(cache supported) for any method or property you call and // throws a EntitiyNotSupportedException if missing // create new instance Excel.Application application = new Excel.Application(); // any reference type in NetOffice implements the EntityIsAvailable method. // you check here your property or method is available. // we check the support for 2 properties at runtime bool enableLivePreviewSupport = application.EntityIsAvailable("EnableLivePreview"); bool openDatabaseSupport = application.Workbooks.EntityIsAvailable("OpenDatabase"); string result = "Excel Runtime Check: " + Environment.NewLine; result += "Support EnableLivePreview: " + enableLivePreviewSupport.ToString() + Environment.NewLine; result += "Support OpenDatabase: " + openDatabaseSupport.ToString() + Environment.NewLine; // quit and dispose application.Quit(); application.Dispose(); HostApplication.ShowMessage(result); }
public void Run() { // this is a simple demonstration how i can convert unkown types at runtime // start application Excel.Application application = new Excel.Application(); application.Visible = false; application.DisplayAlerts = false; foreach (Office.COMAddIn item in application.COMAddIns) { // the application property is an unkown COM object // we need a cast at runtime Excel.Application hostApp = item.Application as Excel.Application; // do some sample stuff string hostAppName = hostApp.Name; bool hostAppVisible = hostApp.Visible; } // quit and dispose excel application.Quit(); application.Dispose(); HostApplication.ShowFinishDialog(); }
public void RunExample() { // start powerpoint PowerPoint.Application powerApplication = new PowerPoint.Application(); // create a utils instance, no need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(powerApplication); // add a new presentation with one new slide PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue); PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank); // add a chart slide.Shapes.AddOLEObject(120, 111, 480, 320, "MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse); // save the document string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example05", DocumentFormat.Normal); presentation.SaveAs(documentFile); // close power point and dispose reference powerApplication.Quit(); powerApplication.Dispose(); // show end dialog HostApplication.ShowFinishDialog(null, documentFile); }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example01", Access.Tools.DocumentFormat.Normal); // delete old database if exists if (System.IO.File.Exists(documentFile)) { System.IO.File.Delete(documentFile); } // create database DAO.Database newDatabase = accessApplication.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, documentFile); }
/// <summary>The base host interface constructor</summary> protected HostInterface(HostApplication host) { Application = host; StaticObjectCache = new Dictionary <ValueTuple <string, bool>, StaticObject>(); AnimatedObjectCollectionCache = new Dictionary <string, AnimatedObjectCollection>(); MissingFiles = new List <string>(); }
private void CreateHostDesignerModel(ServiceContract sc) { hdStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(HostDesignerDomainModel)); hdDomainModel = hdStore.GetDomainModel <HostDesignerDomainModel>(); hdTransaction = hdStore.TransactionManager.BeginTransaction(); hdModel = (HostDesignerModel)hdDomainModel.CreateElement(new Partition(hdStore), typeof(HostDesignerModel), null); HostApplication app = (HostApplication)hdStore.ElementFactory.CreateElement(HostApplication.DomainClassId); app.ImplementationTechnology = new HostDesignerWcfExtensionProvider(); reference = (ServiceReference)hdStore.ElementFactory.CreateElement(ServiceReference.DomainClassId); //mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT.GUID]@[PROJECT]\[MODELFILE] string serviceMoniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}", sc.GetType().Namespace, serviceContractName, sc.Id.ToString(), serviceContractModelProjectName, serviceContractModelFileName); reference.Name = serviceMelReferenceName; reference.ServiceImplementationType = new MockModelBusReference(sc); app.ServiceDescriptions.Add(reference); }
public void RunExample() { // start outlook by trying to access running application first Outlook.Application outlookApplication = new Outlook.Application(true); // SendAndReceive is supported from Outlook 2007 or higher // we check at runtime the feature is available if (outlookApplication.Session.EntityIsAvailable("SendAndReceive")) { // one simple call outlookApplication.Session.SendAndReceive(false); } else { HostApplication.ShowErrorDialog("This version of MS-Outlook doesnt support SendAndReceive.", null); } // close outlook and dispose if (!outlookApplication.FromProxyService) { outlookApplication.Quit(); } outlookApplication.Dispose(); HostApplication.ShowFinishDialog("Done!", null); }
public void Run() { // this example shows you how i still can recieve events from an disposed proxy. // you have to use th Dispose oder DisposeChildInstances method with a parameter. // start application Excel.Application application = new Excel.Application(); application.DisplayAlerts = false; // create new Workbook & attach close event trigger Excel.Workbook book = application.Workbooks.Add(); book.BeforeCloseEvent += new Excel.Workbook_BeforeCloseEventHandler(book_BeforeCloseEvent); // we dispose the instance. the parameter false signals to api dont release the event listener // set parameter to true and the event listener will stopped and you dont get events for the instance // the DisposeChildInstances() method has the same method overload book.Close(); book.Dispose(false); application.Quit(); application.Dispose(); // the application object is ouer root object // dispose them release himself and any childs of application, in this case workbooks and workbook // the excel instance are now removed from process list HostApplication.ShowFinishDialog(); }
public void ValidationPassedWhenProjectDiffersButNameIsSame() { Store store = new Store(typeof(CoreDesignSurfaceDomainModel), typeof(HostDesignerDomainModel)); using (Transaction t = store.TransactionManager.BeginTransaction()) { HostApplication hostApp1 = new HostApplication(store, new PropertyAssignment(HostApplication.ImplementationProjectDomainPropertyId, "Project1")); HostApplication hostApp2 = new HostApplication(store, new PropertyAssignment(HostApplication.ImplementationProjectDomainPropertyId, "SomeOtherProject")); HostDesignerModel model = new HostDesignerModel(store); model.HostApplications.Add(hostApp1); model.HostApplications.Add(hostApp2); ServiceReference serviceReference1 = new ServiceReference(store, new PropertyAssignment(ServiceReference.NameDomainPropertyId, "ServiceRef1")); ServiceReference serviceReference2 = new ServiceReference(store, new PropertyAssignment(ServiceReference.NameDomainPropertyId, "ServiceRef1")); hostApp1.ServiceDescriptions.Add(serviceReference1); hostApp2.ServiceDescriptions.Add(serviceReference2); TestableHostModelContainsUniqueServiceReferencesAcrossHostsValidator validator = new TestableHostModelContainsUniqueServiceReferencesAcrossHostsValidator(); Assert.IsTrue(validator.IsValid(model)); t.Rollback(); } }
public void RunExample() { // start outlook by trying to access running application first // if its failed to resolve a running instance, we create a new one here Outlook.Application outlookApplication = COMObject.CreateByRunningInstance <Outlook.Application>(); // create a new TaskItem. Outlook.TaskItem newTask = outlookApplication.CreateItem(OlItemType.olTaskItem) as Outlook.TaskItem; // Configure the task at hand and save it. newTask.Subject = "Don't forget to check for NoScript updates"; newTask.Body = "check updates here: https://addons.mozilla.org/de/firefox/addon/noscript"; newTask.DueDate = DateTime.Now; newTask.Importance = OlImportance.olImportanceHigh; newTask.Save(); // close outlook and dispose if (!outlookApplication.FromProxyService) { outlookApplication.Quit(); } outlookApplication.Dispose(); HostApplication.ShowFinishDialog("Done!", null); }
public void RunExample() { // start word and turn off msg boxes Word.Application wordApplication = new Word.Application(); wordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone; // create a utils instance, not need for but helpful to keep the lines of code low Word.Tools.CommonUtils utils = new Word.Tools.CommonUtils(wordApplication); // add a new document Word.Document newDocument = wordApplication.Documents.Add(); // insert some text wordApplication.Selection.TypeText("This text is written by NetOffice"); wordApplication.Selection.HomeKey(WdUnits.wdLine, WdMovementType.wdExtend); wordApplication.Selection.Font.Color = WdColor.wdColorSeaGreen; wordApplication.Selection.Font.Bold = 1; wordApplication.Selection.Font.Size = 18; // save the document string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example01", Word.Tools.DocumentFormat.Normal); newDocument.SaveAs(documentFile); // close word and dispose reference wordApplication.Quit(); wordApplication.Dispose(); // show dialog for the user(you!) HostApplication.ShowFinishDialog(null, documentFile); }
public void RunExample() { bool isFailed = false; string workbookFile = null; Excel.Application excelApplication = null; try { // start excel and turn off msg boxes excelApplication = new Excel.Application(); excelApplication.DisplayAlerts = false; excelApplication.Visible = false; // create a utils instance, not need for but helpful to keep the lines of code low Excel.Tools.CommonUtils utils = new Excel.Tools.CommonUtils(excelApplication); // add a new workbook Excel.Workbook workBook = excelApplication.Workbooks.Add(); // add new global Code Module VB.VBComponent globalModule = workBook.VBProject.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule); globalModule.Name = "MyNewCodeModule"; // add a new procedure to the modul globalModule.CodeModule.InsertLines(1, "Public Sub HelloWorld(Param as string)\r\n MsgBox \"Hello from NetOffice!\" & vbnewline & Param\r\nEnd Sub"); // create a click event trigger for the first worksheet int linePosition = workBook.VBProject.VBComponents[2].CodeModule.CreateEventProc("BeforeDoubleClick", "Worksheet"); workBook.VBProject.VBComponents[2].CodeModule.InsertLines(linePosition + 1, "HelloWorld \"BeforeDoubleClick\""); // display info in the worksheet Excel.Worksheet sheet = (Excel.Worksheet)workBook.Worksheets[1]; sheet.Cells[2, 2].Value = "This workbook contains dynamic created VBA Moduls and Event Code"; sheet.Cells[5, 2].Value = "Open the VBA Editor to see the code"; sheet.Cells[8, 2].Value = "Do a double click to catch the BeforeDoubleClick Event from this Worksheet."; // save the book XlFileFormat fileFormat = GetFileFormat(excelApplication); workbookFile = utils.File.Combine(HostApplication.RootDirectory, "Example07", Excel.Tools.DocumentFormat.Macros); workBook.SaveAs(workbookFile, fileFormat); } catch (System.Runtime.InteropServices.COMException throwedException) { isFailed = true; HostApplication.ShowErrorDialog("VBA Error", throwedException); } finally { // close excel and dispose reference excelApplication.Quit(); excelApplication.Dispose(); if ((null != workbookFile) && (!isFailed)) { HostApplication.ShowFinishDialog(null, workbookFile); } } }
public void RunExample() { // start access Access.Application accessApplication = new Access.Application(); // create a utils instance, no need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(accessApplication); // create database file name string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03", DocumentFormat.Normal); // delete old database if exists if (System.IO.File.Exists(documentFile)) { System.IO.File.Delete(documentFile); } // create database DAO.Database newDatabase = accessApplication.DBEngine.Workspaces[0].CreateDatabase(documentFile, LanguageConstants.dbLangGeneral); accessApplication.DBEngine.Workspaces[0].Close(); // setup database connection 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= < access2007 OleDbConnection oleConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + documentFile); oleConnection.Open(); // create table OleDbCommand oleCreateCommand = new OleDbCommand("CREATE TABLE NetOfficeTable(Column1 Text, Column2 Text)", oleConnection); oleCreateCommand.ExecuteReader().Close(); // write some data with plain sql & close for (int i = 0; i < 20000; i++) { string insertCommand = string.Format("INSERT INTO NetOfficeTable(Column1, Column2) VALUES(\"{0}\", \"{1}\")", i, DateTime.Now.ToShortTimeString()); OleDbCommand oleInsertCommand = new OleDbCommand(insertCommand, oleConnection); oleInsertCommand.ExecuteReader().Close(); } oleConnection.Close(); // delete old file if exists string newDocumentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03_Compacted", DocumentFormat.Normal); if (File.Exists(newDocumentFile)) { File.Delete(newDocumentFile); } // now we do CompactDatabase accessApplication.DBEngine.CompactDatabase(documentFile, newDocumentFile); // close access and dispose reference accessApplication.Quit(AcQuitOption.acQuitSaveAll); accessApplication.Dispose(); // show end dialog HostApplication.ShowFinishDialog(null, documentFile); }
internal void Save() { this.OnSettingsChanged(); if (HostApplication != null) { HostApplication.SetStatusText(this, DefaultResources.Saved_Status); } }
public void RunExample() { // start excel and turn off msg boxes Excel.Application excelApplication = new Excel.Application(); excelApplication.DisplayAlerts = false; // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(excelApplication); // add a new workbook //Excel.Workbook workBook = excelApplication.Workbooks.Add(); Excel.Workbook workBook = excelApplication.Workbooks.Open(@"C:\Users\Gilbert Perlaza\Dropbox\HPC\MttoApp\Docs\FORMATO EWO EN BLANCO UNIFICADO OT.XLSX"); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1]; workSheet.Cells[1, 1].Value = "NetOffice Excel Example 04"; // create a star Excel.Shape starShape = workSheet.Shapes.AddShape(MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20); // create a simple textbox Excel.Shape textBox = workSheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50); Excel.Shape rb = workSheet.Shapes.AddFormControl(Excel.Enums.XlFormControl.xlOptionButton, 100, 100, 100, 100); var sh = workSheet.Shapes; foreach (var item in sh) { if (item.Name.Equals("Option Button 1")) { item.ControlFormat.Value = 1; } } rb.TextFrame.Characters().Text = "Hola prueba"; rb.ControlFormat.Value = 0; textBox.TextFrame.Characters().Text = "text"; textBox.TextFrame.Characters().Font.Size = 14; // create a wordart Excel.Shape textEffect = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12, MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250); // create text effect Excel.Shape textDiagram = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14, MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350); // save the book string workbookFile = utils.File.Combine(HostApplication.RootDirectory, "Example04", DocumentFormat.Normal); workBook.SaveAs(workbookFile); // close excel and dispose reference excelApplication.Quit(); excelApplication.Dispose(); // show end dialog HostApplication.ShowFinishDialog(null, workbookFile); }
protected override void OnLoad(System.EventArgs e) { if (!this._editMode) { this._hostApplication = new HostApplication(); } this.LoadHostApplication(); }
private void btnEditHostApplication_Click(object sender, EventArgs e) { HostApplication hostApplication = this.dgvHostApplications.SelectedRows[0].DataBoundItem as HostApplication; AddHostApplicationForm form = new AddHostApplicationForm(hostApplication); form.ShowDialog(); this.dgvHostApplications.EndEdit(); }
/// <summary> /// The run. /// </summary> /// <param name="path"> /// The path. /// </param> /// <param name="timeOutInMilliseconds"> /// The time out in milliseconds. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool Run(string path, int timeOutInMilliseconds) { Logging.Enter(this, MethodBase.GetCurrentMethod().Name); var deviceCareProcessFunctions = new DeviceCareProcessFunctions(); Reporting.Debug("Open DeviceCare"); int processId = deviceCareProcessFunctions.Run(path, timeOutInMilliseconds); return(HostApplication.IsHostApplicationOpen(processId)); }
internal void SavePrinter(Guid networkId, string printer) { this.Settings[networkId + "_PrinterName"] = printer; this.OnSettingsChanged(); if (HostApplication != null) { HostApplication.SetStatusText(this, DefaultResources.Saved_Status); } }
public void RunExample() { bool isFailed = false; string documentFile = null; PowerPoint.Application powerApplication = null; try { // start powerpoint powerApplication = COMObject.Create <PowerPoint.Application>(); // create a utils instance, no need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(powerApplication); // add a new presentation with one new slide PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue); PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank); // add new module and insert macro. the option "Trust access to Visual Basic Project" must be set VB.CodeModule module = presentation.VBProject.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule).CodeModule; string macro = string.Format("Sub NetOfficeTestMacro()\r\n {0}\r\nEnd Sub", "MsgBox \"Thanks for click!\""); module.InsertLines(1, macro); // add button and connect with macro PowerPoint.Shape button = slide.Shapes.AddShape(MsoAutoShapeType.msoShapeActionButtonForwardorNext, 100, 100, 200, 200); button.ActionSettings[PpMouseActivation.ppMouseClick].AnimateAction = MsoTriState.msoTrue; button.ActionSettings[PpMouseActivation.ppMouseClick].Action = PpActionType.ppActionRunMacro; button.ActionSettings[PpMouseActivation.ppMouseClick].Run = "NetOfficeTestMacro"; // save the document documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03", DocumentFormat.Macros); presentation.SaveAs(documentFile); } catch (System.Runtime.InteropServices.COMException throwedException) { isFailed = true; HostApplication.ShowErrorDialog("VBA Error", throwedException); } finally { // close power point and dispose reference if (powerApplication != null) { powerApplication.Quit(); powerApplication.Dispose(); } if ((null != documentFile) && (!isFailed)) { HostApplication.ShowFinishDialog(null, documentFile); } } }
internal void Save(Guid networkId, string homepageUrl, Browsers browsers) { this.Settings[networkId + "_Homepage"] = homepageUrl; this.Settings[networkId + "_Browsers"] = browsers.ToString(); this.OnSettingsChanged(); if (HostApplication != null) { HostApplication.SetStatusText(this, DefaultResources.Saved_Status); } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInstance, ref Array custom) { _logger = new AddInLogger(); _logger.Log("OnConnection"); _addInInstance = (Microsoft.Vbe.Interop.AddIn)addInInstance; try { _hostApplication = CreateHostApplication((VBE)application); _logger.Log("Application is " + _hostApplication.Name); _logger.LogVbProjects(_addInInstance.VBE); } catch (Exception xcp) { _logger.Log(xcp.ToString()); } }
internal AddinUI(HostApplication application) { _application = application; }