Пример #1
0
		public static void Save(DayExtra dayExtra, IBlogDataService dataService)
		{
			FileStream fileStream = FileUtils.OpenForWrite(Path.Combine(ContentPath, dayExtra.FileName));

			if (fileStream != null)
			{
				try
				{
					XmlSerializer ser = new XmlSerializer(typeof (DayExtra), "urn:newtelligence-com:dasblog:runtime:data");
					using (StreamWriter writer = new StreamWriter(fileStream))
					{
						ser.Serialize(writer, dayExtra);
					}
				}
				catch (Exception ex)
				{
					WriteLine(String.Format("ERROR: Cannot write file: {0}", dayExtra.FileName));
					WriteLine(ex.ToString());
				}
				finally
				{
					fileStream.Close();
				}
			}
		}
Пример #2
0
 public void Rebuild()
 {
     // get the lock
     fileLock.AcquireWriterLock(100);
     try
     {
         XmlSerializer     x = new XmlSerializer(typeof(DayExtra));
         CommentCollection rebuiltCollection = new CommentCollection();
         DirectoryInfo     di = new DirectoryInfo(this.contentBaseDirectory);
         foreach (FileInfo file in di.GetFiles("*dayfeedback.xml"))
         {
             using (FileStream fs = file.OpenRead())
             {
                 DayExtra de = (DayExtra)x.Deserialize(fs);
                 rebuiltCollection.AddRange(de.Comments);
             }
         }
         _commentCache = rebuiltCollection;
     }
     catch (Exception e)
     {
         // report error
         ErrorTrace.Trace(TraceLevel.Error, e);
     }
     finally
     {
         // release the lock
         fileLock.ReleaseWriterLock();
     }
 }
Пример #3
0
        internal void LoadDayExtra(string fullPath)
        {
            FileStream fileStream = FileUtils.OpenForRead(fullPath);

            if (fileStream != null)
            {
                try
                {
                    XmlSerializer ser = new XmlSerializer(typeof(DayExtra), Data.NamespaceURI);
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        //XmlNamespaceUpgradeReader upg = new XmlNamespaceUpgradeReader(reader, "", Data.NamespaceURI);
                        DayExtra e = (DayExtra)ser.Deserialize(reader);
                        this._comments  = e.Comments;
                        this._trackings = e.Trackings;
                    }
                }
                catch (Exception e)
                {
                    ErrorTrace.Trace(TraceLevel.Error, e);
                }
                finally
                {
                    fileStream.Close();
                }

                //RepairComments();
            }
        }
Пример #4
0
        public DayExtra GetDayExtra(DateTime day)
        {
            DayExtra d = new DayExtra();

            d.DateUtc = day;
            d.Load(this);
            return(d);
        }
Пример #5
0
		public static void RepairComments(DayExtra dayExtra, IBlogDataService dataService)
		{
			//SDH: Corruption or poorly imported comments can have no entry id! 
			// Create one if it's missing. This will slowly repair the damage
			for (int i = 0; i < dayExtra.Comments.Count; i++)
			{
				if (dayExtra.Comments[i].EntryId == null)
				{
					dayExtra.Comments[i].EntryId = Guid.NewGuid().ToString();

					Entry entry = dataService.GetEntry(dayExtra.Comments[i].TargetEntryId);
					if (entry != null)
					{
						dayExtra.Comments[i].TargetTitle = entry.Title;
					}

					WriteLine(String.Format("...Repaired Comments in {0}", dayExtra.FileName));
				}
			}
		}