public static int addEvent(ImproperCalendarEvent improperEvent)
        {
            CalendarEvent cevent = new CalendarEvent()
            {
                title       = improperEvent.title,
                description = improperEvent.description,
                start       = Convert.ToDateTime(improperEvent.start),
                end         = Convert.ToDateTime(improperEvent.end),
                allDay      = improperEvent.allDay
            };

            if (CheckAlphaNumeric(cevent.title) && CheckAlphaNumeric(cevent.description))
            {
                int key = CalendarConnection.addEvent(cevent);

                List <int> idList = (List <int>)System.Web.HttpContext.Current.Session["idList"];

                if (idList != null)
                {
                    idList.Add(key);
                }

                return(key); //return the primary key of the added cevent object
            }

            return(-1); //return a negative number just to signify nothing has been added
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            DateTime start = Convert.ToDateTime(context.Request.QueryString["start"]);
            DateTime end   = Convert.ToDateTime(context.Request.QueryString["end"]);

            List <int> idList = new List <int>();
            List <ImproperCalendarEvent> tasksList = new List <ImproperCalendarEvent>();

            //Generate JSON serializable events
            foreach (CalendarEvent cevent in CalendarConnection.getEvents(start, end))
            {
                tasksList.Add(new ImproperCalendarEvent
                {
                    id          = cevent.id,
                    title       = cevent.title,
                    start       = String.Format("{0:s}", cevent.start),
                    end         = String.Format("{0:s}", cevent.end),
                    description = cevent.description,
                    allDay      = cevent.allDay,
                    status      = cevent.status
                });
                idList.Add(cevent.id);
            }

            context.Session["idList"] = idList;

            //Serialize events to string
            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string sJSON = oSerializer.Serialize(tasksList);

            //Write JSON to response object
            context.Response.Write(sJSON);
        }
Ejemplo n.º 3
0
        public async static Task Run([TimerTrigger("*/15 * * * * *")] TimerInfo myTimer, ILogger log, ExecutionContext context)
        {
            ServiceClient serviceClient;
            string        connectionString = "HostName=OnAirCalendar.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=2840VypKT55Hbm603+5EEN7BP2FHsoaw2UftJVaJXIg=";
            string        targetDevice     = "arduino";

            serviceClient = ServiceClient.CreateFromConnectionString(connectionString);
            Status status = CalendarConnection.GetStatus(log, context);
            string color  = GetColorString(status);

            log.LogInformation($"Status: {status}");
            var commandMessage = new Message(Encoding.ASCII.GetBytes(color));
            await serviceClient.SendAsync(targetDevice, commandMessage);
        }
        public static String deleteEvent(int id)
        {
            //idList is stored in Session by JsonResponse.ashx for security reasons
            //whenever any event is update or deleted, the event id is checked
            //whether it is present in the idList, if it is not present in the idList
            //then it may be a malicious user trying to delete someone elses events
            //thus this checking prevents misuse
            List <int> idList = (List <int>)System.Web.HttpContext.Current.Session["idList"];

            if (idList != null && idList.Contains(id))
            {
                CalendarConnection.deleteEvent(id);
                return("deleted event with id:" + id);
            }

            return("unable to delete event with id: " + id);
        }
        public static string UpdateEventTime(ImproperCalendarEvent improperEvent)
        {
            List <int> idList = (List <int>)System.Web.HttpContext.Current.Session["idList"];

            if (idList != null && idList.Contains(improperEvent.id))
            {
                CalendarConnection.updateEventTime(improperEvent.id,
                                                   Convert.ToDateTime(improperEvent.start),
                                                   Convert.ToDateTime(improperEvent.end),
                                                   improperEvent.allDay); //allDay parameter added for FullCalendar 2.x

                return("updated event with id:" + improperEvent.id + " update start to: " + improperEvent.start +
                       " update end to: " + improperEvent.end);
            }

            return("unable to update event with id: " + improperEvent.id);
        }
        public static string UpdateEvent(CalendarEvent cevent)
        {
            List <int> idList = (List <int>)System.Web.HttpContext.Current.Session["idList"];

            if (idList != null && idList.Contains(cevent.id))
            {
                if (CheckAlphaNumeric(cevent.title) && CheckAlphaNumeric(cevent.description))
                {
                    CalendarConnection.updateEvent(cevent.id, cevent.title, cevent.description);

                    return("updated event with id:" + cevent.id + " update title to: " + cevent.title +
                           " update description to: " + cevent.description);
                }
            }

            return("unable to update event with id:" + cevent.id + " title : " + cevent.title +
                   " description : " + cevent.description);
        }