コード例 #1
0
ファイル: EntityModel.cs プロジェクト: enjoycode/appbox.clr
        public override void ReadObject(BinSerializer bs)
        {
            base.ReadObject(bs);

            uint propIndex;

            do
            {
                propIndex = bs.ReadUInt32();
                switch (propIndex)
                {
                case 1:
                {
                    int count = bs.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        var m = (EntityMemberModel)bs.Deserialize();
                        Members.Add(m);
                    }
                }
                break;

                case 2: StoreOptions = (IEntityStoreOptions)bs.Deserialize(); break;

                case 3: _devMemberIdSeq = bs.ReadUInt16(); break;

                case 4: _usrMemberIdSeq = bs.ReadUInt16(); break;

                //case 6: _toStringExpression = (Expression)bs.Deserialize(); break;
                case 0: break;

                default: throw new Exception($"Deserialize_ObjectUnknownFieldIndex: {GetType().Name} at {propIndex} ");
                }
            } while (propIndex != 0);
        }
コード例 #2
0
        public override object Read(BinSerializer bs, object instance)
        {
            int         count = VariantHelper.ReadInt32(bs.Stream);
            IDictionary dic   = (IDictionary)instance;

            for (int i = 0; i < count; i++)
            {
                dic.Add(bs.Deserialize(), bs.Deserialize());
            }
            return(instance);
        }
コード例 #3
0
        public async Task ExportTest()
        {
            Store.SqlStore.SetDefaultSqlStore(new Store.PgSqlStore(StoreSettings));

            var appId   = 3250279307u; //env, sys=2660935927
            var appName = "env";

            var pkg = new AppPackage();
            await Store.ModelStore.LoadToAppPackage(appId, appName, pkg);

            //序列化
            using var wfs = File.OpenWrite($"{appName}.apk");
            var wbs = new BinSerializer(wfs);

            wbs.Serialize(pkg);
            wfs.Close();
            //反序列化
            using var rfs = File.OpenRead($"{appName}.apk");
            var rbs = new BinSerializer(rfs);
            var res = (AppPackage)rbs.Deserialize();

            foreach (var model in res.Models)
            {
                output.WriteLine($"{model.Name} {model.ModelType}");
            }
        }
コード例 #4
0
ファイル: WebSession.cs プロジェクト: enjoycode/appbox.clr
        public static WebSession LoadWebSession(this ISession session)
        {
            var data = session.Get(WebSession.UserSessionKey);

            if (data == null)
            {
                return(null);
            }

            ulong        id;
            Guid?        empID = null;
            TreeNodePath path;
            string       tag = null;

            using (var ms = new MemoryStream(data))
            {
                var bs = new BinSerializer(ms); //TODO:使用ThreadCache或参照RoutedSessionReader
                id   = bs.ReadUInt64();
                path = (TreeNodePath)bs.Deserialize();
                bool isExternal = bs.ReadBoolean();
                if (!isExternal)
                {
                    empID = bs.ReadGuid();
                }
                tag = bs.ReadString();
                bs.Clear();
            }

            return(new WebSession(id, path, empID, tag));
        }
コード例 #5
0
        public void ReadObject(BinSerializer bs)
        {
            uint propIndex;

            do
            {
                propIndex = bs.ReadUInt32();
                switch (propIndex)
                {
                case 1: Application = (ApplicationModel)bs.Deserialize(); break;

                case 2: Folders = bs.ReadList <ModelFolder>(); break;

                case 3: Models = bs.ReadList <ModelBase>(); break;

                case 4: SourceCodes = bs.ReadDictionary <ulong, byte[]>(); break;

                case 5: ServiceAssemblies = bs.ReadDictionary <string, byte[]>(); break;

                case 6: ViewAssemblies = bs.ReadDictionary <string, byte[]>(); break;

                case 7: DataStores = bs.ReadList <DataStoreInfo>(); break;

                case 0: break;

                default: throw new Exception($"Deserialize_ObjectUnknownFieldIndex: {GetType().Name} at {propIndex}");
                }
            } while (propIndex != 0);
        }
