/// <summary> /// Sets the stack card back colors. /// </summary> /// <param name="styleHandler">The style handler.</param> /// <remarks>Documented by Dev02, 2008-05-09</remarks> public void SetStackCardBackColors(MLifter.Components.StyleHandler styleHandler) { Dictionary<AnswerResult, Color> stackColors = new Dictionary<AnswerResult, Color>(); foreach (AnswerResult result in Enum.GetValues(typeof(AnswerResult))) { string stylename = string.Format("{0}_{1}", this.Name, result.ToString()); if (styleHandler.CurrentStyle.StyledControls.ContainsKey(stylename) && styleHandler.CurrentStyle.StyledControls[stylename].BackColor != Color.Empty) { Color color = styleHandler.CurrentStyle.StyledControls[stylename].BackColor; stackColors.Add(result, color); } } this.StackCardBackColors = stackColors; }
private PostgreSqlConnectionStringBuilder PreparePostgreSqlConnectionStringBuilder(out Dictionary<string, string> referenceValues) { referenceValues = new Dictionary<string, string>(); referenceValues.Add("Name", "Test ConnectionString"); referenceValues.Add("Database", "db"); referenceValues.Add("Server", "server"); referenceValues.Add("Port", "1234"); referenceValues.Add("SSL", false.ToString()); referenceValues.Add("UserId", "username"); referenceValues.Add("Password", "password"); PostgreSqlConnectionStringBuilder csb = new PostgreSqlConnectionStringBuilder(); csb.Name = referenceValues["Name"]; csb.Database = referenceValues["Database"]; csb.Server = referenceValues["Server"]; csb.Port = int.Parse(referenceValues["Port"]); csb.SSL = bool.Parse(referenceValues["SSL"]); csb.UserId = referenceValues["UserId"]; csb.Password = referenceValues["Password"]; return csb; }
private UncConnectionStringBuilder PrepareUncConnectionStringBuilder(out Dictionary<string, string> referenceValues) { referenceValues = new Dictionary<string, string>(); referenceValues.Add("ConnectionString", @"c:\lms"); referenceValues.Add("Name", "Test ConnectionString"); UncConnectionStringBuilder csb = new UncConnectionStringBuilder(referenceValues["ConnectionString"]); csb.Name = referenceValues["Name"]; return csb; }
/// <summary> /// Loads the content of the web. /// </summary> /// <remarks>Documented by Dev05, 2009-06-26</remarks> public void LoadWebContent(object path) { IsListLoaded = false; IsLoaded = false; string configPath = path as string; nodes = new Dictionary<int, FeedCategoryTreeNode>(); if (TreeView.InvokeRequired) TreeView.Invoke((MethodInvoker)delegate { Nodes.Clear(); }); else Nodes.Clear(); try { if (TreeView.InvokeRequired) TreeView.Invoke((MethodInvoker)delegate { Text = String.IsNullOrWhiteSpace(Feed.Name) ? Resources.FeedTreeNode_Name : Feed.Name; }); else Text = String.IsNullOrWhiteSpace(Feed.Name) ? Resources.FeedTreeNode_Name : Feed.Name; #region read categories XmlReader categoryFeedReader = XmlReader.Create(Feed.CategoriesUri); SyndicationFeed categoryFeed = SyndicationFeed.Load(categoryFeedReader); List<ModuleCategory> categoriesToAdd = new List<ModuleCategory>(); foreach (SyndicationItem item in categoryFeed.Items) { ModuleCategory category = new ModuleCategory() { Id = Convert.ToInt32(item.Id), Title = item.Title.Text, ParentCategory = Convert.ToInt32(item.Links[0].Title) }; categoriesToAdd.Add(category); } categoriesToAdd.Sort((a, b) => a.Id.CompareTo(b.Id)); categoriesToAdd.ForEach(c => AddCategoryNode(c)); #endregion #region read modules XmlReader moduleFeedReader = XmlReader.Create(Feed.ModulesUri); SyndicationFeed moduleFeed = SyndicationFeed.Load(moduleFeedReader); List<ModuleInfo> modules = new List<ModuleInfo>(); XmlSerializer infoSerializer = new XmlSerializer(typeof(ModuleInfo)); Dictionary<string, SyndicationItem> items = new Dictionary<string, SyndicationItem>(); foreach (SyndicationItem item in moduleFeed.Items) { ModuleInfo info; if (item.Summary != null) info = (ModuleInfo)infoSerializer.Deserialize(XmlReader.Create(new StringReader(WebUtility.HtmlDecode(item.Summary.Text)))); else info = new ModuleInfo(); info.Id = item.Id; info.Title = item.Title.Text; info.EditDate = item.LastUpdatedTime.ToString(); if (item.Contributors.Count > 0) { info.Author = item.Contributors[0].Name; info.AuthorMail = item.Contributors[0].Email; info.AuthorUrl = item.Contributors[0].Uri; } if (item.Content is TextSyndicationContent) info.Description = (item.Content as TextSyndicationContent).Text; info.Categories = new SerializableList<string>(); foreach (SyndicationCategory cat in item.Categories) info.Categories.Add(cat.Label); foreach (SyndicationLink link in item.Links) { if (link.RelationshipType == AtomLinkRelationshipType.Module.ToString()) { info.Size = link.Length; info.DownloadUrl = link.Uri.AbsoluteUri; } } modules.Add(info); items.Add(info.Id, item); } categories.ForEach(c => nodes[c.Id].SetModuleList(modules.FindAll(p => p.Categories.Contains(c.Id.ToString())))); #endregion if (TreeView.InvokeRequired) TreeView.Invoke((MethodInvoker)delegate { Expand(); }); else Expand(); IsListLoaded = true; OnContentLoaded(EventArgs.Empty); #region read images using (PersistentMemoryCache<ModuleInfoCacheItem> cache = new PersistentMemoryCache<ModuleInfoCacheItem>("Feed_" + moduleFeed.Id)) { WebClient webClient = new WebClient(); foreach (ModuleInfo basicInfo in modules) { try { ModuleInfo info = basicInfo; SyndicationItem item = items[basicInfo.Id]; string cacheKey = String.Format("{0}##{1}##{2}", moduleFeed.Id, item.Id, item.LastUpdatedTime); if (cache.Contains(cacheKey)) { ModuleInfoCacheItem cacheItem = (ModuleInfoCacheItem)cache[cacheKey]; info.IconSmall = Convert.FromBase64String(cacheItem.IconSmall); info.IconBig = Convert.FromBase64String(cacheItem.IconBig); info.Preview = Convert.FromBase64String(cacheItem.Preview); } else { ModuleInfoCacheItem cacheItem = new ModuleInfoCacheItem(info.Id); foreach (SyndicationLink link in item.Links) { if (link.RelationshipType == AtomLinkRelationshipType.IconSmall.ToString()) cacheItem.IconSmall = Convert.ToBase64String(info.IconSmall = webClient.DownloadData(link.Uri)); if (link.RelationshipType == AtomLinkRelationshipType.IconBig.ToString()) cacheItem.IconBig = Convert.ToBase64String(info.IconBig = webClient.DownloadData(link.Uri)); if (link.RelationshipType == AtomLinkRelationshipType.Preview.ToString()) cacheItem.Preview = Convert.ToBase64String(info.Preview = webClient.DownloadData(link.Uri)); } cache.Set(cacheKey, cacheItem, DateTime.Now.AddYears(1)); } if (TreeView.InvokeRequired) TreeView.Invoke((MethodInvoker)delegate { LoadDetails(info); }); else LoadDetails(info); } catch (Exception exp) { Trace.WriteLine(exp.ToString()); } } cache.Dispose(); } #endregion IsLoaded = true; } catch (Exception) { try { if (TreeView.InvokeRequired) TreeView.Invoke((MethodInvoker)delegate { Text = Resources.FeedTreeNode_Text_Offline; }); else Text = Resources.FeedTreeNode_Text_Offline; } catch (ObjectDisposedException) { } } }
/// <summary> /// Modifies the multiple cards. /// </summary> /// <remarks>Documented by Dev05, 2007-10-12</remarks> private void ModifyMultipleCards() { if (!Multiselect) return; Cursor = Cursors.WaitCursor; LoadStatusMessage statusMessage = new LoadStatusMessage(string.Format(Properties.Resources.CARDEDIT_STATUS_SAVING, cards.Length), cards.Length, true); statusMessage.Show(); string[] question = GetWord(Side.Question).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); string[] answer = GetWord(Side.Answer).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); string questionExample = textBoxQuestionExample.Text; string answerExample = textBoxAnswerExample.Text; foreach (int id in cards) { Dictionary.Cards.ChangeCardOnDifference(id, question, answer, questionExample, answerExample, (comboBoxChapter.SelectedItem is IChapter ? ((IChapter)comboBoxChapter.SelectedItem).Id : -1), Resources.MAINTAIN_UNCHANGED); ICard card = Dictionary.Cards.GetCardByID(id).BaseCard; if (checkBoxActive.CheckState != CheckState.Indeterminate) if (card.Active != checkBoxActive.Checked) card.Active = checkBoxActive.Checked; if (comboBoxCardBox.SelectedIndex != -1 && card.Active) { card.Box = comboBoxCardBox.SelectedIndex; } //Save old Media objects Dictionary<string, IMedia> oldMedia = new Dictionary<string, IMedia>(); IMedia media = null; if ((media = Dictionary.Cards.GetImageObject(card, Side.Answer, true)) != null) oldMedia.Add("answerImage", media); if ((media = Dictionary.Cards.GetImageObject(card, Side.Question, true)) != null) oldMedia.Add("questionImage", media); if ((media = Dictionary.Cards.GetAudioObject(card, Side.Answer, true, false, true)) != null) oldMedia.Add("answerAudio", media); if ((media = Dictionary.Cards.GetAudioObject(card, Side.Question, true, false, true)) != null) oldMedia.Add("questionAudio", media); if ((media = Dictionary.Cards.GetAudioObject(card, Side.Answer, false, true, true)) != null) oldMedia.Add("answerExample", media); if ((media = Dictionary.Cards.GetAudioObject(card, Side.Question, false, true, true)) != null) oldMedia.Add("questionExample", media); if ((media = Dictionary.Cards.GetVideoObject(card, Side.Answer, true)) != null) oldMedia.Add("answerVideo", media); if ((media = Dictionary.Cards.GetVideoObject(card, Side.Question, true)) != null) oldMedia.Add("questionVideo", media); card.ClearAllMedia(false); //Image if (pictureBoxAnswer.Tag as IImage != null && checkBoxSamePicture.CheckState != CheckState.Unchecked) card.AddMedia(pictureBoxAnswer.Tag as IMedia, Side.Answer); else if (pictureBoxAnswer.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerImage") && checkBoxSamePicture.CheckState != CheckState.Unchecked) card.AddMedia(oldMedia["answerImage"], Side.Answer); if (pictureBoxQuestion.Tag as IImage != null) { IMedia image = pictureBoxQuestion.Tag as IMedia; card.AddMedia(image, Side.Question); if (checkBoxSamePicture.CheckState == CheckState.Checked) card.AddMedia(image, Side.Answer); } else if (pictureBoxQuestion.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionImage")) { IMedia image = oldMedia["questionImage"]; card.AddMedia(image, Side.Question); if (checkBoxSamePicture.CheckState == CheckState.Checked) card.AddMedia(image, Side.Answer); } //Audio if (buttonAnswerAudio.Tag as IAudio != null) card.AddMedia(buttonAnswerAudio.Tag as IMedia, Side.Answer); else if (buttonAnswerAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerAudio")) card.AddMedia(oldMedia["answerAudio"], Side.Answer); if (buttonAnswerExampleAudio.Tag as IAudio != null) card.AddMedia(buttonAnswerExampleAudio.Tag as IMedia, Side.Answer); else if (buttonAnswerExampleAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerExample")) card.AddMedia(oldMedia["answerExample"], Side.Answer); if (buttonQuestionAudio.Tag as IAudio != null) card.AddMedia(buttonQuestionAudio.Tag as IMedia, Side.Question); else if (buttonQuestionAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionAudio")) card.AddMedia(oldMedia["questionAudio"], Side.Question); if (buttonQuestionExampleAudio.Tag as IAudio != null) card.AddMedia(buttonQuestionExampleAudio.Tag as IMedia, Side.Question); else if (buttonQuestionExampleAudio.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionExample")) card.AddMedia(oldMedia["questionExample"], Side.Question); //Video if (buttonAnswerVideo.Tag as IVideo != null) card.AddMedia(buttonAnswerVideo.Tag as IMedia, Side.Answer); else if (buttonAnswerVideo.Tag is PreviousValueDummy && oldMedia.ContainsKey("answerVideo")) card.AddMedia(oldMedia["answerVideo"], Side.Answer); if (buttonQuestionVideo.Tag as IVideo != null) card.AddMedia(buttonQuestionVideo.Tag as IMedia, Side.Question); else if (buttonQuestionVideo.Tag is PreviousValueDummy && oldMedia.ContainsKey("questionVideo")) card.AddMedia(oldMedia["questionVideo"], Side.Question); statusMessage.ProgressStep(); } statusMessage.Close(); Modified = false; OnMultiEdit(EventArgs.Empty); Cursor = Cursors.Default; }
private void LoadDictionaryData() { try { loadingDictionaryData = true; Dictionary<ListViewGroup, Queue<LearningModulesIndexEntry>> queues = new Dictionary<ListViewGroup, Queue<LearningModulesIndexEntry>>(); foreach (ListViewGroup group in Groups) { Queue<LearningModulesIndexEntry> queue = new Queue<LearningModulesIndexEntry>(); Thread subWorker = new Thread(new ParameterizedThreadStart(LoadDictionaryData)); subWorker.CurrentCulture = Thread.CurrentThread.CurrentCulture; subWorker.CurrentUICulture = Thread.CurrentThread.CurrentUICulture; subWorker.Name = "LearningModulesScanThread - " + group.Header; subWorker.IsBackground = true; subWorker.Priority = ThreadPriority.Lowest; if (AddThreadToDictionary(group, subWorker)) subWorker.Start(queue); queues.Add(group, queue); } foreach (LearningModulesIndexEntry entry in LearningModules) queues[entry.Group].Enqueue(entry); } catch (ThreadAbortException) { Trace.WriteLine("LearningModulesScan aborted!"); } finally { loadingDictionaryData = false; } }
/// <summary> /// Serializes the index cache. /// </summary> /// <param name="stream">The stream.</param> /// <remarks>Documented by Dev02, 2008-12-04</remarks> private void SerializeIndexCache(Stream stream) { //cache for passwords - they must not be saved in the disk cache Dictionary<string, string> passwords = new Dictionary<string, string>(); foreach (KeyValuePair<string, LearningModulesIndexEntry> pair in indexCache) { if (pair.Value.ConnectionString.Password != string.Empty) { passwords.Add(pair.Key, pair.Value.ConnectionString.Password); ConnectionStringStruct css = pair.Value.ConnectionString; css.Password = string.Empty; pair.Value.ConnectionString = css; } } IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, indexCacheTimestamps); formatter.Serialize(stream, indexCache); foreach (KeyValuePair<string, string> pair in passwords) { LearningModulesIndexEntry entry = indexCache[pair.Key]; ConnectionStringStruct css = entry.ConnectionString; css.Password = pair.Value; entry.ConnectionString = css; } }
/// <summary> /// Serializes to the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <remarks>Documented by Dev02, 2008-12-04</remarks> private static void Serialize(Stream stream) { //cache for passwords - they must not be saved on disk Dictionary<DateTime, string> passwords = new Dictionary<DateTime, string>(); foreach (KeyValuePair<DateTime, LearningModulesIndexEntry> pair in recentModules) { if (pair.Value.ConnectionString.Password != string.Empty) { passwords.Add(pair.Key, pair.Value.ConnectionString.Password); ConnectionStringStruct css = pair.Value.ConnectionString; css.Password = string.Empty; pair.Value.ConnectionString = css; } } IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, recentModules); foreach (KeyValuePair<DateTime, string> pair in passwords) { LearningModulesIndexEntry entry = recentModules[pair.Key]; ConnectionStringStruct css = entry.ConnectionString; css.Password = pair.Value; entry.ConnectionString = css; } }