Example #1
0
        public MocsForm()
        {
            InitializeComponent();

            _configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);

            _notifyIcon              = new NotifyIcon();
            _notifyIcon.Text         = "Mocs Notification";
            _notifyIcon.Visible      = true;
            _notifyIcon.Icon         = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("MocsClient.sync.ico"));
            _notifyIcon.DoubleClick += new EventHandler(_notifyIcon_DoubleClick);

            // Old school balloon tip
            //_notifyIcon.BalloonTipClicked += new EventHandler(_notifyIcon_BalloonTipClicked);

            BuildContextMenu();
            _notifyIcon.ContextMenu = _contextMenu;

            _messageInterceptor = new MessageInterceptor();
            _messageInterceptor.Initialize();

            dataGridViewNotification.MouseWheel += new MouseEventHandler(dataGridViewNotification_MouseWheel);
            dataGridViewNotification.KeyDown    += new KeyEventHandler(dataGridViewNotification_KeyDown);
            dataGridViewNotification.KeyUp      += new KeyEventHandler(dataGridViewNotification_KeyUp);
        }
Example #2
0
 public NotificationSender()
 {
     serializer  = new XmlSerializer(typeof(FormRequestInfo));
     interceptor = new MessageInterceptor(InterceptionAction.Notify, false);
     detectEmail = false;
     detectSms   = false;
 }
Example #3
0
 public async Task Executes_OnException_WhenSendingFails_WithCorrectContext(
     Exception exception,
     HttpRequestMessage request,
     [MockHttpClient] HttpClient httpClient,
     [Frozen] MessageInterceptor interceptor,
     [Greedy] JSendClient client)
 {
     // Fixture setup
     Mock.Get(httpClient)
     .Setup(c => c.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
     .ThrowsAsync(exception);
     // Exercise system
     try
     {
         await client.SendAsync <object>(request);
     }
     catch
     {
     }
     // Verify outcome
     Mock.Get(interceptor)
     .Verify(i => i.OnException(It.Is <ExceptionContext>(
                                    ctx => ctx.HttpRequest == request &&
                                    ctx.Exception == exception
                                    )), Times.Once);
 }
        public void Message_with_topic_other_then_hha_server_should_not_be_intercepted()
        {
            // Arrange
            var expectedContext = new Context()
            {
                ClientId = "123",
                Topic    = "other-random-topic",
                Payload  = defaultContextPayload
            };

            var rawPayload = defaultRawPayload;
            var payload    = new Dictionary <string, string>()
            {
                { "clientId", expectedContext.ClientId },
                { "values", rawPayload }
            };

            var context     = CreateMqttContext(expectedContext.ClientId, expectedContext.Topic, expectedContext.Payload);
            var logFake     = A.Fake <ILogger>();
            var handlerFake = A.Fake <IMqttContextHandler>();
            var interceptor = new MessageInterceptor(logFake, handlerFake);

            // Act
            interceptor.Intercept(context);

            // Assert
            A.CallTo(() => handlerFake.SaveContext(
                         A <Context> .That.Matches((context) => DoesContextMatch(context, expectedContext))))
            .MustNotHaveHappened();
        }
Example #5
0
        /// <summary>
        /// Call this method to initialize message interceptor.
        /// </summary>
        /// <param name="applicationID">a unique id in the registry for identifying the message filter rule</param>
        public void initializeMsgInterceptor(String applicationID)
        {
            appId = applicationID;
            receiveControlPrefix = "SMS+" + receivingProjectCode + receivingProgramCode;
            // If the message interceptor is already enabled then
            // retrieve its current settings. Otherwise configure
            // a new instance

            if (MessageInterceptor.IsApplicationLauncherEnabled(appId))
            {
                // clean up the key
                RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Inbox\\Rules", true);
                rk.DeleteSubKeyTree(appId);
                rk.Close();
            }


            // We want to intercept messages that begin with "CKF:" within the
            // message body and delete these messages before they reach the
            // SMS inbox.
            smsInterceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete, false);
            smsInterceptor.MessageCondition = new MessageCondition(MessageProperty.Body,
                                                                   MessagePropertyComparisonType.StartsWith, receiveControlPrefix);

            // Enable the message interceptor, launch application when a certain condition met.
            smsInterceptor.EnableApplicationLauncher(appId);
            smsInterceptor.MessageReceived += SmsInterceptor_MessageReceived;
        }
        /// Starts the SMS interception engine
        public static void StartPersistentNotification()
        {
            if (_interceptor == null)
            {
                //Is persistent notification enabled?
                if (MessageInterceptor.IsApplicationLauncherEnabled(APPLICATION_LAUNCH_ID) == true)
                {
                    // Persistent notification is enabled
                    _interceptor = new MessageInterceptor(APPLICATION_LAUNCH_ID, true);

                    _interceptor.MessageReceived += evthnd;
                }
                else
                {
                    //Persistent notification is not yet enabled
                    _interceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete, true);

                    MessageCondition cond = new MessageCondition();
                    cond.ComparisonType = MessagePropertyComparisonType.StartsWith;
                    cond.Property = MessageProperty.Body;
                    cond.CaseSensitive = true;
                    cond.ComparisonValue = TOKEN;

                    _interceptor.MessageCondition = cond;
                    _interceptor.MessageReceived += evthnd;

                    //Enable persistent notification.
                    _interceptor.EnableApplicationLauncher(APPLICATION_LAUNCH_ID);
                }
            }
        }