コード例 #6
0
        public void MultipleSerializationTest()
        {
            var input1 = new EnumTestType();

            input1.Field = EnumType.Three;

            var input2 = new GenericType <int, int>();

            input2.FieldOne = 5;
            input2.FieldTwo = 10;

            var stream = new MemoryStream();

            BinSerializer.Serialize(stream, input1);
            BinSerializer.Serialize(stream, input2);
            stream.Position = 0;

            var output1 = BinSerializer.Deserialize <EnumTestType>(stream);
            var output2 = BinSerializer.Deserialize <GenericType <int, int> >(stream);

            Assert.AreEqual(input1.Field, output1.Field);

            Assert.AreEqual(input2.FieldOne, output2.FieldOne);
            Assert.AreEqual(input2.FieldTwo, output2.FieldTwo);
        }
コード例 #7
0
        public virtual void ReadObject(BinSerializer bs)
        {
            uint propIndex;

            do
            {
                propIndex = bs.ReadUInt32();
                switch (propIndex)
                {
                case 1: Owner = (EntityModel)bs.Deserialize(); break;

                case 2: AllowNull = bs.ReadBoolean(); break;

                case 3: Name = bs.ReadString(); break;

                case 4: MemberId = bs.ReadUInt16(); break;

                case 5: _originalName = bs.ReadString(); break;

                case 6: PersistentState = (PersistentState)bs.ReadByte(); break;

                case 7: Comment = bs.ReadString(); break;

                case 0: break;

                default: throw new Exception($"Deserialize_ObjectUnknownFieldIndex: {GetType().Name}");
                }
            } while (propIndex != 0);
        }
コード例 #8
0
        public void SerializeTest()
        {
            var obj = "sys.HelloService.SayHello"; //TestHelper.SysEmploeeModel;

            byte[] data = null;
            using (var ms = new MemoryStream(1024))
            {
                BinSerializer cf = new BinSerializer(ms);
                try { cf.Serialize(obj); }
                catch (Exception) { throw; }
                finally { cf.Clear(); }

                ms.Close();
                data = ms.ToArray();
            }

            Console.WriteLine($"Data length: {data.Length}");
            Console.WriteLine(StringHelper.ToHexString(data));

            object result = null;

            using (var ms = new MemoryStream(data))
            {
                BinSerializer cf = new BinSerializer(ms);
                try { result = cf.Deserialize(); }
                catch (Exception) { throw; }
                finally { cf.Clear(); }
            }

            Console.WriteLine(result);
        }
コード例 #9
0
        void OnLoginReceived(OperationResponse response)
        {
            Debug.Log("[OnLoginReceived]");
            switch ((NextAction)response.ReturnCode)
            {
            case NextAction.LoginSuccess:
                byte[]             bytes = (byte[])DictionaryTool.GetValue <byte, object> (response.Parameters, 1);
                ProtoData.UserData data  = BinSerializer.Deserialize <ProtoData.UserData> (bytes);
                GameManager.Instance.Join(data.nickname, (Race)data.race);
                TransitionManager.Instance.OnSceneTransition(SceneName.GetMainLobby((Race)data.race), TransitionType.Loading01_Slide, null);
                break;

            case NextAction.LoginFailed:
                BasePage.OnMessageBox("로그인에 실패하셨습니다.", true, null, "확인");
                break;

            case NextAction.UserCreateFail:
                BasePage.OnMessageBox("ID길이가 잘못 되었습니다.\n(2글자 ~ 10글자)", true, null, "확인");
                break;

            case NextAction.UserInfoCreate:
                Action action = () =>
                {
                    LoginGameMode gameMode = GameManager.Instance.GameMode as LoginGameMode;
                    GameManager.Instance.GameMode.CurrentPage = gameMode.cutScenePage;
                };
                TransitionManager.Instance.OnTransition(TransitionType.Blank, TransitionType.Slide, action, null);
                break;
            }
        }
