Пример #1
0
        static public _com_OutlookExporer IsOutlookExplorerLoaded( )
        {
            Outlook.Application outlook   = null;
            Outlook.NameSpace   nameSpace = null;
            _com_OutlookExporer explorer  = null;

            _isFileNotFoundHappened = false;
            try
            {
                _tracer.Trace("Looking for explorer");
                OutlookGUIInit.DebugMessageBox("Looking for explorer");

                outlook = new Outlook.ApplicationClass();
                _tracer.Trace("Outlook.Application object has been initialized properly.");

                nameSpace = outlook.GetNamespace("MAPI");
                _tracer.Trace("Outlook.NameSpace object has been initialized properly? - " + (nameSpace != null).ToString());

                explorer = new _com_OutlookExporer(outlook.ActiveExplorer());
                _tracer.Trace("_com_OutlookExporer wrapper object has been initialized properly.");
                OutlookGUIInit.DebugMessageBox("Get ActiveExplorer");

                if (explorer == null)
                {
                    _tracer.Trace("Outlook explorer is not found");
                }
                else
                {
                    _tracer.Trace("Outlook explorer is found");
                }
            }
            catch (FileNotFoundException exception)
            {
                _isFileNotFoundHappened = true;
                _tracer.TraceException(exception);
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidComObjectException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidCastException exception)
            {
                _tracer.TraceException(exception);
            }
            finally
            {
                COM_Object.Release(outlook);
                COM_Object.Release(nameSpace);
            }
            return(explorer);
        }
Пример #2
0
        static public _com_OutlookExporer IsOutlookExplorerReady(int cTimeOut)
        {
            int begin = Environment.TickCount;

            _com_OutlookExporer explorer = null;

            while ((explorer = IsOutlookExplorerLoaded( )) == null && (Environment.TickCount - begin) < cTimeOut)
            {
                _tracer.Trace("Waiting for explorer");
            }
            return(explorer);
        }
Пример #3
0
        public void SendReceive()
        {
            try
            {
                if (!OutlookSession.IsOutlookRun)
                {
                    OutlookGUIInit.StartOutlook(ProcessWindowStyle.Minimized);
                    if (!IsMainWndReady())
                    {
                        return;
                    }
                    OutlookGUIInit.ActivateGUI(_mainWnd);
                }
                _explorer = OutlookGUIInit.IsOutlookExplorerReady(cTimeOut);
                if (_explorer == null)
                {
                    StandartJobs.MessageBox(cErrorCOMInitialize, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ProcessDeliverNow( );
                ReleaseCOM();
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (FileNotFoundException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidComObjectException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidCastException exception)
            {
                _tracer.TraceException(exception);
            }
        }
Пример #4
0
        static public bool StartAndInitializeOutlook(  )
        {
            if (OutlookSession.IsOutlookRun)
            {
                return(true);
            }

            _com_OutlookExporer explorer = null;

            try
            {
                OutlookGUIInit.StartOutlook(ProcessWindowStyle.Minimized);
                IntPtr mainWnd = OutlookGUIInit.PrepareMainWndReady(2000);
                if ((int)mainWnd == 0)
                {
                    return(false);
                }
                ActivateGUI(mainWnd);
                return(IsOutlookExplorerReady(2000) != null);
            }
            catch (COMException exception)
            {
                Tracer._TraceException(exception);
                return(false);
            }
            finally
            {
                if (explorer != null)
                {
                    try
                    {
                        explorer.Release();
                    }
                    catch (COMException exception)
                    {
                        Tracer._TraceException(exception);
                    }
                }
            }
        }