public void Serialize(SerializationStream stream, ArchiveMode mode)
        {
            // Check version number (should be 0 for now, for future use)
            if (mode == ArchiveMode.Serialize)
            {
                stream.Write(0);
            }
            else if (mode == ArchiveMode.Deserialize)
            {
                if (stream.ReadInt32() != 0)
                    throw new InvalidOperationException("Unexpected version number.");
            }

            // Serialize content
            stream.Serialize(ref IsBinary);
            if (IsBinary)
            {
                stream.Serialize(ref BinaryFormat);
                stream.Serialize(ref Binary, mode);
            }
            else
            {
                stream.Serialize(ref Profile);
                stream.Serialize(ref EntryPoint);
                stream.Serialize(ref Source);
            }
        }
Esempio n. 2
0
        /**
         * Creates a new OpenTok session.
         * <p>
         * OpenTok sessions do not expire. However, authentication tokens do expire (see the
         * generateToken() method). Also note that sessions cannot explicitly be destroyed.
         * <p>
         * A session ID string can be up to 255 characters long.
         * <p>
         * Calling this method results in an OpenTokException in the event of an error.
         * Check the error message for details.
         *
         * You can also create a session using the
         * <a href="http://www.tokbox.com/opentok/api/#session_id_production">OpenTok
         * REST API</a> or the <a href="https://dashboard.tokbox.com/projects">OpenTok
         * dashboard</a>.
         *
         * @param location (String) An IP address that the OpenTok servers will use to
         * situate the session in its global network. If you do not set a location hint,
         * the OpenTok servers will be based on the first client connecting to the session.
         *
         * @param mediaMode Whether the session will transmit streams using the
         * OpenTok Media Router (<code>MediaMode.ROUTED</code>) or not
         * (<code>MediaMode.RELAYED</code>). By default, the setting is
         * <code>MediaMode.RELAYED</code>.
         * <p>
         * With the <code>mediaMode</code> parameter set to <code>MediaMode.RELAYED</code>, the
         * session will attempt to transmit streams directly between clients. If clients cannot
         * connect due to firewall restrictions, the session uses the OpenTok TURN server to relay
         * streams.
         * <p>
         * The <a href="https://tokbox.com/opentok/tutorials/create-session/#media-mode"
         * target="_top">OpenTok Media Router</a> provides the following benefits:
         *
         * <ul>
         *   <li>The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.
         *       (When the <code>mediaMode</code> parameter is set to
         *       <code>MediaMode.ROUTED</code>, each client must send a separate audio-video stream
         *      to each client subscribing to it.)</li>
         *   <li>The OpenTok Media Router can improve the quality of the user experience through
         *     <a href="https://tokbox.com/platform/fallback" target="_top">audio fallback and video
         *     recovery</a>. With these features, if a client's connectivity degrades to a degree
         *     that it does not support video for a stream it's subscribing to, the video is dropped
         *     on that client (without affecting other clients), and the client receives audio only.
         *     If the client's connectivity improves, the video returns.</li>
         *   <li>The OpenTok Media Router supports the
         *     <a href="http://tokbox.com/opentok/tutorials/archiving" target="_top">archiving</a>
         *     feature, which lets you record, save, and retrieve OpenTok sessions.</li>
         * </ul>
         *
         * @param archiveMode Whether the session is automatically archived
         * (<code>ArchiveMode.ALWAYS</code>) or not (<code>ArchiveMode.MANUAL</code>). By default,
         * the setting is <code>ArchiveMode.MANUAL</code>, and you must call the
         * StartArchive() method of the OpenTok object to start archiving. To archive the session
         * (either automatically or not), you must set the mediaMode parameter to
         * <code>MediaMode.ROUTED</code>.
         *
         * @return A Session object representing the new session. The <code>Id</code> property of
         * the Session is the session ID, which uniquely identifies the session. You will use
         * this session ID in the client SDKs to identify the session. For example, when using the
         * OpenTok.js library, use the session ID when calling the
         * <a href="http://tokbox.com/opentok/libraries/client/js/reference/OT.html#initSession">
         * OT.initSession()</a> method (to initialize an OpenTok session).
         */
        public Session CreateSession(string location = "", MediaMode mediaMode = MediaMode.RELAYED, ArchiveMode archiveMode = ArchiveMode.MANUAL)
        {

            if (!OpenTokUtils.TestIpAddress(location))
            {
                throw new OpenTokArgumentException(string.Format("Location {0} is not a valid IP address", location));
            }

            if (archiveMode == ArchiveMode.ALWAYS && mediaMode != MediaMode.ROUTED)
            {
                throw new OpenTokArgumentException("A session with always archive mode must also have the routed media mode.");
            }

            string preference = (mediaMode == MediaMode.RELAYED) ? "enabled" : "disabled";

            var headers = new Dictionary<string, string> { { "Content-type", "application/x-www-form-urlencoded" } };
            var data = new Dictionary<string, object>
            {
                {"location", location},
                {"p2p.preference", preference},
                {"archiveMode", archiveMode.ToString().ToLower()}
            };

            var response = Client.Post("session/create", headers, data);
            var xmlDoc = Client.ReadXmlResponse(response);

            if (xmlDoc.GetElementsByTagName("session_id").Count == 0)
            {
                throw new OpenTokWebException("Session could not be provided. Are ApiKey and ApiSecret correctly set?");
            }
            var sessionId = xmlDoc.GetElementsByTagName("session_id")[0].ChildNodes[0].Value;
            var apiKey = Convert.ToInt32(xmlDoc.GetElementsByTagName("partner_id")[0].ChildNodes[0].Value);
            return new Session(sessionId, apiKey, ApiSecret, location, mediaMode, archiveMode);
        }
