Beispiel #1
0
        /// <inheritdoc cref="object.ToString" />
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            GblUtility.NodesToText(result, this);

            return(result.ToString());
        }
Beispiel #2
0
        public void GblFile_FromJson_1()
        {
            string text = "{'items':[{'command':'ADD','parameter1':'300','format1':'Add field 300'},{'command':'DEL','parameter1':'300','parameter2':'*'},{'command':'NOP'}]}"
                          .Replace("'", "\"");

            GblFile gbl = GblUtility.FromJson(text);

            Assert.AreEqual(3, gbl.Statements.Count);
            Assert.AreEqual("ADD", gbl.Statements[0].Command);
        }
Beispiel #3
0
        public void GblFile_FromXml_1()
        {
            string text = "<?xml version='1.0' encoding='utf-16'?><gbl xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>  <item>    <command>ADD</command>    <parameter1>300</parameter1>    <format1>Add field 300</format1>  </item>  <item>    <command>DEL</command>    <parameter1>300</parameter1>    <parameter2>*</parameter2>  </item>  <item>    <command>NOP</command>  </item></gbl>"
                          .Replace("'", "\"");

            GblFile gbl = GblUtility.FromXml(text);

            Assert.IsNotNull(gbl);
            Assert.AreEqual(3, gbl.Statements.Count);
            Assert.AreEqual(0, gbl.Parameters.Count);
        }
Beispiel #4
0
        public void GblFile_ParseLocalXmlFile_1()
        {
            string fileName = Path.Combine
                              (
                TestDataPath,
                "test-gbl.xml"
                              );

            GblFile gbl = GblUtility.ParseLocalXmlFile(fileName);

            Assert.IsNotNull(gbl);
            Assert.AreEqual(3, gbl.Statements.Count);
            Assert.AreEqual(0, gbl.Parameters.Count);
        }
        /// <inheritdoc cref="AbstractCommand.CreateQuery"/>
        public override ClientQuery CreateQuery()
        {
            ClientQuery result = base.CreateQuery();

            result.CommandCode = CommandCode.CorrectVirtualRecord;

            string database = Database ?? Connection.Database;

            if (string.IsNullOrEmpty(database))
            {
                Log.Error
                (
                    "GblVirtualCommand::CreateQuery: "
                    + "database not specified"
                );

                throw new IrbisException("database not specified");
            }
            result.AddAnsi(database);

            result.Add(Actualize);

            if (!string.IsNullOrEmpty(FileName))
            {
                result.AddAnsi(FileName);
            }
            else
            {
                string statements = GblUtility.EncodeStatements
                                    (
                    Statements.ThrowIfNull("Statements")
                                    );
                result.AddUtf8(statements);
            }

            result.Add(Record.ThrowIfNull("Record"));

            return(result);
        }
Beispiel #6
0
        /// <inheritdoc cref="AbstractCommand.CreateQuery"/>
        public override ClientQuery CreateQuery()
        {
            ClientQuery result = base.CreateQuery();

            result.CommandCode = CommandCode.GlobalCorrection;

            string database = Database ?? Connection.Database;

            if (string.IsNullOrEmpty(database))
            {
                Log.Error
                (
                    "GblCommand::CreateQuery: "
                    + "database not specified"
                );

                throw new IrbisException("database not specified");
            }
            result.AddAnsi(database);

            result.Add(Actualize);

            if (!string.IsNullOrEmpty(FileName))
            {
                // @filename without extension
                result.AddAnsi(FileName);
            }
            else
            {
                string statements = GblUtility.EncodeStatements
                                    (
                    Statements.ThrowIfNull("Statements")
                                    );
                result.AddUtf8(statements);
            }

            string preparedSearch = IrbisSearchQuery.PrepareQuery
                                    (
                SearchExpression
                                    );

            result.AddUtf8(preparedSearch);

            result.Add(FirstRecord);
            result.Add(NumberOfRecords);

            result.Add(string.Empty);

            if (ReferenceEquals(MfnList, null))
            {
                // Seems doesn't work with 2015.1
                //result.Add(0);
                //result.Add(MinMfn);
                //result.Add(MaxMfn);

                int count = MaxMfn - MinMfn + 1;
                result.Add(count);
                for (int mfn = MinMfn; mfn < MaxMfn; mfn++)
                {
                    result.Add(mfn);
                }
            }
            else
            {
                if (MfnList.Length == 0)
                {
                    Log.Error
                    (
                        "GblCommand::CreateQuery: "
                        + "MfnList.Length="
                        + MfnList.Length
                    );

                    throw new IrbisException("MfnList.Length == 0");
                }
                result.Add(MfnList.Length);
                foreach (var mfn in MfnList)
                {
                    result.Add(mfn);
                }
            }

            if (!FormalControl)
            {
                result.Add("*");
            }

            if (!AutoIn)
            {
                result.Add("&");
            }

            return(result);
        }