コード例 #1
0
        private void CheckField
        (
            RecordField field
        )
        {
            SubField volume = field.GetFirstSubField('a');
            SubField units  = field.GetFirstSubField('1');

            if (volume == null)
            {
                AddDefect
                (
                    field,
                    5,
                    "Не заполнено подполе 215^a: Объем (цифры)"
                );
            }

            if (units != null)
            {
                if (Utilities.SafeCompare(units.Text, "С.", "С"))
                {
                    AddDefect
                    (
                        field,
                        units,
                        1,
                        "Указана единица измерения 'С' в подполе 215^1"
                    );
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// The subfield must not contain bad characters.
        /// </summary>
        protected void MustNotContainBadCharacters
        (
            [NotNull] RecordField field,
            [NotNull] SubField subField
        )
        {
            string text = subField.Text;

            if (!string.IsNullOrEmpty(text))
            {
                int position = RuleUtility.BadCharacterPosition(text);
                if (position >= 0)
                {
                    AddDefect
                    (
                        field,
                        subField,
                        3,
                        "Подполе {0}^{1} содержит"
                        + "запрещённые символы: {2}",
                        field.Tag,
                        subField.Code,
                        GetTextAtPosition(text, position)
                    );
                }
            }
        }
コード例 #3
0
        public void SubField_Constructor_1()
        {
            SubField subField = new SubField();

            Assert.AreEqual(SubField.NoCode, subField.Code);
            Assert.AreEqual(SubField.NoCodeString, subField.CodeString);
            Assert.AreEqual(null, subField.Value);
            Assert.AreEqual("^\0", subField.ToString());

            subField = new SubField('A', "The value");
            Assert.AreEqual('A', subField.Code);
            Assert.AreEqual("A", subField.CodeString);
            Assert.AreEqual("The value", subField.Value);
            Assert.AreEqual("^aThe value", subField.ToString());

            SubField clone = subField.Clone();

            Assert.AreEqual(subField.Code, clone.Code);
            Assert.AreEqual(subField.CodeString, clone.CodeString);
            Assert.AreEqual(subField.Value, clone.Value);
            Assert.AreEqual("^aThe value", clone.ToString());
            Assert.AreEqual(0, SubField.Compare(subField, clone));

            subField.SetValue("New value");
            Assert.AreEqual("New value", subField.Value);
            subField.SetValue(null);
            Assert.AreEqual(null, subField.Value);
        }
コード例 #4
0
        public static RecordField ParseLine
        (
            [NotNull] string line
        )
        {
            Sure.NotNullNorEmpty(line, "line");

            StringReader reader = new StringReader(line);

            RecordField result = new RecordField
            {
                Tag   = NumericUtility.ParseInt32(_ReadTo(reader, '#')),
                Value = _ReadTo(reader, '^')
            };

            while (true)
            {
                int next = reader.Read();
                if (next < 0)
                {
                    break;
                }
                char     code     = char.ToLower((char)next);
                string   text     = _ReadTo(reader, '^');
                SubField subField = new SubField
                {
                    Code  = code,
                    Value = text
                };
                result.SubFields.Add(subField);
            }

            return(result);
        }
コード例 #5
0
        private void _TestSerialization
        (
            params SubField[] subFields
        )
        {
            SubFieldCollection collection1 = new SubFieldCollection();

            collection1.AddRange(subFields);

            //collection1.SaveToFile("collection1.bin");
            //collection1.SaveToZipFile("collection1.biz");

            byte[] bytes = collection1.SaveToMemory();

            SubFieldCollection collection2 = bytes
                                             .RestoreObjectFromMemory <SubFieldCollection>();

            Assert.AreEqual(collection1.Count, collection2.Count);

            for (int i = 0; i < collection1.Count; i++)
            {
                Assert.AreEqual
                (
                    0,
                    SubField.Compare
                    (
                        collection1[i],
                        collection2[i]
                    )
                );
            }
        }
コード例 #6
0
        public PftGlobalVariable ParseLine
        (
            string line
        )
        {
            StringReader reader = new StringReader(line);
            RecordField  field  = new RecordField(Number.ToInvariantString());

            Fields.Add(field);
            field.Text = _ReadTo(reader, '^');
            while (true)
            {
                int next = reader.Read();
                if (next < 0)
                {
                    break;
                }
                char     code     = char.ToLower((char)next);
                string   text     = _ReadTo(reader, '^');
                SubField subField = new SubField
                {
                    Code = code,
                    Text = text
                };
                field.SubFields.Add(subField);
            }
            return(this);
        }
コード例 #7
0
        public void SubField_ToXml_1()
        {
            SubField     subField = new SubField('a', "Value");
            string       actual   = XmlUtility.SerializeShort(subField);
            const string expected = "<subfield code=\"a\" value=\"Value\" />";

            Assert.AreEqual(expected, actual);
        }
コード例 #8
0
        public void SubFieldUtility_ToJObject_1()
        {
            SubField subField = new SubField('a', "Value");
            JObject  jobject  = subField.ToJObject();

            Assert.AreEqual('a', jobject["code"].Value <char>());
            Assert.AreEqual("Value", jobject["value"].Value <string>());
        }
コード例 #9
0
        public void SubFieldUtility_FromJson_1()
        {
            SubField subField = SubFieldUtility
                                .FromJson("{'code':'a','value':'Value'}");

            Assert.AreEqual('a', subField.Code);
            Assert.AreEqual("Value", subField.Value);
        }
コード例 #10
0
 private void AddSubfield(RecordField field, char subFieldCode, string tagFrom, char codeFrom)
 {
     if (!String.IsNullOrEmpty(recordFrom.FM(tagFrom, codeFrom)))
     {
         SubField subField = new SubField(subFieldCode, recordFrom.FM(tagFrom, codeFrom));
         field.SubFields.Add(subField);
     }
 }
コード例 #11
0
        public void SubField_ReadOnly_1()
        {
            SubField subField = new SubField('a', "Value", true, null);

            Assert.AreEqual("Value", subField.Value);
            subField.Value = "New value";
            Assert.AreEqual("Value", subField.Value);
        }
コード例 #12
0
 public void NewGame(String playerName1, String playerName2)
 {
     _players    = new Player[2];
     _players[0] = new Player(playerName1, Condition.CROSS);
     _players[1] = new Player(playerName2, Condition.ZERO);
     Field       = new MainField();
     _lastPicked = null;
 }
コード例 #13
0
        public void SubField_SetValue_1()
        {
            SubField subField = new SubField('a')
            {
                Value = "Right Value"
            };

            Assert.AreEqual("Right Value", subField.Value);
        }
コード例 #14
0
        public void SubFieldUtility_GetSubFieldValue_1()
        {
            SubField subField = new SubField('a', "Value");

            Assert.AreEqual("Value", subField.GetSubFieldValue());

            subField = null;
            Assert.AreEqual(null, subField.GetSubFieldValue());
        }
コード例 #15
0
        public void SubField_ToJson_1()
        {
            SubField subField = new SubField('a', "Value");

            string       actual   = subField.ToJson();
            const string expected = @"{'code':'a','value':'Value'}";

            Assert.AreEqual(expected, actual);
        }
コード例 #16
0
        public void SubField_ToJObject_1()
        {
            SubField subField = new SubField('a', "Value");

            JObject jObject = subField.ToJObject();

            Assert.AreEqual("a", jObject["code"].ToString());
            Assert.AreEqual("Value", jObject["value"].ToString());
        }
コード例 #17
0
        public void SubField_AsReadOnly_1()
        {
            SubField subField = new SubField('a', "Value")
                                .AsReadOnly();

            Assert.AreEqual("Value", subField.Value);
            subField.Value = "New value";
            Assert.AreEqual("Value", subField.Value);
        }
コード例 #18
0
        public void RecordField_ReadOnly_3()
        {
            RecordField field = _GetField().AsReadOnly();

            Assert.IsTrue(field.ReadOnly);
            SubField subField = field.SubFields[0];

            subField.Value = "New value";
        }
コード例 #19
0
        public void SubField_UserData_1()
        {
            SubField subField = new SubField();

            Assert.IsNull(subField.UserData);

            subField.UserData = "User data";
            Assert.AreEqual("User data", subField.UserData);
        }
コード例 #20
0
        public void SubField_SetModified_1()
        {
            SubField subField = new SubField('a', "Title1");

            Assert.IsFalse(subField.Modified);
            subField.Value = "Title2";
            Assert.IsTrue(subField.Modified);
            subField.NotModified();
            Assert.IsFalse(subField.Modified);
        }
コード例 #21
0
        public void RecordFieldUtility_AddSubFields_2()
        {
            RecordField field1 = new RecordField();

            SubField[]  subFields = new SubField[0];
            RecordField field2    = RecordFieldUtility.AddSubFields(field1, subFields);

            Assert.AreSame(field1, field2);
            Assert.AreEqual(0, field1.SubFields.Count);
        }
コード例 #22
0
        public void SubFieldCollection_InsertItem1()
        {
            SubFieldCollection collection = _GetCollection();

            Assert.AreEqual(3, collection.Count);
            SubField subField = new SubField('d', "Subfield D");

            collection.Insert(1, subField);
            Assert.AreEqual(subField, collection[1]);
            Assert.AreEqual(4, collection.Count);
        }
コード例 #23
0
        public void SubFieldUtility_FromJObject_2()
        {
            JObject jObject = new JObject
            {
                { "code", "a" }
            };
            SubField subField = SubFieldUtility.FromJObject(jObject);

            Assert.AreEqual('a', subField.Code);
            Assert.IsNull(subField.Value);
        }
コード例 #24
0
        internal void CopyRecord(string fromMfn, string toMfn, string recordIndex)
        {
            _recordIndex = "(" + recordIndex + ") ";
            recordFrom   = client.ReadRecord(Int32.Parse(fromMfn));
            recordTo     = client.ReadRecord(Int32.Parse(toMfn));
            try
            {
                RecordField fiedl922 = new RecordField("922");
                AddSubfield(fiedl922, 'C', "200", 'A');
                AddSubfield(fiedl922, 'F', "700", 'A');
                AddSubfield(fiedl922, '?', "700", 'G');
                AddSubfield(fiedl922, '1', "700", '1');
                AddSubfield(fiedl922, 'A', "700", 'C');
                recordTo.Fields.Add(fiedl922);

                CopyField("300");
                CopyField("331");
                CopySubField("215", 'A');
                CopySubField("316", 'A');


                foreach (RecordField field210 in recordFrom.Fields.GetField("210"))
                {
                    if (!field210.ToString().Contains("^5"))
                    {
                        _recordIndex = _recordIndex.Replace(" ", "");
                    }

                    var field   = new RecordField("210");
                    var sub2105 = new SubField('5', _recordIndex + field210.GetFirstSubFieldText('5'));
                    var sub210d = new SubField('D', field210.GetFirstSubFieldText('d'));
                    field.SubFields.Add(sub210d);
                    field.SubFields.Add(sub2105);
                    logging.WriteLine(field.Text);
                    recordTo.Fields.Add(field);
                    logging.WriteLine(recordTo.FM("210"));
                }



                client.WriteRecord
                (
                    recordTo,
                    false,
                    true
                );
            }
            catch (Exception ex)
            {
                logging.WriteLine("ERROR DURING COPYING RECORD! ");
                logging.WriteLine(ex.StackTrace);
                logging.WriteLine(ex.ToString());
            }
        }
コード例 #25
0
        public void SubField_Field_1()
        {
            SubField subField = new SubField('a', "Title");

            Assert.IsNull(subField.Field);

            RecordField field = new RecordField("200");

            field.SubFields.Add(subField);
            Assert.AreEqual(field, subField.Field);
        }
コード例 #26
0
        public void SubFieldCollection_SetItem_1()
        {
            SubFieldCollection collection = _GetCollection();

            Assert.AreEqual(3, collection.Count);
            SubField subField = new SubField('d', "Subfield D");

            collection[1] = subField;
            Assert.AreEqual(3, collection.Count);
            Assert.AreEqual(subField, collection[1]);
        }
コード例 #27
0
        public void SubField_FromJson_1()
        {
            const string text = @"{"
                                + @"  ""code"": ""a"","
                                + @"  ""value"": ""Value"""
                                + @"}";

            SubField subField = SubFieldUtility.FromJson(text);

            Assert.AreEqual('a', subField.Code);
            Assert.AreEqual("Value", subField.Value);
        }
コード例 #28
0
        public void SubField_Verify_1()
        {
            SubField subField = new SubField();

            Assert.IsFalse(subField.Verify(false));

            subField = new SubField('a');
            Assert.IsTrue(subField.Verify(false));

            subField = new SubField('a', "Title");
            Assert.IsTrue(subField.Verify(false));
        }
コード例 #29
0
        public void RecordFieldUtility_GetFirstSubField_1()
        {
            RecordField field    = _GetField();
            SubField    subField = RecordFieldUtility.GetFirstSubField(field, 'a');

            Assert.IsNotNull(subField);

            subField = RecordFieldUtility.GetFirstSubField(field, 'b');
            Assert.IsNotNull(subField);

            subField = RecordFieldUtility.GetFirstSubField(field, 'x');
            Assert.IsNull(subField);
        }
コード例 #30
0
        public void SubFieldUtility_GetFirstSubField_4()
        {
            SubFieldCollection collection = _GetCollection();
            SubField           found      = collection.GetFirstSubField('a', 'b');

            Assert.AreEqual("SubFieldA1", found.Value);

            found = collection.GetFirstSubField('c', 'd');
            Assert.AreEqual("SubFieldC1", found.Value);

            found = collection.GetFirstSubField('d', 'e');
            Assert.IsNull(found);
        }