async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            DateTime checkPoint      = MasterGDPRHelper.GetOffset(context.ConsumerGroupName, context.Lease.PartitionId);
            DateTime lastMessageDate = checkPoint;

            foreach (EventData eventData in messages)
            {
                string data = Encoding.UTF8.GetString(eventData.GetBytes());

                try
                {
                    Type t = typeof(GDPRMessageWrapper);
                    GDPRMessageWrapper w = (GDPRMessageWrapper)Newtonsoft.Json.JsonConvert.DeserializeObject(data, t);

                    if (w.MessageDate > checkPoint)
                    {
                        if (w.MessageDate > lastMessageDate)
                        {
                            lastMessageDate = w.MessageDate;
                        }

                        Console.WriteLine(string.Format("Message received.  Partition: '{0}', Data: '{1}'", context.Lease.PartitionId, data));
                        MasterGDPRHelper.ProcessRequest(w);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Skiping message {0}", eventData.Offset));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(data);
                }
            }

            MasterGDPRHelper.SetOffSet(context.ConsumerGroupName, context.Lease.PartitionId, lastMessageDate);

            //Call checkpoint every 5 minutes, so that worker can resume processing from 5 minutes back if it restarts.
            if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
            {
                await context.CheckpointAsync();

                this.checkpointStopWatch.Restart();
            }
        }
Beispiel #2
0
        public static string CreateGDPRRequest(string emailAddress, string type)
        {
            try
            {
                GDPRMessage msg = new GDPRMessage();

                switch (type)
                {
                case "Consent":
                    DataSubjectConsentMessage dscm = new DataSubjectConsentMessage();
                    msg = dscm;
                    break;

                case "Delete":
                    DataSubjectDeleteMessage dm = new DataSubjectDeleteMessage();
                    msg = dm;
                    break;

                case "Query":
                    DataSubjectQueryMessage nm = new DataSubjectQueryMessage();
                    msg = nm;
                    break;

                case "Update":
                    DataSubjectUpdateMessage um = new DataSubjectUpdateMessage();
                    msg = um;
                    break;
                }

                GDPRSubject s = new GDPRSubject();
                s.Email     = emailAddress;
                msg.Subject = s;

                MasterGDPRHelper.SendMessage(msg);
            }
            catch
            {
                return("Failure");
            }

            return("Success");
        }