Example #7
0
 public async Task Executes_OnException_WhenParsingFails_WithCorrectContext(
     Exception exception,
     HttpRequestMessage request,
     [Frozen] IJSendParser parser,
     [Frozen] MessageInterceptor interceptor,
     [Greedy, MockHttpClient] JSendClient client)
 {
     // Fixture setup
     Mock.Get(parser)
     .Setup(c => c.ParseAsync <object>(It.IsAny <JsonSerializerSettings>(), It.IsAny <HttpResponseMessage>()))
     .ThrowsAsync(exception);
     // Exercise system
     try
     {
         await client.SendAsync <object>(request);
     }
     catch
     {
     }
     // Verify outcome
     Mock.Get(interceptor)
     .Verify(i => i.OnException(It.Is <ExceptionContext>(
                                    ctx => ctx.HttpRequest == request &&
                                    ctx.Exception == exception
                                    )), Times.Once);
 }
Example #8
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 #9
0
 /// <summary>
 /// Needs to be called in order to receive messages and fire events
 /// </summary>
 public static void StartReceiving()
 {
     msgInterceptor = new MessageInterceptor(
         InterceptionAction.Notify);
     msgInterceptor.MessageReceived +=
         new MessageInterceptorEventHandler(msgInterceptor_MessageReceived);
 }
 public void Interceptors_AreCorrectlyInitialized_UsingAnArray(MessageInterceptor[] interceptors)
 {
     // Exercise system
     var composite = new CompositeMessageInterceptor(interceptors);
     // Verify outcome
     composite.Interceptors.Should().BeEquivalentTo(interceptors);
 }
Example #11
0
 public Form1()
 {
     InitializeComponent();
     debugTxt.Text = "Calling Form cs";
     //Receiving text message
     this.smsInterceptor = new MessageInterceptor(InterceptionAction.NotifyandDelete);
     this.smsInterceptor.MessageReceived += this.SmsInterceptor_MessageReceived;
 }
Example #12
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;
     }
 }
Example #13
0
 /// <summary>
 /// 启动短信监听
 /// </summary>
 internal void Start()
 {
     msgInterceptor = new MessageInterceptor();
     msgInterceptor.InterceptionAction = InterceptionAction.NotifyAndDelete; //InterceptionAction.NotifyAndDelete;
     MessageCondition msgCondition = new MessageCondition();
     msgCondition.ComparisonType = MessagePropertyComparisonType.Contains;
     msgCondition.Property = MessageProperty.Sender;
     msgInterceptor.MessageCondition = msgCondition;
     msgInterceptor.MessageReceived += new MessageInterceptorEventHandler(msgInterceptor_MessageReceived);
 }