コード例 #10
0
        public void LongSerializeTest()
        {
            var l1 = 100L;
            var l2 = long.MinValue;
            var l3 = long.MaxValue;
            var l4 = long.MaxValue / 2;

            var stream = new MemoryStream();

            BinSerializer.Serialize(stream, (object)l1);
            BinSerializer.Serialize(stream, (object)l2);
            BinSerializer.Serialize(stream, (object)l3);
            BinSerializer.Serialize(stream, (object)l4);

            stream.Position = 0;

            var tl1 = (long)BinSerializer.Deserialize <object>(stream);
            var tl2 = (long)BinSerializer.Deserialize <object>(stream);
            var tl3 = (long)BinSerializer.Deserialize <object>(stream);
            var tl4 = (long)BinSerializer.Deserialize <object>(stream);

            Assert.AreEqual(l1, tl1);
            Assert.AreEqual(l2, tl2);
            Assert.AreEqual(l3, tl3);
            Assert.AreEqual(l4, tl4);
        }
コード例 #11
0
ファイル: ModelFolder.cs プロジェクト: enjoycode/appbox.clr
        public void ReadObject(BinSerializer cf)
        {
            uint propIndex;

            do
            {
                propIndex = cf.ReadUInt32();
                switch (propIndex)
                {
                case 1: Id = cf.ReadGuid(); break;

                case 2: Name = cf.ReadString(); break;

                case 3: Version = cf.ReadUInt32(); break;

                case 4: Parent = (ModelFolder)cf.Deserialize(); break;

                case 5: _childs = cf.ReadList <ModelFolder>(); break;

                case 6: AppId = cf.ReadUInt32(); break;

                case 7: TargetModelType = (ModelType)cf.ReadByte(); break;

                case 8: SortNum = cf.ReadInt32(); break;

                case 9: IsDeleted = cf.ReadBoolean(); break;

                case 0: break;

                default: throw new Exception($"Deserialize_ObjectUnknownFieldIndex: {GetType().Name}");
                }
            } while (propIndex != 0);
        }
コード例 #12
0
        private static T SerializeDeserialize <T>(T input)
        {
            var stream = new MemoryStream();

            BinSerializer.Serialize(stream, input);
            stream.Position = 0;
            return(BinSerializer.Deserialize <T>(stream));
        }
コード例 #13
0
ファイル: ObjectArray.cs プロジェクト: enjoycode/appbox.clr
        void IBinSerializable.ReadObject(BinSerializer reader)
        {
            var count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                this.Add(reader.Deserialize());
            }
        }
コード例 #14
0
        private static void TestBin(ref Test test)
        {
            MemoryStream stream = new MemoryStream();

            for (int i = 0; i < Count; i++)
            {
                BinSerializer.Serialize(stream, test);
                stream.Position = 0;
                test            = BinSerializer.Deserialize <Test>(stream);
            }
        }
コード例 #15
0
        public void ReadObject(BinSerializer bs)
        {
            uint propIndex;

            do
            {
                propIndex = bs.ReadUInt32();
                switch (propIndex)
                {
                case 1: _storeType = (EntityStoreType)bs.ReadByte(); break;

                case 2: OrderByDesc = bs.ReadBoolean(); break;

                case 3: SchemaVersion = bs.ReadUInt32(); break;

                case 4:
                {
                    int count = bs.ReadInt32();
                    for (int i = 0; i < count; i++)
                    {
                        var idx = (EntityIndexModel)bs.Deserialize();
                        Indexes.Add(idx);
                    }
                }
                break;

                case 5:
                {
                    int count = bs.ReadInt32();
                    PartitionKeys = new PartitionKey[count];
                    for (int i = 0; i < count; i++)
                    {
                        PartitionKeys[i].MemberId     = bs.ReadUInt16();
                        PartitionKeys[i].OrderByDesc  = bs.ReadBoolean();
                        PartitionKeys[i].Rule         = (PartitionKeyRule)bs.ReadByte();
                        PartitionKeys[i].RuleArgument = bs.ReadInt32();
                    }
                }
                break;

                case 6: _devIndexIdSeq = bs.ReadByte(); break;

                case 7: _usrIndexIdSeq = bs.ReadByte(); break;

                case 8: _oldSchemaVersion = bs.ReadUInt32(); break;

                case 0: break;

                default: throw new Exception($"Deserialize_ObjectUnknownFieldIndex: {GetType().Name} at {propIndex} ");
                }
            } while (propIndex != 0);
        }
