コード例 #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);
        }
コード例 #2
0
        /******************************************************************************/
        //TStrings Dico = TStrings.FromJSon("[{\"1\":\"Log\"}, {\"2\":\"Warning\"}, {\"3\":\"Error\"}, {\"4\":\"Critical\"} ]");
        //TStrings Dico = TStrings.FromJSon("[{\"1\" :\"Log\"}, {\"2\": \"Warning\"}, {\"3\" : \"Error\"}, { \"4\":\"Critical\" } ]");
        //TStrings Dico = TStrings.FromJSon("[{\"1\":11 }, {\"2\":22}, {\"3\": 33}, {\"4\": 44 } ]");

        /// <summary>
        /// Creates a new TStrings from JSON ...
        /// <code>
        /// TStrings Dico = TStrings.FromJSon("[{\"1\":\"Log\"}, {\"2\":\"Warning\"}, {\"3\":\"Error\"}, {\"4\":\"Critical\"} ]");
        /// </code>
        /// </summary>
        /// <param name="JSON"></param>
        /// <returns></returns>
        public static TStrings FromJSon(string JSON)
        {
            JSON = LineUpJSON(JSON);

            TStrings Result = new TStrings();

            JSON = JSON.Replace("},", "\n");

            JSON = JSON.Replace("\":\"", "=");

            JSON = JSON.Replace("\":", "=");
            JSON = JSON.Replace("\"\n", "\n");

            JSON = JSON.Replace("\n{\"", "\n");
            JSON = JSON.Replace("\n {\"", "\n");

            JSON = JSON.TrimStart(new char[] { '[', '{', '"', ' ' });
            JSON = JSON.TrimEnd(new char[] { ']', '}', ' ', '"' });

            JSON = JSON.Replace("\",\"", "\n");

            Result.Text = JSON;

            return(Result);
        }
コード例 #3
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);
            }
            ;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public static int LastIndexOfTStrings(this string source, TStrings List)
        {
            if (string.IsNullOrEmpty(source))
            {
                return(-1);
            }
            ;

            if (List.Count == 0)
            {
                return(-1);
            }
            ;

            for (int i = 0; i < List.Count; i++)
            {
                string chars = List[i];

                if (source.LastIndexOf(chars) > 0)
                {
                    return(source.LastIndexOf(chars));
                }
            }

            return(-1);
        }
コード例 #6
0
        public TStrings ReadSections()
        {
            TStrings Result = new TStrings();

            Result.Text = FSections.Text;
            return(Result);
        }
コード例 #7
0
        public TStrings ReadSectionValues(string Section)
        {
            TStrings Strings = new TStrings();

            ReadSectionValues(Section, Strings);

            return(Strings);
        }
コード例 #8
0
        public void TStrings_FromJSon_Test_C()
        {
            string JSON = "[{\"1\":11 }, {\"2\":22}, {\"3\": 33}, {\"4\": 44 } ]";

            TStrings json = TStrings.FromJSon(JSON);

            Assert.IsTrue(json.Count == 4 && json["3"] == "33");
        }
コード例 #9
0
        public void TStrings_FromJSon_Test_B()
        {
            string JSON = "[{\"1\" :\"Log\"}, {\"2\": \"Warning\"}, {\"3\" : \"Error\"}, { \"4\":\"Critical\" } ]";

            TStrings json = TStrings.FromJSon(JSON);

            Assert.IsTrue(json.Count == 4 && json["3"] == "Error");
        }
コード例 #10
0
        public void TStrings_FromJSon_Simple_B()
        {
            string JSON = @"[{'firstName': 'John','lastName': 'Smith','age': 25}]".Replace("'", "\"");

            TStrings json = TStrings.FromJSon(JSON);

            Assert.IsTrue(json.Count == 3 && json["age"] == "25");
        }
コード例 #11
0
        public TStrings AddSection(string Section)
        {
            TStrings Result;

            Result = new TStrings();
            FSections.AddObject(Section, Result);

            return(Result);
        }
コード例 #12
0
        public void TStrings_Load_Test_1()
        {
            TStrings_Save_Test_1();

            TStrings file = new TStrings();

            file.LoadFromFile(FileName);

            Assert.AreEqual("123", file[1]);
        }
