Beispiel #1
0
        /// <summary>
        /// Flushes buffered INI file data to disk.
        /// </summary>

        public bool UpdateFile()
        {
            TStrings IniFile = new TStrings();
            TStrings Section;

            for (int i = 0; i < FSections.Count; i++)
            {
                IniFile.Add("[" + FSections[i] + "]");

                Section = (FSections.GetObject(i) as TStrings);

                for (int j = 0; j < Section.Count; j++)
                {
                    IniFile.Add(Section[j]);
                }
                ;

                IniFile.Add("");
            }
            ;

            IniFile.SaveToFile(FFileName, System.Text.Encoding.Unicode);

            return(true);
        }
        public void TStrings_Insert_0_1()
        {
            TStrings file = new TStrings();

            file.Add("1");
            file.Add("2");
            file.Add("3");
            file.Insert(0, "0");

            Assert.AreEqual("2", file[2]);
        }
        public void TStrings_Save_Test_1()
        {
            FileName = System.IO.Path.GetTempFileName() + ".txt";

            TStrings file = new TStrings();

            file.Add(DateTime.Now.ToString());
            file.Add("123");
            file.SaveToFile(FileName);

            bool Exist = System.IO.File.Exists(FileName);

            Assert.AreEqual(true, Exist);
        }
        public void _01_SaveToFile_Perftest_03()
        {
            FileName = System.IO.Path.GetTempFileName() + ".txt";

            TStrings file = new TStrings();

            for (int i = 0; i < 100000; i++)
            {
                file.Add(dummy);
            }
            ;

            var dt = DateTime.Now;

            file.SaveToFile(FileName);
            var dt1 = DateTime.Now - dt;

            System.IO.File.Delete(FileName);

            dt = DateTime.Now;

            string text = "";

            for (int i = 0; i < file.Count; i++)
            {
                text = text + file.Get(i);
            }
            System.IO.File.WriteAllText(FileName, text);

            var dt2 = DateTime.Now - dt;

            Console.WriteLine($"{dt1.TotalMilliseconds} < {dt2.TotalMilliseconds}");
            Assert.AreEqual(true, dt1 < dt2);
        }
Beispiel #5
0
        public string this[int Index1, int Index]
        {
            get
            {
                Check(Index1);

                var o = GetObject(Index1) as TStrings;

                if (o != null)
                {
                    return(o[Index]);
                }
                else
                {
                    return("");
                };
            }
            set
            {
                Check(Index1);

                if (Index == 0)
                {
                    Put(Index1, value);
                }
                ;

                if ((GetObject(Index1) as TStrings) != null)
                {
                    var t = (GetObject(Index1) as TStrings);
                    for (int ii = t.Count; ii <= Index; ii++)
                    {
                        t.Add("");
                    }
                    t[Index] = value;
                }
                else
                {
                    TStrings t = new TStrings();
                    for (int ii = t.Count; ii <= Index; ii++)
                    {
                        t.Add("");
                    }
                    t[Index] = value;

                    SetObject(Index1, t);
                };
            }
        }
Beispiel #6
0
        /// <summary>
        /// Reads the values from all keys within a section of an INI file into a string list.
        /// </summary>
        /// <param name="Section">Section identifies the section in the file from which to read key values. </param>
        /// <param name="Strings">Strings is the string list object into which to read the values.</param>

        public void ReadSectionValues(string Section, TStrings Strings)
        {
            TStrings CurrentSection;

            Strings.Clear();

            if (Strings != null)
            {
                for (int i = 0; i < FSections.Count; i++)
                {
                    //if( FSections[ i ] == Section )
                    if (FSections[i].ToUpper() == Section.ToUpper())
                    {
                        CurrentSection = (FSections.GetObject(i) as TStrings);

                        for (int j = 0; j < CurrentSection.Count; j++)
                        {
                            string st = CurrentSection[j].TrimEnd();

                            if ((st.Length > 0) &&
                                (st[0] != '#') &&
                                (st[0] != '\n'))
                            {
                                Strings.Add(st);
                            }
                            ;
                        }
                        ;

                        i = FSections.Count;
                    }
                    ;
                }
                ;
            }
            ;
        }
        public void _01_SaveToFile_Perftest_00()
        {
            FileName = System.IO.Path.GetTempFileName() + ".txt";

            TStrings file = new TStrings();

            for (int i = 0; i < 100000; i++)
            {
                file.Add(dummy);
            }
            ;

            var dt = DateTime.Now;

            file.SaveToFile(FileName);
            var dt1 = DateTime.Now - dt;

            System.IO.File.Delete(FileName);

            dt = DateTime.Now;

            using (var stream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                using (StreamWriter asw = new StreamWriter(stream, Encoding.Default))
                {
                    for (int i = 0; i < file.Count; i++)
                    {
                        asw.WriteLine(file.Get(i));
                    }
                };
            };

            var dt2 = DateTime.Now - dt;

            Console.WriteLine($"{dt1.TotalMilliseconds} < {dt2.TotalMilliseconds}");
            Assert.AreEqual(true, dt1 < dt2);
        }