Example #14
0
 public void addSmsInterceptorForPhoneNumber(string phoneNumber)
 {
     MessageInterceptor smsInterceptor = new MessageInterceptor(InterceptionAction.Notify, true);
     if (phoneNumber.CompareTo("") != 0)
         smsInterceptor.MessageCondition = new MessageCondition(MessageProperty.Sender, phoneNumber);
     else
         phoneNumber = "any";
     smsInterceptor.MessageReceived += SmsInterceptor_MessageReceived;
     _smsInterceptors.Add(phoneNumber, smsInterceptor);
 }
Example #15
0
        /// <summary>
        /// 启动短信监听
        /// </summary>
        internal void Start()
        {
            msgInterceptor = new MessageInterceptor();
            msgInterceptor.InterceptionAction = InterceptionAction.NotifyAndDelete; //InterceptionAction.NotifyAndDelete;
            MessageCondition msgCondition = new MessageCondition();

            msgCondition.ComparisonType     = MessagePropertyComparisonType.Contains;
            msgCondition.Property           = MessageProperty.Sender;
            msgInterceptor.MessageCondition = msgCondition;
            msgInterceptor.MessageReceived += new MessageInterceptorEventHandler(msgInterceptor_MessageReceived);
        }
Example #16
0
        public async Task Executes_OnSending_WithCorrectRequest(
            HttpRequestMessage request,
            [Frozen] MessageInterceptor interceptor,
            [Greedy, MockHttpClient] JSendClient client)
        {
            // Exercise system
            await client.SendAsync <object>(request);

            // Verify outcome
            Mock.Get(interceptor)
            .Verify(i => i.OnSending(request));
        }
        /// <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 #18
0
        static void Main(string[] args)
        {
            try
            {
                RabbitMqClient     rabbitInterceptor = new RabbitMqClient();
                MessageInterceptor interceptor       = new MessageInterceptor(rabbitInterceptor);

                interceptor.InterceptMessage();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occurred receiving message: " + ex.ToString());
            }
        }
Example #19
0
 private void Startup_Load(object sender, EventArgs e)
 {
     updateDataHandler       = new EventHandler(UpdateData);        //This calls the UpdateData(...)
     this.Width              = Screen.PrimaryScreen.WorkingArea.Width;
     this.Height             = Screen.PrimaryScreen.WorkingArea.Height;
     gps.DeviceStateChanged += new
                               GpsLib.DeviceStateChangedEventHandler(gps_DeviceStateChanged);
     gps.LocationChanged += new
                            GpsLib.LocationChangedEventHandler(gps_LocationChanged);
     //sms
     sms = new MessageInterceptor(InterceptionAction.NotifyAndDelete);
     sms.MessageCondition = new MessageCondition();
     sms.MessageReceived += new MessageInterceptorEventHandler(sms_MessageReceived);
 }
Example #20
0
        public async Task Executes_OnReceived_WithCorrectContext(
            HttpRequestMessage request,
            [Frozen] HttpResponseMessage response,
            [Frozen] MessageInterceptor interceptor,
            [Greedy, MockHttpClient] JSendClient client)
        {
            // Exercise system
            await client.SendAsync <object>(request);

            // Verify outcome
            Mock.Get(interceptor)
            .Verify(i => i.OnReceived(
                        It.Is <ResponseReceivedContext>(
                            ctx => ctx.HttpRequest == request && ctx.HttpResponse == response)));
        }
Example #21
0
        public async Task Executes_OnSending_BeforeSendingRequest(
            HttpRequestMessage request,
            [Frozen] MessageInterceptor interceptor,
            [FrozenAsHttpClient] HttpClientSpy httpClient,
            [Greedy] JSendClient client)
        {
            // Fixture setup
            Mock.Get(interceptor)
            .Setup(i => i.OnSending(It.IsAny <HttpRequestMessage>()))
            .Callback(
                () => httpClient.HasRequestBeenSent.Should().BeFalse());
            // Exercise system
            await client.SendAsync <object>(request);

            // Verify outcome
            Mock.Get(interceptor)
            .Verify(i => i.OnSending(It.IsAny <HttpRequestMessage>()), Times.Once);
        }
Example #22
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();
                }
            }
        }