コード例 #13
0
        public void StringExt_Top040()
        {
            var output = input4.Top(3);

            var lines = new TStrings();

            lines.Text = output;

            Assert.AreEqual(3, lines.Count);
        }
コード例 #14
0
        public void _00_NameValue_01()
        {
            TStrings file = new TStrings();

            file["A"] = "1";
            file["B"] = "2";
            file["C"] = "3";

            Assert.AreEqual("2", file["B"]);
        }
コード例 #15
0
        public void _00_NameValue_02()
        {
            TStrings file = new TStrings();

            file["A"] = "1";
            file["B"] = "2";
            file["C"] = "3";
            file["B"] = "4";

            Assert.AreEqual(3, file.Count);
        }
コード例 #16
0
        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]);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        /// <summary>
        /// TIniFile creates a new TIniFile object.
        /// </summary>
        /// <param name="IniFileName">On Windows, most INI files are stored in
        /// the \WINDOWS directory. To work with an INI file in another location,
        /// specify the full path name of the file in IniFileName.</param>

        public TIniFile(string FileName)
        {
            FSections = new TStrings();

            if ((FileName != null) && (FileName.Length > 0))
            {
                FFileName = FileName;
                LoadValues();
            }
            else
            {
                FFileName = "";
            };
        }
コード例 #19
0
        public void ReadSectionValues(string Section, string SubSection, TStrings Strings)
        {
            ReadSectionValues(Section, Strings);

            TStrings SubStrings = new TStrings();

            ReadSectionValues(Section + "." + SubSection, SubStrings);

            for (int i = 0; i < SubStrings.Count; i++)
            {
                Strings[SubStrings.Names(i)] = SubStrings.ValueFromIndex(i);
            }
            ;
        }
コード例 #20
0
        /// <summary>
        /// Call AddStrings to add the strings from another TStrings object to the list. If both the source and destination TStrings objects support objects associated with their strings, references to the associated objects will be added as well.  
        /// </summary>
        /// <param name="strings"></param>
        public void AddStrings(TStrings strings)
        {
            for (int i = 0; i < strings.Count; i++)
            {
                int ind = this.Add(strings[i]);

                if (strings.GetObject(i) != null)
                {
                    this.SetObject(ind, strings.GetObject(i));
                }
                ;
            }
            ;
        }
コード例 #21
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);
                };
            }
        }
コード例 #22
0
        /******************************************************************************/

        public void LoadValues()
        {
            TStrings List = new TStrings();
            string   st;
            TStrings Strings;

            if ((FFileName.Length > 0))
            {
                List.LoadFromFile(FFileName, System.Text.Encoding.UTF8);

                Clear();
                Strings = null;

                for (int i = 0; i < List.Count; i++)
                {
                    st = List[i];

                    if ((st.Length > 0) && (st[0] != ';')) // ? Comment
                    {
                        if ((st[0] == '[') &&
                            (st[st.Length - 1] == ']'))       // ? Section
                        {
                            Strings = AddSection(st.Substring(1, st.Length - 2));
                        }
                        else
                        {
                            if (Strings != null)
                            {
                                Strings.Add(st);
                            }
                        };
                    }
                    ;
                }
                ;
            }
            else
            {
                Clear();
            };
        }
コード例 #23
0
        /// <summary>
        /// Writes a TString value to an section of INI file.
        /// </summary>
        /// <param name="Section">Section identifies the section in the file that contain the key to which to write.</param>
        /// <param name="Ident">Ident is the name of the key for which to set a value.</param>
        /// <param name="Values">Values is the TStrings value to write.</param>

        public void WriteSectionValues(string Section, TStrings Values)
        {
            int      i;
            TStrings Strings;

            i = FSections.IndexOf(Section);

            if (i < 0)
            {
                AddSection(Section);
                i = FSections.IndexOf(Section);
            }
            ;

            if (i >= 0)
            {
                Strings      = (FSections.GetObject(i) as TStrings);
                Strings.Text = Values.Text;
            }
            ;
        }
