public void Execute(IActivityRequest request, IActivityResponse response) { userName = settings.UserName; password = settings.Password; domain = settings.Domain; serviceURL = settings.ServiceUrl; exchangeVersion = settings.ExchangeVersion; if (request.Inputs.Contains("Alternate Mailbox")) { alternateMailbox = request.Inputs["Alternate Mailbox"].AsString(); } if (request.Inputs.Contains("Subject Line")) { subjectFilter = request.Inputs["Subject Line"].AsString(); } if (request.Inputs.Contains("Subject Line Match Type")) { subjectFilterType = request.Inputs["Subject Line Match Type"].AsString(); } if (request.Inputs.Contains("From Address")) { fromAddressFilter = request.Inputs["From Address"].AsString(); } if (request.Inputs.Contains("From Address Match Type")) { fromAddressFilterType = request.Inputs["From Address Match Type"].AsString(); } if (request.Inputs.Contains("Recieved Time Offset (Seconds)")) { recievedTimeOffset = Convert.ToInt32(request.Inputs["Recieved Time Offset (Seconds)"].AsString()); } if (request.Inputs.Contains("Recieved Time Filter Type")) { recievedTimeOffsetFilterType = request.Inputs["Recieved Time Filter Type"].AsString(); } folderName = request.Inputs["Folder Name"].AsString(); MonitorInterval = request.Inputs["Monitor Interval [Seconds]"].AsInt32(); bodyFormat = request.Inputs["Body Format"].AsString(); readMailFilter = request.Inputs["Read Mail Filter"].AsString(); ExchangeService service = SetupExchangeConnection(); FindFolder(service); PropertySet propSet = setupPropertySet(); complete = false; while (!complete) { try { SearchFilter.SearchFilterCollection filterCollection = setupFilterCollection(); FindItemsResults <Item> findResults = service.FindItems(folderID, filterCollection, new ItemView(Int32.MaxValue)); if (findResults.TotalCount > 0) { response.WithFiltering().PublishRange(processMail(findResults.Items, service, propSet)); complete = true; break; } } catch (Exception e) { response.ReportWarningEvent("Exchange Monitor Problem", String.Format("{0}\n{1}\n{2}", e.Message, e.Source, e.StackTrace)); service = SetupExchangeConnection(); } // Delay looping by Monitor Interval Thread.Sleep(TimeSpan.FromSeconds(Convert.ToDouble(MonitorInterval))); } }