Beispiel #1
0
        /// <summary>
        /// Recreates an existing Appointment from persistent storage.
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public override DiaryProduct Create(ObjectId objectId)
        {
            // Check if it already exists
            for (int childIndex = 0; childIndex < mAppointments.GetChildCount(); ++childIndex)
            {
                Appointment appointment = mAppointments.GetChild(childIndex);
                if (appointment.GetObjectId() == objectId)
                {
                    return(appointment);
                }
            }

            // Not already loaded ?
            VariableLengthRecord record = Read(objectId);

            if (record != null)
            {
                var label = String.Empty;
                if (record.GetValue(0, ref label))
                {
                    var details = String.Empty;
                    if (record.GetValue(1, ref details))
                    {
                        var occurs = new DateTime();
                        if (record.GetValue(2, ref occurs))
                        {
                            int durationMinutes = 0;
                            if (record.GetValue(3, ref durationMinutes))
                            {
                                var appointment = new Appointment(objectId, label, occurs, durationMinutes, details);

                                mAppointments.Add(appointment);

                                LoadContacts(4, appointment, record); // Now take care of any Contacts

                                return(appointment);
                            }
                        }
                    }
                }
            }

            return(null);  // No such appointment
        }
 /// <summary>
 /// Recreates existing Contacts from persistent storage.
 /// </summary>
 /// <param name="startingField"></param>
 /// <param name="appointment"></param>
 /// <param name="record"></param>
 /// <returns></returns>
 protected int LoadContacts(int startingField, PeriodicAppointment appointment, VariableLengthRecord record)
 {
     using (var creator = new ContactCreator())
     {
         int contactCount = 0;
         if (record.GetValue(startingField, ref contactCount) && contactCount > 0)
         {
             int endingField = startingField + 1 + contactCount;
             for (int field = startingField + 1; field < endingField; field++)
             {
                 var objectId = new ObjectId();
                 if (record.GetValue(field, ref objectId))
                 {
                     var contact = (Contact)creator.Create(objectId);
                     appointment.AddRelation(contact);
                 }
             }
             return(endingField);   // Next possible field
         }
         return(startingField + 1); // Should not get here
     }
 }
Beispiel #3
0
        /// <summary>
        /// Recreates an existing Contact from persistent storage.
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
                public override DiaryProduct Create(ObjectId objectId)
        {
                        // Check if it already exists in memory.
                        for(int childIndex = 0; childIndex < mContacts.GetChildCount(); ++childIndex)
            {
                Contact contact = mContacts.GetChild(childIndex);

                if (contact.GetObjectId() == objectId)
                {
                    return(contact);
                }
            }

                        // Not already loaded ?
                        VariableLengthRecord record = Read(objectId);

            if (record != null)
            {
                var firstName = String.Empty;
                if (record.GetValue(0, ref firstName))
                {
                    var lastName = String.Empty;
                    if (record.GetValue(1, ref lastName))
                    {
                        var contactInfo = String.Empty;
                        if (record.GetValue(2, ref contactInfo))
                        {
                            var contact = new Contact(objectId, firstName, lastName, contactInfo);

                            mContacts.Add(contact);
                            return(contact);
                        }
                    }
                }
            }

            return(null);  // No such contact
                        
        }
Beispiel #4
0
        /// <summary>
        /// Recreates an existing Reminder from persistent storage.
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public override DiaryProduct Create(ObjectId objectId)
        {
                        // Check if it already exists in memory.
                        for(int childIndex = 0; childIndex < mReminders.GetChildCount(); ++childIndex)
            {
                Reminder reminder = mReminders.GetChild(childIndex);

                if (reminder.GetObjectId() == objectId)
                {
                    return(reminder);
                }
            }

                        // Not already loaded ?
                        VariableLengthRecord record = Read(objectId);

            if (record != null)
            {
                var label = String.Empty;
                if (record.GetValue(0, ref label))
                {
                    var date = new Date();
                    if (record.GetValue(1, ref date))
                    {
                        var details = String.Empty;
                        if (record.GetValue(2, ref details))
                        {
                            var reminder = new Reminder(objectId, label, date, details);

                            mReminders.Add(reminder);
                            return(reminder);
                        }
                    }
                }
            }

            return(null);  // No such reminder
        }
        /// <summary>
        /// Recreates an existing PeriodicAppointment from persistent storage.
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public override DiaryProduct Create(ObjectId objectId)
        {
            // Check if it already exists
            for (int childIndex = 0; childIndex < mPeriodicAppointments.GetChildCount(); ++childIndex)
            {
                PeriodicAppointment periodicAppointment = mPeriodicAppointments.GetChild(childIndex);
                if (periodicAppointment.GetObjectId() == objectId)
                {
                    return(periodicAppointment);
                }
            }

            // Not already loaded ?
            VariableLengthRecord record = Read(objectId);

            if (record != null)
            {
                var label = String.Empty;
                if (record.GetValue(0, ref label))
                {
                    var firstOccurs = new DateTime();
                    if (record.GetValue(1, ref firstOccurs))
                    {
                        int durationMinutes = 0;
                        if (record.GetValue(2, ref durationMinutes))
                        {
                            var notToExceedDateTime = new DateTime();
                            if (record.GetValue(3, ref notToExceedDateTime))
                            {
                                int periodHours = 0;
                                if (record.GetValue(4, ref periodHours))
                                {
                                    var details = String.Empty;
                                    if (record.GetValue(5, ref details))
                                    {
                                        var periodicAppointment = new PeriodicAppointment(objectId, label, firstOccurs, durationMinutes, notToExceedDateTime, periodHours, details);

                                        mPeriodicAppointments.Add(periodicAppointment);

                                        LoadContacts(6, periodicAppointment, record); // Now take care of any Contacts

                                        return(periodicAppointment);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(null);  // No such appointment
        }