public static void Run()
        {
            // ExStart:RetrieveCalendarInfo
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_CustomizingCreatedProject();

            // Create a project reader instance
            Project project = new Project(dataDir + "RetrieveCalendarInfo.mpp");

            // Retrieve Calendars Information
            CalendarCollection alCals = project.Calendars;

            foreach (Calendar cal in alCals)
            {
                if (cal.Name != null)
                {
                    Console.WriteLine("Calendar UID : " + cal.Uid);
                    Console.WriteLine("Calendar Name : " + cal.Name);

                    WeekDayCollection alDays = cal.WeekDays;
                    foreach (WeekDay wd in alDays)
                    {
                        TimeSpan ts = wd.GetWorkingTime();
                        if (wd.DayWorking)
                        {
                            Console.WriteLine(wd.DayType.ToString() + ":");
                            Console.WriteLine(ts.ToString());
                        }
                    }
                }
            }
            // ExEnd:RetrieveCalendarInfo
        }
Exemple #2
0
 public void Visit(CalendarCollection calendars)
 {
     using (var textReader = GetTextReader <Calendar>())
     {
         Feed.Calendars = new CalendarCollection(GetEntityParser <Calendar>().Parse(textReader).Cast <Calendar>());
     }
 }
        public virtual enHelperActivityType Process(ref Socket soUDP,
            ref IPEndPoint remoteIpEndPoint, string sessionID, Encoding enc)
        {
            ProcessCommand(ref soUDP, ref remoteIpEndPoint, sessionID, enc);

            // handle 555 BANNED and 598 - UNKNOWN COMMAND
            if (ResponseCode == 598) return enHelperActivityType.UnknownCommand_598;
            if (ResponseCode == 555) return enHelperActivityType.Banned_555;

            if (errorOccurred) return enHelperActivityType.CalendarEmpty;

            //BaseConfig.MyAnimeLog.Write("AniDBCommand_GetCalendar: Response: {0}", socketResponse);

            // Process Response
            string sMsgType = socketResponse.Substring(0, 3);

            switch (sMsgType)
            {
                case "297":
                {
                    calendars = new CalendarCollection(socketResponse);
                    return enHelperActivityType.GotCalendar;
                }
                case "397":
                {
                    return enHelperActivityType.CalendarEmpty;
                }
                case "501":
                {
                    return enHelperActivityType.LoginRequired;
                }
            }

            return enHelperActivityType.CalendarEmpty;
        }
Exemple #4
0
        private async Task <CalendarCollection> FetchCalendarsAsync()
        {
            var result = new CalendarCollection();

            if (!_appSettings.CalendarSources.Any())
            {
                return(await Task.FromResult(result));
            }

            _appSettings.CalendarSources.ForEach(url =>
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        var response = client.GetStringAsync(url).Result;

                        var calendar = Calendar.Load(response);
                        calendar.Properties.Add(new CalendarProperty("Url", url));

                        result.Add(calendar);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Can not retrieve calendar data for the Url: {url}", ex);
                }
            });

            return(await Task.FromResult(result));
        }
Exemple #5
0
        public static void Run()
        {
            //ExStart:RetrieveCalendarInfo
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // Create a project instance
            Project project = new Project(dataDir + "RetrieveCalendarInfo.mpp");

            // Retrieve Calendars Information
            CalendarCollection calendars = project.Calendars;

            foreach (Calendar cal in calendars)
            {
                if (cal.Name == null)
                {
                    continue;
                }

                Console.WriteLine("Calendar UID : " + cal.Uid);
                Console.WriteLine("Calendar Name : " + cal.Name);

                WeekDayCollection days = cal.WeekDays;
                foreach (WeekDay wd in days)
                {
                    TimeSpan ts = wd.GetWorkingTime();
                    if (wd.DayWorking)
                    {
                        Console.WriteLine(wd.DayType + ":");
                        Console.WriteLine(ts.ToString());
                    }
                }
            }
            //ExEnd:RetrieveCalendarInfo
        }