コード例 #16
0
ファイル: SqlModelStore.cs プロジェクト: enjoycode/appbox.clr
        internal static object DeserializeModel(byte[] data)
        {
            object result = null;

            using var ms = new MemoryStream(data);
            BinSerializer cf = new BinSerializer(ms);

            try { result = cf.Deserialize(); }
            catch (Exception) { throw; }
            finally { cf.Clear(); }

            return(result);
        }
コード例 #17
0
        void OnUserResistrationReceived(OperationResponse response)
        {
            Debug.Log("[OnUserResistrationReceived]");
            ReturnCode rc = (ReturnCode)response.ReturnCode;

            if (rc == ReturnCode.Success)
            {
                byte[]             bytes = (byte[])DictionaryTool.GetValue <byte, object> (response.Parameters, 1);
                ProtoData.UserData data  = BinSerializer.Deserialize <ProtoData.UserData> (bytes);
                GameManager.Instance.Join(data.nickname, (Race)data.race);
                TransitionManager.Instance.OnSceneTransition(SceneName.GetMainLobby(GameManager.Instance.LocalPlayer.playerInfo.Race), TransitionType.Loading01_Slide, null);
            }
            else
            {
                BasePage.OnMessageBox("닉네임의 길이가 잘못 되었습니다.\n(3글자 ~ 6글자)", true, null, "확인");
            }
        }
コード例 #18
0
ファイル: StagedService.cs プロジェクト: enjoycode/appbox.clr
        internal StagedItems(IList <Entity> staged)
        {
            if (staged != null && staged.Count > 0)
            {
                Items = new object[staged.Count];
                StagedType type;
                for (int i = 0; i < staged.Count; i++)
                {
                    var data = staged[i].GetBytes(Consts.STAGED_DATA_ID);

                    type = (StagedType)staged[i].GetByte(Consts.STAGED_TYPE_ID);
                    switch (type)
                    {
                    case StagedType.Model:
                    case StagedType.Folder:
                        Items[i] = BinSerializer.Deserialize(data, null);
                        break;

                    case StagedType.SourceCode:
                    {
                        ulong modelId = ulong.Parse(staged[i].GetString(Consts.STAGED_MODELID_ID));         //TODO:fix
                        Items[i] = new StagedSourceCode {
                            ModelId = modelId, CodeData = data
                        };
                    }
                    break;

                    case StagedType.ViewRuntimeCode:
                    {
                        ulong modelId = ulong.Parse(staged[i].GetString(Consts.STAGED_MODELID_ID));         //TODO:fix
                        Items[i] = new StagedViewRuntimeCode {
                            ModelId = modelId, CodeData = data
                        };
                    }
                    break;

                    default:
                        throw ExceptionHelper.NotImplemented();
                    }
                }
            }
        }
コード例 #19
0
        public async Task <IActionResult> Import()
        {
            if (Request.Form.Files.Count != 1)
            {
                return(BadRequest("Please upload one apk file"));
            }

            //设置当前用户会话
            RuntimeContext.Current.CurrentSession = HttpContext.Session.LoadWebSession();
            //TODO:结合前端修改上传方式
            var formFile = Request.Form.Files[0];

            using var ss = formFile.OpenReadStream();
            //反序列化
            var bs     = new BinSerializer(ss);
            var appPkg = (Design.AppPackage)bs.Deserialize();
            await Design.AppStoreService.Import(appPkg);

            return(Ok());
        }
コード例 #20
0
        public override void ReadObject(BinSerializer reader)
        {
            base.ReadObject(reader);

            uint propIndex;

            do
            {
                propIndex = reader.ReadUInt32();
                switch (propIndex)
                {
                case 1: Name = reader.ReadString(); break;

                case 2: Owner = (EntityExpression)reader.Deserialize(); break;

                case 0: break;

                default: throw new Exception("Deserialize_ObjectUnknownFieldIndex: " + GetType().Name);
                }
            } while (propIndex != 0);
        }