Esempio n. 3
0
 // ------------------ Reading ----------------------
 // Open an existing archive for reading
 public bool OpenArchive( string fullpath )
 {
     archive = new FileStream( fullpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite );
     mode = ArchiveMode.ReadingMode;
     return true;
 }
Esempio n. 4
0
 public override void Serialize(ref ParameterCollection parameterCollection, ArchiveMode mode, SerializationStream stream)
 {
     stream.Serialize(ref parameterCollection.parameterKeyInfos, mode);
     stream.SerializeExtended(ref parameterCollection.ObjectValues, mode);
     stream.Serialize(ref parameterCollection.DataValues, mode);
 }
Esempio n. 5
0
 /// <inheritdoc/>
 public abstract void PreSerialize(ref object obj, ArchiveMode mode, SerializationStream stream);
Esempio n. 6
0
 public override void Serialize(ref Header obj, ArchiveMode mode, SerializationStream stream)
 {
     stream.Serialize(ref obj.MagicHeader);
     stream.Serialize(ref obj.Size);
     stream.Serialize(ref obj.Crc);
 }
Esempio n. 7
0
 public override void Serialize(ref NavigationMeshLayer obj, ArchiveMode mode, SerializationStream stream)
 {
     tilesSerializer.Serialize(ref obj.TilesInternal, mode, stream);
 }
