Пример #1
0
 public CartTV8K(DeserializationContext input, MachineBase m) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadExpectedBytes(0x1000), 0x1000);
     BankBaseAddr = input.ReadUInt16();
     LastBankBaseAddr = input.ReadUInt16();
 }
 public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
 {
     return new ModifyWorkItemStateMorphAction(
         element.GetAttribute("typename"),
         element.GetAttribute("fromvalue"),
         element.GetAttribute("tovalue"));
 }
 public static ModifyWorkItemTypeDefinitionSubAction Deserialize(XmlElement element, DeserializationContext context)
 {
     var cdata = element.ChildNodes.OfType<XmlCDataSection>().Single();
     var doc = new XmlDocument();
     doc.LoadXml(cdata.Value);
     var field = new WitdField(doc.DocumentElement);
     return new AddFieldModifyWorkItemTypeDefinitionSubAction(field);
 }
 public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
 {
     var cdata = element.ChildNodes.OfType<XmlCDataSection>().Single();
     var doc = new XmlDocument();
     doc.LoadXml(cdata.Value);
     var typeDef = new WorkItemTypeDefinition(doc);
     return new ImportWorkItemTypeDefinitionMorphAction(typeDef);
 }
Пример #5
0
 public Cart78AB(DeserializationContext input, MachineBase m) : base(input)
 {
     var version = input.CheckVersion(1, 2);
     LoadRom(input.ReadBytes());
     Bank = input.ReadIntegers(4);
     if (version == 1)
         input.ReadInt32();
 }
 public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
 {
     return new CopyWorkItemDataMorphAction(
         element.GetAttribute("typename"),
         element.GetAttribute("fromfieldrefname"),
         element.GetAttribute("tofieldrefname")
         );
 }
        public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
        {
            var action = new ExportWorkItemDataMorphAction(element.GetAttribute("typename"), Convert.ToBoolean(element.GetAttribute("allfields")));

            foreach (var fieldElement in element.ChildNodes.OfType<XmlElement>().Where(e => e.Name == "field"))
            {
                action.AddExportField(fieldElement.GetAttribute("refname"));
            }

            return action;
        }
Пример #8
0
        static void Deserialize(ref DeserializationContext context, out TracebackFrame output)
        {
            var br = new BinaryReader(context.Stream, Encoding.UTF8);

            output = new TracebackFrame();

            output.Offset = br.ReadUInt32();
            if (br.ReadBoolean())
                output.Offset2 = br.ReadUInt32();

            output.Module = ReadString(br);
            output.Function = ReadString(br);
            output.SourceFile = ReadString(br);

            if (br.ReadBoolean())
                output.SourceLine = br.ReadInt32();
        }
Пример #9
0
        public Machine2600(DeserializationContext input, int[] palette) : base(input, palette)
        {
            input.CheckVersion(1);

            Mem = input.ReadAddressSpace(this, 13, 6);  // 2600: 13bit, 64byte pages

            CPU = input.ReadM6502(this, 1);

            TIA = input.ReadTIA(this);
            for (ushort i = 0; i < 0x1000; i += 0x100)
            {
                Mem.Map(i, 0x0080, TIA);
            }

            PIA = input.ReadPIA(this);
            for (ushort i = 0x0080; i < 0x1000; i += 0x100)
            {
                Mem.Map(i, 0x0080, PIA);
            }

            Cart = input.ReadCart(this);
            Mem.Map(0x1000, 0x1000, Cart);
        }
Пример #10
0
        public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
        {
            var serializationId = element.GetAttribute("id");

            var typeName = element.Name;
            var qualifiedTypeName = string.Format("{0}.{1}", typeof(MorphAction).Namespace, typeName);
            var actionType = MorphActionAssembly.GetType(qualifiedTypeName, throwOnError: false, ignoreCase: true);
            if (actionType == null)
            {
                throw new InvalidOperationException(string.Format("Cannot find type '{0}' in assembly '{1}'.", qualifiedTypeName, MorphActionAssembly));
            }
            var deserializeMethod = GetDeserializeMethod(actionType);
            var action = (MorphAction)deserializeMethod.Invoke(null, new object[] { element, context });

            foreach ( var linkElement in element.ChildNodes.OfType<XmlElement>().Where(e => e.Name == "linkedaction"))
            {
                var targetid = linkElement.GetAttribute("target");
                var linkType = (ActionLinkType)Enum.Parse(typeof(ActionLinkType), linkElement.GetAttribute("type"), ignoreCase: true);
                action.LinkedActions.Add(new ActionLink(context.GetLinkableAction(targetid), linkType));
            }

            context.RegisterLinkableAction(serializationId, action);
            return action;
        }
 public static ModifyWorkItemTypeDefinitionSubAction Deserialize(XmlElement element, DeserializationContext context)
 {
     return new AddTransitionModifyWorkItemTypeDefinitionSubAction(
         element.GetAttribute("fromstate"),
         element.GetAttribute("tostate"),
         element.GetAttribute("defaultreason")
         );
 }
