Assert() public static method

public static Assert ( System.Action action, string errMsg ) : void
action System.Action
errMsg string
return void
        public void UpdateSelectedMaidValues()
        {
            if (InvokeRequired)
            {
                InvokeAsync((Action)UpdateSelectedMaidValues);
                return;
            }
            MaidChangeType cType = 0;

            Debugger.Assert(
                () =>
            {
                int processingQueue = currentQueue;
                currentQueue        = 1 - currentQueue;
                if (valueUpdateQueue[processingQueue].Count <= 0)
                {
                    return;
                }
                Debugger.WriteLine(LogLevel.Info, $"Updating values (Queue {processingQueue})...");
                foreach (KeyValuePair <MaidChangeType, Action> type in valueUpdateQueue[processingQueue])
                {
                    cType = type.Key;
                    type.Value();
                }
                valueUpdateQueue[processingQueue].Clear();
            },
                $"Failed to update scheduled maid value. Type: {cType}");
        }
 private void _UnloadMaids()
 {
     Debugger.Assert(
         () =>
     {
         Debugger.WriteLine(LogLevel.Info, "Unloading maids!");
         Debugger.WriteLine(LogLevel.Info, $"Loaded maids: {loadedMaids.Count}");
         loadedMaids.Clear();
         currentQueue = 0;
         valueUpdateQueue[0].Clear();
         valueUpdateQueue[1].Clear();
         if (maidThumbnails.Count > 0)
         {
             maidThumbnails.ForEach(thumb => thumb.Value.Dispose());
         }
         maidThumbnails.Clear();
         UpdateList();
     },
         "Failed to unload maids");
 }
Exemplo n.º 3
0
        public static void InitThumbnail()
        {
            Debugger.Assert(
                () =>
            {
                Debugger.WriteLine("Loading generic maid thumbnail...");
                float size = Translation.GetTranslation("THUMB_TEXT_SIZE").Parse(10.0F);
                float posX = Translation.GetTranslation("THUMB_TEXT_POS_X").Parse(0.0F);
                float posY = Translation.GetTranslation("THUMB_TEXT_POS_Y").Parse(0.0F);

                Debugger.WriteLine(LogLevel.Info, $"Font size: {size}, posX: {posX}, posY: {posY}");

                DefaultThumbnail = new Bitmap(OriginalThumbnail);
                using (Graphics g = Graphics.FromImage(DefaultThumbnail))
                {
                    Font f = new Font("Arial", size);
                    g.DrawString(Translation.GetTranslation("THUMB_NONE"), f, new SolidBrush(Color.Black), posX, posY);
                }
            },
                "Failed to load the generic maid thumbnail");
        }
        private void ReloadMaids(List <Maid> maids)
        {
            Debugger.Assert(
                () =>
            {
                Debugger.WriteLine(LogLevel.Info, "Reloading maids!");
                Debugger.WriteLine(LogLevel.Info, $"Maids: {maids.Count}");
                Debugger.WriteLine(LogLevel.Info, $"Loaded maids: {loadedMaids.Count}");
                loadedMaids.Clear();
                currentQueue = 0;
                valueUpdateQueue[0].Clear();
                valueUpdateQueue[1].Clear();
                if (maidThumbnails.Count > 0)
                {
                    maidThumbnails.ForEach(thumb => thumb.Value.Dispose());
                }
                maidThumbnails.Clear();
                loadedMaids = new SortedList <Maid, MaidInfo>(
                    maids.ToDictionary(m => m, m => new MaidInfo(m, this)),
                    comparer);
                loadedMaids.ForEach(
                    m =>
                {
                    Texture2D thumb = m.Value.Maid.GetThumIcon();
                    if (thumb == null)
                    {
                        return;
                    }
                    using (MemoryStream stream = new MemoryStream(thumb.EncodeToPNG()))
                    {
                        Debugger.WriteLine("Loading PNG of size: " + stream.Length);
                        maidThumbnails.Add(m.Key.Param.status.guid, Image.FromStream(stream));
                    }
                });

                UpdateList();
            },
                "Failed to reload all maids");
        }