Esempio n. 8
0
 // ------------------ Reading ----------------------
 // Open an existing archive for reading
 public bool OpenArchive(string fullpath)
 {
     archive = new FileStream(fullpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     mode    = ArchiveMode.ReadingMode;
     return(true);
 }
Esempio n. 9
0
 public static void SerializeExtended <T>([NotNull] this SerializationStream stream, ref T obj, ArchiveMode mode, DataSerializer <T> dataSerializer = null)
 {
     MemberReuseSerializer <T> .SerializeExtended(ref obj, mode, stream, dataSerializer);
 }
Esempio n. 10
0
        public static void Serialize <T>([NotNull] this SerializationStream stream, ref T obj, ArchiveMode mode)
        {
            var dataSerializer = stream.Context.SerializerSelector.GetSerializer <T>();

            if (dataSerializer == null)
            {
                throw new InvalidOperationException($"Could not find serializer for type {typeof(T)}.");
            }

            dataSerializer.PreSerialize(ref obj, mode, stream);
            dataSerializer.Serialize(ref obj, mode, stream);
        }
Esempio n. 11
0
        public override void Serialize(ref T obj, ArchiveMode mode, SerializationStream stream)
        {
            var referenceSerialization   = stream.Context.Get(ContentSerializerContext.SerializeAttachedReferenceProperty);
            var contentSerializerContext = stream.Context.Get(ContentSerializerContext.ContentSerializerContextProperty);

            if (contentSerializerContext != null)
            {
                if (mode == ArchiveMode.Serialize)
                {
                    var contentReference = new ContentReference <T> {
                        Value = obj
                    };
                    int index = contentSerializerContext.AddContentReference(contentReference);
                    stream.Write(index);
                }
                else
                {
                    int index            = stream.ReadInt32();
                    var contentReference = contentSerializerContext.GetContentReference <T>(index);
                    obj = contentReference.Value;
                    if (obj == null)
                    {
                        // Check if already deserialized
                        var assetReference = contentSerializerContext.AssetManager.FindDeserializedObject(contentReference.Location, typeof(T));
                        if (assetReference != null)
                        {
                            obj = (T)assetReference.Object;
                            if (obj != null)
                            {
                                contentReference.Value = obj;
                            }
                        }
                    }

                    if (obj == null && contentSerializerContext.LoadContentReferences)
                    {
                        var contentSerializer = cachedContentSerializer ?? (cachedContentSerializer = contentSerializerContext.AssetManager.Serializer.GetSerializer(null, typeof(T)));
                        // First time, let's create it
                        obj = (T)contentSerializer.Construct(contentSerializerContext);
                        contentSerializerContext.AssetManager.RegisterDeserializedObject(contentReference.Location, obj);
                        contentReference.Value = obj;
                    }
                }
            }
            else if (referenceSerialization == ContentSerializerContext.AttachedReferenceSerialization.AsNull)
            {
                if (mode == ArchiveMode.Deserialize)
                {
                    obj = default(T);
                }
            }
            else if (referenceSerialization == ContentSerializerContext.AttachedReferenceSerialization.AsSerializableVersion)
            {
                if (mode == ArchiveMode.Serialize)
                {
                    // This case will happen when serializing build engine command hashes: we still want Location to still be written
                    var attachedReference = AttachedReferenceManager.GetAttachedReference(obj);
                    if (attachedReference == null || attachedReference.Url == null)
                    {
                        throw new InvalidOperationException("Error when serializing reference.");
                    }

                    // TODO: Do not use string
                    stream.Write(obj.GetType().AssemblyQualifiedName);
                    stream.Write(attachedReference.Id);
                    stream.Write(attachedReference.Url);
                }
                else
                {
                    var type = Type.GetType(stream.ReadString());
                    var id   = stream.Read <Guid>();
                    var url  = stream.ReadString();

                    obj = (T)AttachedReferenceManager.CreateSerializableVersion(type, id, url);
                }
            }
            else
            {
                // This case will happen when serializing build engine command hashes: we still want Location to still be written
                if (mode == ArchiveMode.Serialize)
                {
                    // This case will happen when serializing build engine command hashes: we still want Location to still be written
                    var attachedReference = AttachedReferenceManager.GetAttachedReference(obj);
                    if (attachedReference == null || attachedReference.Url == null)
                    {
                        throw new InvalidOperationException("Error when serializing reference.");
                    }

                    stream.Write(attachedReference.Url);
                }
                else
                {
                    // No real case yet
                    throw new NotSupportedException();
                }
            }
        }
Esempio n. 12
0
 public abstract Dictionary <MetricType, TimeSeries> ComputePrimitiveTimeSeries(MetricType[] metric, string type, DateTime start, DateTime end, Tag[] filters, ArchiveMode archive);
Esempio n. 13
0
        public Dictionary <MetricInfo, TimeSeries> ComputeTimeSeries(MetricInfo[] metricsInfo, string type, DateTime start, DateTime end, Tag[] filters, ArchiveMode archive)
        {
            var requiredMetrics = GetRequiredMetricsFromRequestedMetrics(metricsInfo);
            var primitiveStore  = ComputePrimitiveTimeSeries(requiredMetrics.ToArray(), type, start, end, filters, archive);

            var metricStore = new ConcurrentDictionary <MetricInfo, TimeSeries>();

            foreach (var metric in metricsInfo)
            {
                if (metric.GetType() != typeof(AverageMetric))
                {
                    metricStore[metric] = primitiveStore[metric.TypeId];
                }
            }
            metricsInfo
            .Distinct()
            .AsParallel()
            .WithDegreeOfParallelism(2)
            .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
            .ForAll(metric => {
                if (metric.GetType() == typeof(AverageMetric))
                {
                    var avg             = (AverageMetric)metric;
                    var avgSeries       = ComputeAverageTimeSeries(primitiveStore, avg.Numerator, avg.Denominator, type, start, end, filters, archive);
                    metricStore[metric] = avgSeries;
                }
            });
            return(metricStore.ToDictionary(x => x.Key, x => x.Value));
        }
Esempio n. 14
0
        public TimeSeries ComputeAverageTimeSeries(Dictionary <MetricType, TimeSeries> metricStore, MetricType numeratorName, MetricType denominatorName, string type, DateTime start, DateTime end, Tag[] filters, ArchiveMode archive)
        {
            var topSeries    = metricStore[numeratorName];
            var bottomSeries = metricStore[denominatorName];

            return(Divide(topSeries, bottomSeries));
        }
Esempio n. 15
0
 /// <inheritdoc/>
 public override void Serialize(ref byte[] obj, ArchiveMode mode, SerializationStream stream)
 {
     stream.Serialize(obj, 0, obj.Length);
 }
Esempio n. 16
0
 // ------------------ Writing ----------------------
 // Create a new archive for writing
 public void NewArchive(string fullpath)
 {
     archive = new FileStream(fullpath, FileMode.Create, FileAccess.Write, FileShare.None);
     mode    = ArchiveMode.WritingMode;
 }
 public override void PreSerialize(ref RuntimeRasterizedSpriteFont texture, ArchiveMode mode, SerializationStream stream)
 {
     // Do not create object during pre-serialize (OK because not recursive)
 }
Esempio n. 18
0
        internal static void Serialize(ArchiveMode mode, SerializationStream stream, Texture texture, bool allowContentStreaming)
        {
            if (mode == ArchiveMode.Deserialize)
            {
                var services = stream.Context.Tags.Get(ServiceRegistry.ServiceRegistryKey);
                var graphicsDeviceService     = services.GetSafeServiceAs <IGraphicsDeviceService>();
                var texturesStreamingProvider = services.GetService <ITexturesStreamingProvider>();

                var isStreamable = stream.ReadBoolean();
                if (!isStreamable)
                {
                    texturesStreamingProvider?.UnregisterTexture(texture);

                    // TODO: Error handling?
                    using (var textureData = Image.Load(stream.NativeStream))
                    {
                        if (texture.GraphicsDevice != null)
                        {
                            texture.OnDestroyed(); //Allows fast reloading todo review maybe?
                        }
                        texture.AttachToGraphicsDevice(graphicsDeviceService.GraphicsDevice);
                        texture.InitializeFrom(textureData.Description, new TextureViewDescription(), textureData.ToDataBox());

                        // Setup reload callback (reload from asset manager)
                        var contentSerializerContext = stream.Context.Get(ContentSerializerContext.ContentSerializerContextProperty);
                        if (contentSerializerContext != null)
                        {
                            texture.Reload = static (graphicsResource, services) =>
                            {
                                var assetManager = services.GetService <ContentManager>();
                                assetManager.TryGetAssetUrl(graphicsResource, out var url);
                                var textureDataReloaded = assetManager.Load <Image>(url);
                                ((Texture)graphicsResource).Recreate(textureDataReloaded.ToDataBox());
                                assetManager.Unload(textureDataReloaded);
                            };
                        }
                    }
                }
                else
                {
                    if (texture.GraphicsDevice != null)
                    {
                        texture.OnDestroyed();
                    }

                    texture.AttachToGraphicsDevice(graphicsDeviceService.GraphicsDevice);
                    texture.Reload = null;

                    // Read image header
                    var imageDescription = new ImageDescription();
                    ImageHelper.ImageDescriptionSerializer.Serialize(ref imageDescription, ArchiveMode.Deserialize, stream);

                    // Read content storage header
                    ContentStorageHeader storageHeader;
                    ContentStorageHeader.Read(stream, out storageHeader);

                    // Check if streaming service is available
                    if (texturesStreamingProvider != null)
                    {
                        // Load initial texture (with limited number of mipmaps)
                        if (storageHeader.InitialImage)
                        {
                            using (var textureData = Image.Load(stream.NativeStream))
                            {
                                if (texture.GraphicsDevice != null)
                                {
                                    texture.OnDestroyed(); //Allows fast reloading todo review maybe?
                                }
                                texture.InitializeFrom(textureData.Description, new TextureViewDescription(), textureData.ToDataBox());
                            }
                        }

                        if (allowContentStreaming)
                        {
                            // Register texture for streaming
                            texturesStreamingProvider.RegisterTexture(texture, ref imageDescription, ref storageHeader);

                            // Note: here we don't load texture data and don't allocate GPU memory
                        }
                        else
                        {
                            // Request texture loading (should be fully loaded)
                            texturesStreamingProvider.FullyLoadTexture(texture, ref imageDescription, ref storageHeader);
                        }
                    }
                    else
                    {
                        // Load initial texture and discard it (we are going to load the full chunk texture right after)
                        if (storageHeader.InitialImage)
                        {
                            using (var textureData = Image.Load(stream.NativeStream))
                            {
                            }
                        }

                        // Deserialize whole texture without streaming feature
                        var contentSerializerContext = stream.Context.Get(ContentSerializerContext.ContentSerializerContextProperty);
                        DeserializeTexture(contentSerializerContext.ContentManager, texture, ref imageDescription, ref storageHeader);
                    }
                }
            }
            else
            {
                var textureData = texture.GetSerializationData();
                if (textureData == null)
                {
                    throw new InvalidOperationException("Trying to serialize a Texture without CPU info.");
                }

                textureData.Write(stream);
            }
        }
Esempio n. 19
0
 /// <summary>
 /// Instanciates a specific compression module, given the file extension and options
 /// </summary>
 /// <param name="fileextension">The file extension to create the instance for</param>
 /// <param name="stream">The stream of the file used to compress/decompress contents</param>
 /// <param name="mode">The mode for compression/decompression</param>
 /// <param name="options">The options to pass to the instance constructor</param>
 /// <returns>The instanciated compression module or null if the file extension is not supported</returns>
 public static ICompression GetModule(string fileextension, Stream stream, ArchiveMode mode, Dictionary <string, string> options)
 {
     return(_compressionLoader.GetModule(fileextension, stream, mode, options));
 }
Esempio n. 20
0
 public List <PersonaVersion> GetPersonas(ArchiveMode mode = ArchiveMode.UnArchived)
 {
     return(Backend.PersonaVersionList(mode));
 }
Esempio n. 21
0
        /**
         * Creates a new OpenTok session.
         * <p>
         * OpenTok sessions do not expire. However, authentication tokens do expire (see the
         * generateToken() method). Also note that sessions cannot explicitly be destroyed.
         * <p>
         * A session ID string can be up to 255 characters long.
         * <p>
         * Calling this method results in an OpenTokException in the event of an error.
         * Check the error message for details.
         *
         * You can also create a session using the
         * <a href="http://www.tokbox.com/opentok/api/#session_id_production">OpenTok
         * REST API</a> or by logging in to your
         * <a href="https://tokbox.com/account">TokBox account</a>.
         *
         * @param location (String) An IP address that the OpenTok servers will use to
         * situate the session in its global network. If you do not set a location hint,
         * the OpenTok servers will be based on the first client connecting to the session.
         *
         * @param mediaMode Whether the session will transmit streams using the
         * OpenTok Media Router (<code>MediaMode.ROUTED</code>) or not
         * (<code>MediaMode.RELAYED</code>). By default, the setting is
         * <code>MediaMode.RELAYED</code>.
         * <p>
         * With the <code>mediaMode</code> parameter set to <code>MediaMode.RELAYED</code>, the
         * session will attempt to transmit streams directly between clients. If clients cannot
         * connect due to firewall restrictions, the session uses the OpenTok TURN server to relay
         * streams.
         * <p>
         * The <a href="https://tokbox.com/opentok/tutorials/create-session/#media-mode"
         * target="_top">OpenTok Media Router</a> provides the following benefits:
         *
         * <ul>
         *   <li>The OpenTok Media Router can decrease bandwidth usage in multiparty sessions.
         *       (When the <code>mediaMode</code> parameter is set to
         *       <code>MediaMode.ROUTED</code>, each client must send a separate audio-video stream
         *      to each client subscribing to it.)</li>
         *   <li>The OpenTok Media Router can improve the quality of the user experience through
         *     <a href="https://tokbox.com/platform/fallback" target="_top">audio fallback and video
         *     recovery</a>. With these features, if a client's connectivity degrades to a degree
         *     that it does not support video for a stream it's subscribing to, the video is dropped
         *     on that client (without affecting other clients), and the client receives audio only.
         *     If the client's connectivity improves, the video returns.</li>
         *   <li>The OpenTok Media Router supports the
         *     <a href="http://tokbox.com/opentok/tutorials/archiving" target="_top">archiving</a>
         *     feature, which lets you record, save, and retrieve OpenTok sessions.</li>
         * </ul>
         *
         * @param archiveMode Whether the session is automatically archived
         * (<code>ArchiveMode.ALWAYS</code>) or not (<code>ArchiveMode.MANUAL</code>). By default,
         * the setting is <code>ArchiveMode.MANUAL</code>, and you must call the
         * StartArchive() method of the OpenTok object to start archiving. To archive the session
         * (either automatically or not), you must set the mediaMode parameter to
         * <code>MediaMode.ROUTED</code>.
         *
         * @return A Session object representing the new session. The <code>Id</code> property of
         * the Session is the session ID, which uniquely identifies the session. You will use
         * this session ID in the client SDKs to identify the session. For example, when using the
         * OpenTok.js library, use the session ID when calling the
         * <a href="http://tokbox.com/opentok/libraries/client/js/reference/OT.html#initSession">
         * OT.initSession()</a> method (to initialize an OpenTok session).
         */
        public Session CreateSession(string location = "", MediaMode mediaMode = MediaMode.RELAYED, ArchiveMode archiveMode = ArchiveMode.MANUAL)
        {
            if (!OpenTokUtils.TestIpAddress(location))
            {
                throw new OpenTokArgumentException(string.Format("Location {0} is not a valid IP address", location));
            }

            if (archiveMode == ArchiveMode.ALWAYS && mediaMode != MediaMode.ROUTED)
            {
                throw new OpenTokArgumentException("A session with always archive mode must also have the routed media mode.");
            }

            string preference = (mediaMode == MediaMode.RELAYED) ? "enabled" : "disabled";

            var headers = new Dictionary <string, string> {
                { "Content-type", "application/x-www-form-urlencoded" }
            };
            var data = new Dictionary <string, object>
            {
                { "location", location },
                { "p2p.preference", preference },
                { "archiveMode", archiveMode.ToString().ToLowerInvariant() }
            };

            var response = Client.Post("session/create", headers, data);
            var xmlDoc   = Client.ReadXmlResponse(response);

            if (xmlDoc.GetElementsByTagName("session_id").Count == 0)
            {
                throw new OpenTokWebException("Session could not be provided. Are ApiKey and ApiSecret correctly set?");
            }
            var sessionId = xmlDoc.GetElementsByTagName("session_id")[0].ChildNodes[0].Value;
            var apiKey    = Convert.ToInt32(xmlDoc.GetElementsByTagName("partner_id")[0].ChildNodes[0].Value);

            return(new Session(sessionId, apiKey, ApiSecret, location, mediaMode, archiveMode));
        }
 /// <inheritdoc/>
 public override void Serialize(ref double obj, ArchiveMode mode, SerializationStream stream)
 {
     stream.Serialize(ref obj);
 }
Esempio n. 23
0
 public override void PreSerialize(ref Texture texture, ArchiveMode mode, SerializationStream stream)
 {
     // Do not create object during preserialize (OK because not recursive)
 }
Esempio n. 24
0
 internal Session(string sessionId, int apiKey, string apiSecret, string location, MediaMode mediaMode, ArchiveMode archiveMode)
 {
     this.Id = sessionId;
     this.ApiKey = apiKey;
     this.ApiSecret = apiSecret;
     this.Location = location;
     this.MediaMode = mediaMode;
     this.ArchiveMode = archiveMode;
 }
Esempio n. 25
0
 /// <inheritdoc/>
 public override void PreSerialize(ref Stride.Core.Collections.SortedList <TKey, TValue> obj, ArchiveMode mode, SerializationStream stream)
 {
     if (mode == ArchiveMode.Deserialize)
     {
         // TODO: Peek the SortedList size
         if (obj == null)
         {
             obj = new Stride.Core.Collections.SortedList <TKey, TValue>();
         }
         else
         {
             obj.Clear();
         }
     }
 }
Esempio n. 26
0
 // ------------------ Writing ----------------------
 // Create a new archive for writing
 public void NewArchive( string fullpath )
 {
     archive = new FileStream( fullpath, FileMode.Create, FileAccess.Write, FileShare.None );
     mode = ArchiveMode.WritingMode;
 }
Esempio n. 27
0
 /// <inheritdoc/>
 public override void Serialize(ref Stride.Core.Collections.SortedList <TKey, TValue> obj, ArchiveMode mode, SerializationStream stream)
 {
     if (mode == ArchiveMode.Deserialize)
     {
         // Should be null if it was
         var count = stream.ReadInt32();
         for (var i = 0; i < count; ++i)
         {
             var key   = default(TKey);
             var value = default(TValue);
             keySerializer.Serialize(ref key, mode, stream);
             valueSerializer.Serialize(ref value, mode, stream);
             obj.Add(key, value);
         }
     }
     else if (mode == ArchiveMode.Serialize)
     {
         stream.Write(obj.Count);
         foreach (var item in obj)
         {
             keySerializer.Serialize(item.Key, stream);
             valueSerializer.Serialize(item.Value, stream);
         }
     }
 }
Esempio n. 28
0
 // ------------------ Reading/Writing ----------------------
 // Closes the currently opened archive files
 public void CloseArchive()
 {
     if( archive != null )
         archive.Close();
     archive = null;
     mode = ArchiveMode.None;
 }
Esempio n. 29
0
            public override void Serialize(ref VertexBufferBinding vertexBufferBinding, ArchiveMode mode, SerializationStream stream)
            {
                if (mode == ArchiveMode.Deserialize)
                {
                    var buffer      = stream.Read <Buffer>();
                    var declaration = stream.Read <VertexDeclaration>();
                    var count       = stream.ReadInt32();
                    var stride      = stream.ReadInt32();
                    var offset      = stream.ReadInt32();

                    vertexBufferBinding = new VertexBufferBinding(buffer, declaration, count, stride, offset);
                }
                else
                {
                    stream.Write(vertexBufferBinding.Buffer);
                    stream.Write(vertexBufferBinding.Declaration);
                    stream.Write(vertexBufferBinding.Count);
                    stream.Write(vertexBufferBinding.Stride);
                    stream.Write(vertexBufferBinding.Offset);
                }
            }
Esempio n. 30
0
 /// <inheritdoc/>
 public abstract void PreSerialize(ref object obj, ArchiveMode mode, SerializationStream stream);
Esempio n. 31
0
 public override void Serialize(ref SettingsProfile obj, ArchiveMode mode, SerializationStream stream)
 {
     throw new NotImplementedException();
 }