Exemplo n.º 1
0
 public static void SerializeObject(string filename, Guestbook objectToSerialize)
 {
     using (Stream stream = File.Open(filename, FileMode.Create))
     {
         try
         {
             XmlSerializer bFormatter = new XmlSerializer(typeof(Guestbook));
             bFormatter.Serialize(stream, objectToSerialize);
         }
         catch (Exception e)
         {
             Common.WriteToLog("Guestbook could not be serialized! Message: " + e.Message);
         }
     }
 }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ValidateGuestbook();
            g = (Library.Guestbook) Application["GuestBook"];

            SetTextOnPage();

            #region Smileys
            if (bool.Parse(ConfigurationManager.AppSettings["GuestbookSmileys"]))
            {
                Session["smileys"] = Common.GetSmileys("*.gif");
                foreach (string myFile in (ArrayList)Session["smileys"])
                    litSmileys.Text += "<img src='" + ConfigurationManager.AppSettings["ImageSmileysPath"] + myFile + "' onclick=\"InsertSmiley('[" + myFile + "]')\" />\n";
            }
            #endregion

            lvGuests.DataSource = g.Guests;
            lvGuests.DataBind();
        }
Exemplo n.º 3
0
 private void ValidateGuestbook()
 {
     // Validate application object
     if (Application["GuestBook"] == null)
         Application["GuestBook"] = g = Library.Guestbook.DeserializeObject(ConfigurationManager.AppSettings["GuestbookFilePath"]);
     else
     {
         g = (Library.Guestbook)Application["GuestBook"];
         if (g.Guests == null || g.Guests.Count == 0)
             Application["GuestBook"] = g = Library.Guestbook.DeserializeObject(ConfigurationManager.AppSettings["GuestbookFilePath"]);
     }
 }
Exemplo n.º 4
0
        private void ValidateApplicationObjects()
        {
            // Validate productCatalog application object
            if (Application["ProductCatalog"] == null)
                Application["ProductCatalog"] = pc = ProductCatalog.DeserializeObject(ConfigurationManager.AppSettings["ProductFilePath"]);
            else
            {
                pc = (ProductCatalog)Application["ProductCatalog"];
                if (pc.Products == null || pc.Products.Count == 0)
                    Application["ProductCatalog"] = pc = ProductCatalog.DeserializeObject(ConfigurationManager.AppSettings["ProductFilePath"]);
            }

            // Validate guestbook application object
            if (Application["GuestBook"] == null)
                Application["GuestBook"] = g = Library.Guestbook.DeserializeObject(ConfigurationManager.AppSettings["GuestbookFilePath"]);
            else
            {
                g = (Library.Guestbook)Application["GuestBook"];
                if (g.Guests == null || g.Guests.Count == 0)
                    Application["GuestBook"] = g = Library.Guestbook.DeserializeObject(ConfigurationManager.AppSettings["GuestbookFilePath"]);
            }
        }