Beispiel #1
0
        /*static Event newEvent = new Event()
         * {
         *  //Summary = "Google I/O 2015",
         *  //Location = "800 Howard St., San Francisco, CA 94103",
         *  //Description = "A chance to hear more about Google's developer products.",
         *
         *
         *  Start = new EventDateTime()
         *  {
         *      //DateTime = DateTime.Parse("2017-06-22T09:00:00-07:00"),
         *      DateTime = new DateTime(2017, 6, 21, 7, 0, 0),
         *      TimeZone = "Europe/Moscow",
         *  },
         *  End = new EventDateTime()
         *  {
         *      //DateTime = DateTime.Parse("2017-06-22T17:00:00-07:00"),
         *      DateTime = new DateTime(2017, 06, 21, 21, 0, 0),
         *      TimeZone = "Europe/Moscow",
         *  }
         * };*/
        public int cal_event(Statement St)
        {
            ServiceAccountCredential credential = GetUserCredential();
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });
            Event newEvent = new Event();

            newEvent.Location = St.Location;
            try
            {
                newEvent.Start = new EventDateTime()
                {
                    DateTime = DateTime.Parse(St.Day + "T" + St.Event_Begin), TimeZone = "Europe/Moscow"
                };
                newEvent.End = new EventDateTime()
                {
                    DateTime = DateTime.Parse(St.Day + "T" + St.Event_End), TimeZone = "Europe/Moscow"
                };
            }
            catch (Exception)
            {
                return(1);
            }
            newEvent.Summary = "На рассмотрении " + St.Name + " " + St.Phone + " " + St.Organization + " " + St.Summary;
            String calendarId = "*****@*****.**";

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
            Event createdEvent = request.Execute();

            return(0);
        }
Beispiel #2
0
        private void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            Event newEvent = createEventBody();

            addAttendees(newEvent);

            if (newEvent != null)
            {
                try
                {
                    EventsResource.InsertRequest insReq = new EventsResource.InsertRequest(myService, newEvent, "primary");
                    insReq.SendNotifications = true;
                    insReq.Execute();

                    if (newEvent.Summary == null)
                    {
                        MessageBox.Show("A new event will be added to your calendar that will start at " + newEvent.Start.DateTime.ToString());
                    }
                    else
                    {
                        MessageBox.Show("A new event, titled \"" + newEvent.Summary + "\", will be added to your calendar that will take place from " + newEvent.Start.DateTime.ToString() + " to " + newEvent.End.DateTime.ToString());
                    }
                }
                catch (Google.GoogleApiException)
                {
                    MessageBox.Show("An invalid time range has been entered. Please make sure your start date occurs before your end date.");
                }

                setReadRequest();
                EventListBox.DataContext = request.Execute();
            }
        }
Beispiel #3
0
        // Methode um *GANZTÄGIGE* Kalendereinträge vorzunehmen (Von AktionsObjekt vorgegebener ID-String)
        public String kalenderEventEintragGanz(String titel, String text, String location, int Farbe, DateTime Start, DateTime Ende, String ID)
        {
            Event toAdd = new Event()
            {
                Summary     = titel,
                Description = text,
                Start       = new EventDateTime()
                {
                    Date = Start.Year + "-" + Start.Month + "-" + Start.Day,
                },
                End = new EventDateTime()
                {
                    Date = Ende.Year + "-" + Ende.Month + "-" + Ende.Day,
                },
                ColorId  = Farbe.ToString(),
                Location = location,
                Id       = ID
            };

            String calendarId = "primary";

            EventsResource.InsertRequest request = dienst.Events.Insert(toAdd, calendarId);
            Event createdEvent = request.Execute();

            return(ID);
        }
Beispiel #4
0
        // Methode um Kalendereinträge vorzunehmen (Von AktionsObjekt vorgegebener ID-String)
        public String kalenderEventEintrag(String titel, String text, int Farbe, DateTime Start, DateTime Ende, String ID)
        {
            Event test = new Event()
            {
                Summary     = titel,
                Description = text,
                Start       = new EventDateTime()
                {
                    DateTime = Start
                },
                End = new EventDateTime()
                {
                    DateTime = Ende
                },
                ColorId = Farbe.ToString(),
                Id      = ID
            };

            String calendarId = "primary";

            EventsResource.InsertRequest request = dienst.Events.Insert(test, calendarId);
            Event createdEvent = request.Execute();

            return(ID);
        }