Пример #12
0
 public Cart7832P(DeserializationContext input, MachineBase m) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadExpectedBytes(0x8000), 0x8000);
     _pokeySound = input.ReadOptionalPokeySound(m);
 }
Пример #13
0
 /// <nodoc />
 public UnaryExpression(DeserializationContext context, LineInfo location)
     : base(location)
 {
     OperatorKind = (UnaryOperator)context.Reader.ReadByte();
     Expression   = ReadExpression(context);
 }
Пример #14
0
 // All integer types allow conversion from double as well.
 protected override object DeserializeDouble(DeserializationContext context, double value) =>
 DeserializeInteger(context, checked ((long)value));
Пример #15
0
        public static void Load(IDockControl dockControl, XElement storedLayout /*, bool keepDockTabItems */)
        {
            ///// <param name="keepDockTabItems">
            ///// If set to <see langword="true"/> all existing <see cref="IDockTabItem"/>s are kept. If
            ///// set to <see langword="false"/>, all current <see cref="IDockTabItem"/>s are closed
            ///// before the new layout is loaded.
            ///// </param>

            if (dockControl == null)
            {
                throw new ArgumentNullException(nameof(dockControl));
            }
            if (storedLayout == null)
            {
                throw new ArgumentNullException(nameof(storedLayout));
            }

            var dockStrategy = dockControl.DockStrategy;

            if (dockStrategy == null)
            {
                throw new ArgumentException("The IDockControl does not have a DockStrategy.");
            }

            const bool keepNonPersistentItems = true;  // Non-persistent items are usually documents and should be kept.
            const bool keepPersistentItems    = false; // Persistent items are usually tool windows.

            // Remember current dock items (visible and hidden items).
            var items = dockControl.GetDockElements()
                        .OfType <IDockTabItem>()
                        .Distinct()
                        .ToArray();

            // Validate DockIds.
            foreach (var item in items)
            {
                if (item.DockId == null)
                {
                    throw new DockException("Could not load docking layout. IDockTabItem does not have a valid DockId.");
                }
            }

            // Check for duplicate DockIds.
            bool duplicateDockIds = items.GroupBy(item => item.DockId)
                                    .Select(group => group.Count())
                                    .Any(count => count > 1);

            if (duplicateDockIds)
            {
                throw new DockException("Could not load docking layout. Two or more IDockTabItems have the same DockId.");
            }

            var context = new DeserializationContext {
                DockControl = dockControl
            };

            dockStrategy.Begin();
            try
            {
                // Remember current IDockTabItems.
                // context.OldItems stores all (because OldItems is used in LoadDockTabItem).
                // Another list stores only the old items which are visible.
                var oldVisibleItems = new List <IDockTabItem>();
                foreach (var item in items)
                {
                    context.OldItems[item.DockId] = item;

                    if (item.DockState != DockState.Hide)
                    {
                        oldVisibleItems.Add(item);
                    }
                }

                // Load IDockTabItems. Do not add to the dock control yet.
                foreach (var itemXElement in storedLayout.Elements("DockTabItems").Elements())
                {
                    var item = LoadDockTabItem(context, itemXElement, onlyReference: false);
                    if (item != null)
                    {
                        context.NewItems[item.DockId] = item;
                    }
                }

                // Try to close all IDockTabItems which we will not keep or which will be hidden.
                // We keep a list of items which we need to keep open.
                var oldItemsToShow = new List <IDockTabItem>();
                foreach (var oldDockTabItem in oldVisibleItems)
                {
                    if (context.NewItems.ContainsKey(oldDockTabItem.DockId) &&
                        oldDockTabItem.DockState != DockState.Hide)
                    {
                        // Item remains in the layout and visible.
                        continue;
                    }

                    // Previously visible item is removed from layout or hidden.
                    // Try to close it. Items that cannot be closed will be shown at the end.
                    bool closed = false;
                    if ((oldDockTabItem.IsPersistent && !keepPersistentItems) ||
                        (!oldDockTabItem.IsPersistent && !keepNonPersistentItems))
                    {
                        if (dockStrategy.CanClose(oldDockTabItem))
                        {
                            // Successfully closed.
                            dockStrategy.Close(oldDockTabItem);
                            closed = true;
                        }
                    }

                    if (!closed)
                    {
                        oldItemsToShow.Add(oldDockTabItem);
                    }
                }

                // The DockControl still contains the old layout with the previous IDockPane
                // view model. The old view models are still attached to the DockControl and
                // react to changes, which may cause the wrong screen conduction.
                // --> Detach IDockTabItems from old layout.
                foreach (var item in items)
                {
                    DockHelper.Remove(dockControl, item);
                }

                dockControl.FloatWindows.Clear();
                dockControl.AutoHideLeft.Clear();
                dockControl.AutoHideRight.Clear();
                dockControl.AutoHideTop.Clear();
                dockControl.AutoHideBottom.Clear();

                var isLocked = (bool?)context.Checked(storedLayout.Attribute("IsLocked"));
                if (isLocked != null)
                {
                    dockControl.IsLocked = isLocked.Value;
                }

                // Load float windows.
                {
                    foreach (var xElement in storedLayout.Elements("FloatWindows").Elements())
                    {
                        var floatWindow = LoadFloatWindow(context, xElement);
                        if (floatWindow != null)
                        {
                            dockControl.FloatWindows.Add(floatWindow);
                        }
                    }
                }

                // Load auto-hide panes.
                {
                    var autoHideBars = new[]
                    {
                        new { Bar = dockControl.AutoHideLeft, Name = "AutoHideLeft" },
                        new { Bar = dockControl.AutoHideRight, Name = "AutoHideRight" },
                        new { Bar = dockControl.AutoHideTop, Name = "AutoHideTop" },
                        new { Bar = dockControl.AutoHideBottom, Name = "AutoHideBottom" },
                    };

                    foreach (var bar in autoHideBars)
                    {
                        foreach (var xElement in storedLayout.Elements(bar.Name).Elements())
                        {
                            var dockPane = LoadDockPane(context, xElement);
                            if (dockPane != null)
                            {
                                bar.Bar.Add((IDockTabPane)dockPane);
                            }
                        }
                    }
                }

                // Load root pane. (We do this after loading the float windows and auto-hide bars,
                // because the dock strategy might want to activate an item in a float window or
                // auto-hide bar).
                dockControl.RootPane = LoadDockPane(context, storedLayout.Elements("RootPane").Elements().FirstOrDefault());

                // Run cleanup to update IsVisible flags. Those should be up-to-date before calling
                // Show() to find good default dock target positions.
                dockStrategy.Cleanup();

                // This is not done in cleanup if we are inside Begin()/End().
                dockControl.ActiveDockTabPane = null;
                dockControl.ActiveDockTabItem = null;

                // Show all old items that are not visible in the loaded layout but could not be closed.
                foreach (var item in oldItemsToShow)
                {
                    dockStrategy.Show(item);
                }

                // Activate item.
                if (context.ActiveItem != null)
                {
                    dockStrategy.Show(context.ActiveItem);
                }

                context.ResetLineInfo();
            }
            catch (Exception exception)
            {
                var message = "Could not load docking layout.";

                if (context.LineInfo != null && context.LineInfo.HasLineInfo())
                {
                    message += Invariant($" Error at line {context.LineInfo.LineNumber}, column {context.LineInfo.LinePosition}.");
                }

                message += " See inner exception for more details.";

                throw new DockException(message, exception);
            }
            finally
            {
                dockStrategy.End();
            }
        }
