Example #1
0
        /// <summary>
        ///     Determines whether the specified <see cref="System.Object" /> is equal to this instance.
        /// </summary>
        /// <param name="obj">
        ///     The <see cref="System.Object" /> to compare with this instance.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            var periodList = obj as IPeriodList;

            if (periodList != null)
            {
                IPeriodList r = periodList;

                IEnumerator <IPeriod> p1Enum = GetEnumerator( );
                IEnumerator <IPeriod> p2Enum = r.GetEnumerator( );

                while (p1Enum.MoveNext( ))
                {
                    if (!p2Enum.MoveNext( ))
                    {
                        return(false);
                    }

                    if (!Equals(p1Enum.Current, p2Enum.Current))
                    {
                        return(false);
                    }
                }

                if (p2Enum.MoveNext( ))
                {
                    return(false);
                }

                return(true);
            }
// ReSharper disable BaseObjectEqualsIsObjectEquals
            return(base.Equals(obj));
// ReSharper restore BaseObjectEqualsIsObjectEquals
        }
Example #2
0
        public override bool Equals(object obj)
        {
            if (obj is IPeriodList)
            {
                IPeriodList r = (IPeriodList)obj;

                IEnumerator <IPeriod> p1Enum = GetEnumerator();
                IEnumerator <IPeriod> p2Enum = r.GetEnumerator();

                while (p1Enum.MoveNext())
                {
                    if (!p2Enum.MoveNext())
                    {
                        return(false);
                    }

                    if (!object.Equals(p1Enum.Current, p2Enum.Current))
                    {
                        return(false);
                    }
                }

                if (p2Enum.MoveNext())
                {
                    return(false);
                }

                return(true);
            }
            return(base.Equals(obj));
        }
Example #3
0
        public override string SerializeToString(object obj)
        {
            IPeriodList        rdt     = obj as IPeriodList;
            ISerializerFactory factory = GetService <ISerializerFactory>();

            if (rdt != null && factory != null)
            {
                IStringSerializer dtSerializer     = factory.Build(typeof(IDateTime), SerializationContext) as IStringSerializer;
                IStringSerializer periodSerializer = factory.Build(typeof(IPeriod), SerializationContext) as IStringSerializer;
                if (dtSerializer != null && periodSerializer != null)
                {
                    List <string> parts = new List <string>();

                    foreach (IPeriod p in rdt)
                    {
                        if (p.EndTime != null)
                        {
                            parts.Add(periodSerializer.SerializeToString(p));
                        }
                        else if (p.StartTime != null)
                        {
                            parts.Add(dtSerializer.SerializeToString(p.StartTime));
                        }
                    }

                    return(Encode(rdt, string.Join(",", parts.ToArray())));
                }
            }
            return(null);
        }
Example #4
0
        public void DetermineStartingRecurrence(IPeriodList rdate, ref IDateTime referenceDateTime)
        {
            var evaluator = rdate.GetService <IEvaluator>();

            var dt2 = referenceDateTime;

            foreach (var p in evaluator.Periods.Where(p => p.StartTime.LessThan(dt2)))
            {
                referenceDateTime = p.StartTime;
            }
        }
Example #5
0
 public override void CopyFrom(ICopyable obj)
 {
     base.CopyFrom(obj);
     if (obj is IPeriodList)
     {
         IPeriodList rdt = (IPeriodList)obj;
         foreach (IPeriod p in rdt)
         {
             Add(p.Copy <IPeriod>());
         }
     }
 }
Example #6
0
        public void DetermineStartingRecurrence(IPeriodList rdate, ref IDateTime dt)
        {
            IEvaluator evaluator = rdate.GetService(typeof(IEvaluator)) as IEvaluator;
            if (evaluator == null)
            {
                // FIXME: throw a specific, typed exception here.
                throw new Exception("Could not determine starting recurrence: a period evaluator could not be found!");
            }

            foreach (IPeriod p in evaluator.Periods)
            {
                if (p.StartTime.LessThan(dt))
                    dt = p.StartTime;
            }
        }
Example #7
0
        /// <summary>
        ///     Copies values from the target object to the
        ///     current object.
        /// </summary>
        /// <param name="obj"></param>
        public override sealed void CopyFrom(ICopyable obj)
        {
            base.CopyFrom(obj);

            var periodList = obj as IPeriodList;

            if (periodList != null)
            {
                IPeriodList rdt = periodList;
                foreach (IPeriod p in rdt)
                {
                    Add(p.Copy <IPeriod>( ));
                }
            }
        }
Example #8
0
        /// <summary>
        ///     Determines the starting recurrence.
        /// </summary>
        /// <param name="periodList">The period list.</param>
        /// <param name="dt">The date time.</param>
        /// <exception cref="System.Exception">Could not determine starting recurrence: a period evaluator could not be found!</exception>
        public void DetermineStartingRecurrence(IPeriodList periodList, ref IDateTime dt)
        {
            var evaluator = periodList.GetService(typeof(IEvaluator)) as IEvaluator;

            if (evaluator == null)
            {
                // FIXME: throw a specific, typed exception here.
                throw new Exception("Could not determine starting recurrence: a period evaluator could not be found!");
            }

            foreach (IPeriod p in evaluator.Periods)
            {
                if (p.StartTime.LessThan(dt))
                {
                    dt = p.StartTime;
                }
            }
        }
Example #9
0
        public override object Deserialize(TextReader tr)
        {
            string value = tr.ReadToEnd();

            // Create the day specifier and associate it with a calendar object
            IPeriodList        rdt     = CreateAndAssociate() as IPeriodList;
            ISerializerFactory factory = GetService <ISerializerFactory>();

            if (rdt != null && factory != null)
            {
                // Decode the value, if necessary
                value = Decode(rdt, value);

                IStringSerializer dtSerializer     = factory.Build(typeof(IDateTime), SerializationContext) as IStringSerializer;
                IStringSerializer periodSerializer = factory.Build(typeof(IPeriod), SerializationContext) as IStringSerializer;
                if (dtSerializer != null && periodSerializer != null)
                {
                    string[] values = value.Split(',');
                    foreach (string v in values)
                    {
                        StringReader reader = new StringReader(v);
                        IDateTime    dt     = dtSerializer.Deserialize(reader) as IDateTime;
                        reader.Dispose();
                        reader = new StringReader(v);
                        IPeriod p = periodSerializer.Deserialize(reader) as IPeriod;
                        reader.Dispose();

                        if (dt != null)
                        {
                            dt.AssociatedObject = rdt.AssociatedObject;
                            rdt.Add(dt);
                        }
                        else if (p != null)
                        {
                            p.AssociatedObject = rdt.AssociatedObject;
                            rdt.Add(p);
                        }
                    }
                    return(rdt);
                }
            }

            return(null);
        }
 public PeriodListEvaluator(IPeriodList rdt)
 {
     m_PeriodList = rdt;
 }
 public PeriodListEvaluator(IPeriodList rdt)
 {
     m_PeriodList = rdt;
 }