public void ICardStyleCloneTest() { TestInfrastructure.DebugLineStart(TestContext); if (TestInfrastructure.IsActive(TestContext)) { using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser)) { IChapter chapter = writeLM.Chapters.AddNew(); ICardStyle style1 = writeLM.CreateCardStyle(); style1.Answer.BackgroundColor = Color.Red; style1.Answer.FontFamily = new FontFamily("Arial"); writeLM.UserSettings.Style = style1; ICardStyle style2 = writeLM.UserSettings.Style.Clone(); //Check if style1 and style2 are equal Assert.AreEqual <Color>(writeLM.UserSettings.Style.Answer.BackgroundColor, style2.Answer.BackgroundColor, "ICardStyle.Clone does not clone the original instance"); Assert.AreEqual <FontFamily>(writeLM.UserSettings.Style.Answer.FontFamily, style2.Answer.FontFamily, "ICardStyle.Clone does not clone the original instance"); style2.Answer.BackgroundColor = Color.Blue; style2.Answer.FontFamily = new FontFamily("Courier New"); //Check if style 1 and style2 are independent Assert.AreNotEqual <Color>(writeLM.UserSettings.Style.Answer.BackgroundColor, style2.Answer.BackgroundColor, "ICardStyle.Clone does not make an independent copy of the original instance"); Assert.AreNotEqual <FontFamily>(writeLM.UserSettings.Style.Answer.FontFamily, style2.Answer.FontFamily, "ICardStyle.Clone does not make an independent copy of the original instance"); } } TestInfrastructure.DebugLineEnd(TestContext); }
public void ICardStyleWatermarkTest01() { TestInfrastructure.DebugLineStart(TestContext); if (TestInfrastructure.IsActive(TestContext) && !(TestContext.DataRow["type"].ToString().ToLower() == "file")) { using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser)) { IChapter chapter = writeLM.Chapters.AddNew(); ICardStyle style = writeLM.CreateCardStyle(); ICard card = writeLM.Cards.AddNew(); card.Chapter = chapter.Id; string image = TestInfrastructure.GetTestImage(); string image2 = TestInfrastructure.GetTestImage(); string image3 = TestInfrastructure.GetTestImage(); Uri imageUri = new Uri(image, UriKind.Absolute); Uri imageUri2 = new Uri(image2, UriKind.Absolute); style.Question.OtherElements.Add("background", String.Format("url({0}) repeat-x", imageUri.AbsoluteUri)); style.Answer.OtherElements.Add("background-image", String.Format("url({0})", imageUri2.AbsolutePath)); style.AnswerExample.OtherElements.Add("background-image", String.Format("url({0})", TestInfrastructure.GetTestImage())); card.Settings.Style = style; writeLM.Save(); ICard card2 = writeLM.Cards.Get(card.Id); string css = card2.Settings.Style.ToString(); MatchCollection mc = cssUrlEntry.Matches(css); if (mc.Count != 3) { Assert.Fail("Invalid number of media objects found! (Should be 3)"); } foreach (Match m in mc) { string url = m.Groups["url"].Value.Trim(new char[] { '"', '\'' }); Uri uri; if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { uri = new Uri(url); WebClient client = new WebClient(); byte[] data = client.DownloadData(uri); if (data.Length <= 0) { Assert.Fail("Invalid media file size! (0)"); } } else { Assert.Fail("Invalid media URI found! ({0})", url); } } } } TestInfrastructure.DebugLineEnd(TestContext); }
/// <summary> /// Initializes the specified actual card. /// </summary> /// <param name="actualCard">The actual card.</param> /// <param name="actualDictionary">The actual dictionary.</param> /// <remarks>Documented by Dev05, 2007-10-31</remarks> public void Initialize(ICard actualCard, ICardStyle actualStyle, Dictionary actualDictionary, object elementToStyle) { styleParent = elementToStyle; dictionary = actualDictionary; style = actualStyle; backupStyle = style.Clone(); card = actualCard; textStyleEditAnswer.Style = style.Answer; textStyleEditAnswerExample.Style = style.AnswerExample; textStyleEditCorrect.Style = style.AnswerCorrect; textStyleEditQuestion.Style = style.Question; textStyleEditQuestionExample.Style = style.QuestionExample; textStyleEditWrong.Style = style.AnswerWrong; ShowPreview(); }
public void IChapterStyleToString() { TestInfrastructure.DebugLineStart(TestContext); if (TestInfrastructure.IsActive(TestContext)) { using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser)) { IChapter chapter = writeLM.Chapters.AddNew(); ICardStyle style = chapter.CreateCardStyle(); ITextStyle defaultTextStyle = style.Answer; //just for init defaultTextStyle.BackgroundColor = Color.Red; defaultTextStyle.FontFamily = new FontFamily("Arial"); defaultTextStyle.FontSize = 8; defaultTextStyle.FontSizeUnit = FontSizeUnit.Pixel; defaultTextStyle.FontStyle = CSSFontStyle.Bold; defaultTextStyle.ForeColor = Color.Red; defaultTextStyle.HorizontalAlign = HorizontalAlignment.Center; defaultTextStyle.VerticalAlign = VerticalAlignment.Bottom; defaultTextStyle.OtherElements.Add("key1", "value1"); style.Answer = defaultTextStyle; style.AnswerCorrect = defaultTextStyle; style.AnswerExample = defaultTextStyle; style.AnswerWrong = defaultTextStyle; style.Question = defaultTextStyle; style.QuestionExample = defaultTextStyle; if (chapter.Settings == null) { chapter.Settings = writeLM.CreateSettings(); } chapter.Settings.Style = style; //This is just a simple fulltext comparison string output = "\n.answer\n{\n\tcolor:\t\t\t\t#ff0000;\n\tbackground-color:\t#ff0000;\n\tfont-family:\t\tArial;\n\tfont-weight:\t\tbold;\n\tText-decoration:none;\n\tfont-size:\t\t\t8px;\n\tvertical-align:\t\tbottom;\n\tText-align:\t\t\tcenter;\n\tkey1:\t\tvalue1;\n}\n\n.answer\n{\n\tcolor:\t\t\t\t#ff0000;\n\tbackground-color:\t#ff0000;\n\tfont-family:\t\tArial;\n\tfont-weight:\t\tbold;\n\tText-decoration:none;\n\tfont-size:\t\t\t8px;\n\tvertical-align:\t\tbottom;\n\tText-align:\t\t\tcenter;\n\tkey1:\t\tvalue1;\n}\n\n.answer\n{\n\tcolor:\t\t\t\t#ff0000;\n\tbackground-color:\t#ff0000;\n\tfont-family:\t\tArial;\n\tfont-weight:\t\tbold;\n\tText-decoration:none;\n\tfont-size:\t\t\t8px;\n\tvertical-align:\t\tbottom;\n\tText-align:\t\t\tcenter;\n\tkey1:\t\tvalue1;\n}\n\n.answer\n{\n\tcolor:\t\t\t\t#ff0000;\n\tbackground-color:\t#ff0000;\n\tfont-family:\t\tArial;\n\tfont-weight:\t\tbold;\n\tText-decoration:none;\n\tfont-size:\t\t\t8px;\n\tvertical-align:\t\tbottom;\n\tText-align:\t\t\tcenter;\n\tkey1:\t\tvalue1;\n}\n\n.answer\n{\n\tcolor:\t\t\t\t#ff0000;\n\tbackground-color:\t#ff0000;\n\tfont-family:\t\tArial;\n\tfont-weight:\t\tbold;\n\tText-decoration:none;\n\tfont-size:\t\t\t8px;\n\tvertical-align:\t\tbottom;\n\tText-align:\t\t\tcenter;\n\tkey1:\t\tvalue1;\n}\n\n.answer\n{\n\tcolor:\t\t\t\t#ff0000;\n\tbackground-color:\t#ff0000;\n\tfont-family:\t\tArial;\n\tfont-weight:\t\tbold;\n\tText-decoration:none;\n\tfont-size:\t\t\t8px;\n\tvertical-align:\t\tbottom;\n\tText-align:\t\t\tcenter;\n\tkey1:\t\tvalue1;\n}\n"; Assert.AreEqual <string>(output.ToLower().Trim(), chapter.Settings.Style.ToString().ToLower().Trim()); } } TestInfrastructure.DebugLineEnd(TestContext); }
public void ICardStyleSaveStylesTest() { TestInfrastructure.DebugLineStart(TestContext); if (TestInfrastructure.IsActive(TestContext)) { using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser)) { IChapter chapter = writeLM.Chapters.AddNew(); ICardStyle style = writeLM.CreateCardStyle(); ICard card = writeLM.Cards.AddNew(); style.Answer.BackgroundColor = Color.Red; style.Answer.FontFamily = new FontFamily("Arial"); card.Settings.Style = style; //Check if style save the settings Assert.AreEqual <Color>(card.Settings.Style.Answer.BackgroundColor, Color.Red, "ICardStyle.Clone does not clone the original instance"); Assert.AreEqual <FontFamily>(card.Settings.Style.Answer.FontFamily, new FontFamily("Arial"), "ICardStyle.Clone does not clone the original instance"); } } TestInfrastructure.DebugLineEnd(TestContext); }
/// <summary> /// Saves the style to the DOM. /// </summary> /// <param name="style">The style.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2007-10-30</remarks> private bool SaveStyleToDOM(ICardStyle style) { bool success = false; StringBuilder stringBuilder = new StringBuilder(); TextWriter stringWriter = new StringWriter(stringBuilder); try { StyleSerializer.Serialize(stringWriter, style); XmlElement xeStyle = m_chapter[m_XPath_Style]; if (xeStyle != null) { m_chapter.RemoveChild(xeStyle); } XmlDocument xdStyle = new XmlDocument(); xdStyle.LoadXml(stringBuilder.ToString()); m_chapter.AppendChild(m_dictionary.ImportNode(xdStyle.DocumentElement, true)); success = true; } catch { } return(success); }
/// <summary> /// Reads the style from DOM. /// </summary> /// <remarks>Documented by Dev03, 2007-11-07</remarks> private void ReadStyleFromDOM() { long lTicks = DateTime.Now.Ticks; //System.Diagnostics.Trace.TraceInformation(@"Read chapter style (id={0}) - {1}", this.Id, DateTime.Now.Ticks - lTicks); //System.Diagnostics.Trace.Indent(); XmlElement xeStyle = m_chapter[m_XPath_Style]; if (xeStyle != null) { if (xeStyle.HasChildNodes) { XmlReader xmlReader = new XmlNodeReader(xeStyle); if (StyleSerializer.CanDeserialize(xmlReader)) { m_Style = (XmlCardStyle)StyleSerializer.Deserialize(xmlReader); (m_Style as XmlCardStyle).Parent = Parent; //System.Diagnostics.Trace.TraceInformation(@"did it - {0}", DateTime.Now.Ticks - lTicks); } } } //System.Diagnostics.Trace.TraceInformation(@"finished - {0}", DateTime.Now.Ticks - lTicks); //System.Diagnostics.Trace.Unindent(); }
public void ICardStyleEmptyValuesTest() { TestInfrastructure.DebugLineStart(TestContext); if (TestInfrastructure.IsActive(TestContext)) { using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser)) { IChapter chapter = writeLM.Chapters.AddNew(); ICardStyle style = writeLM.CreateCardStyle(); ICard card = writeLM.Cards.AddNew(); card.Chapter = chapter.Id; style.Answer.BackgroundColor = new Color(); card.Settings.Style = style; ICard card2 = writeLM.Cards.Get(card.Id); Assert.AreEqual <string>(card.Settings.Style.Answer.BackgroundColor.ToString(), card2.Settings.Style.Answer.BackgroundColor.ToString(), "The Styles (Color) is not empty"); } } TestInfrastructure.DebugLineEnd(TestContext); }
/// <summary> /// Loads the style. /// </summary> /// <param name="actualCard">The actual card.</param> /// <param name="styleToEdit">The style to edit.</param> /// <remarks>Documented by Dev05, 2007-10-31</remarks> public void LoadStyle(ICard actualCard, ICardStyle styleToEdit, Dictionary dictionary, object elementToStyle) { cardStyleEdit.Initialize(actualCard, styleToEdit, dictionary, elementToStyle); }
/// <summary> /// Saves the style to the DOM. /// </summary> /// <param name="style">The style.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2007-10-30</remarks> private bool SaveStyleToDOM(ICardStyle style) { bool success = false; StringBuilder stringBuilder = new StringBuilder(); TextWriter stringWriter = new StringWriter(stringBuilder); try { StyleSerializer.Serialize(stringWriter, style); XmlElement xeStyle = m_generalSettings[m_XPath_Style]; if (xeStyle != null) { m_generalSettings.RemoveChild(xeStyle); } XmlDocument xdStyle = new XmlDocument(); xdStyle.LoadXml(stringBuilder.ToString()); m_generalSettings.AppendChild(m_dictionary.ImportNode(xdStyle.DocumentElement, true)); success = true; } catch { } return success; }
public void SetCardStyle(int id, ICardStyle Style) { using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { if (Style is DbCardStyle) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "UPDATE \"Settings\" SET cardstyle=:csid WHERE id=:id;"; cmd.Parameters.Add("id", id); cmd.Parameters.Add("csid", (Style as DbCardStyle).Id); PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser); } using (NpgsqlCommand cmd2 = con.CreateCommand()) { cmd2.CommandText = "UPDATE \"CardStyles\" SET value=:style WHERE id=:csid;"; cmd2.Parameters.Add("csid", (Style as DbCardStyle).Id); cmd2.Parameters.Add("style", Style.Xml); PostgreSQLConn.ExecuteNonQuery(cmd2, Parent.CurrentUser); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleFk, id, Cache.DefaultSettingsValidationTime)] = (Style as DbCardStyle).Id; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleValue, id, Cache.DefaultSettingsValidationTime)] = Style.Xml; } } else { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO \"CardStyles\"(value) VALUES(:style) RETURNING id; UPDATE \"Settings\" SET cardstyle=currval('\"CardStyles_id_seq\"') WHERE id=:id;"; cmd.Parameters.Add("id", id); cmd.Parameters.Add("style", (Style != null) ? Style.Xml : String.Empty); //PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser); int newId = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser)); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleFk, id, Cache.DefaultSettingsValidationTime)] = newId; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleValue, id, Cache.DefaultSettingsValidationTime)] = (Style != null) ? Style.Xml : String.Empty; } } } }
/// <summary> /// Determines whether [is empty style] [the specified style]. /// </summary> /// <param name="style">The style.</param> /// <returns> /// <c>true</c> if [is empty style] [the specified style]; otherwise, <c>false</c>. /// </returns> /// <remarks>Documented by Dev03, 2008-09-29</remarks> private bool IsEmptyStyle(ICardStyle style) { if (style == null) return true; bool result = true; Type typeCardStyle = style.GetType(); foreach (PropertyInfo property in typeCardStyle.GetProperties()) { if (property.GetType().Equals(typeof(ITextStyle))) { ITextStyle textStyle = property.GetValue(style, null) as ITextStyle; Type typeTextStyle = textStyle.GetType(); foreach (PropertyInfo prop in typeTextStyle.GetProperties()) { if (prop.GetType().Equals(typeof(int))) { int value = (int)prop.GetValue(textStyle, null); result = result && (value == 0); } else if (prop.GetType().Equals(typeof(string))) { string value = (string)prop.GetValue(textStyle, null); result = result && (value.Length == 0); } else if (prop.GetType().Equals(typeof(System.Drawing.Color))) { System.Drawing.Color value = (System.Drawing.Color)prop.GetValue(textStyle, null); result = result && (value == System.Drawing.Color.Empty); } else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily))) { System.Drawing.FontFamily value = (System.Drawing.FontFamily)prop.GetValue(textStyle, null); result = result && (value == null); } else if (prop.GetType().Equals(typeof(FontSizeUnit))) { FontSizeUnit value = (FontSizeUnit)prop.GetValue(textStyle, null); result = result && (value == FontSizeUnit.Pixel); } else if (prop.GetType().Equals(typeof(CSSFontStyle))) { CSSFontStyle value = (CSSFontStyle)prop.GetValue(textStyle, null); result = result && (value == CSSFontStyle.None); } else if (prop.GetType().Equals(typeof(HorizontalAlignment))) { HorizontalAlignment value = (HorizontalAlignment)prop.GetValue(textStyle, null); result = result && (value == HorizontalAlignment.None); } else if (prop.GetType().Equals(typeof(VerticalAlignment))) { VerticalAlignment value = (VerticalAlignment)prop.GetValue(textStyle, null); result = result && (value == VerticalAlignment.None); } else if (prop.Name == "OtherElements") { SerializableDictionary<string, string> otherElements = prop.GetValue(textStyle, null) as SerializableDictionary<string, string>; result = result && (otherElements.Count == 0); } } } } return result; }
/// <summary> /// Reads the style from DOM. /// </summary> /// <remarks>Documented by Dev03, 2007-11-07</remarks> private void ReadStyleFromDOM() { XmlElement xeStyle = m_generalSettings[m_XPath_Style]; if (xeStyle != null) { if (xeStyle.HasChildNodes) { XmlReader xmlReader = new XmlNodeReader(xeStyle); if (StyleSerializer.CanDeserialize(xmlReader)) { m_Style = (XmlCardStyle)StyleSerializer.Deserialize(xmlReader); (m_Style as XmlCardStyle).Parent = Parent; } } } }
/// <summary> /// Compares two objects that implement ICardStyle. /// </summary> /// <param name="one">The first ICardStyle object one.</param> /// <param name="two">The second ICardStyle object.</param> /// <remarks>Documented by Dev03, 2008-09-26</remarks> private void CompareStyles(ICardStyle one, ICardStyle two) { if ((one == null) || (two == null)) { Assert.IsTrue(IsEmptyStyle(one), "Both styles should be null! (one)"); Assert.IsTrue(IsEmptyStyle(two), "Both styles should be null! (two)"); return; } Type typeCardStyle = one.GetType(); foreach (PropertyInfo property in typeCardStyle.GetProperties()) { if (property.GetType().Equals(typeof(ITextStyle))) { ITextStyle textStyleOne = property.GetValue(one, null) as ITextStyle; ITextStyle textStyleTwo = property.GetValue(two, null) as ITextStyle; Type typeTextStyle = textStyleOne.GetType(); foreach (PropertyInfo prop in typeTextStyle.GetProperties()) { if (prop.GetType().Equals(typeof(int))) { int valueOne = (int)prop.GetValue(textStyleOne, null); int valueTwo = (int)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(string))) { string valueOne = (string)prop.GetValue(textStyleOne, null); string valueTwo = (string)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(System.Drawing.Color))) { System.Drawing.Color valueOne = (System.Drawing.Color)prop.GetValue(textStyleOne, null); System.Drawing.Color valueTwo = (System.Drawing.Color)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily))) { System.Drawing.FontFamily valueOne = (System.Drawing.FontFamily)prop.GetValue(textStyleOne, null); System.Drawing.FontFamily valueTwo = (System.Drawing.FontFamily)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(FontSizeUnit))) { FontSizeUnit valueOne = (FontSizeUnit)prop.GetValue(textStyleOne, null); FontSizeUnit valueTwo = (FontSizeUnit)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(CSSFontStyle))) { CSSFontStyle valueOne = (CSSFontStyle)prop.GetValue(textStyleOne, null); CSSFontStyle valueTwo = (CSSFontStyle)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(HorizontalAlignment))) { HorizontalAlignment valueOne = (HorizontalAlignment)prop.GetValue(textStyleOne, null); HorizontalAlignment valueTwo = (HorizontalAlignment)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(VerticalAlignment))) { VerticalAlignment valueOne = (VerticalAlignment)prop.GetValue(textStyleOne, null); VerticalAlignment valueTwo = (VerticalAlignment)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.Name == "OtherElements") { SerializableDictionary<string, string> otherElementsOne = prop.GetValue(textStyleOne, null) as SerializableDictionary<string, string>; SerializableDictionary<string, string> otherElementsTwo = prop.GetValue(textStyleTwo, null) as SerializableDictionary<string, string>; foreach (string key in otherElementsOne.Keys) { Assert.IsTrue((otherElementsTwo.ContainsKey(key) && otherElementsOne[key].Equals(otherElementsTwo[key])), String.Format("Both values for {0}[{1}] should be equal!", prop.Name, key)); } } } } } }
/// <summary> /// Determines whether [is empty style] [the specified style]. /// </summary> /// <param name="style">The style.</param> /// <returns> /// <c>true</c> if [is empty style] [the specified style]; otherwise, <c>false</c>. /// </returns> /// <remarks>Documented by Dev03, 2008-09-29</remarks> private bool IsEmptyStyle(ICardStyle style) { if (style == null) { return(true); } bool result = true; Type typeCardStyle = style.GetType(); foreach (PropertyInfo property in typeCardStyle.GetProperties()) { if (property.GetType().Equals(typeof(ITextStyle))) { ITextStyle textStyle = property.GetValue(style, null) as ITextStyle; Type typeTextStyle = textStyle.GetType(); foreach (PropertyInfo prop in typeTextStyle.GetProperties()) { if (prop.GetType().Equals(typeof(int))) { int value = (int)prop.GetValue(textStyle, null); result = result && (value == 0); } else if (prop.GetType().Equals(typeof(string))) { string value = (string)prop.GetValue(textStyle, null); result = result && (value.Length == 0); } else if (prop.GetType().Equals(typeof(System.Drawing.Color))) { System.Drawing.Color value = (System.Drawing.Color)prop.GetValue(textStyle, null); result = result && (value == System.Drawing.Color.Empty); } else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily))) { System.Drawing.FontFamily value = (System.Drawing.FontFamily)prop.GetValue(textStyle, null); result = result && (value == null); } else if (prop.GetType().Equals(typeof(FontSizeUnit))) { FontSizeUnit value = (FontSizeUnit)prop.GetValue(textStyle, null); result = result && (value == FontSizeUnit.Pixel); } else if (prop.GetType().Equals(typeof(CSSFontStyle))) { CSSFontStyle value = (CSSFontStyle)prop.GetValue(textStyle, null); result = result && (value == CSSFontStyle.None); } else if (prop.GetType().Equals(typeof(HorizontalAlignment))) { HorizontalAlignment value = (HorizontalAlignment)prop.GetValue(textStyle, null); result = result && (value == HorizontalAlignment.None); } else if (prop.GetType().Equals(typeof(VerticalAlignment))) { VerticalAlignment value = (VerticalAlignment)prop.GetValue(textStyle, null); result = result && (value == VerticalAlignment.None); } else if (prop.Name == "OtherElements") { SerializableDictionary <string, string> otherElements = prop.GetValue(textStyle, null) as SerializableDictionary <string, string>; result = result && (otherElements.Count == 0); } } } } return(result); }
/// <summary> /// Sets the card style. /// </summary> /// <param name="id">The id.</param> /// <param name="Style">The style.</param> /// <remarks>Documented by Dev05, 2009-01-15</remarks> public void SetCardStyle(int id, ICardStyle Style) { if (Style is DbCardStyle) { SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser); cmd.CommandText = "UPDATE \"Settings\" SET cardstyle=@csid WHERE id=@id;"; cmd.Parameters.Add("@id", id); cmd.Parameters.Add("@csid", (Style as DbCardStyle).Id); MSSQLCEConn.ExecuteNonQuery(cmd); SqlCeCommand cmd2 = MSSQLCEConn.CreateCommand(Parent.CurrentUser); cmd2.CommandText = "UPDATE \"CardStyles\" SET value=@style WHERE id=@csid;"; cmd2.Parameters.Add("@csid", (Style as DbCardStyle).Id); cmd2.Parameters.Add("@style", Style.Xml); MSSQLCEConn.ExecuteNonQuery(cmd2); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleFk, id, Cache.DefaultSettingsValidationTime)] = (Style as DbCardStyle).Id; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleValue, id, Cache.DefaultSettingsValidationTime)] = Style.Xml; } else { SqlCeCommand cmd = MSSQLCEConn.CreateCommand(Parent.CurrentUser); cmd.CommandText = "INSERT INTO \"CardStyles\"(value) VALUES(@style); UPDATE \"Settings\" SET cardstyle=@@IDENTITY WHERE id=@id; SELECT @@IDENTITY;"; cmd.Parameters.Add("@id", id); cmd.Parameters.Add("@style", (Style != null) ? Style.Xml : String.Empty); //MSSQLCEConn.ExecuteNonQuery(cmd); int newId = Convert.ToInt32(MSSQLCEConn.ExecuteScalar(cmd)); //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleFk, id, Cache.DefaultSettingsValidationTime)] = newId; Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCardStyleValue, id, Cache.DefaultSettingsValidationTime)] = (Style != null) ? Style.Xml : String.Empty; } }
/// <summary> /// Compares two objects that implement ICardStyle. /// </summary> /// <param name="one">The first ICardStyle object one.</param> /// <param name="two">The second ICardStyle object.</param> /// <remarks>Documented by Dev03, 2008-09-26</remarks> private void CompareStyles(ICardStyle one, ICardStyle two) { if ((one == null) || (two == null)) { Assert.IsTrue(IsEmptyStyle(one), "Both styles should be null! (one)"); Assert.IsTrue(IsEmptyStyle(two), "Both styles should be null! (two)"); return; } Type typeCardStyle = one.GetType(); foreach (PropertyInfo property in typeCardStyle.GetProperties()) { if (property.GetType().Equals(typeof(ITextStyle))) { ITextStyle textStyleOne = property.GetValue(one, null) as ITextStyle; ITextStyle textStyleTwo = property.GetValue(two, null) as ITextStyle; Type typeTextStyle = textStyleOne.GetType(); foreach (PropertyInfo prop in typeTextStyle.GetProperties()) { if (prop.GetType().Equals(typeof(int))) { int valueOne = (int)prop.GetValue(textStyleOne, null); int valueTwo = (int)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(string))) { string valueOne = (string)prop.GetValue(textStyleOne, null); string valueTwo = (string)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(System.Drawing.Color))) { System.Drawing.Color valueOne = (System.Drawing.Color)prop.GetValue(textStyleOne, null); System.Drawing.Color valueTwo = (System.Drawing.Color)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily))) { System.Drawing.FontFamily valueOne = (System.Drawing.FontFamily)prop.GetValue(textStyleOne, null); System.Drawing.FontFamily valueTwo = (System.Drawing.FontFamily)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(FontSizeUnit))) { FontSizeUnit valueOne = (FontSizeUnit)prop.GetValue(textStyleOne, null); FontSizeUnit valueTwo = (FontSizeUnit)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(CSSFontStyle))) { CSSFontStyle valueOne = (CSSFontStyle)prop.GetValue(textStyleOne, null); CSSFontStyle valueTwo = (CSSFontStyle)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(HorizontalAlignment))) { HorizontalAlignment valueOne = (HorizontalAlignment)prop.GetValue(textStyleOne, null); HorizontalAlignment valueTwo = (HorizontalAlignment)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.GetType().Equals(typeof(VerticalAlignment))) { VerticalAlignment valueOne = (VerticalAlignment)prop.GetValue(textStyleOne, null); VerticalAlignment valueTwo = (VerticalAlignment)prop.GetValue(textStyleTwo, null); Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name)); } else if (prop.Name == "OtherElements") { SerializableDictionary <string, string> otherElementsOne = prop.GetValue(textStyleOne, null) as SerializableDictionary <string, string>; SerializableDictionary <string, string> otherElementsTwo = prop.GetValue(textStyleTwo, null) as SerializableDictionary <string, string>; foreach (string key in otherElementsOne.Keys) { Assert.IsTrue((otherElementsTwo.ContainsKey(key) && otherElementsOne[key].Equals(otherElementsTwo[key])), String.Format("Both values for {0}[{1}] should be equal!", prop.Name, key)); } } } } } }
public void IChapterStyle() { //Todo: OtherElements, ITextStyle.ToString() TestInfrastructure.DebugLineStart(TestContext); if (TestInfrastructure.IsActive(TestContext)) { using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser)) { IChapter chapter = writeLM.Chapters.AddNew(); chapter.Title = "Chapter xyz"; ICardStyle style = chapter.CreateCardStyle(); ITextStyle defaultTextStyle = style.Answer; //just for init defaultTextStyle.BackgroundColor = Color.Red; defaultTextStyle.FontFamily = new FontFamily("Arial"); defaultTextStyle.FontSize = 8; defaultTextStyle.FontSizeUnit = FontSizeUnit.Pixel; defaultTextStyle.FontStyle = CSSFontStyle.Bold; defaultTextStyle.ForeColor = Color.Red; defaultTextStyle.HorizontalAlign = HorizontalAlignment.Center; defaultTextStyle.VerticalAlign = VerticalAlignment.Bottom; defaultTextStyle.OtherElements.Add("key1", "value1"); style.Answer = defaultTextStyle; style.AnswerCorrect = defaultTextStyle; style.AnswerExample = defaultTextStyle; style.AnswerWrong = defaultTextStyle; style.Question = defaultTextStyle; style.QuestionExample = defaultTextStyle; if (chapter.Settings == null) { chapter.Settings = writeLM.CreateSettings(); //only occurs in DB mode } chapter.Settings.Style = style; //assign Style to chapter //Check IChapter chap = writeLM.Chapters.Find("Chapter xyz"); ITextStyle[] checkStyle = new ITextStyle[6]; checkStyle[0] = chapter.Settings.Style.Answer; checkStyle[1] = chapter.Settings.Style.AnswerCorrect; checkStyle[2] = chapter.Settings.Style.AnswerExample; checkStyle[3] = chapter.Settings.Style.AnswerWrong; checkStyle[4] = chapter.Settings.Style.Question; checkStyle[5] = chapter.Settings.Style.QuestionExample; foreach (ITextStyle sty in checkStyle) { Assert.AreEqual(Color.Red, sty.BackgroundColor, "Style BackgroundColor was not saved to ICardStyle()"); Assert.AreEqual(new FontFamily("Arial").Name, sty.FontFamily.Name, "Style FontFamily was not saved to ICardStyle()"); Assert.AreEqual(8, sty.FontSize, "Style FontSize was not saved to ICardStyle()"); Assert.AreEqual(FontSizeUnit.Pixel, sty.FontSizeUnit, "Style FontSizeUnit was not saved to ICardStyle()"); Assert.AreEqual(CSSFontStyle.Bold, sty.FontStyle, "Style FontStyle was not saved to ICardStyle()"); Assert.AreEqual(Color.Red, sty.ForeColor, "Style ForeColor was not saved to ICardStyle()"); Assert.AreEqual(HorizontalAlignment.Center, sty.HorizontalAlign, "Style HorizontalAlign was not saved to ICardStyle()"); Assert.AreEqual(VerticalAlignment.Bottom, sty.VerticalAlign, "Style VerticalAlign was not saved to ICardStyle()"); Assert.AreEqual("value1", sty.OtherElements["key1"], "Style OtherElements(key, value) was not saved to ICardStyle()"); } } } TestInfrastructure.DebugLineEnd(TestContext); }