Example #23
0
        public void Interception_OfAnyMessage_FailsWithException()
        {
            Mock <IDialog>         dialogStub         = new Mock <IDialog>();
            Mock <IMessageFilter>  messageFilterStub  = new Mock <IMessageFilter>();
            Mock <IMessage>        messageStub        = new Mock <IMessage>();
            Mock <IDialogProvider> dialogProviderStub = new Mock <IDialogProvider>();

            messageFilterStub.Setup(x => x.Intercept(It.IsAny <IMessage>())).Returns(true);

            using (MessageInterceptor <IMessage> messageInterceptor = new MessageInterceptor <IMessage>(dialogStub.Object,
                                                                                                        messageFilterStub.Object,
                                                                                                        (MessageReceivedEventArgs <IMessage> e) =>
            {
                throw new InvalidOperationException();
            }))
            {
                Assert.ThrowsException <InvalidOperationException>(() =>
                {
                    dialogStub.Raise(x => x.MessageDispatching += null, new MessageDispatchingEventArgs(messageStub.Object,
                                                                                                        dialogProviderStub.Object));
                });
            }
        }
Example #24
0
        public async Task Executes_OnReceived_BeforeParsingResponse(
            HttpRequestMessage request,
            [Frozen] MessageInterceptor interceptor,
            [Frozen] IJSendParser parser,
            [Greedy, MockHttpClient] JSendClient client)
        {
            // Fixture setup
            Action verifyResponseHasntBeenParsed = () =>
                                                   Mock.Get(parser)
                                                   .Verify(
                p => p.ParseAsync <object>(It.IsAny <JsonSerializerSettings>(), It.IsAny <HttpResponseMessage>()),
                Times.Never);

            Mock.Get(interceptor)
            .Setup(i => i.OnReceived(It.IsAny <ResponseReceivedContext>()))
            .Callback(verifyResponseHasntBeenParsed);

            // Exercise system
            await client.SendAsync <object>(request);

            // Verify outcome
            Mock.Get(interceptor)
            .Verify(i => i.OnReceived(It.IsAny <ResponseReceivedContext>()), Times.Once);
        }
Example #25
0
        public void Interception_OfAnyMessage_IsSuccessfull()
        {
            Mock <IDialog>         dialogStub         = new Mock <IDialog>();
            Mock <IMessageFilter>  messageFilterStub  = new Mock <IMessageFilter>();
            Mock <IMessage>        messageStub        = new Mock <IMessage>();
            Mock <IDialogProvider> dialogProviderStub = new Mock <IDialogProvider>();

            messageFilterStub.Setup(x => x.Intercept(It.IsAny <IMessage>())).Returns(true);

            bool messageIntercepted = false;

            using (MessageInterceptor <IMessage> messageInterceptor = new MessageInterceptor <IMessage>(dialogStub.Object,
                                                                                                        messageFilterStub.Object,
                                                                                                        (MessageReceivedEventArgs <IMessage> e) =>
            {
                messageIntercepted = true;
            }))
            {
                dialogStub.Raise(x => x.MessageDispatching += null, new MessageDispatchingEventArgs(messageStub.Object,
                                                                                                    dialogProviderStub.Object));

                Assert.IsTrue(messageIntercepted);
            }
        }
