private string AddReminders(string icsString, SchemaRequest req)
        {
            var calendar      = Ical.Net.Calendar.Load(icsString);
            var summaryString = $"{req.UserName} Ssk";
            var quarterAlarm  = new Alarm()
            {
                Summary = summaryString,
                Trigger = new Trigger(TimeSpan.FromMinutes(-15)),
                Action  = AlarmAction.Display
            };
            var hourAlarm = new Alarm()
            {
                Summary = summaryString,
                Trigger = new Trigger(TimeSpan.FromHours(-1)),
                Action  = AlarmAction.Display
            };

            calendar.ProductId = "En tjänst skapad av Linus Nyrén";
            var currentDate = DateTime.Now.ToUniversalTime().AddHours(1);

            foreach (var ev in calendar.Events)
            {
                ev.Summary = summaryString;
                ev.Alarms.Add(quarterAlarm);
                ev.Alarms.Add(hourAlarm);
                ev.GeographicLocation = new GeographicLocation(57.6824618, 11.9614532);
                ev.Location           = "Sahlgrenska Universitetssjukhuset 413 45 Göteborg, Sverige";
                ev.Description        = $"En tjänst skapad av Linus Nyrén, \nSenaste uppdateringen från Heroma: {currentDate.ToString("HH:mm dd/MM")}";
                ev.Url = new Uri("https://github.com/linusnyren/VgrICalSubscription");
            }
            return(new CalendarSerializer().SerializeToString(calendar));
        }
Beispiel #2
0
        /// <summary>
        /// Create a definition.
        /// </summary>
        /// <param name="library">The library in which to create the definition.</param>
        /// <returns>The created definition.</returns>
        private async Task <Definition> CreateDefinition(Library library)
        {
            // The schema properties can be constructed as a JSON string and then parsed into a JObject object.
            string demoPSetDefSchemaPropsStr = @"
            {
                ""str"":
                {
                    ""type"": ""string"",
                    ""description"": ""A string.""
                },
                ""num"":
                {
                    ""type"": ""integer"",
                    ""description"": ""A number.""
                }
            }";

            var demoPSetDefSchema = new SchemaRequest
            {
                Open       = false,
                Properties = JObject.Parse(demoPSetDefSchemaPropsStr), // Parse the schema properties JSON string into a JObject object
            };

            // The optional I18N can be constructed as a JSON string and then parsed into a JObject object.
            string testPSetDefSchemaI18NStr = @"
            {
	            ""en"": {
                    ""name"": ""Test PSet"",
		            ""description"": ""This is a test PSet"",
		            ""props"": {
                        ""str"": ""String property."",
			            ""num"": ""Numeric property.""
                    }
                }
            }";

            var createDefinitionRequest = new CreateDefinitionRequest
            {
                LibraryId   = library.Id,
                Id          = $"CDMServicesDemo:PSet:Definition-{Guid.NewGuid().ToString()}", // Optional (if not specified, the service will auto-generate it)
                Name        = "DemoDefinition",                                               // Optional
                Description = "A demo definition",                                            // Optional
                Schema      = demoPSetDefSchema,
                I18N        = JObject.Parse(testPSetDefSchemaI18NStr),                        // Optional. Parse the I18N JSON string into a JObject object
                Types       = new string[] { "Wall", "Slab" },
            };

            Console.WriteLine($"Creating definition with LibraryId={createDefinitionRequest.LibraryId}, Id={createDefinitionRequest.Id}" +
                              $", Name={createDefinitionRequest.Name}, Description={createDefinitionRequest.Description}...");

            Definition definition = await this.psetClient.CreateDefinitionAsync(createDefinitionRequest).ConfigureAwait(false);

            Console.Write($"Created definition: ");
            this.PrintDefinition(definition);
            Console.WriteLine();

            return(definition);
        }
        public async Task <string> GetCalendarAsync(SchemaRequest req)
        {
            var cookies = seleniumTokenService.GetCookiesAsync(req.UserName, req.Password);
            var res     = await calendarService.GetIcalAsync(cookies, req.Months);

            var response = AddReminders(res.Content, req);

            return(response);
        }
Beispiel #4
0
        public async Task <string> Get(string user, string password, int months)
        {
            logger.LogInformation("New incoming request from " + user);
            var req = new SchemaRequest
            {
                UserName = user,
                Password = password,
                Months   = months
            };
            var key = $"{user}-{password}-{months}";

            return(await cache.GetOrCreateAsync(key, async entry => {
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(options.TtlHours);
                return await schemaService.GetCalendarAsync(req);
            }));
        }
Beispiel #5
0
        public async Task <SchemaResponse> GetSchemaAsync(SchemaRequest req)
        {
            await Task.Delay(1000);

            return(default(SchemaResponse));
        }