Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic saveto for a single appointment (Read 5932 times)
awarren
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Sep 17th, 2008
saveto for a single appointment
Sep 29th, 2008 at 4:09pm
Print Post  
I want to use the saveto - loadfrom to save single appointments but am having trouble with figuring out how to do it.

When I have some selected items I want to serialize them then send them to other users through email, ftp.  I do not want to do the whole schedule, just the changed items.  Is this possible?

_schedule.ItemSelection.Items(iloop).SaveTo


If you could give me an example how this would work I would greatly appreciate it.

Then after I have saved the item I want to append or modify the schedule in the other users schedule to synchronize with the master schedule.  I do not know which command to import the appointments( they could be new ones or they could be existing)

Thank you,

  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: saveto for a single appointment
Reply #1 - Sep 30th, 2008 at 7:13am
Print Post  
Below are some code snippets that can help you achieve the desired result. The code uses a member variable for storing items' contents:

Code
Select All
private MemoryStream save = null; 


Here is the code that saves the currently selected items in a memory stream:

Code
Select All
if (save != null)
{
      save.Dispose();
      save = null;
}

// Create the buffer
save = new MemoryStream();

// Create the buffer writer
BinaryWriter writer = new BinaryWriter(save);

// Create the serialization context
BinarySerializationContext context =
      new BinarySerializationContext(calendar1.Schedule);

// Save the item count
writer.Write(calendar1.ItemSelection.Items.Length);

// Save the selected items
foreach (Item item in calendar1.ItemSelection.Items)
{
      // Save the item Id. This will help us detect whether the
      // item already exists in the schedule before loading
      writer.Write(item.Id);

      // Save the item itself
      item.SaveTo(writer, context);
} 


Here is the code that loads the previously saved appointments.

Code
Select All
if (save == null)
      return;

// Seek to the beginning of the stream
save.Seek(0, SeekOrigin.Begin);

// Create a buffer reader
BinaryReader reader = new BinaryReader(save);

// Read the item count
int count = reader.ReadInt32();
if (count == 0)
      return;

// Create the deserialization context
BinarySerializationContext context =
      new BinarySerializationContext(calendar1.Schedule);

// Read the items
for (int i = 0; i < count; i++)
{
      // Read the id
      string id = reader.ReadString();

      // Check if an item with this id already exists
      Item item = calendar1.Schedule.Items[id];

      // If the item doesn't exist, create it.
      // Note: in the general case we have to be aware of the actual
      // type of the item that was serialized. For the purposes of
      // this sample we will assume its type is an Appointment
      if (item == null)
      {
            item = new Appointment();
            calendar1.Schedule.Items.Add(item);
      }

      // Load the item's contents from the stream
      item.LoadFrom(reader, context);
} 



Meppy
  
Back to top
 
IP Logged
 
awarren
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Sep 17th, 2008
Re: saveto for a single appointment
Reply #2 - Nov 5th, 2008 at 11:20pm
Print Post  
Ok, I have this part working where a calendar on a different machine gets updated from the serialization file.  The problem I am having is with recurring appointments.  If I update one occurance in a series it updates the single occurance on the creation computer but the updating computer gets all the occurances changed.  I am changing the imageindex, brush, descriptiontext,tag and they all change on the recicving computer.  I see a read only occuranceindex property but cannot figure out how to bring the appointment across in the same exact state as it was when it left the issuing computer.  I have tried both xml and binary serialization using the saveto and loadfrom of the Itemselection.items.




Please help.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: saveto for a single appointment
Reply #3 - Nov 6th, 2008 at 10:20am
Print Post  
When applying the changes on the target machine, you need to apply them to the occurrence that has been changed, rather than the master item of the recurrence. Applying the changes to the master item (the one you assign the Recurrence object to) will cause them to affect all items in the recurrence sequence. In order to retrieve an individual occurrence of a recurrence pattern, invoke the GetOccurrence method of the Recurrence object and supply the index of the occurrence of interest. The method returns an instance of the Item class representing the occurrence with the specified index. For example, if you change the 5th occurrence of a recurring sequence and you want to transfer the changes to the target machine, remember the occurrence index (5), then when applying the changes to the target machine, invoke the GetOccurrence method and supply 5 as its first argument. Then, apply the changes to the returned Item instance.

Let me know if this is clear enough.

Meppy
  
Back to top
 
IP Logged
 
awarren
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Sep 17th, 2008
Re: saveto for a single appointment
Reply #4 - Nov 7th, 2008 at 5:24am
Print Post  
Thank you very much.  I did not see GetOccurrence.  That takes care of it.  Thank you for the quick response.
  
Back to top
 
IP Logged
 
SuperKing
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Oct 24th, 2008
Re: saveto for a single appointment
Reply #5 - Jan 26th, 2009 at 2:41pm
Print Post  
Figured I'd jump on this topic instead of creating a new one since my question is also related to serialization of appointments.

I have my own C# class that inherits from the MindFusion.Scheduling.Appointment class (call it AppointmentClass). I have created my own XML serialization to serialize some of the existing Appointment properties, like ID, Subject, etc, as well as some properties I've added. I am also serializing/deserializing the Contacts collection from the Appointment (similar to the Appointment, I have a new ContactClass that adds several properties to the Mindfusion.Scheduling.Contact class, and is serialized in the same manner).

My problem is, after deserializing the AppointmentClass objects and adding them to the schedule, they do not actually display on the schedule once the schedule is closed. That is, when I check the Schedule.Items collection in the debugger after deserialization, they are present, with the correct properties/IDs of the original Appointments prior to serialization. Is there perhaps some property on the Appointment class that isn't being set after I deserialize, and is causing this? Thanks.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: saveto for a single appointment
Reply #6 - Jan 26th, 2009 at 3:00pm
Print Post  
If you are using grouping, you have to ensure that the appropriate Calendar collection is filled with the resources you want to group by. For example, if you are grouping by contacts, you need to fill the contacts to group by in the Calendar.Contacts collection (and set the Calendar.GroupType to the appropriate value).

Meppy
  
Back to top
 
IP Logged
 
SuperKing
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Oct 24th, 2008
Re: saveto for a single appointment
Reply #7 - Jan 26th, 2009 at 3:32pm
Print Post  
Thanks for the quick response Meppy.

I am using grouping, and I already have the grouping set (GroupByContacts). My Calendar.Contacts collection already contains the list of ContactClass objects, some of which will be in the AppointmentClass.Contacts list.

Nothing has changed with either of these two properties.

Is it correct that the only field required to match up on the Contacts in these two groups (Appointment.Contacts and Calendar.Contacts) for the appointment to show up under the contact on the calendar is the Contact.ID? Thanks.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: saveto for a single appointment
Reply #8 - Jan 26th, 2009 at 3:50pm
Print Post  
The contacts in Calendar.Contacts and Appointment.Contacts collections must reference the same objects (simple Id matching will not be sufficient). Therefore, if you load a Schedule (Appointments, Contacts and so on), you will also have to refresh the Calendar.Contacts collection with the newly loaded Contact objects.

Hope this helps,
Meppy
  
Back to top
 
IP Logged
 
SuperKing
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Oct 24th, 2008
Re: saveto for a single appointment
Reply #9 - Jan 27th, 2009 at 1:59pm
Print Post  
That did the trick, I was taking that for granted before when not serializing that I was using the exact same Contacts. Thanks for the help Meppy, keep up the good work.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint