Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the class
        /// <param name="factory">factory core instead of default core</param>
        /// <param name="tryProxyServiceFirst">try to get a running application first before create a new application</param>
        /// </summary>
        public Application(Core factory = null, bool tryProxyServiceFirst = false) : base()
        {
            object proxy = null;

            if (tryProxyServiceFirst)
            {
                proxy = ProxyService.GetActiveInstance("Outlook", "Application", false);
                if (null != proxy)
                {
                    CreateFromProxy(proxy, true);
                    FromProxyService = true;
                }
            }

            if (null == proxy)
            {
                CreateFromProgId("Outlook.Application", true);
            }

            Factory = null != factory ? factory : Core.Default;
            TryRequestVersion();
            RegisterAsApplicationVersionProvider();
            OnCreate();
            _isInitialized = true;
        }
Ejemplo n.º 2
0
        public void Run()
        {
            // In some situations you want use NetOffice with an already running application.
            // this tutorial shows how its possible.

            // 1)
            //
            // GetActiveInstance take the first instance in memory
            Excel.Application application = ProxyService.GetActiveInstance <Excel.Application>();
            if (null != application)
            {
                application.Dispose();
            }

            // 2)
            //
            // GetActiveInstances takes all instances in memory
            var applications = ProxyService.GetActiveInstances <Excel.Application>();

            applications.Dispose();

            // 3)
            //
            // Use special ctor to try access a running application first
            // and if its failed create a new application
            application = new Excel.ApplicationClass(new Core(), true);
            // quit only if its a new application
            if (!application.FromProxyService)
            {
                application.Quit();
            }
            application.Dispose();

            // 4)
            //
            // Creates instance from interop proxy
            Type   interopType = Type.GetTypeFromProgID("Excel.Application");
            object proxy       = Activator.CreateInstance(interopType);

            application = COMObject.Create <Excel.Application>(proxy);
            application.Quit();
            application.Dispose();


            HostApplication.ShowFinishDialog();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of Application
        /// <param name="enableProxyService">try to get a running application first before create a new application</param>
        /// </summary>
        public Application(Core factory = null, bool enableProxyService = false) : base()
        {
            object proxy = null;

            if (enableProxyService)
            {
                proxy = ProxyService.GetActiveInstance("Publisher", "Application", false);
                if (null != proxy)
                {
                    CreateFromProxy(proxy, true);
                    FromProxyService = true;
                }
            }

            if (null == proxy)
            {
                CreateFromProgId("Publisher.Application", true);
            }

            _callQuitInDispose = null == ParentObject;
            Factory            = null != factory ? factory : Core.Default;
            OnCreate();
            ModulesLegacy.ApplicationModule.Instance = this;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns first running Outlook.Application instance from the environment/system that passed a predicate filter
 /// </summary>
 /// <param name="predicate">filter predicate</param>
 /// <param name="throwExceptionIfNotFound">throw exception if unable to find an instance</param>
 /// <returns>Outlook.Application instance or null(Nothing in Visual Basic)</returns>
 /// <exception cref="ArgumentOutOfRangeException">occurs if no instance match and throwExceptionIfNotFound is set</exception>
 public static Application GetActiveInstance(Func <Application, bool> predicate, bool throwExceptionIfNotFound = false)
 {
     return(ProxyService.GetActiveInstance <Application>("Outlook", "Application", predicate, throwExceptionIfNotFound));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns a running Publisher.Application instance from the environment/system
 /// </summary>
 /// <param name="throwExceptionIfNotFound">throw exception if unable to find an instance</param>
 /// <returns>Publisher.Application instance or null(Nothing in Visual Basic)</returns>
 public static Application GetActiveInstance(bool throwExceptionIfNotFound = false)
 {
     return(ProxyService.GetActiveInstance <Application>("Publisher", "Application", throwExceptionIfNotFound));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns a running Excel.Worksheet instance from the environment/system
 /// </summary>
 /// <param name="throwExceptionIfNotFound">throw exception if unable to find an instance</param>
 /// <returns>Excel.Worksheet instance or null</returns>
 public static Application GetActiveInstance(bool throwExceptionIfNotFound = false)
 {
     return(ProxyService.GetActiveInstance <Application>("Excel", "Worksheet", throwExceptionIfNotFound));
 }