コード例 #21
0
        public override void ReadObject(BinSerializer cf)
        {
            base.ReadObject(cf);

            uint propIndex;

            do
            {
                propIndex = cf.ReadUInt32();
                switch (propIndex)
                {
                case 1: cf.ReadBoolean(); break;     //todo: 待全部转换完后移除

                case 2: ModelID = cf.ReadUInt64(); break;

                case 3: _user = cf.Deserialize(); break;

                case 0: break;

                default: throw new Exception("Deserialize_ObjectUnknownFieldIndex: " + GetType().Name);
                }
            } while (propIndex != 0);
        }
コード例 #22
0
        internal static unsafe object DeserializeModel(IntPtr dataPtr, int dataSize, int offset = 0)
        {
            byte *dp = (byte *)dataPtr.ToPointer();

            object        result = null;
            var           stream = new UnmanagedMemoryStream(dp + offset, dataSize - offset);
            BinSerializer cf     = new BinSerializer(stream);

            try { result = cf.Deserialize(); }
            catch (Exception) { throw; }
            finally { cf.Clear(); }

            stream.Close();

            if (result != null && result is ApplicationModel && offset == APP_DATA_OFFSET)
            {
                var app = (ApplicationModel)result;
                app.StoreId = dp[0];
                uint *devIdCounterPtr = (uint *)(dp + 1);
                //uint* usrIdCounterPtr = (uint*)(dp + 5);
                app.DevModelIdSeq = *devIdCounterPtr;
            }
            return(result);
        }
コード例 #23
0
        public virtual void ReadObject(BinSerializer bs)
        {
            uint propIndex;

            do
            {
                propIndex = bs.ReadUInt32();
                switch (propIndex)
                {
                case 1: Owner = (EntityModel)bs.Deserialize(); break;

                case 2: IndexId = bs.ReadByte(); break;

                case 3: Name = bs.ReadString(); break;

                case 4: Unique = bs.ReadBoolean(); break;

                case 6:
                    int count = bs.ReadInt32();
                    Fields = new FieldWithOrder[count];
                    for (int i = 0; i < count; i++)
                    {
                        Fields[i].ReadObject(bs);
                    }
                    break;

                case 7: StoringFields = bs.ReadUInt16Array(); break;

                case 9: PersistentState = (PersistentState)bs.ReadByte(); break;

                case 0: break;

                default: throw new Exception(string.Format("Deserialize_ObjectUnknownFieldIndex: {0} at {1} ", GetType().Name, propIndex));
                }
            } while (propIndex != 0);
        }
コード例 #24
0
 public static T Deserialize <T>(Stream stream)
 {
     return(BinSerializer.Deserialize <T>(stream));
 }
コード例 #25
0
 public override void ReadObject(BinSerializer bs)
 {
     LeftOperand  = (Expression)bs.Deserialize();
     BinaryType   = (BinaryOperatorType)bs.ReadByte();
     RightOperand = (Expression)bs.Deserialize();
 }
コード例 #26
0
 public static T Deserialize <T>(byte[] message)
 {
     using (MemoryStream stream = new MemoryStream(message))
         return(BinSerializer.Deserialize <T>(stream));
 }
コード例 #27
0
 public static ManualGenericType <T1, T2> ReadManualGeneric <T1, T2>(Stream stream, ManualGenericType <T1, T2> instance, int version)
 {
     instance.FieldOne = BinSerializer.Deserialize <T1>(stream);
     instance.FieldTwo = BinSerializer.Deserialize <T2>(stream);
     return(instance);
 }