Exemplo n.º 5
0
 public static void ApplyTranslation()
 {
     Debugger.WriteLine(LogLevel.Info, "Applying translation");
     Debugger.Assert(
         () =>
     {
         foreach (KeyValuePair <string, List <Action <string> > > translationItems in translatableControlsDictionary)
         {
             string translation;
             if (translationDictionary.TryGetValue(translationItems.Key, out translation))
             {
                 translationItems.Value.ForEach(a => a.Invoke(translation));
             }
             else
             {
                 translationItems.Value.ForEach(a => a.Invoke(translationItems.Key));
             }
         }
         Resources.InitThumbnail();
     },
         "Failed to apply translation.");
 }
        private void UpdateMaids(List <Maid> newMaids)
        {
            Debugger.Assert(
                () =>
            {
                if (newMaids.Count != loadedMaids.Count)
                {
                    goto update;
                }

                newMaids.Sort((m1, m2) => comparer.Compare(m1, m2));
                if (newMaids.SequenceEqual(loadedMaids.Values.Select(m => m.Maid), comparer))
                {
                    return;
                }

                update:
#if DEBUG
                Stopwatch sw = Stopwatch.StartNew();
#endif
                Debugger.WriteLine(LogLevel.Info, "Updating maid list!");
                Debugger.WriteLine(LogLevel.Info, $" New count:  {newMaids.Count}, Loaded count: {loadedMaids.Count}");
                loadedMaids = new SortedList <Maid, MaidInfo>(
                    loadedMaids.Where(
                        m =>
                {
                    bool result = newMaids.Contains(m.Key);
                    if (result)
                    {
                        newMaids.Remove(m.Key);
                    }
                    else
                    {
                        if (SelectedMaid != null && m.Value.Maid == SelectedMaid.Maid)
                        {
                            currentQueue = 0;
                            valueUpdateQueue[0].Clear();
                            valueUpdateQueue[1].Clear();
                        }
                        if (maidThumbnails.ContainsKey(m.Key.Param.status.guid))
                        {
                            maidThumbnails[m.Key.Param.status.guid].Dispose();
                        }
                        maidThumbnails.Remove(m.Key.Param.status.guid);
                    }
                    return(result);
                }).ToList().Union(
                        newMaids.Select(
                            m =>
                {
                    Debugger.WriteLine(LogLevel.Info, "Adding new maid info.");
                    MaidInfo info = new MaidInfo(m, this);
                    Debugger.WriteLine(LogLevel.Info, "Loading thumbnail");
                    Texture2D thumb = m.GetThumIcon();
                    if (thumb == null)
                    {
                        return(new KeyValuePair <Maid, MaidInfo>(m, info));
                    }
                    using (MemoryStream stream = new MemoryStream(thumb.EncodeToPNG()))
                    {
                        Debugger.WriteLine("Loading PNG of size: " + stream.Length);
                        maidThumbnails.Add(m.Param.status.guid, Image.FromStream(stream));
                    }
                    return(new KeyValuePair <Maid, MaidInfo>(m, info));
                })).ToDictionary(m => m.Key, m => m.Value),
                    comparer);


                Debugger.WriteLine(LogLevel.Info, $"New loaded maids count: {loadedMaids.Count}");
#if DEBUG
                sw.Stop();
                Debugger.WriteLine(LogLevel.Info, $"Updated maid list in {sw.Elapsed.TotalMilliseconds} ms");

                newMaids.ForEach(
                    m => Debugger.WriteLine($"Added {m.Param.status.first_name} {m.Param.status.last_name}"));
                Debugger.WriteLine();
#endif
                Debugger.WriteLine("Updating list.");
                UpdateList();
                Debugger.WriteLine("Finished updating list.");
            },
                "Failed to update maid list");
        }
Exemplo n.º 7
0
        public static void LoadTranslation(string filename)
        {
            Debugger.Assert(
                () =>
            {
                Debugger.WriteLine($"Loading translation: {filename}");
                string filePath = Path.Combine(MaidFiddler.DATA_PATH, $@"{TRANSLATIONS_PATH}\{filename}.txt");
                string version  = string.Empty;
                Debugger.WriteLine(LogLevel.Info, $"File path: {filePath}");
                if (!File.Exists(filePath))
                {
                    Debugger.WriteLine(LogLevel.Error, "Failed to find such translation file.");
                    filename = string.Empty;
                }
                else
                {
                    Debugger.WriteLine(LogLevel.Info, "Loading translation labels.");
                    Dictionary <string, string> newTranslationDictionary = new Dictionary <string, string>();
                    using (TextReader reader = File.OpenText(filePath))
                    {
                        string line = reader.ReadLine();
                        if (line != null)
                        {
                            Match match = TagPattern.Match(line);
                            if (match.Success)
                            {
                                version = match.Groups["ver"].Value;
                                Debugger.WriteLine(
                                    LogLevel.Info,
                                    $"Found translation tag! Language: '{match.Groups["lang"]}', Version: '{match.Groups["ver"]}', Author(s): '{match.Groups["auth"]}'");
                            }
                            else
                            {
                                Debugger.WriteLine(LogLevel.Warning, "Did not find any translation tags!");
                            }
                        }
                        while ((line = reader.ReadLine()) != null)
                        {
                            line = line.Trim();
                            if (line == string.Empty || line.StartsWith(";"))
                            {
                                continue;
                            }

                            string[] parts = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                            if (parts.Length != 2)
                            {
                                continue;
                            }

                            string text = parts[1].Replace(@"\n", "\n").Replace(@"\r", "\r");

                            if (text.Trim() == string.Empty)
                            {
                                Debugger.WriteLine(
                                    LogLevel.Warning,
                                    $"Translation for {parts[0]} is empty! Skipping...");
                                continue;
                            }

                            if (!newTranslationDictionary.ContainsKey(parts[0]))
                            {
                                newTranslationDictionary.Add(parts[0], text);
                            }
                            else
                            {
                                Debugger.WriteLine(
                                    LogLevel.Warning,
                                    $"Translation for {parts[0]} already exists! Replacing with a newer version...");
                                newTranslationDictionary[parts[0]] = text;
                            }
                        }
                    }
                    translationDictionary.Clear();
                    translationDictionary = newTranslationDictionary;
                }
                Debugger.WriteLine(LogLevel.Info, "Texts loaded");
                CurrentTranslationFile    = filename;
                CurrentTranslationVersion = version;
                ApplyTranslation();
            },
                "Failed to load texts");
        }