Example #1
0
        private void EnableInterceptor()
        {
            // Make sure we're unregistered....
            if (!MessageInterceptor.IsApplicationLauncherEnabled(AppRegisterName))
            {
                // instance the Interceptor
                smsInterceptor = new MessageInterceptor();

                try
                {
                    // register the interceptor.
                    string smsEngine = Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("SmsToEmail.exe", "SmsEngine.exe");
                    smsInterceptor.MessageCondition.Property        = MessageProperty.MessageClass;
                    smsInterceptor.InterceptionAction               = InterceptionAction.Notify;
                    smsInterceptor.MessageCondition.CaseSensitive   = false;
                    smsInterceptor.MessageCondition.ComparisonType  = MessagePropertyComparisonType.Contains;
                    smsInterceptor.MessageCondition.ComparisonValue = "SMS";
                    smsInterceptor.EnableApplicationLauncher(AppRegisterName,
                                                             smsEngine,
                                                             "1");
                }
                catch
                {
                    MessageBox.Show("Unable to register MessageInterceptor, please contact Carbon Software Tech-Support");
                }
                finally
                {
                    smsInterceptor.Dispose();
                }
            }
        }
Example #2
0
 /// <summary>
 /// Call this method at Form_Closed to clean up the message intercepter.
 /// </summary>
 public void cleanUpInterceptor()
 {
     // Tidy up the resources used by the message interceptor
     if (smsInterceptor != null)
     {
         smsInterceptor.MessageReceived -= SmsInterceptor_MessageReceived;
         smsInterceptor.Dispose();
         smsInterceptor = null;
     }
 }
        /// <summary>
        /// Starts the output process by sending the according request to the storage system.
        /// </summary>
        void IOutputProcess.Start()
        {
            lock (_syncLock)
            {
                if (_currentState != OutputProcessState.Created)
                {
                    return;
                }
            }

            var request = new OutputRequestEnvelope()
            {
                OutputRequest = this
            };
            var outputMessageInterceptor = new MessageInterceptor(this.Id, typeof(OutputMessage));

            _messageDispatcher.AddInterceptor(outputMessageInterceptor);

            var response = (OutputResponse)_messageDispatcher.SendAndWaitForResponse(request,
                                                                                     this.Id,
                                                                                     typeof(OutputResponse));

            if (response == null)
            {
                _messageDispatcher.RemoveInterceptor(outputMessageInterceptor);
                outputMessageInterceptor.Dispose();
                throw new ArgumentException("Waiting for the message 'OutputResponse' failed.");
            }

            if ((response.Details == null) || (Enum.TryParse <OutputProcessState>(response.Details.Status, out _currentState) == false))
            {
                _currentState = OutputProcessState.Unknown;
            }

            if (_currentState != OutputProcessState.Queued)
            {
                if (_finished != null)
                {
                    this.Trace("Raising event 'Finished'.");
                    _finished(this, new EventArgs());
                }
            }
            else
            {
                // wait for completion
                if (ThreadPool.QueueUserWorkItem(new WaitCallback(WaitForOutputMessage),
                                                 outputMessageInterceptor) == false)
                {
                    throw new ApplicationException("Starting observation thread failed.");
                }
            }
        }
Example #4
0
        private void DisableInterceptor()
        {
            // Make sure we're registered....
            if (MessageInterceptor.IsApplicationLauncherEnabled(AppRegisterName))
            {
                // instance the Interceptor
                smsInterceptor = new MessageInterceptor(AppRegisterName);

                try
                {
                    // unregister the interceptor.
                    smsInterceptor.DisableApplicationLauncher();
                }
                catch { }
                finally
                {
                    smsInterceptor.Dispose();
                }
            }
        }
        /// <summary>
        /// Initiates the input process by sending the according request to the storage system.
        /// </summary>
        void IInitiateInputRequest.Start()
        {
            lock (_syncLock)
            {
                if (_currentState != InitiateInputRequestState.Created)
                {
                    return;
                }
            }

            var request = new InitiateInputRequestEnvelope()
            {
                InitiateInputRequest = this
            };
            var initiateInputMessageInterceptor = new MessageInterceptor(this.Id, typeof(InitiateInputMessage));

            _messageDispatcher.AddInterceptor(initiateInputMessageInterceptor);

            var response = (InitiateInputResponse)_messageDispatcher.SendAndWaitForResponse(request,
                                                                                            this.Id,
                                                                                            typeof(InitiateInputResponse));

            if (response == null)
            {
                _messageDispatcher.RemoveInterceptor(initiateInputMessageInterceptor);
                initiateInputMessageInterceptor.Dispose();
                throw new ArgumentException("Waiting for the message 'InitiateInputResponse' failed.");
            }

            if ((response.Details == null) ||
                (Enum.TryParse <InitiateInputRequestState>(response.Details.Status, out _currentState) == false))
            {
                _currentState = InitiateInputRequestState.Unknown;
            }

            if (_currentState != InitiateInputRequestState.Accepted)
            {
                if (this.Finished != null)
                {
                    this.Trace("Raising event 'Finished'.");
                    this.Finished(this, new EventArgs());
                }
            }
            else
            {
                this.Details.InputPoint = (response.Details != null) ? response.Details.InputPoint : "0";

                if (response.Article != null)
                {
                    lock (_syncLock)
                    {
                        _inputArticles.AddRange(response.Article);
                    }
                }

                // wait for completion
                if (ThreadPool.QueueUserWorkItem(new WaitCallback(WaitForInitiateInputMessage),
                                                 initiateInputMessageInterceptor) == false)
                {
                    throw new ApplicationException("Starting observation thread failed.");
                }
            }
        }
Example #6
0
        private void smsInterceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
        {
            try
            {
                // Increment the SMS count
                COUNT = COUNT + 1;

                SmsMessage sms = (SmsMessage)e.Message;

                // If Prompt is enabled
                if (dbManager.CanPrompt())
                {
                    string text = sms.Body;

                    if (sms.Body.Length > 90)
                    {
                        text = sms.Body.Substring(0, 90) + " ...";
                    }

                    if (MessageBox.Show("From : " + sms.From.Address + "\r\n" + "Text : " + text,
                                        "Forward via SMS to Email ?" + " (" + COUNT.ToString() + ")",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Exclamation,
                                        MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        // Forward the SMS message
                        this.ForwardSms(sms);
                    }
                }
                else
                {
                    // Forward the SMS message
                    this.ForwardSms(sms);
                }
            }
            catch (StackOverflowException) { }
            catch (Exception) { }
            finally
            {
                // Decrement the COUNT once an SMS has been processed
                COUNT = COUNT - 1;

                // If all pending SMS messages have been processed, dispose and close.
                if (COUNT <= 0)
                {
                    // If we sent an SMS message
                    if (this.bSent)
                    {
                        // Sync the Outbox now if we can
                        if (this.dbManager.CanSynchronize())
                        {
                            MessagingApplication.Synchronize(this.emailAccount);
                        }
                    }

                    // Remove the MessageReceived event handler
                    smsInterceptor.MessageReceived -= smsInterceptor_MessageReceived;

                    // Dispose of the MessageInterceptor
                    smsInterceptor.Dispose();

                    // Close and Exit
                    this.Close();
                }
            }
        }