Пример #16
0
 public CartPB8K(DeserializationContext input, MachineBase m) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadExpectedBytes(0x2000), 0x2000);
     SegmentBase = input.ReadUnsignedShorts();
 }
Пример #17
0
 public CartDC8K(DeserializationContext input) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadExpectedBytes(0x2000), 0x2000);
 }
Пример #18
0
 /// <nodoc />
 public ExpressionStatement(DeserializationContext context, LineInfo location)
     : base(location)
 {
     Expression = ReadExpression(context);
 }
 protected override object DeserializeArray(DeserializationContext context, RepeatedField <Value> values) =>
 throw new NotSupportedException($"Type {TargetType} cannot be used for deserialization; only serialization.");
Пример #20
0
 internal BoolLiteral(DeserializationContext context, LineInfo location)
     : base(location)
 {
     m_unboxedValue = context.Reader.ReadBoolean();
 }
Пример #21
0
 /// <nodoc />
 public NamedTypeReference(DeserializationContext context, LineInfo location)
     : base(location)
 {
     TypeName      = context.Reader.ReadReadOnlyList(r => r.ReadSymbolAtom());
     TypeArguments = ReadArrayOf <Type>(context);
 }
Пример #22
0
        public override object Read(Stream stream, DeserializationContext context)
        {
            ulong ul = stream.ReadULong();

            return(new UIntPtr(ul));
        }
