public TestResult DoTest() { Excel.Application application = null; DateTime startTime = DateTime.Now; try { application = new NetOffice.ExcelApi.Application(); application.Visible = true; application.DisplayAlerts = false; application.Workbooks.Add(); Excel.Worksheet sheet = application.Workbooks[1].Sheets[1] as Excel.Worksheet; Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "ExcelAddinCSharp.TestAddin" select a).FirstOrDefault(); if(null == addin) return new TestResult(false, DateTime.Now.Subtract(startTime), "COMAddin ExcelAddinCSharp.TestAddin not found.", null, ""); bool ribbonIsOkay = false; bool taskPaneIsOkay = false; if (null != addin.Object) { COMObject addinProxy = new COMObject(null, addin.Object); ribbonIsOkay = (bool)Invoker.PropertyGet(addinProxy, "RibbonUIPassed"); taskPaneIsOkay = (bool)Invoker.PropertyGet(addinProxy, "TaskPanePassed"); addinProxy.Dispose(); } if( ribbonIsOkay && taskPaneIsOkay) return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""); else return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("Ribbon:{0} TaskPane:{1}", ribbonIsOkay, taskPaneIsOkay), null, ""); } catch (Exception exception) { return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""); } finally { if (null != application) { application.Quit(); application.Dispose(); } } }
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { _application = Core.Default.CreateObjectFromComProxy(null, Application); /* * _application is stored as COMObject the common base type for all reference types in NetOffice * because this addin is loaded in different office application. * * with the CreateObjectFromComProxy method the _application instance is created as corresponding wrapper based on the com proxy type */ if (_application is Excel.Application) _hostApplicationName = "Excel"; else if (_application is Word.Application) _hostApplicationName = "Word"; else if (_application is Outlook.Application) _hostApplicationName = "Outlook"; else if (_application is PowerPoint.Application) _hostApplicationName = "PowerPoint"; else if (_application is Access.Application) _hostApplicationName = "Access"; } catch (Exception exception) { if(_hostApplicationName != null) OfficeRegistry.LogErrorMessage(_hostApplicationName, _progId, "Error occured in OnConnection. ", exception); } }
public COMObject(COMObject replacedObject) { Factory.CheckInitialize(); // copy proxy _underlyingObject = replacedObject.UnderlyingObject; _parentObject = replacedObject.ParentObject; _instanceType = replacedObject.InstanceType; // copy childs foreach (COMObject item in replacedObject.ListChildObjects) AddChildObject(item); // remove old object from parent chain if (!Object.ReferenceEquals(replacedObject.ParentObject, null)) { COMObject parentObject = replacedObject.ParentObject; parentObject.RemoveChildObject(replacedObject); // add himself as child to parent object parentObject.AddChildObject(this); } Factory.RemoveObjectFromList(replacedObject); Factory.AddObjectToList(this); }
public COMObject(Core factory, COMObject replacedObject) { // copy current factory info or set default if (null == factory) factory = Core.Default; Factory = factory; // copy proxy _underlyingObject = replacedObject.UnderlyingObject; _parentObject = replacedObject.ParentObject; _instanceType = replacedObject.InstanceType; // copy childs foreach (COMObject item in replacedObject.ListChildObjects) AddChildObject(item); // remove old object from parent chain if (!Object.ReferenceEquals(replacedObject.ParentObject, null)) { COMObject parentObject = replacedObject.ParentObject; parentObject.RemoveChildObject(replacedObject); // add himself as child to parent object parentObject.AddChildObject(this); } Factory.RemoveObjectFromList(replacedObject); Factory.AddObjectToList(this); }
// ITaskpane Member public void OnConnection(COMObject application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments) { ParentPane = parentPane; LastParentPaneVisible = parentPane.Visible; commandPane1.OnConnection(application, parentPane, customArguments); propertyPane1.OnConnection(application, parentPane, customArguments); infoPane1.OnConnection(application, parentPane, customArguments); }
public void OnConnection(COMObject application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments) { ApplicationHandler = new OfficeApplicationManager(application); AvailableProxy[] proxies = ApplicationHandler.GetAvailableProxies(); if (proxies.Length > 0) { comboBoxTarget.DataSource = proxies; comboBoxTarget.SelectedIndex = 0; } }
private IEnumerator GetProxyEnumeratorAsProperty(COMObject comObject) { object enumProxy = Invoker.Default.PropertyGet(comObject, "_NewEnum"); COMObject enumerator = new COMObject(Core.Default, comObject, enumProxy, true); Invoker.Default.MethodWithoutSafeMode(enumerator, "Reset", null); bool isMoveNextTrue = (bool)Invoker.Default.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); while (true == isMoveNextTrue) { object itemProxy = Invoker.Default.PropertyGetWithoutSafeMode(enumerator, "Current", null); COMObject returnClass = new COMObject(enumerator, itemProxy); isMoveNextTrue = (bool)Invoker.Default.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); yield return returnClass; } }
/// <summary> /// returns enumerator with scalar variables /// </summary> /// <param name="comObject"></param> /// <returns></returns> public static IEnumerator GetScalarEnumeratorAsProperty(COMObject comObject) { Factory.CheckInitialize(); object enumProxy = Invoker.PropertyGet(comObject, "_NewEnum"); COMObject enumerator = new COMObject(comObject, enumProxy, true); Invoker.MethodWithoutSafeMode(enumerator, "Reset", null); bool isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); while (true == isMoveNextTrue) { object item = Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null); isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); yield return item; } }
/// <summary> /// returns enumerator with com proxies /// </summary> /// <param name="comObject"></param> /// <returns></returns> public static IEnumerator GetProxyEnumeratorAsMethod(COMObject comObject) { Factory.CheckInitialize(); object enumProxy = Invoker.MethodReturn(comObject, "_NewEnum"); COMObject enumerator = new COMObject(comObject, enumProxy, true); Invoker.MethodWithoutSafeMode(enumerator, "Reset", null); bool isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); while (true == isMoveNextTrue) { object itemProxy = Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null); COMObject returnClass = Factory.CreateObjectFromComProxy(enumerator, itemProxy); isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); yield return returnClass; } }
public static void MethodWithoutSafeMode(COMObject comObject, string name, object[] paramsArray) { try { if (comObject.IsDisposed) throw new InvalidComObjectException(); comObject.InstanceType.InvokeMember(name, BindingFlags.InvokeMethod | BindingFlags.GetProperty, null, comObject.UnderlyingObject, paramsArray, Settings.ThreadCulture); } catch (Exception throwedException) { DebugConsole.WriteException(throwedException); throw new System.Runtime.InteropServices.COMException(GetExceptionMessage(throwedException), throwedException); } }
/// <summary> /// perform method as latebind call with parameters /// </summary> /// <param name="comObject">target object</param> /// <param name="name">name of method</param> /// <param name="paramsArray">array with parameters</param> public static void Method(COMObject comObject, string name, object[] paramsArray) { try { if(comObject.IsDisposed) throw new InvalidComObjectException(); if( (Settings.EnableSafeMode) && (!comObject.EntityIsAvailable(name,SupportEntityType.Method))) throw new EntityNotSupportedException(string.Format("Method {0} is not available.", name)); comObject.InstanceType.InvokeMember(name, BindingFlags.InvokeMethod | BindingFlags.GetProperty, null, comObject.UnderlyingObject, paramsArray, Settings.ThreadCulture); } catch (Exception throwedException) { DebugConsole.WriteException(throwedException); throw new System.Runtime.InteropServices.COMException(GetExceptionMessage(throwedException), throwedException); } }
public TestResult DoTest() { Excel.Application application = null; DateTime startTime = DateTime.Now; try { application = new NetOffice.ExcelApi.Application(); application.Visible = true; application.DisplayAlerts = false; application.Workbooks.Add(); Excel.Worksheet sheet = application.Workbooks[1].Sheets[1] as Excel.Worksheet; Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.ExcelTestAddinCSharp" select a).FirstOrDefault(); if (null == addin || null == addin.Object) return new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.ExcelTestAddinCSharp or addin.Object not found.", null, ""); bool addinStatusOkay = false; string errorDescription = string.Empty; if (null != addin.Object) { COMObject addinProxy = new COMObject(addin.Object); addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay"); errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription"); addinProxy.Dispose(); } if (addinStatusOkay) return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""); else return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.ExcelTestAddinCSharp Addin Status {0}", errorDescription), null, ""); } catch (Exception exception) { return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""); } finally { if (null != application) { application.Quit(); application.Dispose(); } } }
public TestResult DoTest() { Word.Application application = null; DateTime startTime = DateTime.Now; try { application = new Word.Application(); application.Visible = true; application.DisplayAlerts = Word.Enums.WdAlertLevel.wdAlertsNone; application.Documents.Add(); Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.WordTestAddinCSharp" select a).FirstOrDefault(); if (null == addin || null == addin.Object) return new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.WordTestAddinCSharp or addin.Object not found.", null, ""); bool addinStatusOkay = false; string errorDescription = string.Empty; if (null != addin.Object) { COMObject addinProxy = new COMObject(addin.Object); addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay"); errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription"); addinProxy.Dispose(); } if (addinStatusOkay) return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""); else return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.WordTestAddinCSharp Addin Status {0}", errorDescription), null, ""); } catch (Exception exception) { return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""); } finally { if (null != application) { application.Quit(WdSaveOptions.wdDoNotSaveChanges); application.Dispose(); } } }
/// <summary> /// Returns an enumerator with com proxies /// </summary> /// <param name="comObject">COMObject instance as any</param> /// <returns>IEnumerator instance</returns> public static IEnumerator GetProxyEnumeratorAsProperty(COMObject comObject) { if (null == comObject) throw new ArgumentNullException("comObject"); lock (_lockUtils) { comObject.Factory.CheckInitialize(); object enumProxy = comObject.Factory.Invoker.PropertyGet(comObject, "_NewEnum"); COMObject enumerator = new COMObject(comObject.Factory, comObject, enumProxy, true); comObject.Factory.Invoker.MethodWithoutSafeMode(enumerator, "Reset", null); bool isMoveNextTrue = (bool)comObject.Factory.Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); while (true == isMoveNextTrue) { object itemProxy = comObject.Factory.Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null); COMObject returnClass = comObject.Factory.CreateObjectFromComProxy(enumerator, itemProxy); yield return returnClass; isMoveNextTrue = (bool)comObject.Factory.Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null); } } }
/// <summary> /// try to find connection point by EnumConnectionPoints /// </summary> /// <param name="comInstance"></param> /// <param name="connectionPointContainer"></param> /// <param name="point"></param> /// <param name="sinkIds"></param> /// <returns></returns> private static string EnumConnectionPoint(COMObject comInstance, IConnectionPointContainer connectionPointContainer, ref IConnectionPoint point, params string[] sinkIds) { IConnectionPoint[] points = new IConnectionPoint[1]; IEnumConnectionPoints enumPoints = null; try { connectionPointContainer.EnumConnectionPoints(out enumPoints); while (enumPoints.Next(1, points, IntPtr.Zero) == 0) // S_OK = 0 , S_FALSE = 1 { if (null == points[0]) break; Guid interfaceGuid; points[0].GetConnectionInterface(out interfaceGuid); for (int i = sinkIds.Length; i > 0; i--) { string id = interfaceGuid.ToString().Replace("{", "").Replace("}", ""); if (true == sinkIds[i - 1].Equals(id, StringComparison.InvariantCultureIgnoreCase)) { Marshal.ReleaseComObject(enumPoints); enumPoints = null; point = points[0]; return id; } } } return null; } catch (Exception throwedException) { comInstance.Console.WriteException(throwedException); return null; } finally { if (null != enumPoints) Marshal.ReleaseComObject(enumPoints); } }
/// <summary> /// try to find connection point by FindConnectionPoint /// </summary> /// <param name="comInstance"></param> /// <param name="connectionPointContainer"></param> /// <param name="point"></param> /// <param name="sinkIds"></param> /// <returns></returns> private static string FindConnectionPoint(COMObject comInstance, IConnectionPointContainer connectionPointContainer, ref IConnectionPoint point, params string[] sinkIds) { try { for (int i = sinkIds.Length; i > 0; i--) { Guid refGuid = new Guid(sinkIds[i - 1]); IConnectionPoint refPoint = null; connectionPointContainer.FindConnectionPoint(ref refGuid, out refPoint); if (null != refPoint) { point = refPoint; return sinkIds[i - 1]; } } return null; } catch (Exception throwedException) { comInstance.Console.WriteException(throwedException); return null; } }
public IChartCategory(COMObject parentObject, object comProxy) : base(parentObject, comProxy) { }
///<param name="factory">current used factory core</param> ///<param name="parentObject">object there has created the proxy</param> ///<param name="comProxy">inner wrapped COM proxy</param> public IChartCategory(Core factory, COMObject parentObject, object comProxy) : base(factory, parentObject, comProxy) { }
public EDocument_SinkHelper(COMObject eventClass, IConnectionPoint connectPoint): base(eventClass) { _eventClass = eventClass; _eventBinding = (IEventBinding)eventClass; SetupEventBinding(connectPoint); }
public IMarkupPointer2(COMObject replacedObject) : base(replacedObject) { }
public IMarkupPointer2(COMObject parentObject, object comProxy, NetRuntimeSystem.Type comProxyType) : base(parentObject, comProxy, comProxyType) { }
public IMarkupPointer2(COMObject parentObject, object comProxy) : base(parentObject, comProxy) { }
public TextInput(COMObject replacedObject) : base(replacedObject) { }
public TextInput(COMObject parentObject, object comProxy, NetRuntimeSystem.Type comProxyType) : base(parentObject, comProxy, comProxyType) { }
public TextInput(COMObject parentObject, object comProxy) : base(parentObject, comProxy) { }
///<param name="factory">current used factory core</param> ///<param name="parentObject">object there has created the proxy</param> ///<param name="comProxy">inner wrapped COM proxy</param> public TextInput(Core factory, COMObject parentObject, object comProxy) : base(factory, parentObject, comProxy) { }
public DisplayUnitLabel_(COMObject replacedObject) : base(replacedObject) { }
/// <summary> /// Connect the command with the office host application /// </summary> /// <param name="hostApplication"></param> public void Initialize(NetOffice.COMObject hostApplication) { HostApplication = hostApplication; }
public IChartCategory(COMObject parentObject, object comProxy, NetRuntimeSystem.Type comProxyType) : base(parentObject, comProxy, comProxyType) { }
public IChartCategory(COMObject replacedObject) : base(replacedObject) { }
///<param name="factory">current used factory core</param> ///<param name="parentObject">object there has created the proxy</param> ///<param name="comProxy">inner wrapped COM proxy</param> public IMarkupPointer2(Core factory, COMObject parentObject, object comProxy) : base(factory, parentObject, comProxy) { }