public void Deserialize(SerializationToken serializationToken, IGenericSerialierToken serializerToken,
                                DeserializeResult deserializeResult)
        {
            string token = (string)serializerToken.Deserialize((SerializationToken)serializationToken.Data).Result;

            deserializeResult.Result = _fortScriptableObject.Tokens[token];
        }
示例#2
0
        /// <summary>
        /// Получить заголовок пакета данных
        /// </summary>
        /// <param name="data">Входящие данные</param>
        /// <param name="userID">Ключ пользователя</param>
        /// <param name="synchDate">Дата синхронизации</param>
        /// <returns></returns>
        public bool TryGetHeaderData(byte[] data, out uint userID, out DateTime synchDate)
        {
            var serializerProvider = GetSerializeProvider();

            DeserializeResult output = null;

            foreach (var formatFrovider in _formatProviders)
            {
                if (formatFrovider.TryDecodeData(GetRSA, data, out output))
                {
                    break;
                }
            }

            var result = output != null;

            if (result)
            {
                userID    = output.UserID;
                synchDate = output.SynchDate;
            }
            else
            {
                userID    = default(uint);
                synchDate = default(DateTime);
            }

            return(result);
        }
示例#3
0
        /// <summary>Декодировать сообщение в читаемый вид</summary>
        /// <param name="mass">Шифрованное сообщение</param>
        /// <param name="Tables">Таблицы</param>
        /// <param name="UserID">Полученный идентификатор пользователя</param>
        /// <param name="SynchDT">Полученная дата создания синхронизации</param>
        /// <returns></returns>
        public unsafe string GetValues(uint ForceUserID, byte[] mass, out DeserializeResult Tables, out bool SPoolExisted, bool CheckSPoolExist = false)
        {
            SPoolExisted = false;

            if (mass == null)
            {
                Tables = null;
                return("Сообщение не найдено");
            }
            else
            {
                var serializerProvider = GetSerializeProvider();

                DeserializeResult result = null;

                foreach (var formatFrovider in _formatProviders)
                {
                    if (formatFrovider.TryDecodeData(GetRSA, mass, out result))
                    {
                        break;
                    }
                }

                if (result == null)
                {
                    CheckSPoolExist = false;
                    Tables          = null;
                    return("Не удалось декодировать сообщение");
                }

                Tables = result;

                uint SPoolID = 0;
                if (CheckSPoolExist)
                {
                    //такой пул уже существует, загрузка не требуется
                    SPoolExisted = (bool)_sPool.QUERRY().EXIST.WHERE.C(C.SPool.SUser, Tables.UserID).AND.C(C.SPool.Date, Tables.SynchDate).DO()[0].Value;

                    if (!SPoolExisted)
                    {
                        _sPool.QUERRY()
                        .ADD
                        .C(C.SPool.AUser, Tables.UserID)
                        .C(C.SPool.SUser, Tables.UserID)
                        .C(C.SPool.Local, false)
                        .C(C.SPool.Date, Tables.SynchDate)
                        .DO();
                        SPoolID = _sPool.Rows.GetID(_sPool.Rows.Count - 1);
                    }
                }

                return(null);
            }
        }
示例#4
0
        public Tables_Form(DeserializeResult Tables)
        {
            this.Tables = Tables;
            InitializeComponent();

            var SPoolID = (uint)G.SPool.QUERRY().GET.ID().WHERE.C(C.SPool.Date, Tables.SynchDate).DO()[0].Value;

            Descryption_label.Text = SPoolID.ToString() + " - " + Tables.SynchDate.ToString() + ' ' + T.User.Rows.Get <string>(Tables.UserID, C.User.Login);

            this.Tables_Grid.Columns.Add("Таблица", "Таблица");

            this.Tables_Grid.VirtualMode = true;
            this.Tables_Grid.RowCount    = Tables.Tables.Count();
        }
示例#5
0
        private async void Update()
        {
            string jsonString = ClipboardManager.TryGetText();
            bool   possible   = !string.IsNullOrWhiteSpace(jsonString) && this.MainWindow.Raw_TextBox.Text != jsonString;

            if (possible)
            {
                DeserializeResult deserializeResult = await JsonObjectFactory.TryAgressiveDeserialize(jsonString);

                this.SetCanExecute(deserializeResult.IsSuccessful());
            }
            else
            {
                this.SetCanExecute(false);
            }
        }