Пример #23
0
 public override object Read(Stream stream, DeserializationContext context)
 {
     byte[] buffer = new byte[FloatSizeInBytes];
     stream.Read(buffer, 0, FloatSizeInBytes);
     return(BitConverter.ToSingle(buffer, 0));
 }
Пример #24
0
 /// <nodoc />
 public PackageDeclaration(DeserializationContext context, LineInfo location)
     : base(context, location)
 {
     PackageKeyword     = ReadSymbolAtom(context);
     PackageExpressions = ReadExpressions(context);
 }
        public void ExceptionSerializer_UnknownException()
        {
            var expected = GetNewException();

            var knowsException = new ILBasedExceptionSerializer(this.serializerGenerator, new TypeSerializer(new CachedTypeResolver()));

            var writer  = new BinaryTokenStreamWriter();
            var context = new SerializationContext(this.environment.SerializationManager)
            {
                StreamWriter = writer
            };

            knowsException.Serialize(expected, context, null);

            // Deep copies should be reference-equal.
            var copyContext = new SerializationContext(this.environment.SerializationManager);

            Assert.Equal(expected, knowsException.DeepCopy(expected, copyContext), ReferenceEqualsComparer.Instance);

            // Create a deserializer which doesn't know about the expected exception type.
            var reader = new DeserializationContext(this.environment.SerializationManager)
            {
                StreamReader = new BinaryTokenStreamReader(writer.ToByteArray())
            };

            // Ensure that the deserialized object has the fallback type.
            var doesNotKnowException = new ILBasedExceptionSerializer(this.serializerGenerator, new TestTypeSerializer(new CachedTypeResolver()));
            var untypedActual        = doesNotKnowException.Deserialize(null, reader);

            Assert.IsType <RemoteNonDeserializableException>(untypedActual);

            // Ensure that the original type name is preserved correctly.
            var actualDeserialized = (RemoteNonDeserializableException)untypedActual;

            Assert.Equal(RuntimeTypeNameFormatter.Format(typeof(ILExceptionSerializerTestException)), actualDeserialized.OriginalTypeName);

            // Re-serialize the deserialized object using the serializer which does not have access to the original type.
            writer  = new BinaryTokenStreamWriter();
            context = new SerializationContext(this.environment.SerializationManager)
            {
                StreamWriter = writer
            };
            doesNotKnowException.Serialize(untypedActual, context, null);

            reader = new DeserializationContext(this.environment.SerializationManager)
            {
                StreamReader = new BinaryTokenStreamReader(writer.ToByteArray())
            };

            // Deserialize the round-tripped object and verify that it has the original type and all properties are
            // correctly.
            untypedActual = knowsException.Deserialize(null, reader);
            Assert.IsType <ILExceptionSerializerTestException>(untypedActual);

            var actual = (ILExceptionSerializerTestException)untypedActual;

            Assert.Equal(expected.BaseField.Value, actual.BaseField.Value, StringComparer.Ordinal);
            Assert.Equal(expected.SubClassField, actual.SubClassField, StringComparer.Ordinal);
            Assert.Equal(expected.OtherField.Value, actual.OtherField.Value, StringComparer.Ordinal);

            // Check for referential equality in the two fields which happened to be reference-equals.
            Assert.Equal(actual.BaseField, actual.OtherField, ReferenceEqualsComparer.Instance);
        }
