Exemple #1
0
        public void getAndDeleteAppointment(int id)
        {
            #region get appointment
            string appstring = wc.DownloadString("https://progenda.be/api/v2/calendars/" + calendar_ID +
                                                 "/appointments/" + id + "?user_email=" + email + "&user_token=" + token);
            Appointment  app2         = JsonConvert.DeserializeObject <Appointment>(appstring);
            Appointment2 appointment2 = app2.appointment;
            #endregion

            #region delete appointment
            WebRequest request = WebRequest.Create("https://progenda.be/api/v2/calendars/" + calendar_ID +
                                                   "/appointments/" + id + "?user_email=" + email + "&user_token=" + token);
            request.Method = "DELETE";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (appointment2.patient_id != null)
            {
                PatientInformation.MakeFile(app2, center_ID, email, token, calendar_ID);
            }
            #endregion
        }
Exemple #2
0
        public void GoogleCalendar()
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("primary");
            request.TimeMin      = DateTime.Now;
            request.ShowDeleted  = false;
            request.SingleEvents = true;
            request.MaxResults   = 10;
            request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.

            string email       = "*****@*****.**";
            string token       = "aLYj5i2DnGcqYSrW4OvdBrdbClI7j/hKpXeZyl0dzLw=";
            int    calendar_ID = 6599;


            Events events = request.Execute();

            Console.WriteLine("Upcoming events:");
            if (events.Items != null && events.Items.Count > 0)
            {
                foreach (var eventItem in events.Items)
                {
                    string when = eventItem.Start.DateTime.ToString();
                    string end  = eventItem.End.DateTime.ToString();
                    string id   = eventItem.Id;
                    if (String.IsNullOrEmpty(when))
                    {
                        when = eventItem.Start.Date;
                        end  = eventItem.End.Date;
                    }
                    Console.WriteLine("{0}", id);
                    Console.WriteLine("{0} (startdate: {1} enddate: {2})", eventItem.Summary, when, end);
                    Appointment2 a = new Appointment2();
                    a.remote_id = id;
                    a.start     = (Int32)ToUnixTime((DateTime)eventItem.Start.DateTime);
                    a.stop      = (Int32)ToUnixTime((DateTime)eventItem.End.DateTime);
                    a.notes     = "true";
                    a.title     = eventItem.Summary;
                    a.color     = "#FFEB3B";
                    a.status    = "booked";

                    try {
                        WebClient wc = new WebClient();
                        wc.Headers.Add("Content-Type", "application/json");
                        string body          = "{\"appointment\":{\"start\":\"" + a.start + "\", \"stop\":\"" + a.stop + "\", \"remote_id\":\"" + a.remote_id + "\", \"notes\":\"" + a.notes + "\", \"title\":\"" + a.title + "\", \"color\":\"" + a.color + "\"}}";
                        byte[] postArray     = Encoding.ASCII.GetBytes(body);
                        string url           = "https://progenda.be/api/v2/calendars/" + calendar_ID + "/appointments?user_email=" + email + "&user_token=" + token;
                        byte[] responseArray = wc.UploadData(url, "POST", postArray);
                    } catch (Exception) {
                        try {
                            WebClient w = new WebClient();
                            w.Headers.Add("Content-Type", "application/json");
                            string body          = "{\"appointment\":{\"start\":\"" + a.start + "\", \"stop\":\"" + a.stop + "\", \"remote_id\":\"" + a.remote_id + "\", \"notes\":\"" + a.notes + "\", \"title\":\"" + a.title + "\", \"color\":\"" + a.color + "\", \"status\":\"" + a.status + "\"}}";
                            byte[] postArray     = Encoding.ASCII.GetBytes(body);
                            string url           = "https://progenda.be/api/v2/calendars/" + calendar_ID + "/appointments/remote_id:" + a.remote_id + "?user_email=" + email + "&user_token=" + token;
                            byte[] responseArray = w.UploadData(url, "PUT", postArray);
                        } catch (Exception) {
                            break;
                        }
                    }
                }
            }
        }