public async Task ProcessIncomingNotification()
        {
            //_event.Process(await Request.Content.ReadAsStringAsync());
            string eventPayLoadContent = await Request.Content.ReadAsStringAsync();

            await _eventReporter.Broadcast(await _event.Process(eventPayLoadContent));
        }
        public async Task <IHttpActionResult> ProcessIncomingIssue()
        {
            var eventPayLoadContent = await Request.Content.ReadAsStringAsync();

            await _eventReporter.Broadcast(await _event.ProcessExternalEvents(eventPayLoadContent));

            return(Ok());
        }
        public async Task <IHttpActionResult> ProcessIncomingNotification()
        {
            string eventPayLoadContent = await Request.Content.ReadAsStringAsync();

            Debug.WriteLine($"Processing event request {eventPayLoadContent}");

            await _reporter.Broadcast(await _event.Process(_container, eventPayLoadContent));

            return(Ok("Processed DocuSign event notification successfully."));
        }
        public async Task <IHttpActionResult> ProcessIncomingMedia()
        {
            var    hash = Request.Headers.GetValues("x-hub-signature").FirstOrDefault();
            string eventPayLoadContent = await Request.Content.ReadAsStringAsync();

            var instagramEvent = await _event.ProcessUserEvents(_container, eventPayLoadContent);

            await _eventReporter.Broadcast(instagramEvent);

            return(Ok());
        }