Пример #26
0
        protected override ISerializable DeserializeBase(BinaryReader reader, Type objectType, DeserializationContext context)
        {
            CustomInit();
            ISerializable result = (ISerializable)context.CurrentReferenceTypeObject;

            if (!FullyTrusted)
            {
                string message = $@"Type '{CurrentType}' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data." + Environment.NewLine +
                                 @"To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true." + Environment.NewLine;
                throw new SerializationException(message);
            }

            var memberCount = BinaryConverters.Length;
            SerializationInfo serializationInfo = new SerializationInfo(CurrentType, new FormatterConverter());

            for (var i = 0; i < memberCount; i++)
            {
                object value;
                value = BinaryConverters[i].Deserialize(reader, BinaryConverterTypesForISerializable[i], context);
                serializationInfo.AddValue(ItemNamesForISerializable[i], value, BinaryConverterTypesForISerializable[i]);
            }

            TargetCreateInstanceMethod.Invoke(result, new object[] { serializationInfo, _context });
            //result = (ISerializable)EntityMetaData.ReflectionEmitPropertyAccessor.CreateInstanceForISerialzableObject(serializationInfo, _context);
            return(result);
        }
Пример #27
0
        static void DeserializeHeapList(ref DeserializationContext context, out HeapSnapshot.HeapInfo[] output)
        {
            var br = new BinaryReader(context.Stream);

            int count = br.ReadInt32();
            output = new HeapSnapshot.HeapInfo[count];

            uint offset = 4;
            uint size = BlittableSerializer<HeapSnapshot.HeapInfo>.Size;
            for (int i = 0; i < count; i++) {
                context.DeserializeValue(BlittableSerializer<HeapSnapshot.HeapInfo>.Deserialize, offset, size, out output[i]);
                offset += size;
            }
        }
Пример #28
0
 /// <nodoc />
 public PrimitiveType(DeserializationContext context, LineInfo location)
     : base(location)
 {
     TypeKind = (PrimitiveTypeKind)context.Reader.ReadByte();
 }
Пример #29
0
 private static T Deserialize(DeserializationContext context) => ProtobufMarshallerFactory.Deserialize <T>(context, RuntimeTypeModel.Default);
Пример #30
0
 protected override object DeserializeDouble(DeserializationContext context, double value) => value;
Пример #31
0
 protected override object DeserializeReference(DeserializationContext context, string value) =>
 context.Database.GetDocumentReferenceFromResourceName(value);
Пример #32
0
 // We allow serialization from integer values as some interactions with Firestore end up storing
 // an integer value even when a double value is expected, if the value happens to be an integer.
 // See https://github.com/googleapis/google-cloud-dotnet/issues/3013
 protected override object DeserializeInteger(DeserializationContext context, long value) => (double)value;
Пример #33
0
 protected override object DeserializeInteger(DeserializationContext context, long value) => checked ((ushort)value);
Пример #34
0
 protected override object DeserializeBoolean(DeserializationContext context, bool value) => value;
        public DeserializationContext Deserialize(SerializedMonitor data)
        {
            DeserializationContext context = new DeserializationContext();

            if (MinTiffFileSize != data.Monitor.MinTiffFileSize)
            {
                Trace.TraceWarning("Min tiff size does not match restored information.  Using current setting ({0:F2} MB).", MinTiffFileSize);
            }

            WhenCached = data.WhenCached;

            List<int> validIndices = new List<int>();

            foreach (var day in data.Monitor.Days.Where(s => s != null).OrderBy(x => x.Index))
            {
                var fullPath = Path.Combine(this.Location, day.RelativePath);

                if (!UserOptions.Default.VerifyDeserializationPaths || Directory.Exists(fullPath))
                {
                    TileDay tileDay = CreateOrGetDay(fullPath);
                    validIndices.Add(tileDay.Index);
                }
                else
                {
                    Trace.TraceWarning("Failed to find existing directory for cached tileDay location {0}.", fullPath);
                }
            }

            foreach (var dayIndex in validIndices)
            {
                foreach (Tile tile in data.TileMap[dayIndex])
                {
                    tile.ExpectedChannelCount = ExpectedChannelCount;
                    tile.MinTiffFileSize = MinTiffFileSize;
                    tile.IsEvaluated = true;
                }

                var dayData = this.Days[dayIndex].Deserialize(data.TileMap[dayIndex]);

                context.CompleteCount += dayData.Item1;
                context.Incomplete.AddRange(dayData.Item2);

                foreach (Tile tile in data.TileMap[dayIndex])
                {
                    foreach (ImageContent c in tile.Contents.ImageContents)
                    {
                        if (c.Exists)
                        {
                            if (Double.IsNaN(c.Luminance))
                            {
                                context.QueueImage(Path.Combine(tile.FullPath, String.Format("{0:D5}-ngc.{1}.tif", tile.Id, c.Channel)), tile, c.Channel);
                            }

                            if (c.FrameCount > 0)
                            {
                                context.ConsiderImplicitFrameData(c.FileSize, c.FrameCount);
                            }
                        }
                    }
                }
            }

            return context;
        }