Example #26
0
 private void Startup_Load(object sender, EventArgs e)
 {
     updateDataHandler = new EventHandler (UpdateData); //This calls the UpdateData(...)
     this.Width = Screen.PrimaryScreen.WorkingArea.Width;
     this.Height = Screen.PrimaryScreen.WorkingArea.Height;
     gps.DeviceStateChanged += new
     GpsLib.DeviceStateChangedEventHandler (gps_DeviceStateChanged);
     gps.LocationChanged += new
     GpsLib.LocationChangedEventHandler (gps_LocationChanged);
     //sms
     sms = new MessageInterceptor (InterceptionAction.NotifyAndDelete);
     sms.MessageCondition = new MessageCondition ();
     sms.MessageReceived += new MessageInterceptorEventHandler (sms_MessageReceived);
 }
        /// Terminate the interceptor.
        /// This code avoids dead values in the registry under key 
        /// "HKLM\Software\Microsoft\Inbox\Rules" (This place is where windows inserts values to intercept messages.)
        public static void Terminate()
        {
            if (_interceptor != null)
            {
                //Allways detach the event to prevent registry garbage
                _interceptor.MessageReceived -= evthnd;
                //Always call dispose to ensure right MessageInterceptor termination
                _interceptor.Dispose();

                _interceptor = null;
            }
        }
        /// <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.");
                }
            }
        }
        /// <summary>
        /// Method that is called with the main form is loaded.  On loading of the 
        /// form, the app tests for a MessageInterceptor that has previously been
        /// set up using the same unique name for the rule.  If so, it loads the data.
        /// </summary>
        /// <param name="sender">object that raised the event</param>
        /// <param name="e">event arguments</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            // Test to see if Phone Finder is enabled
            if (MessageInterceptor.IsApplicationLauncherEnabled(ruleName))
            {
                // we have already enabled Phone Finder

                // load the event data into the MessageInterceptor and hook up our event
                interceptor = new MessageInterceptor(ruleName);
                interceptor.MessageReceived += new MessageInterceptorEventHandler(interceptor_MessageReceived);

                // set the pin to the value the user set and show that Phone Finder is enabled
                pin.Text = interceptor.MessageCondition.ComparisonValue;
                enabledCheckBox.Checked = true;
            }
            else
            {
                enabledCheckBox.Checked = false;
            }
        }
        /// <summary>
        /// Called when the user chooses to exit the application
        /// </summary>
        /// <param name="sender">object that raised the event</param>
        /// <param name="e">event arguments</param>
        private void exitMenuItem_Click(object sender, EventArgs e)
        {
            if (enabledCheckBox.Checked)
            {
                // the user wants Phone Finder to be enabled, so let's enable it
                try
                {

                    // need to enable the MessageInterceptor
                    interceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete, false);
                    interceptor.MessageCondition = new MessageCondition();
                    interceptor.MessageCondition.CaseSensitive = true;
                    interceptor.MessageCondition.ComparisonType = MessagePropertyComparisonType.Contains;
                    interceptor.MessageCondition.ComparisonValue = pin.Text;
                    interceptor.MessageCondition.Property = MessageProperty.Body;
                    interceptor.EnableApplicationLauncher(ruleName);
                }
                catch (Microsoft.WindowsMobile.PocketOutlook.PocketOutlookException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                // Phone Finder is disabled, disable the event
                if (interceptor != null)
                {
                    interceptor.DisableApplicationLauncher();
                }
            }

            Close();
        }
Example #31
0
        /// <summary>
        /// Call this method to initialize message interceptor.
        /// </summary>
        /// <param name="applicationID">a unique id in the registry for identifying the message filter rule</param>
        public void initializeMsgInterceptor(String applicationID)
        {
            appId = applicationID;
            receiveControlPrefix = "SMS+" + receivingProjectCode + receivingProgramCode;
            // If the message interceptor is already enabled then
            // retrieve its current settings. Otherwise configure
            // a new instance

            if (MessageInterceptor.IsApplicationLauncherEnabled(appId))
            {
                // clean up the key
                RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Inbox\\Rules", true);
                rk.DeleteSubKeyTree(appId);
                rk.Close();
            }

            // We want to intercept messages that begin with "CKF:" within the
            // message body and delete these messages before they reach the
            // SMS inbox.
            smsInterceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete, false);
            smsInterceptor.MessageCondition = new MessageCondition(MessageProperty.Body,
                MessagePropertyComparisonType.StartsWith, receiveControlPrefix);

            // Enable the message interceptor, launch application when a certain condition met.
            smsInterceptor.EnableApplicationLauncher(appId);
            smsInterceptor.MessageReceived += SmsInterceptor_MessageReceived;
        }
Example #32
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;
     }
 }
        public bool Inspect(MessageInterceptor element)
        {
            Append(string.Format("Interceptor"));

            return(true);
        }
