Ejemplo n.º 1
0
        public void RemoveSelectionPeriods()
        {
            FactorList factors;
            IFactor    factor1, factor2;
            Int32      speciesFactCount;
            ITaxon     taxon1, taxon2;
            PeriodList periods;
            TaxonList  taxa;

            factor1 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.RedlistCategory);
            factor2 = CoreData.FactorManager.GetFactor(GetUserContext(), FactorId.Redlist_OrganismLabel1);
            taxon1  = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.DrumGrasshopper);
            taxon2  = CoreData.TaxonManager.GetTaxon(GetUserContext(), TaxonId.Wolverine);
            factors = new FactorList();
            factors.Add(factor1);
            factors.Add(factor2);
            taxa = new TaxonList();
            taxa.Add(taxon1);
            taxa.Add(taxon2);
            GetDataSet(true).AddSelection(GetUserContext(), factors);
            GetDataSet().AddSelectionTaxa(GetUserContext(), taxa);

            GetDataSet().AddSelection(GetUserContext(), CoreData.FactorManager.GetPeriods(GetUserContext()));
            speciesFactCount = GetDataSet().SpeciesFacts.Count;
            periods          = new PeriodList();
            periods.Add(GetDataSet().Periods[0]);
            periods.Add(GetDataSet().Periods[1]);
            GetDataSet().RemoveSelection(GetUserContext(), periods);
            Assert.IsFalse(GetDataSet().Factors.IsEmpty());
            Assert.IsFalse(GetDataSet().SpeciesFacts.IsEmpty());
            Assert.IsTrue(speciesFactCount > GetDataSet().SpeciesFacts.Count);
            periods = null;
            GetDataSet().RemoveSelection(GetUserContext(), periods);
        }
Ejemplo n.º 2
0
        public void PeriodList1()
        {
            IPeriodList pl = new PeriodList();

            pl.Add(new Period(new iCalDateTime(DateTime.Now.AddHours(2)), new iCalDateTime(DateTime.Now.AddHours(3))));
            pl.Add(new Period(new iCalDateTime(DateTime.Now.AddHours(4)), new iCalDateTime(DateTime.Now.AddHours(5))));
            SerializeTest(pl, "PeriodList1.xml");
        }