Пример #36
0
 protected override object DeserializeTimestamp(DeserializationContext context, wkt::Timestamp value) => Timestamp.FromProto(value);
Пример #37
0
 protected override object DeserializeGeoPoint(DeserializationContext context, LatLng value) => GeoPoint.FromProto(value);
Пример #38
0
 protected override object DeserializeBytes(DeserializationContext context, ByteString value) => value.ToByteArray();
        public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
        {
            var action = new ModifyWorkItemTypeDefinitionMorphAction(element.GetAttribute("typename"));

            foreach (var subActionElement in element.ChildNodes.OfType<XmlElement>())
            {
                var subAction = ModifyWorkItemTypeDefinitionSubAction.Deserialize(subActionElement, context);
                action._subActions.Add(subAction);
            }

            return action;
        }
 public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
 {
     return new DestroyWitdMorphAction(element.GetAttribute("typename"));
 }
 public static ModifyWorkItemTypeDefinitionSubAction Deserialize(XmlElement element, DeserializationContext context)
 {
     return new RemoveStateModifyWorkItemTypeDefinitionSubAction(element.GetAttribute("refname"));
 }
Пример #42
0
 public Cart78AC(DeserializationContext input, MachineBase m) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadBytes());
     Bank = input.ReadIntegers(8);
 }
Пример #43
0
 public CartMN16K(DeserializationContext input, MachineBase m) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadExpectedBytes(0x4000), 0x4000);
     RAM = input.ReadExpectedBytes(0x800);
     BankBaseAddr = input.ReadUInt16();
     BankBaseRAMAddr = input.ReadUInt16();
     RAMBankOn = input.ReadBoolean();
 }
