private void TextFrameAssert(ITextFrameProperties textFrame, string fontName, float fontSize)
 {
     if (textFrame.Paragraphs != null)
     {
         foreach (TextParagraph paragraph in textFrame.Paragraphs)
         {
             if (paragraph.TextRanges != null)
             {
                 foreach (TextRange text in paragraph.TextRanges)
                 {
                     if (text.LatinFont != null)
                     {
                         Assert.Equal(fontName, text.LatinFont.FontName);
                     }
                     if (!float.IsNaN(text.FontHeight))
                     {
                         Assert.Equal(fontSize, text.FontHeight);
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        private static string GetEvents(ITextFrameProperties textFrame)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("calendrier-famille.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;
                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   = 50;
            request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;
            request.TimeMax      = DateTime.Now.AddDays(7);

            // List events.
            Events events = request.Execute();

            Console.WriteLine("Upcoming events:");

            var eventsByDay = from @event in events.Items
                              let dateTime = @event.Start.DateTime
                                             where dateTime != null
                                             group @event by dateTime.Value.Date
                                             into day
                                             select new { Day = day.Key, Events = day };

            StringBuilder result = new StringBuilder();

            textFrame.Paragraphs.Clear();
            textFrame.Paragraphs.Append(new TextParagraph()
            {
                Text = "", BulletType = TextBulletType.None
            });
            var tp = textFrame.TextRange.Paragraph;

            tp.TextRanges.Clear();
            foreach (var currentDay in eventsByDay)
            {
                //result.AppendLine(currentDay.Day.ToString("dddd d MMMM").Translate());
                var textRange = new TextRange(string.Format("{0}\n", currentDay.Day.ToString("dddd d MMMM").Translate()));
                tp.TextRanges.Append(textRange);

                foreach (var @event in currentDay.Events)
                {
                    if (@event.Start.DateTime.HasValue && @event.End.DateTime.HasValue)
                    {
                        var tr = new TextRange(string.Format(" - {0}-{1}: {2}\n",
                                                             @event.Start.DateTime.Value.ToString("HH:mm"),
                                                             @event.End.DateTime.Value.ToString("HH:mm"),
                                                             @event.Summary));
                        tr.Format.FontHeight = 16;
                        tr.Format.LatinFont  = new TextFont("Lucida Handwriting");
                        tp.TextRanges.Append(tr);
                    }
                }
            }

            return(result.ToString());
        }