Beispiel #5
0
        public static void CreateGoogleCalendarEvent(string title, DateTime startTime, DateTime endTime, string calendar)
        {
            AuthorizeGoogleCalendar();

            CalendarListResource.ListRequest calRequest = calendarService.CalendarList.List();
            calRequest.MinAccessRole = CalendarListResource.ListRequest.MinAccessRoleEnum.Owner;
            CalendarList calendars = calRequest.Execute();

            CalendarListEntry reminderCalendar = calendars.Items.Where(p => p.Summary == calendar).FirstOrDefault();

            Event newReminderEvent = new Event()
            {
                Summary = title
            };

            newReminderEvent.Start = new EventDateTime()
            {
                DateTime = startTime
            };
            newReminderEvent.End = new EventDateTime()
            {
                DateTime = endTime
            };

            EventsResource.InsertRequest createRequest = calendarService.Events.Insert(newReminderEvent, reminderCalendar.Id);
            createRequest.Execute();
        }
        public string CreateGoogleCalendarEvent(Event newEvent)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                var pathString = "Credential file saved to: " + credPath;
            }

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

            String calendarId = "primary";

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
            Event createdEvent = request.Execute();

            return(string.Format(createdEvent.HtmlLink));
        }
        /*
         * Method that adds an event to the Google Calendar
         * Summary - string : Enter a summary of the event (Title)
         * Location - string : Enter the location of the event, if there's no location provide an empty string
         * Description - string : Enter a description of the event, if there's no description provide an empty string
         * startDateTime - string : Enter the datetime when the event starts in a format parsable by DateTime
         * endDateTime - string : Enter the datetime when the event ends in a format parsable by DateTime
         */
        public void createEvent(string summary, string location, string description, string startDateTime, string endDateTime)
        {
            Event newEvent = new Event()
            {
                Summary     = summary,
                Location    = location,
                Description = description,
                Start       = new EventDateTime()
                {
                    DateTime = DateTime.Parse(startDateTime),
                    TimeZone = "Europe/Amsterdam",
                },
                End = new EventDateTime()
                {
                    DateTime = DateTime.Parse(endDateTime),
                    TimeZone = "Europe/Amsterdam",
                },
            };
            String calendarId = "primary";

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
            Event createdEvent = request.Execute();

            updateEvents();
        }
        private void createEvent(CalendarService service, String summary, String location, EventDateTime start, EventDateTime end, String desc)
        {
            // Refer to the .NET quickstart on how to setup the environment:
            // https://developers.google.com/calendar/quickstart/dotnet
            // Change the scope to CalendarService.Scope.Calendar and delete any stored
            // credentials.
            Event newEvent = new Event()
            {
                Summary     = summary,
                Location    = location,
                Description = desc,
                Start       = start,
                End         = end,
            };
            String calendarId = "primary";

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
            Event createdEvent = request.Execute();

            Console.WriteLine("Event created: {0}", createdEvent.HtmlLink);

            String startDate = start.DateTime.ToString().Split(' ')[0];
            String startTime = start.DateTime.ToString().Split(' ')[1];

            Console.WriteLine("Summary: " + summary +
                              "\nLocation: " + location +
                              "\nDescription: " + desc +
                              "\nStart: " + start.DateTime.ToString() +
                              "\nEnd: " + end.Date);
            t.Speak("Evento " + summary + " criado no dia " + startDate + " às " + startTime);
        }
Beispiel #9
0
        public void CreateEvent(String title, String[] participants, DateTime startDateTime, DateTime finishDateTime)
        {
            UserCredential  credential = GetCredential(UserRole.Admin);
            CalendarService service    = GetService(credential);

            Event newEvent = new Event()
            {
                Summary = title,
                Start   = new EventDateTime()
                {
                    DateTime = startDateTime
                },
                End = new EventDateTime()
                {
                    DateTime = finishDateTime
                },
                Attendees = new List <EventAttendee>()
            };

            foreach (var participant in participants)
            {
                var attendee = new EventAttendee
                {
                    Email = participant
                };
                newEvent.Attendees.Add(attendee);
            }

            string calendarId = "primary";

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
            request.SendNotifications = true;
            Event createdEvent = request.Execute();
        }
Beispiel #10
0
        public async Task AddEvent(CommandContext ctx, string date, params string[] name)
        {
            CalendarCredentials CalCred = new CalendarCredentials();

            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = CalCred.credential,
                ApplicationName       = CalendarCredentials.ApplicationName,
            });

            Event newEvent = new Event()
            {
                Summary = GetNameFromArray(name),
                Start   = new EventDateTime()
                {
                    Date = date
                },
                End = new EventDateTime()
                {
                    Date = date
                },
            };

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, "primary");
            Event createdEvent = request.Execute();
            await ctx.RespondAsync("Az esemény el lett tárolva.");
        }
        public override Event InserirEvento(string titulo, DateTime dataInicial, DateTime dataFinal, string calendarId)
        {
            Event ev = CriarEvento(titulo, dataInicial, dataFinal);

            EventsResource.InsertRequest request = CalendarService.Events.Insert(ev, calendarId);
            return(request.Execute());
        }
        static void AddCalendarEvent(CalendarEvent oCalEvent)
        {
            UserCredential credential;

            using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "admin",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

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

            Event evntNew = new Event();

            evntNew.Summary     = oCalEvent.Summary;
            evntNew.Location    = oCalEvent.Location;
            evntNew.Description = oCalEvent.Description;
            evntNew.Start       = oCalEvent.Start.ToEventDateTime();
            evntNew.End         = oCalEvent.Stop.ToEventDateTime();
            EventsResource.InsertRequest insertRequest = service.Events.Insert(evntNew, "primary");
            insertRequest.Execute();
        }
        private void CreateEvent(CalendarService _service, string UserEmail)
        {
            Event         body = new Event();
            EventAttendee a    = new EventAttendee();

            a.Email = "*****@*****.**";
            List <EventAttendee> attendes = new List <EventAttendee>();

            attendes.Add(a);
            body.Attendees = attendes;
            EventDateTime start   = new EventDateTime();
            string        iString = "2020-05-30 06:12 PM";
            DateTime      oDate   = DateTime.ParseExact(iString, "yyyy-MM-dd hh:mm tt", System.Globalization.CultureInfo.InvariantCulture);

            start.DateTime = oDate;

            EventDateTime end      = new EventDateTime();
            string        ieString = "2020-05-30 08:12 PM";
            DateTime      oeDate   = DateTime.ParseExact(ieString, "yyyy-MM-dd hh:mm tt", System.Globalization.CultureInfo.InvariantCulture);

            end.DateTime = oeDate;

            body.Start    = start;
            body.End      = end;
            body.Location = "Newberg, OR 97132, USA";
            body.Summary  = "Video ";
            // body.Description = "prayag";
            EventsResource.InsertRequest request = new EventsResource.InsertRequest(_service, body, UserEmail);
            Event response = request.Execute();
        }
        public Boolean CreateEvent(Event evento)
        {
            try
            {
                EventsResource.InsertRequest request = service.Events.Insert(evento, "primary");
                var respuesta = request.Execute();
                if (ConfiguracionAplicacion.Default.Idioma.Equals("ES"))
                {
                    MessageBox.Show("Evento introducido exitosamente");
                }
                else
                {
                    MessageBox.Show("The event has been added sucessfully");
                }
                return(true);
            }
            catch (Exception e)
            {
                if (ConfiguracionAplicacion.Default.Idioma.Equals("ES"))
                {
                    MessageBox.Show("Hubo un error " + e);
                }
                else
                {
                    MessageBox.Show("There was an error " + e);
                }
                return(false);

                throw;
            }
        }