Пример #44
0
		public object Deserialize(BinaryReader reader)
		{
			if (reader.ReadInt32() != magic)
				throw new SerializationException("The data cannot be read by FastSerializer (unknown magic value)");
			
			DeserializationContext context = new DeserializationContext();
			context.Reader = reader;
			context.Objects = new object[reader.ReadInt32()];
			context.Types = new Type[reader.ReadInt32()];
			string[] assemblyNames = new string[reader.ReadInt32()];
			int fixedInstanceCount = reader.ReadInt32();
			
			if (fixedInstanceCount != 0) {
				if (this.FixedInstances == null || this.FixedInstances.Length != fixedInstanceCount)
					throw new SerializationException("Number of fixed instances doesn't match");
				for (int i = 0; i < fixedInstanceCount; i++) {
					context.Objects[i + 1] = this.FixedInstances[i];
				}
			}
			
			for (int i = 0; i < assemblyNames.Length; i++) {
				assemblyNames[i] = reader.ReadString();
			}
			int stringTypeID = -1;
			for (int i = 0; i < context.Types.Length; i++) {
				byte typeKind = reader.ReadByte();
				switch (typeKind) {
					case Type_ReferenceType:
					case Type_ValueType:
						int assemblyID;
						if (assemblyNames.Length <= ushort.MaxValue)
							assemblyID = reader.ReadUInt16();
						else
							assemblyID = reader.ReadInt32();
						string assemblyName = assemblyNames[assemblyID];
						string typeName = reader.ReadString();
						Type type;
						if (SerializationBinder != null) {
							type = SerializationBinder.BindToType(assemblyName, typeName);
						} else {
							type = Assembly.Load(assemblyName).GetType(typeName);
						}
						if (type == null)
							throw new SerializationException("Could not find '" + typeName + "' in '" + assemblyName + "'");
						if (typeKind == Type_ValueType && !type.IsValueType)
							throw new SerializationException("Expected '" + typeName + "' to be a value type, but it is reference type");
						if (typeKind == Type_ReferenceType && type.IsValueType)
							throw new SerializationException("Expected '" + typeName + "' to be a reference type, but it is value type");
						context.Types[i] = type;
						if (type == typeof(string))
							stringTypeID = i;
						break;
					case Type_SZArray:
						context.Types[i] = context.Types[context.ReadTypeID()].MakeArrayType();
						break;
					case Type_ParameterizedType:
						Type genericType = context.Types[context.ReadTypeID()];
						int typeParameterCount = genericType.GetGenericArguments().Length;
						Type[] typeArguments = new Type[typeParameterCount];
						for (int j = 0; j < typeArguments.Length; j++) {
							typeArguments[j] = context.Types[context.ReadTypeID()];
						}
						context.Types[i] = genericType.MakeGenericType(typeArguments);
						break;
					default:
						throw new SerializationException("Unknown type kind");
				}
			}
			context.DeserializeTypeDescriptions();
			int[] typeIDByObjectID = new int[context.Objects.Length];
			for (int i = 1 + fixedInstanceCount; i < context.Objects.Length; i++) {
				int typeID = context.ReadTypeID();
				
				object instance;
				if (typeID == stringTypeID) {
					instance = reader.ReadString();
				} else {
					Type type = context.Types[typeID];
					if (type.IsArray) {
						int length = reader.ReadInt32();
						instance = Array.CreateInstance(type.GetElementType(), length);
					} else {
						instance = FormatterServices.GetUninitializedObject(type);
					}
				}
				context.Objects[i] = instance;
				typeIDByObjectID[i] = typeID;
			}
			List<CustomDeserialization> customDeserializatons = new List<CustomDeserialization>();
			ObjectReader[] objectReaders = new ObjectReader[context.Types.Length]; // index: type ID
			for (int i = 1 + fixedInstanceCount; i < context.Objects.Length; i++) {
				object instance = context.Objects[i];
				int typeID = typeIDByObjectID[i];
				Log("0x{2:x6} Read #{0}: {1}", i, context.Types[typeID].Name, reader.BaseStream.Position);
				ISerializable serializable = instance as ISerializable;
				if (serializable != null) {
					Type type = context.Types[typeID];
					SerializationInfo info = new SerializationInfo(type, formatterConverter);
					int count = reader.ReadInt32();
					for (int j = 0; j < count; j++) {
						string name = reader.ReadString();
						object val = context.ReadObject();
						info.AddValue(name, val);
					}
					CustomDeserializationAction action = GetCustomDeserializationAction(type);
					customDeserializatons.Add(new CustomDeserialization(instance, info, action));
				} else {
					ObjectReader objectReader = objectReaders[typeID];
					if (objectReader == null) {
						objectReader = GetReader(context.Types[typeID]);
						objectReaders[typeID] = objectReader;
					}
					objectReader(context, instance);
				}
			}
			Log("File was read successfully, now running {0} custom deserializations...", customDeserializatons.Count);
			foreach (CustomDeserialization customDeserializaton in customDeserializatons) {
				customDeserializaton.Run(streamingContext);
			}
			for (int i = 1 + fixedInstanceCount; i < context.Objects.Length; i++) {
				IDeserializationCallback dc = context.Objects[i] as IDeserializationCallback;
				if (dc != null)
					dc.OnDeserialization(null);
			}
			
			return context.ReadObject();
		}
Пример #45
0
        static unsafe void DeserializeAddresses(ref DeserializationContext context, out UInt32[] output)
        {
            var stream = context.Stream;

            var pointer = context.Source;
            var count = *(int *)pointer;
            var addresses = new UInt32[count];

            if ((count * 4) + 4 > context.SourceLength)
                throw new InvalidDataException();

            fixed (UInt32 * pAddresses = addresses)
                Native.memmove((byte *)pAddresses, pointer + 4, new UIntPtr((uint)count * 4));

            output = addresses;
        }
Пример #46
0
 public CartA4K(DeserializationContext input, MachineBase m) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadExpectedBytes(0x1000), 0x1000);
 }