示例#6
0
        public bool TryDecodeData(GetRsaDelegate getRSA, byte[] bytes, out DeserializeResult deserializeResult)
        {
            var result = false;

            deserializeResult = null;

            var decodedBytes = _cryption.Decode(bytes, getRSA);

            if (decodedBytes != null && _formatChecker.Check(decodedBytes))
            {
                deserializeResult = _serializeProvider.Deserialize(decodedBytes);
                result            = true;
            }

            return(result);
        }
示例#7
0
        /// <summary>
        /// Convert xml files to binary
        /// </summary>
        /// <param name="logFile">File to be converted</param>
        /// <param name="newLogFile">New file name</param>
        /// <param name="resultPort">DSS result port</param>
        /// <returns>ITask enumerator</returns>
        private IEnumerator <ITask> ConvertXmlLogToBinary(string logFile, string newLogFile, Port <LogFileResult> resultPort)
        {
            var envelopes = new List <Envelope>(DefaultInitialEnvelopeCapacity);

            using (var fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.None, 1))
            {
                if (fs.Length != 0)
                {
                    using (var newFs = new FileStream(newLogFile, FileMode.Create, FileAccess.Write, FileShare.None, 1))
                    {
                        using (var bw = new BinaryWriter(newFs))
                        {
                            var reader = XmlReader.Create(fs);
                            while (ReadToNextEnvelopeNode(reader))
                            {
                                var deserHeader = new Deserialize(reader);
                                SerializerPort.Post(deserHeader);

                                DeserializeResult headerDeserResult = null;
                                yield return(Arbiter.Choice(
                                                 deserHeader.ResultPort,
                                                 w3cHeader => headerDeserResult = w3cHeader,
                                                 failure => LogError(failure)));

                                if (headerDeserResult != null && ReadToNextBodyNode(reader))
                                {
                                    var deserBody = new Deserialize(reader);
                                    SerializerPort.Post(deserBody);

                                    DeserializeResult bodyDeserResult = null;

                                    yield return(Arbiter.Choice(
                                                     deserBody.ResultPort,
                                                     bodyContents => bodyDeserResult = bodyContents,
                                                     failure => LogError(failure)));

                                    if (bodyDeserResult != null)
                                    {
                                        this.SerializeToBinary(headerDeserResult, bodyDeserResult, bw);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#8
0
        private void CheckTables(IEnumerable <DataBase.ISTable> sTables, DeserializeResult deserializeResult)
        {
            Assert.AreEqual(sTables.Count(), deserializeResult.Tables.Count());

            var compares = Enumerable.Zip(deserializeResult.Tables, sTables, (x1, x2) => new { DTable = x1, STable = x2 });

            foreach (var compare in compares)
            {
                var rows = compare.DTable.Rows.ToArray();

                for (int i = 0; i < compare.STable.Rows.Count; i++)
                {
                    for (int j = 0; j < compare.STable.Parent.Columns.Count - 1; j++)
                    {
                        var column = compare.STable.Parent.GetColumn(j);

                        if (!column.Protect)
                        {
                            var row = compare.STable.Rows.Get_Row(i);

                            var rowValue   = rows[i].Values[j];
                            var tableValue = compare.STable.Parent.Rows.GetObject_UnShow(row.ID, j);

                            if (rowValue != null && rowValue.GetType() == typeof(RIU32))
                            {
                                rowValue = (uint)(RIU32)rowValue;
                            }

                            try
                            {
                                Assert.AreEqual(rowValue, tableValue);
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                }
            }
        }
示例#9
0
        /// <summary>
        /// Serailizer to binary format
        /// </summary>
        /// <param name="headerDeserResult">Result of deserialization of header</param>
        /// <param name="bodyDeserResult">Result of deserialization of body</param>
        /// <param name="bw">Binary writer</param>
        private void SerializeToBinary(DeserializeResult headerDeserResult, DeserializeResult bodyDeserResult, BinaryWriter bw)
        {
            MemoryStream ms     = null;
            BinaryWriter tempBw = null;

            try
            {
                ms = new MemoryStream();
                bw = new BinaryWriter(ms);

                var originalHeader = headerDeserResult.Instance as W3C.Soap.Header;

                var forwarderEnvelope = new ForwarderEnvelope();
                forwarderEnvelope.Action    = HeaderParser.ParseAction(originalHeader.Any);
                forwarderEnvelope.MessageId = HeaderParser.ParseMessageId(originalHeader.Any);
                forwarderEnvelope.TimeStamp = HeaderParser.ParseTimeStamp(originalHeader.Any);
                forwarderEnvelope.To        = HeaderParser.ParseTo(originalHeader.Any);
                forwarderEnvelope.From      = HeaderParser.ParseFrom(originalHeader.Any);

                forwarderEnvelope.Body = bodyDeserResult.Instance;

                forwarderEnvelope.Serialize(tempBw);

                bw.Write(BitConverter.GetBytes(ms.Position), 0, sizeof(long));
                forwarderEnvelope.Serialize(bw);
            }
            finally
            {
                if (tempBw != null)
                {
                    tempBw.Dispose();
                }

                if (ms != null)
                {
                    ms.Dispose();
                }
            }
        }
示例#10
0
 public LoadSPool(DeserializeResult Tables, Func <DataBase.ISTable, uint, DataBase.State, object[], bool> saveToDBFunc) :
     base(false)
 {
     this.Tables   = Tables;
     _saveToDBFunc = saveToDBFunc;
 }
 public bool Deserialize()
 {
     if (this._data == null)
     {
         this._result = DeserializeResult.NoData;
         return(false);
     }
     if (this._result == DeserializeResult.Success)
     {
         return(true);
     }
     try
     {
         this._data.position = (int)this._offset;
         ushort num1 = this._data.ReadUShort();
         for (int index = 0; index < (int)num1; ++index)
         {
             string      str         = this._data.ReadString();
             ClassMember classMember = (ClassMember)null;
             System.Type key         = (System.Type)null;
             if (str.StartsWith("@"))
             {
                 if (this._extraProperties == null)
                 {
                     this._extraProperties = new MultiMap <string, object>();
                 }
                 byte num2 = this._data.ReadByte();
                 if (((int)num2 & 1) != 0)
                 {
                     byte num3 = (byte)((uint)num2 >> 1);
                     BinaryClassMember.typeMap.TryGetKey(num3, out key);
                 }
                 else
                 {
                     key = Editor.GetType(this._data.ReadString());
                 }
                 str = str.Substring(1, str.Length - 1);
             }
             else
             {
                 classMember = Editor.GetMember(this.GetType(), str);
                 if (classMember != null)
                 {
                     key = classMember.type;
                 }
             }
             uint num4 = this._data.ReadUInt();
             if (key != (System.Type)null)
             {
                 int position = this._data.position;
                 if (typeof(BinaryClassChunk).IsAssignableFrom(key))
                 {
                     BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(key, this._data, root: false);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)binaryClassChunk);
                     }
                     else
                     {
                         this._headerDictionary[str] = binaryClassChunk;
                     }
                     this._data.position = position + (int)num4;
                 }
                 else if (key.IsArray)
                 {
                     Array array = this.DeserializeArray(key, key.GetElementType(), this._data);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)array);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)array);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(List <>))
                 {
                     Array array    = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance = Activator.CreateInstance(key) as IList;
                     foreach (object obj in array)
                     {
                         instance.Add(obj);
                     }
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)instance);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)instance);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(HashSet <>))
                 {
                     Array array     = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance1 = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(key.GetGenericArguments()[0]));
                     foreach (object obj in array)
                     {
                         instance1.Add(obj);
                     }
                     object instance2 = Activator.CreateInstance(key, (object)instance1);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, instance2);
                     }
                     else
                     {
                         classMember.SetValue((object)this, instance2);
                     }
                 }
                 else
                 {
                     object element = !key.IsEnum ? this._data.Read(key, false) : (object)this._data.ReadInt();
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, element);
                     }
                     else
                     {
                         classMember.SetValue((object)this, element);
                     }
                 }
             }
             else
             {
                 this._data.position += (int)num4;
             }
         }
     }
     catch (Exception ex)
     {
         this._exception = ex;
         this._result    = DeserializeResult.ExceptionThrown;
         return(false);
     }
     this._result = DeserializeResult.Success;
     return(true);
 }
示例#12
0
 public static bool IsSuccessful(this DeserializeResult deserializeResult)
 {
     return(deserializeResult?.Dictionary != null);
 }