00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections.Generic;
00014 using System.IO;
00015 using System.Runtime.Serialization.Formatters.Binary;
00016
00017 namespace Mcs.Epm.MicrosoftProject.mpFx.WinForms
00018 {
00019
00020
00021
00022 [Serializable]
00023 public class ProjectsCache
00024 {
00025 #region Nested Classes
00026
00027
00028
00029
00030 [Serializable]
00031 public class CachedProject
00032 {
00033 #region Constructors
00034
00035 public CachedProject(Guid _Guid, string _Name, List<string> _CustomFieldValues)
00036 {
00037 Guid = _Guid;
00038 Name = _Name;
00039 CustomFieldValues = _CustomFieldValues.ToArray();
00040 }
00041
00042 #endregion
00043
00044 #region Public Properties
00045
00046 public Guid Guid { get; set; }
00047
00048 public string Name { get; set; }
00049
00050 public string[] CustomFieldValues { get; set; }
00051
00052 #endregion
00053 }
00054
00055 #endregion
00056
00057 #region Public Static Methods
00058
00059 public static void Serialze(ProjectsCache projectsCache, string path)
00060 {
00061 if (File.Exists(path))
00062 {
00063 File.Delete(path);
00064 }
00065
00066 using (FileStream targetFile = new FileStream(path,
00067 FileMode.Create))
00068 {
00069 BinaryFormatter formatter = new BinaryFormatter();
00070
00071 formatter.Serialize(targetFile,
00072 projectsCache);
00073
00074 targetFile.Flush();
00075 targetFile.Close();
00076 }
00077 }
00078
00079 public static ProjectsCache Deserialze(string path)
00080 {
00081 ProjectsCache returnCache;
00082
00083 using (FileStream targetFile = new FileStream(path,
00084 FileMode.Open))
00085 {
00086 BinaryFormatter formatter = new BinaryFormatter();
00087
00088 returnCache = formatter.Deserialize(targetFile) as ProjectsCache;
00089
00090 targetFile.Flush();
00091 targetFile.Close();
00092 }
00093
00094 return returnCache;
00095 }
00096
00097 #endregion
00098
00099 #region Constructors
00100
00101 public ProjectsCache(ICollection<KeyValuePair<Guid, string>> customFields, int projectCount)
00102 {
00103 CachedCustomFields = new string[customFields.Count];
00104
00105 int counter = 0;
00106
00107 foreach (KeyValuePair<Guid, string> customField in customFields)
00108 {
00109 CachedCustomFields[counter++] = customField.Key + "~" + customField.Value;
00110 }
00111
00112 CachedProjects = new CachedProject[projectCount];
00113 }
00114
00115 public ProjectsCache() { }
00116
00117 #endregion
00118
00119 #region Public Properties
00120
00121 public string[] CachedCustomFields { get; private set; }
00122
00123 public CachedProject[] CachedProjects { get; set; }
00124
00125 #endregion
00126
00127 }
00128 }