Beispiel #15
0
        public static void CreateEvent(CalendarService service)
        {
            // https://developers.google.com/calendar/v3/reference/events/insert
            Event NewEvent = new Event();

            NewEvent.GuestsCanInviteOthers = true;
            NewEvent.Location = "In the middle of no where";
            EventDateTime StartTime = new EventDateTime();

            StartTime.TimeZone    = "America/Chicago";
            StartTime.DateTimeRaw = ExtendedMethods.ToRfc3339String(new DateTime(2020, 07, 14, (10 + 5), 00, 00));
            NewEvent.Start        = StartTime;
            EventDateTime EndTime = new EventDateTime();

            EndTime.DateTimeRaw   = ExtendedMethods.ToRfc3339String(new DateTime(2020, 07, 14, (11 + 5), 00, 00));
            NewEvent.End          = EndTime;
            NewEvent.Summary      = "This is a super important meeting";
            NewEvent.Transparency = "transparent";
            List <EventAttendee> attendees = new List <EventAttendee>()
            {
                new EventAttendee {
                    DisplayName = "Ben", Email = "*****@*****.**", Organizer = true
                },
                new EventAttendee {
                    DisplayName = "Benjamin", Email = "*****@*****.**",
                }
            };

            NewEvent.Attendees = attendees;
            EventsResource.InsertRequest InsertEvent = service.Events.Insert(NewEvent, "*****@*****.**");
            InsertEvent.Execute();
        }
        public static void InsertGoogleAPIEvent(GoogleAccountRequest googleRequest)
        {
            try
            {
                Authenticate(googleRequest);
                CalendarService service = InitService();

                MyCalendarEvent myEvent  = googleRequest.CalendarEvent;
                Event           newEvent = new Event()
                {
                    Summary     = myEvent.SummaryText,
                    Location    = myEvent.LocationText,
                    Description = myEvent.Description,
                    Start       = new EventDateTime()
                    {
                        DateTime = myEvent.BeginDate,
                        TimeZone = IsraelDefaultTimeZone,
                    },
                    End = new EventDateTime()
                    {
                        DateTime = myEvent.EndDate,
                        TimeZone = IsraelDefaultTimeZone,
                    },


                    Reminders = new Event.RemindersData()
                    {
                        UseDefault = false,
                        Overrides  = new EventReminder[]
                        {
                            new EventReminder()
                            {
                                Method = "popup", Minutes = 24 * 60
                            },
                            new EventReminder()
                            {
                                Method = "popup", Minutes = 15
                            },
                            new EventReminder()
                            {
                                Method = "popup", Minutes = 3 * 60
                            },
                        }
                    }
                };
                if (!string.IsNullOrEmpty(myEvent.Frequency) && myEvent.FrequencyCount > 0)
                {
                    newEvent.Recurrence = new String[] { $"RRULE:FREQ={myEvent.Frequency};COUNT={myEvent.FrequencyCount}" }
                }
                ;

                String calendarId = "primary";
                EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
                Event createdEvent = request.Execute();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public CalendarEventParam InsertEvent(CalendarEventParam calendar)
        {
            CalendarService service = new CalendarService(new BaseClientService.Initializer()//new Service
            {
                HttpClientInitializer = credential
            });

            newEvent = new Event()
            {
                Summary     = calendar.summary,//Title of the event.
                Location    = calendar.location,
                Description = calendar.description,
                Start       = new EventDateTime()
                {
                    DateTime = DateTime.Parse(calendar.start_date_time),
                },
                End = new EventDateTime()
                {
                    DateTime = DateTime.Parse(calendar.end_date_time),
                }
            };
            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendar.calendar_id);

            Event createdEvent = request.Execute();

            return(calendar);
        }
Beispiel #18
0
        /// <summary>
        /// Inserts the event.
        /// </summary>
        /// <param name="calendarService">The calendar service.</param>
        /// <param name="newEvent">The new event.</param>
        public Event InsertEvent(
            CalendarService calendarService,
            Event newEvent)
        {
            EventsResource.InsertRequest request = calendarService.Events.Insert(newEvent, DefaultCalendarId);

            return(request.Execute());
        }
        public void CreateEvent(Event newEvent, string calendarId)
        {
            //String calendarId = "primary";
            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
            Event createdEvent = request.Execute();

            Console.WriteLine("Event created: {0}", createdEvent.HtmlLink);
        }
        // capture event ID after inserting
        public static string insertEvent(Event entry)
        {
            var service = getCalendarService();

            EventsResource.InsertRequest insert = service.Events.Insert(entry, calendarname);
            // TODO: try catch here; will be throw exception if bad datetime
            return(insert.Execute().Id);
        }
        private void InsertNewEvent(CalendarService service, string eventName, string description, string startDate, string endDate, string location, string teacher, string group, EventAttendee[] mails)
        {
            Event.ExtendedPropertiesData exProp = new Event.ExtendedPropertiesData {
                Shared = new Dictionary <string, string> {
                    { "GroupName", @group }
                }
            };

            Event newEvent = new Event()
            {
                Summary     = eventName,
                Location    = location,
                Description = description,
                Start       = new EventDateTime()
                {
                    DateTime = DateTime.Parse(startDate),
                    TimeZone = "Europe/Moscow",
                },
                End = new EventDateTime()
                {
                    DateTime = DateTime.Parse(endDate),
                    TimeZone = "Europe/Moscow",
                },
                ExtendedProperties = exProp,
                //Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" },

                /*Organizer = new Event.OrganizerData()
                 * {
                 *  DisplayName = teacher,
                 *  Email = teacher,
                 *  Self = false
                 * },*/
                Attendees = mails
                ,
                Reminders = new Event.RemindersData()
                {
                    UseDefault = false,
                    Overrides  = new EventReminder[] {
                        new EventReminder()
                        {
                            Method = "email", Minutes = 24 * 60
                        },
                        new EventReminder()
                        {
                            Method = "email", Minutes = 1 * 60
                        },
                        //new EventReminder() { Method = "sms", Minutes = 10 },
                    }
                },
            };

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, CalendarId);
            request.SendNotifications = true;
            Event createdEvent = request.Execute();

            richTextBox2.Text = richTextBox2.Text + "Event '" + createdEvent.Summary + "' created: " + createdEvent.HtmlLink + '\n';
            Thread.Sleep(1000);
        }
        public void CreateEvent(DateTime date, string roomName, string name, string phone, string email, string googleCredPath)
        {
            var myEventStart = new EventDateTime();

            myEventStart.DateTime = date;
            myEventStart.TimeZone = _settings.TimeZone;

            var myEventEnd = new EventDateTime();

            myEventEnd.DateTime = date.AddHours(1);
            myEventEnd.TimeZone = _settings.TimeZone;
            var reminders = new Event.RemindersData()
            {
                UseDefault = false,
                Overrides  = new EventReminder[] {
                    new EventReminder()
                    {
                        Method = "email", Minutes = 2 * 60
                    },
                    new EventReminder()
                    {
                        Method = "popup", Minutes = 60
                    }
                }
            };



            var myEvent = new Event();

            myEvent.Summary     = $"Interview - {name}";
            myEvent.Description = $"{name}, {email}, {phone}";
            myEvent.Start       = myEventStart;
            myEvent.End         = myEventEnd;
            myEvent.Location    = $"Kolektif House - Maslak, {roomName}";
            myEvent.Reminders   = reminders;

            //File.AppendAllText("googleCalendar.txt", JsonConvert.SerializeObject(myEvent));

            UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                new ClientSecrets {
                ClientId     = _settings.ClientId,
                ClientSecret = _settings.ClientSecret,
            },
                new[] { CalendarService.Scope.Calendar },
                "user",
                CancellationToken.None, new FileDataStore(googleCredPath)).Result;

            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = _settings.ApplicationName,
            });

            EventsResource.InsertRequest request = service.Events.Insert(myEvent, _settings.CalendarId);
            Event createdEvent = request.Execute();
        }
Beispiel #23
0
        private async void insertevent()
        {
            UserData user = (UserData)Session["User"];



            UserCredential credential;

            using (var stream =
                       new FileStream(Server.MapPath("client_secret.json"), FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);;
                credPath = Path.Combine(credPath, ".credentials/calendarinsert-dotnet-quickstart.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,
            });

            CalendarService cs = service;



            Event newEvent = new Event()
            {
                Summary     = "Project: " + txtprojname.Value.ToString(),
                Location    = "On Fincal",
                Description = txtmeetd.Value.ToString(),
                Start       = new EventDateTime()
                {
                    DateTime = DateTime.Parse(XmlConvert.ToString(DateTime.Parse(txtmeetdate.Value.ToString()), XmlDateTimeSerializationMode.Utc)), //DateTime.pr dt.ToUniversalTime().ToString("YYYY-MM-DD'T'HH:mm:ssZ"),
                    TimeZone = "Europe/Paris",
                },
                End = new EventDateTime()
                {
                    DateTime = DateTime.Parse(XmlConvert.ToString(DateTime.Parse(txtmeetdate.Value.ToString()), XmlDateTimeSerializationMode.Utc)),

                    TimeZone = "Europe/Paris",
                },
            };



            String calendarId = "primary";

            EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
            Event newevent = await request.ExecuteAsync();
        }
Beispiel #24
0
        private static void AddEventsToCalendar(List <Event> events)
        {
            string calendarId = "primary";
            var    service    = GetRequestService();

            foreach (var e in events)
            {
                EventsResource.InsertRequest request = service.Events.Insert(e, calendarId);
                request.Execute();
            }
        }
Beispiel #25
0
 private static void tryExecuteEvent(EventsResource.InsertRequest gEvent, int tries)
 {
     for (int i = 0; i < tries; i++)
     {
         try
         {
             gEvent.Execute();
             return;
         }
         catch { };
     }
 }
        public async Task <string> AddEvent(Event e, string calendar = "primary")
        {
            if (calService == null)
            {
                await Auth(EditScopes);
            }

            EventsResource.InsertRequest req = calService.Events.Insert(e, calendar);
            var ev = await req.ExecuteAsync();

            return(ev.Id);
        }