Exemple #6
0
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                //ExStart:ReplaceCalendarWithNewCalendar
                // Create project
                Project project = new Project(dataDir + "Project5.mpp");

                // Access project calendars
                CalendarCollection calColl = project.Calendars;
                foreach (Calendar myCalendar in calColl)
                {
                    if (myCalendar.Name == "TestCalendar")
                    {
                        // Remove calendar
                        calColl.Remove(myCalendar);
                    }
                }

                // Add new calendar
                Calendar newCalendar = calColl.Add("TestCalendar");
                project.Save(dataDir + "ReplaceCalendar_out.mpp", SaveFileFormat.MPP);
                //ExEnd:ReplaceCalendarWithNewCalendar
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Exemple #7
0
        private async Task CreateDefaultCalendar(Dictionary <string, string> propertiesAndHeaders)
        {
            #region Extracting Properties

            string principalId;
            propertiesAndHeaders.TryGetValue("principalId", out principalId);

            string collectionName;
            propertiesAndHeaders.TryGetValue("collectionName", out collectionName);

            string url;
            propertiesAndHeaders.TryGetValue("url", out url);

            #endregion

            //Adding the collection to the database

            var principal = await _principalRepository.GetByIdentifierAsync(principalId);

            var collection = new CalendarCollection(url, collectionName);

            principal.CalendarCollections.Add(collection);
            await _principalRepository.SaveChangesAsync();

            //Adding the collection folder.
            StorageManagement.AddCalendarCollectionFolder(url);
        }
Exemple #8
0
        public static void Run()
        {
            //ExStart:ReplaceCalendar
            // The path to the documents directory.
            string  dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            Project project = new Project(dataDir + "ReplaceCalendar.mpp");

            // Add a new calendar to the project's calendars collection
            project.Calendars.Add("New cal1", project.Get(Prj.Calendar));

            // Now traverse through project calendars and replace the already added calendar with a new one
            CalendarCollection calColl = project.Calendars;

            foreach (Calendar c in calColl)
            {
                if (c.Name != "New cal1")
                {
                    continue;
                }

                calColl.Remove(c);
                calColl.Add("New cal2", project.Get(Prj.Calendar));
                break;
            }
            //ExEnd:ReplaceCalendar
        }
