Exemple #1
0
        internal void LoadDayExtra(string fullPath)
        {
            FileStream fileStream = FileUtils.OpenForRead(fullPath);

            if (fileStream != null)
            {
                try
                {
                    XmlSerializer ser = new XmlSerializer(typeof(DayExtraOld), "urn:newtelligence-com:dasblog:runtime:data");
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        //TODO: SDH: We need to have a better namespace upgrading solution for Medium Trust for folks with the OLD XML format
                        //XmlNamespaceUpgradeReader upg = new XmlNamespaceUpgradeReader(reader, "", "urn:newtelligence-com:dasblog:runtime:data");
                        DayExtraOld e = (DayExtraOld)ser.Deserialize(reader);
                        this._date      = e.DateLocalTime;
                        this._comments  = e.Comments;
                        this._trackings = e.Trackings;
                    }
                }
                catch (Exception e)
                {
                    ErrorTrace.Trace(TraceLevel.Error, e);
                }
                finally
                {
                    fileStream.Close();
                }
            }
        }
Exemple #2
0
		public static void Upgrade(string path)
		{
			// more aggresive way to upgrade files
			foreach (FileInfo fi in new DirectoryInfo(path).GetFiles("*.dayextra.xml"))
			{
				DayExtraOld dayExtra = new DayExtraOld(fi.FullName);
				string filename = dayExtra.DateLocalTime.ToUniversalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + ".dayfeedback.xml";
				FileStream fileStream = FileUtils.OpenForWrite(Path.Combine(path, filename));
				if (fileStream != null)
				{
					try
					{
						XmlSerializer ser = new XmlSerializer(typeof (DayExtraOld), "urn:newtelligence-com:dasblog:runtime:data");
						using (StreamWriter writer = new StreamWriter(fileStream))
						{
							ser.Serialize(writer, dayExtra);
						}

						try
						{
							WriteLine(String.Format("Saved {0}", fi.Name));

							DirectoryInfo backup = new DirectoryInfo(Path.Combine(path, "backup"));

							if (!backup.Exists)
							{
								backup.Create();
							}

							fi.MoveTo(Path.Combine(backup.FullName, fi.Name));
						}
						catch (Exception ex)
						{
							WriteLine(String.Format("ERROR: Cannot delete file: {0}", fi.FullName));
							WriteLine(ex.ToString());
						}
					}
					catch (Exception e)
					{
						ErrorTrace.Trace(TraceLevel.Error, e);
						// truncate the file if this fails
						fileStream.SetLength(0);
					}
					finally
					{
						fileStream.Close();
					}
				}
			}
		}