コード例 #24
0
        // - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -

        /// <summary>
        /// Returns the specified number first lines of a text.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="Nb"></param>
        /// <returns></returns>
        public static string Top(this string source, int Nb)
        {
            if (string.IsNullOrEmpty(source))
            {
                return(source);
            }
            ;

            string Result = "";

            var list = new TStrings();

            list.Text = source;

            for (int i = 0; i < Nb && i < list.Count; i++)
            {
                Result = Result + list[i] + Environment.NewLine;
            }
            ;

            return(Result);
        }
コード例 #25
0
        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);
        }
コード例 #26
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;
                    }
                    ;
                }
                ;
            }
            ;
        }
コード例 #27
0
        /******************************************************************************/

        public static TStrings FromJSonValue(string Text)
        {
            TStrings Result = new TStrings();

            if (Text != "" && Text != "[]")
            {
                if ((Text[0] == '[') && (Text[Text.Length - 1] == ']'))
                {
                    Text = Text.Substring(1, Text.Length - 2);
                }
                ;

                if ((Text[0] == '{') && (Text[Text.Length - 1] == '}'))
                {
                    Text = Text.Substring(1, Text.Length - 2);
                }
                ;

                Text = Text.Replace("\",", "\"\n");

                Result.Text = Text;

                for (int i = 0; i < Result.Count; i++)
                {
                    if (Result.ValueFromIndex(i).StartsWith("\"") && Result.ValueFromIndex(i).EndsWith("\""))
                    {
                        Result[i] = Result.Names(i) + "=" + Result.ValueFromIndex(i).Substring(1, Result.ValueFromIndex(i).Length - 2);
                    }
                    ;
                }
                ;
            }
            ;

            return(Result);
        }
コード例 #28
0
 void ReadSection(string Section, TStrings Strings)
 {
 }
コード例 #29
0
        static internal TStrings GetConfig(TStrings Log)
        {
            String Format = "{0,20} {1}";

            if (Log == null)
            {
                Log = new TStrings();
            }
            ;

            Log.Add(String.Format(Format, "OS", GetOSandServicepack()));
            Log.Add("");

            ManagementObjectSearcher   query1           = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectCollection queryCollection1 = query1.Get();

            foreach (ManagementObject mo in queryCollection1)
            {
                Log.Add(String.Format(Format, "Name", mo["name"].ToString()));
                Log.Add(String.Format(Format, "Version", mo["version"].ToString()));
                Log.Add("");
                Log.Add(String.Format(Format, "Manufacturer", mo["Manufacturer"].ToString()));
                Log.Add(String.Format(Format, "Computer Name", mo["csname"].ToString()));
                Log.Add(String.Format(Format, "Windows Directory", mo["WindowsDirectory"].ToString()));
            }

            Log.Add("");

            query1           = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
            queryCollection1 = query1.Get();
            foreach (ManagementObject mo in queryCollection1)
            {
                Log.Add(String.Format(Format, "Manufacturer", mo["manufacturer"].ToString()));
                Log.Add(String.Format(Format, "Model", mo["model"].ToString()));
                Log.Add(String.Format(Format, "", mo["systemtype"].ToString()));
                Log.Add(String.Format(Format, "Total Physical Memory", mo["totalphysicalmemory"].ToString()));
            }

            query1           = new ManagementObjectSearcher("SELECT * FROM Win32_processor");
            queryCollection1 = query1.Get();
            foreach (ManagementObject mo in queryCollection1)
            {
                Log.Add(String.Format(Format, "", mo["caption"].ToString()));
            }

            Log.Add("");

            query1           = new ManagementObjectSearcher("SELECT * FROM Win32_bios");
            queryCollection1 = query1.Get();
            foreach (ManagementObject mo in queryCollection1)
            {
                Log.Add(String.Format(Format, "", mo["version"].ToString()));
            }

            try
            {
                query1           = new ManagementObjectSearcher("SELECT * FROM Win32_timezone");
                queryCollection1 = query1.Get();
                foreach (ManagementObject mo in queryCollection1)
                {
                    Log.Add(String.Format(Format, "", mo["caption"].ToString()));
                }
                ;
            }
            catch {};

            return(Log);
        }
コード例 #30
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);
                    };
                };
            }
        }