Ejemplo n.º 3
0
 private static void PopulateTimeZoneInfoRecurrenceDates(ITimeZoneInfo tzi, List <ZoneInterval> intervals, TimeSpan delta)
 {
     foreach (var interval in intervals)
     {
         var periodList = new PeriodList();
         var time       = interval.IsoLocalStart.ToDateTimeUnspecified();
         var date       = new CalDateTime(time).Add(delta) as CalDateTime;
         if (date == null)
         {
             continue;
         }
         date.HasTime = true;
         periodList.Add(date);
         tzi.RecurrenceDates.Add(periodList);
     }
 }
        /// <summary>
        /// Read rows from the excel xml format.
        /// Overridden by each class that inherits this class.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name='xmlDoc'>The xml document that the row node will be read from.</param>
        /// <param name="nsmgr">Namespacemanager containing all namespaces used by the excel compatible xml format</param>
        protected override void ReadExcelXmlRows(IUserContext userContext,
                                                 XmlDocument xmlDoc,
                                                 XmlNamespaceManager nsmgr)
        {
            PeriodList  periods;
            XmlNode     dataNode;
            XmlNodeList rowNodes;

            rowNodes = xmlDoc.SelectNodes("/ss:Workbook/ss:Worksheet/ss:Table/ss:Row", nsmgr);
            periods  = new PeriodList();
            foreach (XmlNode rowNode in rowNodes)
            {
                dataNode = rowNode.SelectSingleNode("ss:Cell/ss:Data", nsmgr);
                periods.Add(CoreData.FactorManager.GetPeriod(userContext, dataNode.InnerText.WebParseInt32()));
            }

            Periods = periods;
        }
        /// <summary>
        /// Convert a list of WebPeriod instances
        /// to a PeriodList.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="webPeriods">List of WebPeriod instances.</param>
        /// <returns>An instances of PeriodList.</returns>
        private PeriodList GetPeriods(IUserContext userContext,
                                      List <WebPeriod> webPeriods)
        {
            PeriodList periods;

            periods = null;
            if (webPeriods.IsNotEmpty())
            {
                periods = new PeriodList();
                foreach (WebPeriod webPeriod in webPeriods)
                {
                    periods.Add(GetPeriod(userContext, webPeriod));
                }

                periods.Sort();
            }

            return(periods);
        }
        /// <summary>
        /// Get previouly red list categories species facts.
        /// </summary>
        private void GetRedListOldCategorySpeciesFactsToCache()
        {
            ISpeciesFactSearchCriteria searchCriteria = new SpeciesFactSearchCriteria();

            searchCriteria.Factors = new FactorList();
            IFactor factor = CoreData.FactorManager.GetFactor(mContext, FactorId.RedlistCategory);

            searchCriteria.Factors.Add(factor);
            searchCriteria.IndividualCategories = new IndividualCategoryList
            {
                CoreData.FactorManager.GetDefaultIndividualCategory(mContext)
            };
            PeriodList periodsList   = CoreData.FactorManager.GetPublicPeriods(mContext);
            IPeriod    currentPeriod = CoreData.FactorManager.GetCurrentRedListPeriod(mContext);
            var        oldPeriods    = new PeriodList();

            foreach (IPeriod period in periodsList)
            {
                if (period.Id != currentPeriod.Id)
                {
                    oldPeriods.Add(period);
                }
            }
            searchCriteria.Periods = oldPeriods;
            ISpeciesFactDataSource speciesFactDataSource = new RedListSpeciesFactDataSource();
            SpeciesFactList        speciesFacts          = speciesFactDataSource.GetSpeciesFacts(mContext, searchCriteria);

            if (speciesFacts.IsNotEmpty())
            {
                foreach (ISpeciesFact speciesFact in speciesFacts)
                {
                    if (TaxonInformationCache.TaxonInformation.ContainsKey(speciesFact.Taxon.Id))
                    {
                        TaxonInformationCache.TaxonInformation[speciesFact.Taxon.Id].SetSpeciesFact(speciesFact, currentPeriod);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void TestInitialize()
        {
            var today = RockDateTime.Now;

            var nextMonth = RockDateTime.Now.AddMonths(1).Month;

            // Add specific dates that exist for every month of the year.
            _specificDates = new List <DateTime>();
            _specificDates.Add(new DateTime(today.Year, nextMonth, 1));
            _specificDates.Add(new DateTime(today.Year, nextMonth, 3));
            _specificDates.Add(new DateTime(today.Year, nextMonth, 5));
            _specificDates.Add(new DateTime(today.Year, nextMonth, 7));
            _specificDates.Add(new DateTime(today.Year, nextMonth, 10));
            _specificDates.Add(new DateTime(today.Year, nextMonth, 20));
            _specificDates.Add(new DateTime(today.Year, nextMonth, 28));

            var recurrenceDates = new PeriodList();

            _specificDates.ForEach(x => recurrenceDates.Add(new CalDateTime(x)));

            var firstDate = _specificDates.First();

            // Create a calendar for an event that recurs on specific dates.
            _calendarSpecificDates = new Calendar()
            {
                // Create an event for the first scheduled date (1am-2am), and set the recurring dates.
                Events = { new Event
                           {
                               DtStart         = new CalDateTime(firstDate.Year, firstDate.Month, firstDate.Day, 1, 0, 0),
                               DtEnd           = new CalDateTime(firstDate.Year, firstDate.Month, firstDate.Day, 2, 0, 0),
                               DtStamp         = new CalDateTime(firstDate.Year, firstDate.Month, firstDate.Day),
                               RecurrenceDates = new List <IPeriodList>{
                                   recurrenceDates
                               },
                               Sequence = 0,
                           } }
            };
        }
Ejemplo n.º 8
0
        public void PeriodListTests()
        {
            var startTimesA = new List <DateTime>
            {
                new DateTime(2017, 03, 02, 06, 00, 00),
                new DateTime(2017, 03, 03, 06, 00, 00),
                new DateTime(2017, 03, 06, 06, 00, 00),
                new DateTime(2017, 03, 07, 06, 00, 00),
                new DateTime(2017, 03, 08, 06, 00, 00),
                new DateTime(2017, 03, 09, 06, 00, 00),
                new DateTime(2017, 03, 10, 06, 00, 00),
                new DateTime(2017, 03, 13, 06, 00, 00),
                new DateTime(2017, 03, 14, 06, 00, 00),
                new DateTime(2017, 03, 17, 06, 00, 00),
                new DateTime(2017, 03, 20, 06, 00, 00),
                new DateTime(2017, 03, 21, 06, 00, 00),
                new DateTime(2017, 03, 22, 06, 00, 00),
                new DateTime(2017, 03, 23, 06, 00, 00),
                new DateTime(2017, 03, 24, 06, 00, 00),
                new DateTime(2017, 03, 27, 06, 00, 00),
                new DateTime(2017, 03, 28, 06, 00, 00),
                new DateTime(2017, 03, 29, 06, 00, 00),
                new DateTime(2017, 03, 30, 06, 00, 00),
                new DateTime(2017, 03, 31, 06, 00, 00),
                new DateTime(2017, 04, 03, 06, 00, 00),
                new DateTime(2017, 04, 05, 06, 00, 00),
                new DateTime(2017, 04, 06, 06, 00, 00),
                new DateTime(2017, 04, 07, 06, 00, 00),
                new DateTime(2017, 04, 10, 06, 00, 00),
                new DateTime(2017, 04, 11, 06, 00, 00),
                new DateTime(2017, 04, 12, 06, 00, 00),
                new DateTime(2017, 04, 13, 06, 00, 00),
                new DateTime(2017, 04, 17, 06, 00, 00),
                new DateTime(2017, 04, 18, 06, 00, 00),
                new DateTime(2017, 04, 19, 06, 00, 00),
                new DateTime(2017, 04, 20, 06, 00, 00),
                new DateTime(2017, 04, 21, 06, 00, 00),
                new DateTime(2017, 04, 24, 06, 00, 00),
                new DateTime(2017, 04, 25, 06, 00, 00),
                new DateTime(2017, 04, 27, 06, 00, 00),
                new DateTime(2017, 04, 28, 06, 00, 00),
                new DateTime(2017, 05, 01, 06, 00, 00),
            }
            .Select(dt => new Period(new CalDateTime(dt))).ToList();
            var a = new PeriodList();

            foreach (var period in startTimesA)
            {
                a.Add(period);
            }

            //Difference from A: first element became the second, and last element became the second-to-last element
            var startTimesB = new List <DateTime>
            {
                new DateTime(2017, 03, 03, 06, 00, 00),
                new DateTime(2017, 03, 02, 06, 00, 00),
                new DateTime(2017, 03, 06, 06, 00, 00),
                new DateTime(2017, 03, 07, 06, 00, 00),
                new DateTime(2017, 03, 08, 06, 00, 00),
                new DateTime(2017, 03, 09, 06, 00, 00),
                new DateTime(2017, 03, 10, 06, 00, 00),
                new DateTime(2017, 03, 13, 06, 00, 00),
                new DateTime(2017, 03, 14, 06, 00, 00),
                new DateTime(2017, 03, 17, 06, 00, 00),
                new DateTime(2017, 03, 20, 06, 00, 00),
                new DateTime(2017, 03, 21, 06, 00, 00),
                new DateTime(2017, 03, 22, 06, 00, 00),
                new DateTime(2017, 03, 23, 06, 00, 00),
                new DateTime(2017, 03, 24, 06, 00, 00),
                new DateTime(2017, 03, 27, 06, 00, 00),
                new DateTime(2017, 03, 28, 06, 00, 00),
                new DateTime(2017, 03, 29, 06, 00, 00),
                new DateTime(2017, 03, 30, 06, 00, 00),
                new DateTime(2017, 03, 31, 06, 00, 00),
                new DateTime(2017, 04, 03, 06, 00, 00),
                new DateTime(2017, 04, 05, 06, 00, 00),
                new DateTime(2017, 04, 06, 06, 00, 00),
                new DateTime(2017, 04, 07, 06, 00, 00),
                new DateTime(2017, 04, 10, 06, 00, 00),
                new DateTime(2017, 04, 11, 06, 00, 00),
                new DateTime(2017, 04, 12, 06, 00, 00),
                new DateTime(2017, 04, 13, 06, 00, 00),
                new DateTime(2017, 04, 17, 06, 00, 00),
                new DateTime(2017, 04, 18, 06, 00, 00),
                new DateTime(2017, 04, 19, 06, 00, 00),
                new DateTime(2017, 04, 20, 06, 00, 00),
                new DateTime(2017, 04, 21, 06, 00, 00),
                new DateTime(2017, 04, 24, 06, 00, 00),
                new DateTime(2017, 04, 25, 06, 00, 00),
                new DateTime(2017, 04, 27, 06, 00, 00),
                new DateTime(2017, 05, 01, 06, 00, 00),
                new DateTime(2017, 04, 28, 06, 00, 00),
            }
            .Select(dt => new Period(new CalDateTime(dt))).ToList();
            var b = new PeriodList();

            foreach (var period in startTimesB)
            {
                b.Add(period);
            }

            var collectionEqual = CollectionHelpers.Equals(a, b);

            Assert.AreEqual(true, collectionEqual);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());

            var listOfListA = new List <IPeriodList> {
                a
            };
            var listOfListB = new List <IPeriodList> {
                b
            };

            Assert.IsTrue(CollectionHelpers.Equals(listOfListA, listOfListB));

            var aThenB = new List <IPeriodList> {
                a, b
            };
            var bThenA = new List <IPeriodList> {
                b, a
            };

            Assert.IsTrue(CollectionHelpers.Equals(aThenB, bThenA));
        }
 public void PeriodList1()
 {
     IPeriodList pl = new PeriodList();
     pl.Add(new Period(new iCalDateTime(DateTime.Now.AddHours(2)), new iCalDateTime(DateTime.Now.AddHours(3))));
     pl.Add(new Period(new iCalDateTime(DateTime.Now.AddHours(4)), new iCalDateTime(DateTime.Now.AddHours(5))));
     SerializeTest(pl, "PeriodList1.xml");
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates the iCalendar object and populates it with events
        /// </summary>
        /// <param name="calendarProps">The calendar props.</param>
        /// <returns></returns>
        private Calendar CreateICalendar(CalendarProps calendarProps)
        {
            // Get a list of Rock Calendar Events filtered by calendarProps
            List <EventItem> eventItems = GetEventItems(calendarProps);

            // Create the iCalendar.
            // Allow ICal to create the VTimeZone object from the local time zone to ensure that we get the correct name and daylight saving offset.
            var icalendar = new Calendar();

            var vtz = VTimeZone.FromLocalTimeZone();

            icalendar.AddTimeZone(vtz);

            var timeZoneId = vtz.TzId;

            // Create each of the events for the calendar(s)
            foreach (EventItem eventItem in eventItems)
            {
                foreach (EventItemOccurrence occurrence in eventItem.EventItemOccurrences)
                {
                    if (occurrence.Schedule == null)
                    {
                        continue;
                    }

                    var serializer = new CalendarSerializer();
                    var ical       = (CalendarCollection)serializer.Deserialize(occurrence.Schedule.iCalendarContent.ToStreamReader());

                    foreach (var icalEvent in ical[0].Events)
                    {
                        // We get all of the schedule info from Schedule.iCalendarContent
                        var ievent = icalEvent.Copy <Ical.Net.Event>();

                        ievent.Summary  = !string.IsNullOrEmpty(eventItem.Name) ? eventItem.Name : string.Empty;
                        ievent.Location = !string.IsNullOrEmpty(occurrence.Location) ? occurrence.Location : string.Empty;

                        // Create the list of exceptions.
                        // Exceptions must meet RFC 5545 iCalendar specifications to be correctly processed by third-party calendar applications
                        // such as Microsoft Outlook and Google Calendar. Specifically, an exception must have exactly the same start time
                        // and time zone as the template event, and the time zone must be expressed as an IANA name.
                        // The most recent version of iCal.Net (v2.3.5) that supports .NET framework v4.5.2 has some inconsistencies in the
                        // iCalendar serialization process, so we need to force the Start, End and Exception dates to render in exactly the same format.
                        ievent.Start = new CalDateTime(icalEvent.Start.Value, timeZoneId);
                        ievent.Start.IsUniversalTime = false;

                        ievent.End = new CalDateTime(icalEvent.End.Value, timeZoneId);
                        ievent.End.IsUniversalTime = false;

                        var eventStartTime = new TimeSpan(ievent.DtStart.Hour, ievent.DtStart.Minute, ievent.DtStart.Second);

                        var newExceptionDatesList = new List <Ical.Net.Interfaces.DataTypes.IPeriodList>();

                        foreach (var exceptionDateList in ievent.ExceptionDates)
                        {
                            var newDateList = new PeriodList()
                            {
                                TzId = timeZoneId
                            };

                            foreach (var exceptionDate in exceptionDateList)
                            {
                                var newDateTime = exceptionDate.StartTime.HasTime ? exceptionDate.StartTime.Value : exceptionDate.StartTime.Value.Add(eventStartTime);

                                newDateTime = new DateTime(newDateTime.Year, newDateTime.Month, newDateTime.Day, newDateTime.Hour, newDateTime.Minute, newDateTime.Second, newDateTime.Millisecond, DateTimeKind.Local);

                                var newDate = new CalDateTime(newDateTime);
                                newDate.IsUniversalTime = false;

                                newDateList.Add(newDate);
                            }

                            newExceptionDatesList.Add(newDateList);
                        }

                        ievent.ExceptionDates = newExceptionDatesList;

                        // Rock has more descriptions than iCal so lets concatenate them
                        string description = CreateEventDescription(eventItem, occurrence);

                        // Don't set the description prop for outlook to force it to use the X-ALT-DESC property which can have markup.
                        if (interactionDeviceType != "Outlook")
                        {
                            ievent.Description = description.ConvertBrToCrLf()
                                                 .Replace("</P>", "")
                                                 .Replace("</p>", "")
                                                 .Replace("<P>", Environment.NewLine)
                                                 .Replace("<p>", Environment.NewLine)
                                                 .Replace("&nbsp;", " ")
                                                 .SanitizeHtml();
                        }

                        // HTML version of the description for outlook
                        ievent.AddProperty("X-ALT-DESC;FMTTYPE=text/html", "<html>" + description + "</html>");

                        // classification: "PUBLIC", "PRIVATE", "CONFIDENTIAL"
                        ievent.Class = "PUBLIC";

                        if (!string.IsNullOrEmpty(eventItem.DetailsUrl))
                        {
                            Uri result;
                            if (Uri.TryCreate(eventItem.DetailsUrl, UriKind.Absolute, out result))
                            {
                                ievent.Url = result;
                            }
                            else if (Uri.TryCreate("http://" + eventItem.DetailsUrl, UriKind.Absolute, out result))
                            {
                                ievent.Url = result;
                            }
                        }

                        // add contact info if it exists
                        if (occurrence.ContactPersonAlias != null)
                        {
                            ievent.Organizer            = new Organizer(string.Format("MAILTO:{0}", occurrence.ContactPersonAlias.Person.Email));
                            ievent.Organizer.CommonName = occurrence.ContactPersonAlias.Person.FullName;

                            // Outlook doesn't seems to use Contacts or Comments
                            string contactName  = !string.IsNullOrEmpty(occurrence.ContactPersonAlias.Person.FullName) ? "Name: " + occurrence.ContactPersonAlias.Person.FullName : string.Empty;
                            string contactEmail = !string.IsNullOrEmpty(occurrence.ContactEmail) ? ", Email: " + occurrence.ContactEmail : string.Empty;
                            string contactPhone = !string.IsNullOrEmpty(occurrence.ContactPhone) ? ", Phone: " + occurrence.ContactPhone : string.Empty;
                            string contactInfo  = contactName + contactEmail + contactPhone;

                            ievent.Contacts.Add(contactInfo);
                            ievent.Comments.Add(contactInfo);
                        }

                        // TODO: categories - comma delimited list of whatever, might use audience
                        foreach (var a in eventItem.EventItemAudiences)
                        {
                            ievent.Categories.Add(a.DefinedValue.Value);
                        }

                        //// No attachments for now.
                        ////if ( eventItem.PhotoId != null )
                        ////{
                        ////    // The DDay Attachment obj doesn't allow you to name the attachment. Nice huh? So just add prop manually...
                        ////    ievent.AddProperty( "ATTACH;VALUE=BINARY;ENCODING=BASE64;X-FILENAME=\"" + eventItem.Photo.FileName + "\"", Convert.ToBase64String( eventItem.Photo.ContentStream.ReadBytesToEnd().ToArray() ) );
                        ////}

                        icalendar.Events.Add(ievent);
                    }
                }
            }

            return(icalendar);
        }
Ejemplo n.º 11
0
        static public void AddNewEvent(iCalendar iCal, EventInfo ei)
        {
            Event evt = iCal.Create <Event>();

            if (ei.Pattern != null)
            {
                evt.DTStart = new iCalDateTime(ei.Pattern.BeginDate.Year, ei.Pattern.BeginDate.Month, ei.Pattern.BeginDate.Day, ei.Begin.Hour, ei.Begin.Minute, ei.Begin.Second);
                evt.DTEnd   = new iCalDateTime(ei.Pattern.BeginDate.Year, ei.Pattern.BeginDate.Month, ei.Pattern.BeginDate.Day, ei.End.Hour, ei.End.Minute, ei.End.Second);
            }
            else
            {
                evt.DTStart = new iCalDateTime(ei.Begin.Year, ei.Begin.Month, ei.Begin.Day, ei.Begin.Hour, ei.Begin.Minute, ei.Begin.Second);
                evt.DTEnd   = new iCalDateTime(ei.End.Year, ei.End.Month, ei.End.Day, ei.End.Hour, ei.End.Minute, ei.End.Second);
            }
            //evt.Description = "#Disc:" + ei.Discipline + "#Type:" + ei.Type + "#Teacher:" + ei.Teacher + "#IsMoved:" + ei.IsMoved.ToString();

            evt.Properties.Add(new CalendarProperty("Название дисциплины", ei.Discipline));
            evt.Properties.Add(new CalendarProperty("Короткое название дисциплины", ei.DisciplineShort));
            evt.Properties.Add(new CalendarProperty("Тип занятия", ei.Type));
            evt.Properties.Add(new CalendarProperty("Полное имя преподавателя", ei.Teacher.Name));
            evt.Properties.Add(new CalendarProperty("ФИО преподавателя", ei.Teacher.ShortName));
            evt.Properties.Add(new CalendarProperty("Группы", ei.CalcUnit));

            evt.Location = ei.Room;
            evt.Summary  = ei.DisciplineShort + ", " + ei.Type + ", " + ei.CalcUnit + ", " + ei.Teacher.ShortName + ", " + ei.Room;

            PeriodList pl = new PeriodList();

            if (ei.Exceptions != null)
            {
                foreach (DateTime dt in ei.Exceptions)
                {
                    pl.Add(new Period(new DDay.iCal.iCalDateTime(dt)));
                }
            }

            if (pl.Count > 0)
            {
                evt.ExceptionDates.Add(pl);
            }

            //if (ei.IsMoved) evt.Summary = evt.Summary + " Перенесено.";

            if (ei.Pattern != null)
            {
                FrequencyType ft = FrequencyType.None;

                switch (ei.Pattern.Type)
                {
                case 1: ft = FrequencyType.Daily;
                    break;

                case 2: ft = FrequencyType.Weekly;
                    break;

                case 3: ft = FrequencyType.Monthly;
                    break;
                }

                RecurrencePattern rp = new RecurrencePattern(ft, ei.Pattern.Frequency);

                List <WeekDay> wdList = GetDayFromMask(ei.Pattern.RepeatMask);
                foreach (WeekDay wd in wdList)
                {
                    rp.ByDay.Add(wd);
                }

                rp.Until = ei.Pattern.EndDate;

                evt.RecurrenceRules.Add(rp);
            }
        }