コード例 #1
0
        private bool ApplySyncData(string data, long timestamp)
        {
            var regex = new Regex("^[01][0-9A-Z=]+$", RegexOptions.Compiled);
            var table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ=";

            var length = data.Length;
            var pos    = 0;

            var list = new List <SyncData>();

            while (pos < length)
            {
                var size = table.IndexOf(data[pos++]);
                var q    = data.Substring(pos, size);

                if (size < 4)
                {
                    return(false);
                }
                if (q.Length != size)
                {
                    return(false);
                }
                if (!regex.IsMatch(q))
                {
                    return(false);
                }

                int[] tmp = null;
                var   id  = SyncData.Decode(q.Substring(1, 2));
                if (id == 215)                 // 로호
                {
                    tmp = new int[] { 0 };
                }

                list.Add(new SyncData
                {
                    Active = SyncData.Decode(q[0].ToString()) > 0,
                    Id     = id,
                    Count  = SyncData.DecodeList(q.Substring(3), tmp)
                });
            }

            foreach (var item in list)
            {
                var tracker = this.trackingAvailable.FirstOrDefault(x => x.Id == item.Id);
                if (tracker == null)
                {
                    continue;
                }

                tracker.LastUpdated = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timestamp).ToLocalTime();
                tracker.IsTracking  = item.Active;                // Needed?
                tracker.SetRawDatas(item.Count);
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Decode counter list
        /// </summary>
        /// <param name="input">Encoded counter data</param>
        /// <param name="ExtIndexes">Equal or Over 36 index list</param>
        /// <returns></returns>
        public static int[] DecodeList(string input, int[] ExtIndexes = null)
        {
            var _length = input.Length;
            var _output = new List <int>();
            var _idx    = 0;

            for (var i = 0; i < _length; i++)
            {
                if (EncodingTable.IndexOf(input[i]) < 0)
                {
                    return(null);
                }
                if (ExtIndexes != null && ExtIndexes.Contains(_idx++))
                {
                    _output.Add(SyncData.Decode(input.Substring(i++, 2)));
                }
                else
                {
                    _output.Add(SyncData.Decode(input.Substring(i, 1)));
                }
            }
            return(_output.ToArray());
        }