public static void SaveChartCSV(Chart c, string filename)
        {
            String save = "text,count\r\n";

            foreach (var dp in c.Series[0].Points.Reverse())
            {
                save += dp.AxisLabel + "," + dp.YValues[0] + "\r\n";
            }
            FileExtras.SaveToFile(StringExtras.ReplaceAllChars(filename, ":", "_"), save);
        }
        public static void replaceChar(IEnumerable <Mp3Lib.Mp3File> mp3s, bool checkFirst)
        {
            var RC = new replacechar();

            var newDataEX = new TagHandlerUpdate(mp3s.First());

            RC.titleExample  = newDataEX.Title;
            RC.albumExample  = newDataEX.Album;
            RC.artistExample = newDataEX.Artist;

            RC.ShowDialog();
            if (RC.result1 == '\0')
            {
                return;
            }

            foreach (var MF in mp3s)
            {
                var newData = new TagHandlerUpdate(MF);

                var orig = MF.TagHandler;

                if (RC.titleoptionb)
                {
                    newData.Title = StringExtras.ReplaceAllChars(newData.Title, RC.result1, RC.result2);
                }
                else if (RC.albumoptionb)
                {
                    newData.Album = StringExtras.ReplaceAllChars(newData.Album, RC.result1, RC.result2);
                }
                else if (RC.artistoptionb)
                {
                    newData.Artist = StringExtras.ReplaceAllChars(newData.Artist, RC.result1, RC.result2);
                }

                if (queryUserMakeChangesAndContinue(newData, MF, checkFirst) == false)
                {
                    return;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Load a file into a tree structure based on levels. by default '1 \n \t 2' in a file will create a parent with a
        /// child node
        /// </summary>
        /// <typeparam name="T">class type, usually string</typeparam>
        /// <param name="filename">The filename.</param>
        /// <param name="root">The root.</param>
        /// <param name="addfunc">T must be able to be instantiated with a string. call with a=&gt;new T(a) where T is your class, or
        /// the return string method</param>
        /// <param name="levelSeparator">The level separator.</param>
        /// <param name="RecreateFileIfInvalid">if set to <c>true</c> [recreate file if invalid].</param>
        /// <exception cref="Exception"></exception>
        public static void LoadFileIntoTree <T>(string filename, Btree <T> root, Func <string, T> addfunc,
                                                string levelSeparator = "\t", bool RecreateFileIfInvalid = true)
        {
            root.Children = new List <Btree <T> >();

            FileStream   fs = null;
            StreamReader sr = null;

            try
            {
                fs = new FileStream(filename, FileMode.OpenOrCreate);
                sr = new StreamReader(fs);

                var line         = sr.ReadLine();
                var parentT      = root;
                var currentlevel = 0;
                while (line != null)
                {
                    var level = StringExtras.ContainsSubStringCount(line, levelSeparator);
                    if (level > (currentlevel + 1))
                    {
                        throw new Exception();
                    }
                    if (level == 0)
                    {
                        parentT = root;
                    }
                    else if (currentlevel > (level - 1))
                    {
                        while (currentlevel != (level - 1))
                        {
                            parentT = parentT.Parent;
                            currentlevel--;
                        }
                    }

                    var rc = StringExtras.ReplaceAllChars(line, levelSeparator, "");

                    var t = new Btree <T> {
                        Name = addfunc(rc), Parent = parentT
                    };
                    if (parentT.Children == null)
                    {
                        parentT.Children = new List <Btree <T> >();
                    }

                    parentT.Children.Add(t);
                    parentT      = t;
                    currentlevel = level;
redo:
                    line = sr.ReadLine();
                    if (line != null && line.Length == 0)
                    {
                        goto redo;
                    }
                }

                sr.Close();
                fs.Close();
            }

            catch
            {
                if (sr != null)
                {
                    sr.Close();
                }

                if (fs != null)
                {
                    fs.Close();
                }

                if (RecreateFileIfInvalid)
                {
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                    File.Create(filename);
                }

                root.Children = new List <Btree <T> >();
            }
        }