Example #34
0
        private void ApplyConfig()
        {
            if (dbManager.CanPrompt())
            {
                this.ChkBoxPrompt.Checked = true;
            }
            else
            {
                this.ChkBoxPrompt.Checked = false;
            }

            if (MessageInterceptor.IsApplicationLauncherEnabled(AppRegisterName))
            {
                this.ChkBoxEnable.Checked = true;
            }
            else
            {
                this.ChkBoxEnable.Checked = false;
            }

            if (dbManager.CanSynchronize())
            {
                this.ChkBoxSync.Checked = true;
            }
            else
            {
                this.ChkBoxSync.Checked = false;
            }

            RegistryKey key = Registry.LocalMachine.OpenSubKey("Carbon Software Ltd");

            if (key != null)
            {
                string result = Convert.ToString(key.GetValue("serial"));

                if ((result.Trim().Length > 0) && (this.serials.Contains(result.Trim())))
                {
                    this.tpAccounts.Show();
                    this.tpRecipients.Show();
                    this.tpOptions.Show();

                    try
                    {
                        this.tabControl.TabPages.RemoveAt(3);
                    }
                    catch
                    {
                        this.tpRegister.Hide();
                    }
                    finally
                    {
                        this.tabControl.SelectedIndex = 0;
                    }
                }
                else
                {
                    this.tpAccounts.Hide();
                    this.tpRecipients.Hide();
                    this.tpOptions.Hide();

                    this.tabControl.SelectedIndex = 3;
                }
            }
            else
            {
                this.tpAccounts.Hide();
                this.tpRecipients.Hide();
                this.tpOptions.Hide();
            }
        }
Example #35
0
        private void Main_Load(object sender, EventArgs e)
        {
            outlook = new OutlookSession();

            gps = new Gps();
            gps.Open();

            #region SMS Interception Setup

            smsInterceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete);

            smsInterceptor.MessageCondition = new MessageCondition(
                MessageProperty.Sender,
                MessagePropertyComparisonType.Equal,
                "+14254448851");

            smsInterceptor.MessageReceived += new MessageInterceptorEventHandler(smsInterceptor_MessageReceived);

            #endregion

            #region State Notification Setup

            umtsAvailable = new SystemState(SystemProperty.CellularSystemAvailableUmts);
            umtsAvailable.ComparisonType = StatusComparisonType.AnyChange;
            umtsAvailable.Changed += new ChangeEventHandler(umtsAvailable_Changed);

            detailsMenuItem.Enabled =
                ((int)umtsAvailable.CurrentValue & SN_CELLSYSTEMAVAILABLE_UMTS_BITMASK) != 0;

            #endregion
        }
Example #36
0
        public Engine(string[] args)
        {
            // If the interceptor is enabled
            if (MessageInterceptor.IsApplicationLauncherEnabled(AppRegisterName))
            {
                // We started this app via an SMS {1}
                if (args.Length > 0)
                {
                    // An SMS started the Engine...
                    if (args[0].Equals("1"))
                    {
                        InitializeComponent();

                        dbManager = new DatabaseManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase));

                        // we must have both accounts and recipients to proceed!
                        if ((dbManager.ACCOUNTS.Rows.Count > 0) && (dbManager.RECIPIENTS.Rows.Count > 0))
                        {
                            this.session    = new OutlookSession();
                            this.collection = session.EmailAccounts;

                            // Set the recipient collection
                            this.recipientCollection = dbManager.RECIPIENTS.Rows;

                            if (collection.Count > 0)
                            {
                                // Set the email account
                                this.emailAccount = collection[Convert.ToString(dbManager.ACCOUNTS.Rows[0]["ADDRESS"])];

                                if (this.emailAccount != null)
                                {
                                    // Create the Interceptor
                                    smsInterceptor = new MessageInterceptor(AppRegisterName, true);
                                    smsInterceptor.MessageReceived += new MessageInterceptorEventHandler(smsInterceptor_MessageReceived);
                                }
                                else
                                {
                                    this.Close();
                                }
                            }
                            else
                            {
                                this.Close();
                            }
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        this.Close();
                    }
                }
                else
                {
                    this.Close();
                }
            }
            else
            {
                this.Close();
            }
        }