コード例 #28
0
ファイル: EntityMember.cs プロジェクト: wangyougui/appbox.clr
        internal void Read(BinSerializer bs)
        {
            Id         = bs.ReadUInt16();
            MemberType = (EntityMemberType)bs.ReadByte();
            ValueType  = (EntityFieldType)bs.ReadByte();
            Flag.Data  = bs.ReadByte();

            switch (MemberType)
            {
            case EntityMemberType.DataField:
                switch (ValueType)
                {
                case EntityFieldType.Boolean: BooleanValue = bs.ReadBoolean(); break;

                case EntityFieldType.Byte: ByteValue = bs.ReadByte(); break;

                case EntityFieldType.Float: FloatValue = bs.ReadFloat(); break;

                case EntityFieldType.Double: DoubleValue = bs.ReadDouble(); break;

                case EntityFieldType.Enum: Int32Value = bs.ReadInt32(); break;

                case EntityFieldType.Int16: Int16Value = bs.ReadInt16(); break;

                case EntityFieldType.UInt16: UInt16Value = bs.ReadUInt16(); break;

                case EntityFieldType.Int32: Int32Value = bs.ReadInt32(); break;

                case EntityFieldType.UInt32: UInt32Value = bs.ReadUInt32(); break;

                case EntityFieldType.Int64: Int64Value = bs.ReadInt64(); break;

                case EntityFieldType.UInt64: UInt64Value = bs.ReadUInt64(); break;

                case EntityFieldType.DateTime: DateTimeValue = bs.ReadDateTime(); break;

                case EntityFieldType.Guid: GuidValue = bs.ReadGuid(); break;

                case EntityFieldType.Decimal: DecimalValue = bs.ReadDecimal(); break;

                case EntityFieldType.String: ObjectValue = bs.ReadString(); break;

                case EntityFieldType.Binary: ObjectValue = bs.ReadByteArray(); break;

                default: throw new NotSupportedException();
                }
                break;

            case EntityMemberType.EntityRef:
            case EntityMemberType.EntitySet: ObjectValue = bs.Deserialize(); break;

            //case EntityMemberType.ImageRef: this.ObjectValue = bs.Deserialize(); break;
            //case EntityMemberType.FieldSet:
            //switch (this.ValueType)
            //{
            //    case EntityFieldType.String:
            //        {
            //            var array = bs.ReadStringArray();
            //            this.ObjectValue = array == null ? null : new HashSet<string>(array);
            //        }
            //        break;
            //    case EntityFieldType.Integer:
            //        {
            //            var array = bs.ReadInt32Array();
            //            this.ObjectValue = array == null ? null : new HashSet<int>(array);
            //        }
            //        break;
            //    case EntityFieldType.Guid:
            //        {
            //            var array = bs.ReadGuidArray();
            //            this.ObjectValue = array == null ? null : new HashSet<Guid>(array);
            //        }
            //        break;
            //    case EntityFieldType.Float:
            //        {
            //            var array = bs.ReadFloatArray();
            //            this.ObjectValue = array == null ? null : new HashSet<float>(array);
            //        }
            //        break;
            //    case EntityFieldType.Double:
            //        {
            //            var array = bs.ReadDoubleArray();
            //            this.ObjectValue = array == null ? null : new HashSet<double>(array);
            //        }
            //        break;
            //    case EntityFieldType.Decimal:
            //        {
            //            var array = bs.ReadDecimalArray();
            //            this.ObjectValue = array == null ? null : new HashSet<Decimal>(array);
            //        }
            //        break;
            //    case EntityFieldType.DateTime:
            //        {
            //            var array = bs.ReadDateTimeArray();
            //            this.ObjectValue = array == null ? null : new HashSet<DateTime>(array);
            //        }
            //        break;
            //    case EntityFieldType.Byte:
            //        {
            //            var array = bs.ReadByteArray();
            //            this.ObjectValue = array == null ? null : new HashSet<byte>(array);
            //        }
            //        break;
            //    default: throw new NotSupportedException($"不支持二进制反序列化FieldSet: {ValueType}");
            //}
            //break;
            default:
                GuidValue   = bs.ReadGuid();
                ObjectValue = bs.Deserialize();
                break;
            }
        }
コード例 #29
0
 public TestData BinSerializer_Deserialize()
 {
     _serializedStreamBin.Position = 0;
     return(BinSerializer.Deserialize <TestData>(_serializedStreamBin));
 }
コード例 #30
0
 public override void ReadObject(BinSerializer bs)
 {
     Expression = (Expression)bs.Deserialize();
     AliasName  = bs.ReadString();
     Owner      = (ISqlSelectQuery)bs.Deserialize();
 }