Exemplo n.º 1
0
        /// <summary>
        /// Saves Contacts in memory to persistent storage.
        /// </summary>
        protected void SaveContacts(PeriodicAppointment appointment, VariableLengthRecord record)
        {
            Relation1M <Contact> contacts = appointment.GetContacts();

            record.AppendValue(contacts.GetChildCount());   //#4  //might be a 0
            for (int contactIndex = 0; contactIndex < contacts.GetChildCount(); ++contactIndex)
            {
                record.AppendValue(contacts.GetChild(contactIndex).GetObjectId());   //#5 - N
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the input DiaryProduct to persistent storage.
        /// </summary>
        /// <param name="objectId"></param>
        /// <param name="record"></param>
        public void Write(ObjectId objectId, VariableLengthRecord record)
        {
            int dataFileOffset = 0;
            int dataSize       = 0;

            if (sDataFile.Append(record, ref dataFileOffset, ref dataSize))
            {
                sKeyFile.Update(objectId, dataFileOffset, dataSize);
                sKeyFile.Save();
            }
        }
Exemplo n.º 3
0
        /// <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
        }
Exemplo n.º 4
0
        public bool Read(int dataFileOffset, int dataSizeBytes, VariableLengthRecord record)
        {
            try
            {
                mFileStream.seek(dataFileOffset); // Seek to the end of the file

                return(record.Deserialize(mFileStream));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves Reminders in memory to persistent storage.
        /// </summary>
        public override void Save()
        {
            // Step through any previously loaded records and save to file.
            for (int childIndex = 0; childIndex < mReminders.GetChildCount(); ++childIndex)
            {
                Reminder reminder = mReminders.GetChild(childIndex);

                var record = new VariableLengthRecord();
                record.AppendValue(reminder.GetLabel());
                record.AppendValue(reminder.GetDate());
                record.AppendValue(reminder.GetDetails());

                Write(reminder.GetObjectId(), record);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Saves Contacts in memory to persistent storage.
        /// </summary>
        public override void Save()
        {
            // Step through any previously loaded records and save to file.
            for (int childIndex = 0; childIndex < mContacts.GetChildCount(); ++childIndex)
            {
                Contact contact = mContacts.GetChild(childIndex);

                var      record = new VariableLengthRecord();
                String[] names  = contact.GetName();
                record.AppendValue(names[0]);
                record.AppendValue(names[1]);
                record.AppendValue(contact.GetContactInfo());

                Write(contact.GetObjectId(), record);
            }
        }
Exemplo n.º 7
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
        }
Exemplo n.º 8
0
        /// <summary>
        /// Saves Appointments in memory to persistent storage.
        /// </summary>
        public override void Save()
        {
            // Step through any previously loaded records and save to file.
            for (int childIndex = 0; childIndex < mAppointments.GetChildCount(); ++childIndex)
            {
                Appointment appointment = mAppointments.GetChild(childIndex);

                var record = new VariableLengthRecord();
                record.AppendValue(appointment.GetLabel());           //#1
                record.AppendValue(appointment.GetDetails());         //#2
                record.AppendValue(appointment.GetStartTime());       //#3
                record.AppendValue(appointment.GetDurationMinutes()); //#4

                // Now take care of contacts appointment might be related to
                SaveContacts(appointment, record);

                Write(appointment.GetObjectId(), record);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Reads a variable length record by object id.  
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns>Returns null if the record does not exist.</returns>
        public VariableLengthRecord Read(ObjectId objectId)
        {
            int dataFileOffset = 0;
            int dataSize       = 0;

            if (sKeyFile.Get(objectId, ref dataFileOffset, ref dataSize))
            {
                var record = new VariableLengthRecord();
                if (sDataFile.Read(dataFileOffset, dataSize, record))
                {
                    return(record);
                }
                else
                {
                    int x = dataFileOffset;
                }
            }
            return(null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adds the record and returns the starting offset and number of bytes written.
        /// </summary>
        /// <param name="record"></param>
        /// <param name="dataFileOffset"></param>
        /// <param name="dataSizeBytes"></param>
        /// <returns></returns>
        public bool Append(VariableLengthRecord record, ref int dataFileOffset, ref int dataSizeBytes)
        {
            try
            {
                dataFileOffset = (int)mFileStream.length();
                mFileStream.seek(dataFileOffset);                 // Seek to the end of the file

                dataSizeBytes = record.Serialize(mFileStream);    // Convert the record to the stream
                mBytesUsed   += dataSizeBytes;

                mFileStream.seek(0);
                mFileStream.writeInt(mBytesUsed);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 11
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
                        
        }
Exemplo n.º 12
0
 /// <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, Appointment 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
     }
 }
Exemplo n.º 13
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
        }