// Function for sending protobuf object
        private void SendDistEvent(CalEvent objCalEvent)
        {
            DistCalendarEvent objDistEvent = new DistCalendarEvent();

            try
            {
                objDistEvent.id       = objCalEvent.ID;
                objDistEvent.type     = (DistCalendarEvent.EventType)Enum.Parse(typeof(DistCalendarEvent.EventType), objCalEvent.EventType.ToString());
                objDistEvent.title    = objCalEvent.Title;
                objDistEvent.location = objCalEvent.Location;
                objDistEvent.date     = (long)(objCalEvent.DateofEvent - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds;

                if (objCalEvent.IsAllDay == false)
                {
                    objDistEvent.start_time = objCalEvent.StartTime.ToString();
                    objDistEvent.end_time   = objCalEvent.EndTime.ToString();
                }
                else
                {
                    objDistEvent.allday = objCalEvent.IsAllDay;
                }

                Program.calendarPub.SendObject(objDistEvent);
            }
            catch (Exception ex)
            {
                objDistEvent  = new DistCalendarEvent();
                lblError.Text = ex.Message;
            }
        }
Beispiel #2
0
        public void ReceiveObject(object obj, org.umundo.core.Message msg)
        {
            DistCalendarEvent distEventObj = (DistCalendarEvent)obj;

            if (distEventObj != null)
            {
                frmCalendarMain.ReceiveDistEvent(distEventObj);
                frmCalendarMain.notifyStatus = "Event Object Received!";
            }
        }
Beispiel #3
0
        static void Main()
        {
            string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;

            string dllPath = projectPath + "\\dlls";

            if (System.Environment.Is64BitProcess)
            {
                SetDllDirectory(dllPath + "\\csharp64");
            }
            else
            {
                SetDllDirectory(dllPath + "\\csharp");
            }

            calendarNode = new Node();
            calendarRcv  = new CalendarReceiver();
            calendarSub  = new TypedSubscriber("s11nCalendar");
            calendarSub.setReceiver(calendarRcv);
            calendarPub = new TypedPublisher("s11nCalendar");

            DistCalendarEvent eventObj = new DistCalendarEvent();

            calendarSub.RegisterType(eventObj.GetType().Name, eventObj.GetType());

            calendarNode.addPublisher(calendarPub);
            calendarNode.addSubscriber(calendarSub);

            disc = new Discovery(Discovery.DiscoveryType.MDNS);
            disc.add(calendarNode);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmCalendarMain());

            calendarNode.removePublisher(calendarPub);
            calendarNode.removeSubscriber(calendarSub);
            disc.remove(calendarNode);
            System.GC.Collect();
        }
        // Function for receiving protobuf object
        public static void ReceiveDistEvent(DistCalendarEvent distEventObj)
        {
            CalEvent newCalEventObj = new CalEvent();

            try
            {
                // Getting values from the rcv object
                newCalEventObj.ID        = distEventObj.id;
                newCalEventObj.EventType = (CalEventType)Enum.Parse(typeof(CalEventType), distEventObj.type.ToString());
                newCalEventObj.Title     = distEventObj.title;
                newCalEventObj.Location  = distEventObj.location;
                newCalEventObj.IsAllDay  = distEventObj.allday;

                if (distEventObj.date != 0)
                {
                    long     milliSec    = distEventObj.date;
                    DateTime time        = new DateTime(1970, 1, 1, 0, 0, 0);
                    DateTime currentTime = time.AddMilliseconds(milliSec);
                    newCalEventObj.DateofEvent = currentTime;
                }

                if (distEventObj.allday == false)
                {
                    newCalEventObj.StartTime = DateTime.Parse(distEventObj.start_time).TimeOfDay;
                    newCalEventObj.EndTime   = DateTime.Parse(distEventObj.end_time).TimeOfDay;
                }

                CalEventList.Add(newCalEventObj);

                notifyStatus = "Event Notification Received! ";
            }
            catch (Exception ex)
            {
                notifyStatus = ex.Message;
            }
        }