Пример #47
0
        static void DeserializeModuleList(ref DeserializationContext context, out string[] output)
        {
            var br = new BinaryReader(context.Stream);

            int count = br.ReadInt32();
            output = new string[count];

            for (int i = 0; i < count; i++)
                output[i] = br.ReadString();
        }
Пример #48
0
 public Machine7800PAL(DeserializationContext input) : base(input, MariaTables.PALPalette, 312)
 {
     input.CheckVersion(1);
 }
Пример #49
0
 protected override object DeserializeBytes(DeserializationContext context, ByteString value) => Blob.FromByteString(value);
Пример #50
0
 public Machine2600NTSC(DeserializationContext input) : base(input, TIATables.NTSCPalette)
 {
     input.CheckVersion(1);
 }
Пример #51
0
 public Machine7800NTSC(DeserializationContext input) : base(input, MariaTables.NTSCPalette, 262)
 {
     input.CheckVersion(1);
 }
Пример #52
0
 protected override object DeserializeTimestamp(DeserializationContext context, wkt::Timestamp value) => value.ToDateTimeOffset();
Пример #53
0
 public Machine2600NTSC(DeserializationContext input) : base(input, TIATables.NTSCPalette)
 {
     input.CheckVersion(1);
 }
Пример #54
0
 protected override object DeserializeTimestamp(DeserializationContext context, wkt::Timestamp value) => value.Clone();
Пример #55
0
        public Machine7800(DeserializationContext input, int[] palette, int scanlines) : base(input, palette)
        {
            input.CheckVersion(1);

            Mem = input.ReadAddressSpace(this, 16, 6);  // 7800: 16bit, 64byte pages

            CPU = input.ReadM6502(this, 4);

            Maria = input.ReadMaria(this, scanlines);
            Mem.Map(0x0000, 0x0040, Maria);
            Mem.Map(0x0100, 0x0040, Maria);
            Mem.Map(0x0200, 0x0040, Maria);
            Mem.Map(0x0300, 0x0040, Maria);

            PIA = input.ReadPIA(this);
            Mem.Map(0x0280, 0x0080, PIA);
            Mem.Map(0x0480, 0x0080, PIA);
            Mem.Map(0x0580, 0x0080, PIA);

            RAM1 = input.ReadRAM6116();
            RAM2 = input.ReadRAM6116();
            Mem.Map(0x1800, 0x0800, RAM1);
            Mem.Map(0x2000, 0x0800, RAM2);

            Mem.Map(0x0040, 0x00c0, RAM2); // page 0 shadow
            Mem.Map(0x0140, 0x00c0, RAM2); // page 1 shadow
            Mem.Map(0x2800, 0x0800, RAM2); // shadow1
            Mem.Map(0x3000, 0x0800, RAM2); // shadow2
            Mem.Map(0x3800, 0x0800, RAM2); // shadow3

            BIOS = input.ReadOptionalBios7800();
            HSC = input.ReadOptionalHSC7800();

            if (HSC != null)
            {
                Mem.Map(0x1000, 0x800, HSC.SRAM);
                Mem.Map(0x3000, 0x1000, HSC);
            }

            Cart = input.ReadCart(this);
            Mem.Map(0x4000, 0xc000, Cart);
        }
Пример #56
0
 public override object DeserializeValue(DeserializationContext context, Value value) => value.Clone();
Пример #57
0
 static void Deserialize(ref DeserializationContext context, out SpecialType output)
 {
     var br = new BinaryReader(context.Stream);
     output = new SpecialType(context.Key, br.ReadUInt32());
 }
Пример #58
0
 protected override object DeserializeGeoPoint(DeserializationContext context, LatLng value) => value.Clone();
Пример #59
0
 public CartDPC(DeserializationContext input, MachineBase m) : base(input)
 {
     input.CheckVersion(1);
     LoadRom(input.ReadExpectedBytes(0x2800), 0x2800);
     BankBaseAddr = input.ReadUInt16();
     Tops = input.ReadExpectedBytes(8);
     Bots = input.ReadExpectedBytes(8);
     Counters = input.ReadUnsignedShorts(8);
     Flags = input.ReadExpectedBytes(8);
     MusicMode = input.ReadBooleans(3);
     LastSystemClock = input.ReadUInt64();
     FractionalClocks = input.ReadDouble();
     _ShiftRegister = input.ReadByte();
 }
Пример #60
0
 protected override object DeserializeString(DeserializationContext context, string value) => value;