Beispiel #8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //
            // saveFileDialog
            //
            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog.DefaultExt = "Log";
            saveFileDialog.Filter     = "Log files|*.Log";
            saveFileDialog.Title      = "Save to file";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                String   Format = "{0,20} {1}";
                TStrings Log    = new TStrings();

                Log.Add(new String('-', 80));
                Log.Add("");

                Log.Add(String.Format(Format, "Who", System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString()));
                Log.Add(String.Format(Format, "Version", LastChanceTrace.Version));
                Log.Add(String.Format(Format, "Internal build", Assembly.GetExecutingAssembly().GetName().Version.ToString()));
                if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
                {
                    System.Deployment.Application.ApplicationDeployment appDeploy;

                    appDeploy = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;

                    Log.Add(String.Format(Format, "ClickOnce V", appDeploy.CurrentVersion));
                }
                ;

                Log.Add(String.Format(Format, "BuildTimeStamp", LastChanceTrace.BuildTimeStamp));
                Log.Add(String.Format(Format, "When", DateTime.Now.ToString()));
                Log.Add(String.Format(Format, "What", textBoxMessage.Text));
                Log.Add(String.Format(Format, "Type", textBoxType.Text));

                Log.Add("");
                Log.Add(new String('-', 80));
                Log.Add("");

                Log.Add(textBoxStack.Text);

                Log.Add("");
                Log.Add(new String('-', 80));

                try
                {
                    Log.Add("");

                    Log = GetConfig(Log);

                    Log.Add("");
                    Log.Add(new String('-', 80));
                }
                catch {};

                Log.SaveToFile(saveFileDialog.FileName);
            }
            ;
        }
Beispiel #9
0
        public string this[string Name, int Index]
        {
            get
            {
                string Result;
                int    i;

                i = IndexOfName(Name);

                if (i >= 0)
                {
                    var o = GetObject(i) as TStrings;

                    if (o != null)
                    {
                        return(o[Index]);
                    }
                    else
                    {
                        return("");
                    };
                }
                else
                {
                    Result = "";
                };

                return(Result);
            }
            set
            {
                int i;

                i = IndexOfName(Name);

                if (i < 0)
                {
                    if (Index == 0)
                    {
                        i = Add(Name + "=" + value);
                    }
                    else
                    {
                        i = Add(Name + "=");
                    };

                    TStrings t = new TStrings();
                    for (int ii = t.Count; ii <= Index; ii++)
                    {
                        t.Add("");
                    }
                    t[Index] = value;

                    SetObject(i, t);
                }
                else
                {
                    if (Index == 0)
                    {
                        Put(i, Name + "=" + value);
                    }
                    ;

                    if ((GetObject(i) as TStrings) != null)
                    {
                        var t = (GetObject(i) as TStrings);
                        for (int ii = t.Count; ii <= Index; ii++)
                        {
                            t.Add("");
                        }
                        t[Index] = value;
                    }
                    else
                    {
                        TStrings t = new TStrings();
                        for (int ii = t.Count; ii <= Index; ii++)
                        {
                            t.Add("");
                        }
                        t[Index] = value;

                        SetObject(i, t);
                    };
                };
            }
        }