Exemple #9
0
        public void EmptyLines2()
        {
            var calendars = CalendarCollection.Load(IcsFiles.EmptyLines2);

            Assert.AreEqual(2, calendars.Count);
            Assert.AreEqual(2, calendars[0].Events.Count, "iCalendar should have 2 events");
            Assert.AreEqual(2, calendars[1].Events.Count, "iCalendar should have 2 events");
        }
        public static string ReadEventAsJsonObject(CalendarCollection calendars, string uid)
        {
            foreach (var calendar in calendars)
            {
                var result = ReadEventAsJsonObject(calendar, uid);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Exemple #11
0
        public void UnitTest8()
        {
            using (var cont = new CalDavContext())
            {
                var col = new CalendarCollection(SystemProperties._groupCollectionUrl + _group + "/",
                                                 $"Group {_group} Calendar");

                cont.CalendarCollections.Add(col);
                cont.SaveChanges();

                // Assert.NotNull(cont.CalendarCollections.FirstOrDefault(x=>x.Group == _group));
            }
        }
Exemple #12
0
        public virtual enHelperActivityType Process(ref Socket soUDP,
                                                    ref IPEndPoint remoteIpEndPoint, string sessionID, Encoding enc)
        {
            ProcessCommand(ref soUDP, ref remoteIpEndPoint, sessionID, enc);

            // handle 555 BANNED and 598 - UNKNOWN COMMAND
            if (ResponseCode == 598)
            {
                return(enHelperActivityType.UnknownCommand_598);
            }
            if (ResponseCode == 555)
            {
                return(enHelperActivityType.Banned_555);
            }

            if (errorOccurred)
            {
                return(enHelperActivityType.CalendarEmpty);
            }

            //BaseConfig.MyAnimeLog.Write("AniDBCommand_GetCalendar: Response: {0}", socketResponse);

            // Process Response
            string sMsgType = socketResponse.Substring(0, 3);


            switch (sMsgType)
            {
            case "297":
            {
                calendars = new CalendarCollection(socketResponse);
                return(enHelperActivityType.GotCalendar);
            }

            case "397":
            {
                return(enHelperActivityType.CalendarEmpty);
            }

            case "501":
            {
                return(enHelperActivityType.LoginRequired);
            }
            }

            return(enHelperActivityType.CalendarEmpty);
        }
Exemple #13
0
        public async void Run(object state)
        {
            var response = await _client.GetAsync(_options.Value.UpstreamICalUrl);

            response.EnsureSuccessStatusCode();

            var stream = await response.Content.ReadAsStreamAsync();

            var calendars = CalendarCollection.Load(stream);
            var calendar  = calendars.FirstOrDefault();

            if (calendar is null)
            {
                _logger.LogWarning("Calendar is empty. Skipping sync");
                return;
            }

            // Add or update events
            var upstreamCalendarEvents = calendar.Events.OrderBy(x => x.Start).ToList();

            foreach (var calendarEvent in upstreamCalendarEvents)
            {
                var entry = _mapper.Map <CalendarEventEntity>(calendarEvent);
                entry.Source = _options.Value.UpstreamICalUrl;

                await _calendarService.AddOrUpdateCalendarEntryAsync(entry);
            }

            // Purge obsolete events
            var events           = (await _calendarService.GetAllEventsAsync()).ToList();
            var obsoleteEventIds = events.Where(x => x.Source == _options.Value.UpstreamICalUrl)
                                   .Select(x => x.Id)
                                   .Except(upstreamCalendarEvents
                                           .Select(x => x.Uid));

            // TODO: Add tests
            foreach (var obsoleteEventId in obsoleteEventIds)
            {
                await _calendarService.RemoveEventAsync(obsoleteEventId);
            }

            _logger.LogInformation("Synchronized calendar from upstream source ({UpstreamSourceUrl})",
                                   _options.Value.UpstreamICalUrl);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string  dataDir = RunExamples.GetDataDir_Projects();
            Project project = new Project(dataDir + "ReplaceCalendar.mpp");

            Aspose.Tasks.Calendar cal     = new Aspose.Tasks.Calendar("New Cal");
            CalendarCollection    calColl = project.Calendars;

            foreach (Aspose.Tasks.Calendar c in calColl)
            {
                if (c.Name == "Standard")
                {
                    calColl.Remove(c);
                    calColl.Add("Standard", cal);
                    break;
                }
            }
        }
        public Worker CreateWorkerInSystem(string email, string password,
                                           string fullName, string faculty, string department)
        {
            var worker = new Worker(fullName, email, password, department, faculty);

            worker.Password = worker.PasswordHasher(password);


            //create useful properties for the principal
            var calHomeSet = PropertyCreation.CreateCalendarHomeSet(SystemProperties.PrincipalType.User, email,
                                                                    SystemProperties._defualtInitialCollectionName);
            var displayName = PropertyCreation.CreateProperty("displayname", "D", fullName);

            //create the principal the represents the user
            var principal = new Principal(email, SystemProperties.PrincipalType.User,
                                          displayName, calHomeSet);

            worker.Principal = principal;

            //create the collection for the user.
            var col =
                new CalendarCollection(
                    $"{SystemProperties._userCollectionUrl}{email}/{SystemProperties._defualtInitialCollectionName}/",
                    SystemProperties._defualtInitialCollectionName)
            {
                Principal = principal
            };

            //add the calaendar to the collection of the principal
            principal.CalendarCollections.Add(col);

            //create the folder that will contain the
            //calendars of the user
            new FileSystemManagement().AddCalendarCollectionFolder(col.Url);

            //add the user and its principal to the context
            _context.Workers.Add(worker);
            _context.Principals.Add(principal);
            _context.CalendarCollections.Add(col);

            _context.SaveChanges();
            return(worker);
        }
        public IEnumerable <FCEventModel> Events()
        {
            var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", "fbevents.ics");
            var file     = new FileInfo(filePath);
            IICalendarCollection calList = new CalendarCollection();

            var list        = new List <FCEventModel>();
            var fbEventFeed = ConfigurationManager.AppSettings["FBEventFeed"];
            var fbEventKey  = ConfigurationManager.AppSettings["FBEventKey"];
            var fullPath    = fbEventFeed + "&key=" + fbEventKey;

            WebClient client = new WebClient();

            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            if (!IsFileLocked(file) && file.LastWriteTime < DateTime.Now.AddMinutes(-30))
            {
                client.DownloadFile(fullPath, filePath);
            }
            if (!IsFileLocked(file))
            {
                calList = Calendar.LoadFromFile(filePath);
            }

            TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

            foreach (var cal in calList)
            {
                foreach (var item in cal.Events)
                {
                    var newEvent = new FCEventModel()
                    {
                        title = item.Summary,
                        start = TimeZoneInfo.ConvertTimeFromUtc(item.Start.Value, easternZone).ToString(),
                        end   = TimeZoneInfo.ConvertTimeFromUtc(item.End.Value, easternZone).ToString()
                    };
                    list.Add(newEvent);
                }
            }

            return(list);
        }
Exemple #17
0
        public static void Run()
        {
            // ExStart:ReplaceCalendarWithNewCalendar
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_CustomizingCreatedProject();

            Project            project  = new Project(dataDir + "Project5.mpp");
            Calendar           calendar = new Calendar("New Cal");
            CalendarCollection calColl  = project.Calendars;

            foreach (Calendar getcalendar in calColl)
            {
                if (getcalendar.Name == "Standard")
                {
                    calColl.Remove(getcalendar);
                    calColl.Add("Standard", getcalendar);
                    break;
                }
            }
            // ExEnd:ReplaceCalendarWithNewCalendar
        }
        public static void Run()
        {
            // ExStart:ReplaceCalendar
            // The path to the documents directory.
            string  dataDir = RunExamples.GetDataDir_WorkingWithProjects();
            Project project = new Project(dataDir + "ReplaceCalendar.mpp");

            // Add a new calendar to the project's calendars collection
            project.Calendars.Add("New cal1", project.Get(Prj.Calendar));

            // Now traverse through project calendars and replace the already added calendar with a new one
            CalendarCollection calColl = project.Calendars;

            foreach (Calendar c in calColl)
            {
                if (c.Name == "New cal1")
                {
                    calColl.Remove(c);
                    calColl.Add("New cal2", project.Get(Prj.Calendar));
                    break;
                }
            }
            // ExEnd:ReplaceCalendar
        }
Exemple #19
0
        public CalendarCollection icalendar(SerializationContext ctx)
        {
            CalendarCollection iCalendars = new CalendarCollection();


            SerializationUtil.OnDeserializing(iCalendars);

            Calendar cal = null;

            ctx.GetService <ISerializationSettings>();

            { // ( ... )*
                for (;;)
                {
                    if ((LA(1) == CRLF || LA(1) == BEGIN))
                    {
                        { // ( ... )*
                            for (;;)
                            {
                                if ((LA(1) == CRLF))
                                {
                                    match(CRLF);
                                }
                                else
                                {
                                    goto _loop4_breakloop;
                                }
                            }
_loop4_breakloop:
                            ;
                        } // ( ... )*
                        match(BEGIN);
                        match(COLON);
                        match(VCALENDAR);
                        { // ( ... )*
                            for (;;)
                            {
                                if ((LA(1) == CRLF))
                                {
                                    match(CRLF);
                                }
                                else
                                {
                                    goto _loop6_breakloop;
                                }
                            }
_loop6_breakloop:
                            ;
                        } // ( ... )*

                        var processor = ctx.GetService(typeof(CompositeProcessor <Calendar>)) as CompositeProcessor <Calendar>;

                        // Do some pre-processing on the calendar:
                        processor?.PreDeserialization(cal);

                        cal = new Calendar();
                        SerializationUtil.OnDeserializing(cal);

                        // Push the iCalendar onto the serialization context stack
                        ctx.Push(cal);

                        icalbody(ctx, cal);
                        match(END);
                        match(COLON);
                        match(VCALENDAR);
                        { // ( ... )*
                            for (;;)
                            {
                                if ((LA(1) == CRLF) && (LA(2) == EOF || LA(2) == CRLF || LA(2) == BEGIN) && (tokenSet_0_.member(LA(3))))
                                {
                                    match(CRLF);
                                }
                                else
                                {
                                    goto _loop8_breakloop;
                                }
                            }
_loop8_breakloop:
                            ;
                        } // ( ... )*

                        // Do some final processing on the calendar:
                        processor?.PostDeserialization(cal);

                        // Notify that the iCalendar has been loaded
                        cal.OnLoaded();
                        iCalendars.Add(cal);

                        SerializationUtil.OnDeserialized(cal);

                        // Pop the iCalendar off the serialization context stack
                        ctx.Pop();
                    }
                    else
                    {
                        goto _loop9_breakloop;
                    }
                }
_loop9_breakloop:
                ;
            } // ( ... )*

            SerializationUtil.OnDeserialized(iCalendars);

            return(iCalendars);
        }
Exemple #20
0
        public override void Run(IProgress <ICommand> progress = null)
        {
            logger.Info("Processing CommandRequest_GetCalendar");

            try
            {
                // we will always assume that an anime was downloaded via http first
                ReportInit(progress);

                using (var upd = Repo.Instance.ScheduledUpdate.BeginAddOrUpdate(() => Repo.Instance.ScheduledUpdate.GetByUpdateType((int)ScheduledUpdateType.AniDBCalendar), () => new ScheduledUpdate {
                    UpdateType = (int)ScheduledUpdateType.AniDBCalendar, UpdateDetails = string.Empty
                }))
                {
                    if (upd.IsUpdate())
                    {
                        int freqHours = Utils.GetScheduledHours(ServerSettings.Instance.AniDb.Calendar_UpdateFrequency);

                        // if we have run this in the last 12 hours and are not forcing it, then exit
                        TimeSpan tsLastRun = DateTime.Now - upd.Entity.LastUpdate;
                        if (tsLastRun.TotalHours < freqHours)
                        {
                            if (!ForceRefresh)
                            {
                                ReportFinish(progress);
                                return;
                            }
                        }
                    }
                    upd.Entity.LastUpdate = DateTime.Now;
                    upd.Commit();
                }

                ReportUpdate(progress, 50);

                CalendarCollection colCalendars = ShokoService.AnidbProcessor.GetCalendarUDP();
                if (colCalendars == null || colCalendars.Calendars == null)
                {
                    ReportError(progress, "Could not get calendar from AniDB");
                    return;
                }

                ReportUpdate(progress, 80);
                List <ICommand> cmds = new List <ICommand>();
                foreach (Calendar cal in colCalendars.Calendars)
                {
                    SVR_AniDB_Anime anime  = Repo.Instance.AniDB_Anime.GetByAnimeID(cal.AnimeID);
                    var             update = Repo.Instance.AniDB_AnimeUpdate.GetByAnimeID(cal.AnimeID);
                    if (anime != null && update != null)
                    {
                        // don't update if the local data is less 2 days old
                        TimeSpan ts = DateTime.Now - update.UpdatedAt;
                        if (ts.TotalDays >= 2)
                        {
                            cmds.Add(new CmdAniDBGetAnimeHTTP(cal.AnimeID, true, false));
                        }
                        else
                        {
                            // update the release date even if we don't update the anime record
                            if (anime.AirDate != cal.ReleaseDate)
                            {
                                using (var upd = Repo.Instance.AniDB_Anime.BeginAddOrUpdate(anime))
                                {
                                    upd.Entity.AirDate = cal.ReleaseDate;
                                    anime = upd.Commit();
                                }

                                SVR_AnimeSeries ser = Repo.Instance.AnimeSeries.GetByAnimeID(anime.AnimeID);
                                if (ser != null)
                                {
                                    Repo.Instance.AnimeSeries.Touch(ser, (true, false, false, false));
                                }
                            }
                        }
                    }
                    else
                    {
                        cmds.Add(new CmdAniDBGetAnimeHTTP(cal.AnimeID, true, false));
                    }
                }

                ReportUpdate(progress, 90);
                if (cmds.Count > 0)
                {
                    Queue.Instance.AddRange(cmds);
                }
                ReportFinish(progress);
            }
            catch (Exception ex)
            {
                ReportError(progress, $"Error processing Command AniDB.GetCalendar: {ex}", ex);
            }
        }
        /// <summary>
        ///     Add a user to the system.
        /// </summary>
        /// <param name="context">The system Db context.</param>
        /// <param name="email">The user email.</param>
        /// <param name="fullName">The user full name. This gonna be the displayname for the system.</param>
        /// <param name="password">THe user not encrypted password</param>
        /// <returns>
        ///     The instance of the new User. Have to change the changes with the
        ///     returned object.
        /// </returns>
        public Principal CreateUserInSystem(string email, string fullName,
                                            string password)
        {
            //create the core passHasher
            var passHasher = new PasswordHasher <User>();


            var user = new User
            {
                Email       = email,
                Password    = password,
                DisplayName = fullName
            };

            var defaultCalName = email;

            //create useful properties for the principal
            var calHomeSet = PropertyCreation.CreateCalendarHomeSet(SystemProperties.PrincipalType.User, email,
                                                                    defaultCalName);
            var displayName = PropertyCreation.CreateProperty("displayname", "D", fullName);


            //create the principal the represents the user
            var principal = new Principal(email, SystemProperties.PrincipalType.User,
                                          displayName, calHomeSet);

            user.Principal = principal;

            #region create the collection for the principal

            //create the collection for the user.
            var col =
                new CalendarCollection(
                    $"{SystemProperties._userCollectionUrl}{email}/{defaultCalName}/",
                    defaultCalName)
            {
                Principal = principal
            };

            //add the ACL properties to the collection
            var ownerProp = PropertyCreation.CreateProperty("owner", "D", $"<D:href>{principal.PrincipalURL}</D:href>",
                                                            false, false);

            col.Properties.Add(ownerProp);
            col.Properties.Add(PropertyCreation.CreateAclPropertyForUserCollections(principal.PrincipalURL));

            //add the calaendar to the collection of the principal
            principal.CalendarCollections.Add(col);

            #endregion

            //create the folder that will contain the
            //calendars of the user
            new FileSystemManagement().AddCalendarCollectionFolder(col.Url);

            //hass the user password
            // the instance of the user has to be pass but is not used
            // so it need to be updated
            var hashedPassword = passHasher.HashPassword(user, password);
            user.Password = hashedPassword;

            //add the user and its principal to the context
            _context.Users.Add(user);
            _context.Principals.Add(principal);
            _context.CalendarCollections.Add(col);

            _context.SaveChanges();

            return(principal);
        }
Exemple #22
0
 public static CalendarCollection GetCalendars(string incoming) => CalendarCollection.Load(incoming);
        private void ConvertIcalendarToAppointment(byte[] iCalendarPayload)
        {
            var iCalendarStream    = new MemoryStream(iCalendarPayload);
            var calendarCollection = CalendarCollection.Load(iCalendarStream);

            if (calendarCollection.Count >= 1)
            {
                if (calendarCollection.Count >= 2)
                {
                    Debug.WriteLine("Note: the library only parses the first calendar object.");
                }
                var curCalendar = calendarCollection.First();
                ProductId = curCalendar.ProductId;

                if (curCalendar.Events != null && curCalendar.Events.Count >= 1)
                {
                    if (curCalendar.Events.Count >= 2)
                    {
                        Debug.WriteLine("Note: the library only parses the first event object.");
                    }
                    var evt = curCalendar.Events.First();

                    // Internalize event data
                    var ap = new Appointment
                    {
                        // Event description and main properties
                        Subject = evt.Summary,
                        Details = evt.Description,

                        // Time
                        StartTime = evt.Start.AsUtc,
                        Duration  = evt.Duration,
                        AllDay    = evt.IsAllDay,

                        // Location
                        Location = evt.Location,

                        // TODO: recurrence
                    };
                    if (evt.Url != null)
                    {
                        ap.Uri = evt.Url;
                    }
                    if (evt.Organizer != null)
                    {
                        ap.Organizer = new AppointmentOrganizer
                        {
                            DisplayName = evt.Organizer.CommonName
                        };
                        if (evt.Organizer.Value != null)
                        {
                            ap.Organizer.Address = evt.Organizer.Value.ToString();
                        }
                    }

                    // Reminder
                    if (evt.Alarms != null && evt.Alarms.Count > 0)
                    {
                        ap.Reminder = evt.Alarms.First().Trigger.Duration;
                    }

                    AppointmentData = ap;
                }
                else
                {
                    throw new NdefException(NdefExceptionMessagesUwp.ExIcalendarNoEventFound);
                }
            }
            else
            {
                throw new NdefException(NdefExceptionMessagesUwp.ExIcalendarNoCalendarFound);
            }
        }
Exemple #24
0
 public void Visit(CalendarCollection calendars)
 {
     SetValidity(calendars);
 }
Exemple #25
0
        private async Task GetICalFeedAsync()
        {
            _calendarCollection = await LoadFromUriAsync(Uri);

            _firstCalendar = _calendarCollection.First() as Calendar;
        }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_GetCalendar");

            try
            {
                // we will always assume that an anime was downloaded via http first

                ScheduledUpdate sched =
                    RepoFactory.ScheduledUpdate.GetByUpdateType((int)ScheduledUpdateType.AniDBCalendar);
                if (sched == null)
                {
                    sched = new ScheduledUpdate
                    {
                        UpdateType    = (int)ScheduledUpdateType.AniDBCalendar,
                        UpdateDetails = string.Empty
                    };
                }
                else
                {
                    int freqHours = Utils.GetScheduledHours(ServerSettings.Instance.AniDb.Calendar_UpdateFrequency);

                    // if we have run this in the last 12 hours and are not forcing it, then exit
                    TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate;
                    if (tsLastRun.TotalHours < freqHours)
                    {
                        if (!ForceRefresh)
                        {
                            return;
                        }
                    }
                }

                sched.LastUpdate = DateTime.Now;
                RepoFactory.ScheduledUpdate.Save(sched);

                CalendarCollection colCalendars = ShokoService.AnidbProcessor.GetCalendarUDP();
                if (colCalendars == null || colCalendars.Calendars == null)
                {
                    logger.Error("Could not get calendar from AniDB");
                    return;
                }
                foreach (Calendar cal in colCalendars.Calendars)
                {
                    SVR_AniDB_Anime anime  = RepoFactory.AniDB_Anime.GetByAnimeID(cal.AnimeID);
                    var             update = RepoFactory.AniDB_AnimeUpdate.GetByAnimeID(cal.AnimeID);
                    if (anime != null && update != null)
                    {
                        // don't update if the local data is less 2 days old
                        TimeSpan ts = DateTime.Now - update.UpdatedAt;
                        if (ts.TotalDays >= 2)
                        {
                            CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(cal.AnimeID, true,
                                                                                                   false);
                            cmdAnime.Save();
                        }
                        else
                        {
                            // update the release date even if we don't update the anime record
                            if (anime.AirDate != cal.ReleaseDate)
                            {
                                anime.AirDate = cal.ReleaseDate;
                                RepoFactory.AniDB_Anime.Save(anime);
                                SVR_AnimeSeries ser = RepoFactory.AnimeSeries.GetByAnimeID(anime.AnimeID);
                                if (ser != null)
                                {
                                    RepoFactory.AnimeSeries.Save(ser, true, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        CommandRequest_GetAnimeHTTP cmdAnime =
                            new CommandRequest_GetAnimeHTTP(cal.AnimeID, true, false);
                        cmdAnime.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error processing CommandRequest_GetCalendar: " + ex);
            }
        }
Exemple #27
0
        private void OnCalendarCmd(object parameter)
        {
            CalendarCollection.show();

            //InputDatetime.Invoke(DateTime.Now);
        }
Exemple #28
0
 protected virtual void OnCalendarsChecked(CalendarCollection calendars, ValidationEventArgs e)
 {
     CalendarsChecked?.Invoke(calendars, e);
 }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_GetCalendar");

            try
            {
                // we will always assume that an anime was downloaded via http first
                ScheduledUpdateRepository repSched = new ScheduledUpdateRepository();
                AniDB_AnimeRepository     repAnime = new AniDB_AnimeRepository();

                ScheduledUpdate sched = repSched.GetByUpdateType((int)ScheduledUpdateType.AniDBCalendar);
                if (sched == null)
                {
                    sched               = new ScheduledUpdate();
                    sched.UpdateType    = (int)ScheduledUpdateType.AniDBCalendar;
                    sched.UpdateDetails = "";
                }
                else
                {
                    int freqHours = Utils.GetScheduledHours(ServerSettings.AniDB_Calendar_UpdateFrequency);

                    // if we have run this in the last 12 hours and are not forcing it, then exit
                    TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate;
                    if (tsLastRun.TotalHours < freqHours)
                    {
                        if (!ForceRefresh)
                        {
                            return;
                        }
                    }
                }

                sched.LastUpdate = DateTime.Now;
                repSched.Save(sched);

                CalendarCollection colCalendars = JMMService.AnidbProcessor.GetCalendarUDP();
                if (colCalendars == null || colCalendars.Calendars == null)
                {
                    logger.Error("Could not get calendar from AniDB");
                    return;
                }
                foreach (AniDBAPI.Calendar cal in colCalendars.Calendars)
                {
                    AniDB_Anime anime = repAnime.GetByAnimeID(cal.AnimeID);
                    if (anime != null)
                    {
                        // don't update if the local data is less 2 days old
                        TimeSpan ts = DateTime.Now - anime.DateTimeUpdated;
                        if (ts.TotalDays >= 2)
                        {
                            CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(cal.AnimeID, true,
                                                                                                   false);
                            cmdAnime.Save();
                        }
                        else
                        {
                            // update the release date even if we don't update the anime record
                            if (anime.AirDate != cal.ReleaseDate)
                            {
                                anime.AirDate = cal.ReleaseDate;
                                repAnime.Save(anime);
                                AnimeSeriesRepository srepo = new AnimeSeriesRepository();
                                AnimeSeries           ser   = srepo.GetByAnimeID(anime.AnimeID);
                                if (ser != null)
                                {
                                    srepo.Save(ser, true, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        CommandRequest_GetAnimeHTTP cmdAnime = new CommandRequest_GetAnimeHTTP(cal.AnimeID, true, false);
                        cmdAnime.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error processing CommandRequest_GetCalendar: " + ex.ToString(), ex);
                return;
            }
        }
Exemple #30
0
 public void Visit(CalendarCollection calendars)
 {
     OnCalendarsChecked(calendars, new ValidationEventArgs(CheckValidity(calendars)));
 }