Beispiel #27
0
        public void GoogleSender()
        {
            for (int i = 0; i < ListPost.Count; i++)
            {
                UserCredential credential;

                using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
                {
                    string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                    credPath   = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result;
                }

                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential, ApplicationName = ApplicationName,
                });

                {
                    E.Add(new EventReminder {
                        Method = "popup", Minutes = Convert.ToInt32(frm.ReminderMinutes),
                    });

                    Event newEvent = new Event()
                    {
                        Summary = ListPost[i],

                        Start = new EventDateTime()
                        {
                            DateTime = DateTime.Parse(ListStart[i]),
                        },

                        End = new EventDateTime()
                        {
                            DateTime = DateTime.Parse(ListEind[i]),
                        },

                        Location = "BEATRIJSLAAN 100, 2050 ANTWERPEN",

                        Reminders = new Event.RemindersData()
                        {
                            Overrides  = E,
                            UseDefault = false,
                        },
                    };

                    String calendarId = "primary";
                    EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
                    Event createdEvent = request.Execute();
                }
            }
        }
        public ActionResult NewEvent(EventModel model)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream(@"" + Convert.ToString(ConfigurationManager.AppSettings["credentials"]), 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 = @"" + Convert.ToString(ConfigurationManager.AppSettings["tokenpath"]) + "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,
            });

            //create new event using input data

            EventsResource.InsertRequest createEventRequest =
                service.Events.Insert(
                    new Event
            {
                Summary     = model.Summary,
                Description = model.Description,
                Start       = model.Start.ToEventDateTime(),
                End         = model.End.ToEventDateTime()
            }
                    , "primary");

            Event createdEvent = createEventRequest.Execute();

            if (string.IsNullOrEmpty(Convert.ToString(createdEvent.Created)))
            {
                TempData["msg"] = "Issue in event creation";
            }
            else
            {
                TempData["msg"] = "Event created on " + Convert.ToString(createdEvent.Created);
            }

            return(View());
        }
Beispiel #29
0
 public void Add(string calendarId, IDirectResponseSchema newCalendarEvent)
 {
     try
     {
         var body = newCalendarEvent as Event;
         EventsResource.InsertRequest request = service.Events.Insert(body, calendarId);
         request.Execute();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Создание нового события в календаре
        /// </summary>
        /// <param name="summary">Заголовок события</param>
        /// <param name="start">Дата начала</param>
        /// <param name="end">Дата конца</param>
        /// <param name="calendarName">Идентификатор календаря</param>
        /// <param name="location">Место проведения</param>
        /// <param name="Emails">Адреса упоминаний</param>
        public void CreateEvent(string summary, DateTime start, DateTime end, string calendarName, string description = null, List <string> Emails = null, string location = null)
        {
            Event body = new Event();


            if (Emails != null)
            {
                List <EventAttendee> attendees = new List <EventAttendee>();
                foreach (var mail in Emails)
                {
                    attendees.Add(new EventAttendee {
                        Email = mail
                    });
                }

                body.Attendees = attendees;
            }



            EventDateTime _start = new EventDateTime();

            _start.Date = start.Date.ToString("yyyy-MM-dd");

            EventDateTime _end = new EventDateTime();

            _end.Date = end.Date.ToString("yyyy-MM-dd");

            body.Start       = _start;
            body.End         = _end;
            body.Location    = location;
            body.Summary     = summary;
            body.Description = description;


            if (isConnect)
            {
                EventsResource.InsertRequest request = new EventsResource.InsertRequest(Service, body, calendarName);

                Event response = request.Execute();
            }
            else
            {
                for (int i = 0; i < 16; i++)
                {
                    body.Id += Identity[ran.Next(0, Identity.Length)].ToString();
                }

                WorkBD.Execution_query($"insert into Ins_Event (Cal_Id, New_Ev, Id_New_Ev) values ((select Id from Name_Calendar where Id_Calendar = N'{calendarName}' and Id_User = (select Id from Users where UserName = N'{User}')), N'{JsonConvert.SerializeObject(body)}', N'{body.Id}')");
            }
        }
        public void InsertEvent(Event ev)
        {
            try
            {
                CreateGoogleService();

                var insertRequest = new EventsResource.InsertRequest(GoogleService, ev, CalendarEmail);

                insertRequest.SendNotifications = true;

                insertRequest.Execute();
            }
            catch (Exception e)
            {
                throw new Exception("Error inserting event to Google: " + e.Message, e);
            }
        }