示例#5
0
        public async Task <PollingDataDTO> Poll(PollingDataDTO pollingData)
        {
            if (string.IsNullOrEmpty(pollingData.AdditionalConfigAttributes))
            {
                pollingData.Result = false;
                return(pollingData);
            }

            var attributesObject = JObject.Parse(pollingData.AdditionalConfigAttributes);

            var groupId = attributesObject["GroupId"]?.ToString();
            var statId  = attributesObject["StatId"]?.ToString();

            if (string.IsNullOrEmpty(groupId) || string.IsNullOrEmpty(statId))
            {
                pollingData.Result = false;
                return(pollingData);
            }

            if (string.IsNullOrEmpty(pollingData.Payload))
            {
                //polling is called for the first time
                var latestStatWithValues = await GetLatestStatItem(pollingData.AuthToken, groupId, statId);

                pollingData.Payload = JsonConvert.SerializeObject(latestStatWithValues);
            }
            else
            {
                var statXCM = JsonConvert.DeserializeObject <StatXItemCM>(pollingData.Payload);
                var latestStatWithValues = await GetLatestStatItem(pollingData.AuthToken, groupId, statId);

                //check value by value to see if a difference exist.
                if (StatXUtilities.CompareStatsForValueChanges(statXCM, latestStatWithValues))
                {
                    var eventReportContent = new EventReportCM
                    {
                        EventNames        = "StatXValueChange_" + statId.Substring(0, 18),
                        EventPayload      = new CrateStorage(Crate.FromContent("StatXValueChange", latestStatWithValues)),
                        Manufacturer      = "StatX",
                        ExternalAccountId = pollingData.ExternalAccountId
                    };

                    pollingData.Payload = JsonConvert.SerializeObject(latestStatWithValues);

                    await _hubReporter.Broadcast(Crate.FromContent("Standard Event Report", eventReportContent));
                }
            }

            pollingData.Result = true;
            return(pollingData);
        }
        private async Task PushEnvelopesToTerminalEndpoint(IEnumerable <DocuSignEnvelopeCM_v2> envelopesToNotify)
        {
            foreach (var envelope in envelopesToNotify)
            {
                var eventReportContent = new EventReportCM
                {
                    EventNames        = DocuSignEventParser.GetEventNames(envelope),
                    EventPayload      = new CrateStorage(Crate.FromContent("DocuSign Connect Event", envelope)),
                    Manufacturer      = "DocuSign",
                    ExternalAccountId = envelope.ExternalAccountId
                };

                await _reporter.Broadcast(Crate.FromContent("Standard Event Report", eventReportContent));
            }
        }
        public async Task <IHttpActionResult> ProcessIncomingNotification()
        {
            //lets verify request is made from facebook
            var    hash = Request.Headers.GetValues("x-hub-signature").FirstOrDefault();
            string eventPayLoadContent = await Request.Content.ReadAsStringAsync();

            //first 5 characters of hash is "sha1="
            //therefore we are removing it
            if (hash == null || hash.Length < 6 || !IsHashValid(hash.Substring(5), eventPayLoadContent))
            {
                return(NotFound());
            }
            Debug.WriteLine($"Processing event request for fb: {eventPayLoadContent}");
            var eventList = await _event.ProcessUserEvents(_container, eventPayLoadContent);

            foreach (var fbEvent in eventList)
            {
                await _reporter.Broadcast(fbEvent);
            }
            return(Ok("Processed Facebook event notification successfully."));
        }
        public async Task <IHttpActionResult> ProcessIncomingNotification()
        {
            string eventPayLoadContent = Request.Content.ReadAsStringAsync().Result;

            await _eventReporter.Broadcast(await _event.ProcessEvent(eventPayLoadContent));

            //We need to acknowledge the request from Salesforce
            //Creating a SOAP XML response to acknowledge
            string response   = @"<?xml version=""1.0"" encoding=""UTF-8""?>
                            <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" 
                            xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
                             <soapenv:Body>
                              <notificationsResponse xmlns=""http://soap.sforce.com/2005/09/outbound"">
                                     <Ack>true</Ack>
                                  </notificationsResponse>
                              </soapenv:Body>
                            </soapenv:Envelope>";
            var    responeXml = XElement.Parse(response);

            return(Content(HttpStatusCode.OK, responeXml, GlobalConfiguration.Configuration.Formatters.XmlFormatter));
        }
        public async Task <PollingDataDTO> Poll(PollingDataDTO pollingData, GDrivePollingType pollingType)
        {
            var googleAuthToken = JsonConvert.DeserializeObject <GoogleAuthDTO>(pollingData.AuthToken);
            var driveService    = await _googleDrive.CreateDriveService(googleAuthToken);

            string startPageToken;

            if (string.IsNullOrEmpty(pollingData.Payload))
            {
                var response = driveService.Changes.GetStartPageToken().Execute();
                startPageToken = response.StartPageTokenValue;
            }
            else
            {
                startPageToken = pollingData.Payload;
            }

            var changedFiles = new Dictionary <string, string>();

            var pageToken = startPageToken;

            while (pageToken != null)
            {
                var request = driveService.Changes.List(pageToken);
                request.Fields = "changes,kind,newStartPageToken,nextPageToken";
                request.Spaces = "drive";

                var changes = request.Execute();
                foreach (var change in changes.Changes)
                {
                    if (!string.IsNullOrEmpty(change.File.MimeType) &&
                        change.File.MimeType.ToUpper() == _fileTypes[pollingType])
                    {
                        if (!changedFiles.ContainsKey(change.FileId))
                        {
                            changedFiles.Add(change.FileId, change.File.Name);
                        }
                    }
                }

                if (!string.IsNullOrEmpty(changes.NewStartPageToken))
                {
                    startPageToken = changes.NewStartPageToken;
                }

                pageToken = changes.NextPageToken;
            }

            if (changedFiles.Count > 0)
            {
                var changedFilesCM = new KeyValueListCM();
                foreach (var pair in changedFiles)
                {
                    changedFilesCM.Values.Add(new KeyValueDTO(pair.Key, pair.Value));
                }

                var eventReportContent = new EventReportCM
                {
                    EventNames        = _eventNames[pollingType],
                    EventPayload      = new CrateStorage(Crate.FromContent("ChangedFiles", changedFilesCM)),
                    Manufacturer      = "Google",
                    ExternalAccountId = pollingData.ExternalAccountId
                };

                Logger.Info("Polling for Google Drive: changed files of type \"" + pollingType.ToString() + "\"");
                await _reporter.Broadcast(Crate.FromContent("Standard Event Report", eventReportContent));
            }

            pollingData.Payload = startPageToken;
            return(pollingData);
        }
        public async Task <PollingDataDTO> Poll(PollingDataDTO pollingData)
        {
            Logger.Info($"Polling for Gmail was launched {pollingData.ExternalAccountId}");

            var serv            = new GoogleGmail();
            var googleAuthToken = JsonConvert.DeserializeObject <GoogleAuthDTO>(pollingData.AuthToken);
            var service         = await serv.CreateGmailService(googleAuthToken);

            if (string.IsNullOrEmpty(pollingData.Payload))
            {
                //Polling is called for the first time
                //we have no history id to synchronise partitially, so we request the last message from the inbox
                UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List(pollingData.ExternalAccountId);
                request.RequestParameters["maxResults"] = new Parameter()
                {
                    DefaultValue = "1", Name = "maxResults", ParameterType = "query"
                };
                var list = request.Execute();

                //then we have to get its details and historyId (to use with history listing API method)

                pollingData.Payload = GetHistoryId(service, list.Messages.FirstOrDefault().Id, pollingData.ExternalAccountId);
                Logger.Info($"Polling for Gmail {pollingData.ExternalAccountId}: remembered the last email in the inbox");
            }
            else
            {
                var request = service.Users.History.List(pollingData.ExternalAccountId);
                request.StartHistoryId = ulong.Parse(pollingData.Payload);
                var result = request.Execute();
                Logger.Info($"Polling for Gmail {pollingData.ExternalAccountId}: received a history of changes");
                if (result.History != null)
                {
                    foreach (var historyRecord in result.History)
                    {
                        if (historyRecord.MessagesAdded != null)
                        {
                            foreach (var mail in historyRecord.MessagesAdded.Reverse())
                            {
                                //TODO: make a batch request for emails, instead of calling one by one
                                var email = GetEmail(service, mail.Message.Id, pollingData.ExternalAccountId);
                                var eventReportContent = new EventReportCM
                                {
                                    EventNames        = "GmailInbox",
                                    EventPayload      = new CrateStorage(Crate.FromContent("GmailInbox", email)),
                                    Manufacturer      = "Google",
                                    ExternalAccountId = pollingData.ExternalAccountId
                                };

                                pollingData.Payload = email.MessageID;
                                Logger.Info("Polling for Gmail: got a new email, broadcasting an event to the Hub");
                                await _reporter.Broadcast(Crate.FromContent("Standard Event Report", eventReportContent));
                            }
                        }
                    }
                }
                else
                {
                    Logger.Info($"Polling for Gmail {pollingData.ExternalAccountId}: no new emails");
                }
            }
            pollingData.Result = true;
            return(pollingData);
        }