Esempio n. 1
0
        public static void runCal()
        {
            // Define the syncToken var
            string syncToken;
            bool   ran = false;

            // Sync all calendars and send a message to RMQ
            foreach (var item in syncCalendars(out syncToken))
            {
                // Try to send the message to the queue
                try
                {
                    SyncConverter.sendMessage(SyncConverter.calMessage(item));
                    ran = true;
                }
                // Could not send the message, do not save the syncToken!
                catch (Exception e)
                {
                    // Set the token to null
                    syncToken = null;
                }
            }

            // Update
            if (ran && !String.IsNullOrEmpty(syncToken))
            {
                uuidMaster.PutUpdateUUID(calendarSyncTokenUUID, syncToken, Calendarss.getversion(calendarSyncTokenUUID) + 1);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            GService   t = new GService();
            Calendarss c = new Calendarss();

            Calendarss.newCalendar("testName", "testloc", "testDes");
            Console.Read();
        }
        public void deleteCalendar(XmlDocument doc)
        {
            XmlNodeList uuid = doc.GetElementsByTagName("id");

            Console.WriteLine(uuid[0].InnerText);

            Calendarss calendarss = new Calendarss(); // connectie maken - service

            Calendarss.deleteCalendarById(uuid[0].InnerText);
        }
        public void createCalendar(XmlDocument doc)
        {
            Console.WriteLine("nice");
            XmlNodeList titel = doc.GetElementsByTagName("name");

            Console.WriteLine(titel[0].InnerText);

            Calendarss calendarss = new Calendarss(); // connectie maken - service

            Calendarss.newCalendar(titel[0].InnerText);
        }
Esempio n. 5
0
        public static void testEvent()
        {
            GService g = new GService();
            // these always need to be changed before testing
            string uuid         = "UUIDTESTefefERezfzesefeKE12&";
            string uuid2        = "efeefefe";
            string uuid3        = "efefefefefef";
            string calendarName = "test12345634567VIJF";
            Person testPerson   = makePerson("testName2", "TestLastName", "*****@*****.**");

            Attendee.InewAttendee(testPerson, uuid, "1");
            IList <EventAttendee> attendees = new List <EventAttendee>();
            EventAttendee         test      = new EventAttendee()
            {
                //Email = "testname2",
                DisplayName = "*****@*****.**"
            };

            IList <string> UUIDS = new List <string>();

            UUIDS.Add(testPerson.UserDefined[0].Value);

            Console.WriteLine("attendee created");
            Console.ReadKey();

            //create event
            //create calendar
            var testCalendar = Calendarss.InewCalendar(makeCalendar(calendarName), uuid3, "1");

            DateTime start = new DateTime(2019, 5, 7, 14, 30, 0);
            DateTime end   = new DateTime(2019, 5, 7, 15, 30, 0);

            Google.Apis.Calendar.v3.Data.Event ev = makeEvent("1223432123HG23F2V32H2", "tesstlocation", "testDisc", start, end, convertPersonToAttendee(UUIDS));
            Eventss.InewEvent(ev, uuid3, uuid2, "1");
            Console.WriteLine("event created");
            Console.ReadKey();

            //update event
            ev.Summary = "newTestsSummery";

            Eventss.IupdateEventById(ev, uuid3, uuid2, "2");
            Console.WriteLine("event updated");
            Console.ReadKey();

            //delete event
            Eventss.IDeleteEventById(uuid2, uuid3);
            Calendarss.IdeleteCalendarById(uuid3);
            Console.WriteLine("event deleted");
            Console.ReadKey();
        }
Esempio n. 6
0
        // Delete a calendar using PlanningLibrary (layered code on google calendar)
        public void deleteCalendar(XmlDocument doc)
        {
            // Parsing data from XmlDocument
            XmlNodeList id = doc.GetElementsByTagName("UUID");

            // Logging parsed data
            Console.WriteLine(id[0].InnerText);

            // Delete a calendar, filled with parsed data from XmlDocument and finally sent with PlanningLibrary method.
            // Expects a UUID
            Calendarss.IdeleteCalendarById(id[0].InnerText);

            Console.WriteLine("Event successfully deleted");
            ControlRoom.SendConfirmationMessage("Planning: Event successfully deleted");
        }
Esempio n. 7
0
        // Sync all the cal triggers
        public static IList <CalendarListEntry> syncTriggers()
        {
            // Fetch all cals in order to refresh their triggers
            IList <CalendarListEntry> allCals = Calendarss.IgetAllCalendars();

            foreach (var cal in allCals)
            {
                if (cal.Id.Equals(calIgnore))
                {
                    continue;
                }

                // Create a new trigger to watch for event updates
                GService.service.Events.Watch(newChannel(String.Format("&calId={0}", cal.Id)), cal.Id).Execute();
            }

            return(allCals);
        }
Esempio n. 8
0
        // Update a calendar using PlanningLibrary (layered code on google calendar)
        public void updateCalendar(XmlDocument doc)
        {
            // Parsing data from XmlDocument
            XmlNodeList titel      = doc.GetElementsByTagName("eventName");
            XmlNodeList id         = doc.GetElementsByTagName("UUID");
            XmlNodeList xmlVersion = doc.GetElementsByTagName("version");

            // Logging parsed data
            Console.WriteLine(titel[0].InnerText);
            Console.WriteLine(id[0].InnerText);
            Console.WriteLine(xmlVersion[0].InnerText);

            // Creating a new <google.api> calendar to update an existing one, filled with parsed data from XmlDocument and finally sent with PlanningLibrary method.
            // Expects a <google.api> calendar, UUID, version
            Google.Apis.Calendar.v3.Data.Calendar calendar = new Google.Apis.Calendar.v3.Data.Calendar();
            calendar.Summary = titel[0].InnerText;
            Calendarss.IupdateCalendarById(calendar, id[0].InnerText, xmlVersion[0].InnerText);

            Console.WriteLine("Event successfully updated");
            ControlRoom.SendConfirmationMessage("Planning: Event successfully updated");
        }
Esempio n. 9
0
        public static void testCalendar()
        {
            GService g    = new GService();
            string   uuid = "testUUID3";
            //create calendar
            //!ALways change the UUID!
            var testCalendar = Calendarss.InewCalendar(makeCalendar("calTest"), uuid, "1");

            Console.WriteLine("calendar created");
            Console.ReadKey();

            //update Calendar
            testCalendar.Summary = "updateCalTest";
            Calendarss.IupdateCalendarById(testCalendar, uuid, "2");
            Console.WriteLine("calendar updated");
            Console.ReadKey();

            //delete Calendar
            Calendarss.IdeleteCalendarById(uuid);
            Console.WriteLine("calendar deleted");
            Console.ReadKey();
        }
        public void updateCalendar(XmlDocument doc)
        {
            XmlNodeList titel = doc.GetElementsByTagName("name");
            //XmlNodeList old_titel = doc.GetElementsByTagName("old_titel"); // not really needed
            XmlNodeList uuid = doc.GetElementsByTagName("id");

            if (uuid == null)
            {
                if (uuid[0].InnerText == String.Empty)
                {
                    uuid[0].InnerText = "primary";
                }
            }

            Console.WriteLine(titel[0].InnerText);
            //Console.WriteLine(old_titel[0].InnerText); // not really needed
            Console.WriteLine(uuid[0].InnerText);

            Calendarss calendarss = new Calendarss(); // connectie maken - service

            Calendarss.updateCalendarById(titel[0].InnerText, uuid[0].InnerText);
        }
Esempio n. 11
0
        // Create a calendar XML message
        public static string calMessage(CalendarListEntry cal)
        {
            string version = "";
            string uuid    = "";

            try
            {
                // Fetch data from the UUID master
                UUID uuidMaster = new UUID();

                // Check if the calendar exists or not; create or update the UUID
                try
                {
                    uuid = uuidMaster.GetUuidBy(7, cal.Id);

                    // uuid exists, so it is an update request -> check time name difference with
                    IdOutput output = JsonConvert.DeserializeObject <IdOutput>(uuidMaster.GetIdBy(uuid, 7));

                    // Delete detected
                    if (cal.Deleted == true)
                    {
                        // Event was made trough the interface, not us
                        version = (output.version + 1).ToString();
                    }
                    else
                    {
                        IdOutput name = JsonConvert.DeserializeObject <IdOutput>(uuidMaster.GetIdBy(String.Format("name-property-{0}", cal.Id), 7));

                        // Name change detected
                        if (!cal.Summary.Trim().Equals(name.id))
                        {
                            // update the name in the uuid master
                            uuidMaster.PutUpdateUUID(String.Format("name-property-{0}", cal.Id), cal.Summary.Trim(), Calendarss.getversion(String.Format("name-property-{0}", cal.Id)) + 1);

                            // Event was made trough the interface, not us
                            version = (output.version + 1).ToString();
                        }
                    }

                    if (version.Equals(output.version))
                    {
                        return("");
                    }

                    uuidMaster.PutUpdateUUID(uuid, cal.Id, Convert.ToInt32(version));
                }
                // UUID did not exist for the calendar, create it and make an entry for the calendar name
                catch (Exception e)
                {
                    // Create listener :)
                    GService.service.Events.Watch(KeySync.newChannel(String.Format("&calId={0}", cal.Id)), cal.Id).Execute();

                    uuid = uuidMaster.PutCreateUUID(cal.Id);
                    uuidMaster.PutUpdateUUID(String.Format("name-property-{0}", cal.Id), cal.Summary.Trim(), 1);

                    version = "1";
                }
            }
            catch (Exception e)
            {
                // Notify CR when something happens
                ControlRoom.SendErrorMessage("Google Calendar Sync Error", e.Message);
                return("");
            }

            // Construct the XML msg
            return("<message>" +
                   "<header><messageType>CreateEvent</messageType><description>CRUD of an event</description><sender>planning</sender></header>" +
                   "<datastructure>" +
                   "<UUID>" + uuid + "</UUID>" +
                   "<eventName>" + cal.Summary + "</eventName>" +
                   "<timestamp>" + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds() + "</timestamp>" +
                   "<isActive>" + (cal.Deleted == true ? "0" : "1") + "</isActive>" +
                   "<version>" + version + "</version>" +
                   "<extraField></extraField>" +
                   "</datastructure>" +
                   "</message>");
        }
Esempio n. 12
0
        public static void Main(string[] args)
        {
            new GService();

            // Create RMQ connection
            var factory = new ConnectionFactory()
            {
                HostName = ConfigurationManager.AppSettings["server"].ToString(), UserName = ConfigurationManager.AppSettings["username"].ToString(), Password = ConfigurationManager.AppSettings["password"].ToString(), Port = Convert.ToInt16(ConfigurationManager.AppSettings["port"].ToString())
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    // Configurating channel
                    channel.ExchangeDeclare(exchange: ConfigurationManager.AppSettings["exchange"].ToString(), type: ConfigurationManager.AppSettings["type"].ToString());
                    channel.QueueBind(queue: ConfigurationManager.AppSettings["queue"].ToString(), exchange: ConfigurationManager.AppSettings["exchange"].ToString(), routingKey: ConfigurationManager.AppSettings["routingKey"].ToString());

                    Console.WriteLine("[*] Waiting for messages.");

                    // Create a RMQ listener
                    var consumer = new EventingBasicConsumer(channel);

                    consumer.Received += (model, ea) =>
                    {
                        try
                        {
                            // Load in the the message
                            var message = Encoding.UTF8.GetString(ea.Body);
                            //check validity of message with controlroom nuget package / library
                            var valid = ControlRoom.CheckMessage(message);
                            Console.WriteLine("Message is valid: " + valid);
                            Console.WriteLine(" [x] {0}", message);

                            if (!valid)
                            {
                                throw new CleanException();
                            }

                            // Create a new xml doc to catch message
                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(message);

                            // Find out who the sender is and if it is set or not
                            // Discard any messages that we send ourselves so we do not create a loop
                            XmlNodeList xmlSender = doc.GetElementsByTagName("sender");
                            if (xmlSender.Count == 0 || xmlSender[0].InnerText.ToLower().Equals("planning"))
                            {
                                throw new CleanException();
                            }

                            // Get a the messageType, stop if we cannot find it
                            // Create a local messagetype variable (lower version)
                            XmlNodeList xmlMessageType = doc.GetElementsByTagName("messageType");
                            if (xmlMessageType.Count == 0)
                            {
                                throw new CleanException();
                            }

                            string messageType = xmlMessageType[0].InnerText.ToLower();

                            // Check if the message is supported or not
                            if (!messageTypes.Contains(messageType))
                            {
                                Console.WriteLine("Unsupported messageType found {0}", messageType);
                                throw new CleanException();
                            }

                            // Version checks & parsing, get the latest version from the UUID master
                            XmlNodeList xmlVersion = doc.GetElementsByTagName("version");
                            int         version    = 0;

                            XmlNodeList xmlUUID = doc.GetElementsByTagName("session_UUID");

                            if (xmlUUID.Count == 0)
                            {
                                xmlUUID = doc.GetElementsByTagName("UUID");
                            }

                            int latestVersion = Calendarss.getversion(xmlUUID[0].InnerText);

                            if (xmlVersion.Count > 0)
                            {
                                if (xmlVersion[0].InnerText != string.Empty)
                                {
                                    version = Convert.ToInt32(xmlVersion[0].InnerText);
                                }
                            }

                            // Check if we should discard the message or not
                            if (latestVersion >= version)
                            {
                                Console.WriteLine("Receiving old data, discarding; Received: {0} Latest: {1}", version, latestVersion);
                                throw new CleanException();
                            }

                            // IsActive checks & parsing
                            bool        isActive    = true;
                            XmlNodeList xmlIsActive = doc.GetElementsByTagName("isActive");
                            if (xmlIsActive.Count > 0)
                            {
                                if (xmlIsActive[0].InnerText != string.Empty)
                                {
                                    isActive = Convert.ToBoolean(Convert.ToInt16(xmlIsActive[0].InnerText));
                                }
                            }

                            Console.WriteLine("Trying to process a messageType {0}, with version {1} and active state of {2}", messageType, version, isActive);

                            // Picking up messageType (event/session/employee) with CRUD operation based off isActive/version
                            switch (messageType)
                            {
                            case "createevent":
                                if (isActive == false)
                                {
                                    new ReceiveMessage().deleteCalendar(doc);
                                    break;
                                }
                                else if (version == 1)
                                {
                                    new ReceiveMessage().createCalendar(doc);
                                    break;
                                }
                                else if (version > 1)
                                {
                                    new ReceiveMessage().updateCalendar(doc);
                                    break;
                                }

                                break;

                            case "createsession":
                                if (isActive == false)
                                {
                                    new ReceiveMessage().deleteEvent(doc);
                                    break;
                                }
                                else if (version == 1)
                                {
                                    new ReceiveMessage().createEvent(doc);
                                    break;
                                }
                                else if (version > 1)
                                {
                                    new ReceiveMessage().updateEvent(doc);
                                    break;
                                }
                                break;

                            case "createemployee":
                                if (isActive == false)
                                {
                                    new ReceiveMessage().deleteEmployee(doc);
                                    break;
                                }
                                else if (version == 1)
                                {
                                    new ReceiveMessage().createEmployee(doc);
                                    break;
                                }
                                else if (version > 1)
                                {
                                    new ReceiveMessage().updateEmployee(doc);
                                    break;
                                }

                                break;

                            default:
                                break;
                            }

                            // Nothing went wrong?! Good! Send an ack to RMQ
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                        }

                        catch (CleanException e)
                        {
                            // Nothing went wrong, we're just invalidating this message
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                        }
                        // Attendee overlay exception
                        catch (AttendeeOverlayException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Attendee overlay error", e.Message);
                        }
                        // Date is invalid
                        catch (DateExpception e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Invalid date error", e.Message);
                        }

                        catch (DeletedException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Delete error", e.Message);
                        }
                        // Duplication error
                        catch (DuplicationException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Duplication error", e.Message);
                        }
                        // Format error (could possibly appear with dates)
                        catch (FormatException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Formatting error", e.Message);
                        }
                        // Location overlaying with another
                        catch (LocationOverlayException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Location overlay error", e.Message);
                        }
                        // Unexpectedly could not delete
                        catch (NotDeletedException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Not deleted error", e.Message);
                        }
                        // Not found exception
                        catch (NotFoundException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Not found error", e.Message);
                        }
                        // Requirements do not match
                        catch (RequirementsNotMetcs e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Requirements not met error", e.Message);
                        }
                        // Server error
                        catch (ServerFault e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Server error", e.Message);
                        }
                        // Wrong version of message (got vers < curr vers)
                        catch (WrongVersionException e)
                        {
                            // Something went wrong, we're just invalidating this message & notifying the CR
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            ControlRoom.SendErrorMessage("Planning Wrong version error", e.Message);
                        }

                        //all exceptions catcher
                        catch (Exception e)
                        {
                            Console.WriteLine(e.StackTrace);

                            // In case something goes wrong...
                            //channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: false);
                            ControlRoom.SendErrorMessage("Planning Receiver error", e.Message);
                        }
                    };

                    channel.BasicConsume(queue: ConfigurationManager.AppSettings["queue"].ToString(), autoAck: Convert.ToBoolean(ConfigurationManager.AppSettings["autoAck"].ToString()), consumer: consumer);
                    Console.WriteLine("Press any key to exit planning RabbitMQ receiver");
                    Console.ReadKey(true);
                }
        }