Example #1
0
        public void ToRawTest()
        {
            string       tag      = "001";
            string       data     = "  2007032296";
            ControlField target   = new ControlField(tag, data);
            string       expected = "  2007032296" + FileMARC.END_OF_FIELD.ToString();
            string       actual   = target.ToRaw();

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void ToStringTest()
        {
            string       tag      = "001";
            string       data     = "  2007032296";
            ControlField target   = new ControlField(tag, data);
            string       expected = "001       2007032296";
            string       actual   = target.ToString();

            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public void ToXMLTest()
        {
            string       tag    = "001";
            string       data   = "  2007032296";
            ControlField target = new ControlField(tag, data);

            XElement expected = new XElement(FileMARCXML.Namespace + "controlfield", new XAttribute("tag", "001"), "  2007032296");
            XElement actual   = target.ToXML();

            Assert.IsTrue(XNode.DeepEquals(expected, actual));
        }
Example #4
0
        public void DeleteControlField(ControlField controlField)
        {
            using (var db = new CMSContext())
            {
                var dbControlField = db.ControlFields.FirstOrDefault(c => c.ControlId == controlField.ControlId &&
                                                                     c.FieldId == controlField.FieldId);

                db.ControlFields.Remove(dbControlField);
                db.SaveChanges();
            };
        }
Example #5
0
 public void roadField()
 {
     control_field = controlField.GetComponent <ControlField>();
     this.field_ob = control_field.field_ob;
     for (int y = 0; y < Y; y++)
     {
         for (int x = 0; x < X; x++)
         {
             road[y, x] = this.field_ob[y, x].GetComponent <Road>();
         }
     }
 }
Example #6
0
        public void DataTest()
        {
            string       tag      = "001";
            string       data     = "  2007032296";
            ControlField target   = new ControlField(tag, data);
            string       expected = "  2011022800";

            target.Data = expected;
            string actual = target.Data;

            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public ControlField CreateControlField(ControlField controlField)
        {
            using (var db = new CMSContext())
            {
                var newControlField = db.ControlFields.Add(controlField);

                db.SaveChanges();

                return(db.ControlFields.FirstOrDefault(f => f.ControlId == newControlField.ControlId &&
                                                       f.FieldId == newControlField.FieldId));
            };
        }
Example #8
0
        public void ControlFieldConstructorTest()
        {
            string       tag      = "001";
            string       data     = "  2007032296";
            ControlField target   = new ControlField(tag, data);
            string       expected = "001";
            string       actual   = target.Tag;

            Assert.AreEqual(expected, actual);
            expected = "  2007032296";
            actual   = target.Data;
            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void IsEmptyTest()
        {
            string       tag      = "001";
            string       data     = "  2007032296";
            ControlField target   = new ControlField(tag, data);
            bool         expected = false;
            bool         actual   = target.IsEmpty();

            Assert.AreEqual(expected, actual);
            target   = new ControlField(tag, string.Empty);
            expected = true;
            actual   = target.IsEmpty();
            Assert.AreEqual(expected, actual);
        }
Example #10
0
        public void ItemTest()
        {
            Record       target       = new Record();
            string       tag          = "245";
            ControlField controlField = new ControlField("001", "I am data! (But not Data from Star Trek TNG)");
            DataField    dataField    = new DataField(tag);
            DataField    dataField2   = new DataField(tag, new List <Subfield>(), ' ', '1');

            target.Fields.Add(controlField);
            target.Fields.Add(dataField);
            target.Fields.Add(dataField2);
            Field expected = dataField;
            Field actual   = target[tag];

            Assert.AreEqual(expected, actual);
        }
Example #11
0
        public void FieldsTest()
        {
            Record       target       = new Record();
            ControlField controlField = new ControlField("001", "I am data! (But not Data from Star Trek TNG)");
            DataField    dataField    = new DataField("245");
            DataField    dataField2   = new DataField("521", new List <Subfield>(), ' ', '1');

            target.Fields.Add(controlField);
            target.Fields.Add(dataField);
            target.Fields.Add(dataField2);

            {
                int expected = 3;
                int actual   = target.Fields.Count;
                Assert.AreEqual(expected, actual);
            }

            {
                Field expected = controlField;
                Field actual   = target.Fields[0];
                Assert.AreSame(expected, actual);
                expected = dataField;
                actual   = target.Fields[1];
                Assert.AreSame(expected, actual);
                expected = dataField2;
                actual   = target.Fields[2];
                Assert.AreSame(expected, actual);
            }

            {
                List <Field> expected = new List <Field> {
                    controlField, dataField, dataField2
                };
                target.Fields = expected;
                List <Field> actual = target.Fields;
                Assert.AreSame(expected, actual);
            }
        }
Example #12
0
        public void CloneTest()
        {
            string       tag    = "001";
            string       data   = "  2007032296";
            ControlField target = new ControlField(tag, data);

            Field expected = target;
            Field actual   = target.Clone();

            Assert.AreNotEqual(expected, actual);

            target.Data = "  2011063096";

            string expectedString = data;
            string actualString   = ((ControlField)actual).Data;

            Assert.AreEqual(expectedString, actualString);

            target.Tag = "002";

            expectedString = tag;
            actualString   = ((ControlField)actual).Tag;
            Assert.AreEqual(expectedString, actualString);
        }
Example #13
0
 public StatusApdu(byte[] rawData)
 {
     _controlField = new ControlField(rawData[0], rawData[1]);
 }
Example #14
0
 public StatusApdu(byte[] rawData)
 {
     _controlField = new ControlField(rawData[0], rawData[1]);
 }
Example #15
0
        /// <summary>
        /// Makes a deep clone of this instance.
        /// </summary>
        /// <returns></returns>
        public override Field Clone()
        {
            Field clone = new ControlField(Tag, Data);

            return(clone);
        }
Example #16
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        internal virtual Field CreateControlField()
        {
            Field target = new ControlField("001", "  2007032296");

            return(target);
        }
Example #17
0
 void start()
 {
     control_field = controlField.GetComponent <ControlField>();
     control_char  = controlChar.GetComponent <ControlChar>();
 }
Example #18
0
 void Awake()
 {
     makeField();
     control_scr = control_ob.GetComponent <ControlField>();
 }
        public virtual string ReadMsg()
        {
            string msg = "";

            if (RawDataChar == null)
            {
                return("无数据");
            }

            if (RawDataChar.Length >= 14)
            {
                if (RawDataChar[0] == BaseProtocol.BeginChar && RawDataChar[RawDataChar.Length - 1] == BaseProtocol.EndChar)
                {
                    Length = (int)RawDataChar[1];
                    byte[] Body_b = new byte[Length];
                    byte   bState = RawDataChar[2];

                    IsPW = bState % 2 > 0;
                    IsTP = bState % 4 > 2;

                    Array.Copy(RawDataChar, 3, Body_b, 0, Body_b.Length);
                    CC  = RawDataChar[RawDataChar.Length - 2];
                    AFN = RawDataChar[14];
                    byte   CCN = FormatHelper.GetXorByte(Body_b, 0, Body_b.Length);
                    string s   = "CCN = " + CCN + "  Length =  " + Length + " body_b .length is " + Body_b.Length;
                    //update by kqz 2017-10:40 解决文件下发问题
                    if ((AFN == (byte)BaseProtocol.AFN.ToDtuSendFile) || (CCN == CC))
                    {
                        ControlField = RawDataChar[3];
                        //if (ControlField == (byte)BaseProtocol.ControlField.FromDtu)
                        if (Enum.IsDefined(typeof(BaseProtocol.ControlField), (int)ControlField))
                        {
                            StationType = RawDataChar[11];
                            StationCode = Convert.ToInt32(HexStringUtility.ByteArrayToHexString(new byte[] { RawDataChar[12], RawDataChar[13] }), 16);
                            AFN         = RawDataChar[14];
                            if (Enum.IsDefined(typeof(BaseProtocol.AFN), (int)AFN))
                            {
                                byte[] AddressField_b = new byte[7];
                                Array.Copy(RawDataChar, 4, AddressField_b, 0, 7);
                                AddressField = HexStringUtility.ByteArrayToHexString(AddressField_b);

                                //用户数据长度为长度减控制域1字节减地址域7字节减应用层功能码1字节减设备类型1字节减射频地址2字节减密码减时间戳
                                UserDataBytes = new byte[Length - 1 - 7 - 1 - 1 - 2 - (IsTP ? 2 : 0) - (IsPW ? 5 : 0)];
                                Array.Copy(RawDataChar, 15, UserDataBytes, 0, UserDataBytes.Length);
                                UserData = HexStringUtility.ByteArrayToHexString(UserDataBytes);

                                try
                                {
                                    if (IsTP)
                                    {
                                        byte[] TPBytes = new byte[5];
                                        Array.Copy(RawDataChar, RawDataChar.Length - 2 - 5, TPBytes, 0, TPBytes.Length);
                                        TP = HexStringUtility.ByteArrayToHexString(TPBytes);
                                    }
                                    if (IsPW)
                                    {
                                        byte[] PWBytes = new byte[2];
                                        Array.Copy(RawDataChar, RawDataChar.Length - 2 - 2 - (IsTP ? 5 : 0), PWBytes, 0, PWBytes.Length);
                                        PW = HexStringUtility.ByteArrayToHexString(PWBytes);
                                    }
                                }
                                catch
                                {
                                    msg = "密码时间戳格式不正确,IsPW:" + (IsPW ? "yes" : "no") + ",IsTP:" + (IsTP ? "yes" : "no");
                                }
                            }
                            else
                            {
                                msg = "功能码不对," + AFN.ToString("X");
                            }
                        }
                        else
                        {
                            msg = "控制域不对," + ControlField.ToString("X");
                        }
                    }
                    else
                    {
                        msg = s + "   校验码不对," + CC;
                    }
                }
                else
                {
                    msg = "开始结束字符不对," + RawDataChar[0].ToString("X") + " " + RawDataChar[RawDataChar.Length - 1].ToString("X");
                }
            }
            else
            {
                msg = "长度不足14," + RawDataChar.Length;
            }

            return(msg);
        }
Example #20
0
 /// <summary>
 /// Makes a deep clone of this instance.
 /// </summary>
 /// <returns></returns>
 public override Field Clone()
 {
     Field clone = new ControlField(Tag, Data);
     return clone;
 }