Exemple #1
0
        /// <summary>
        /// Creates the storage network.
        /// </summary>
        /// <param name="simulator">The simulator.</param>
        /// <returns>The storage network based on the given simulator instance.</returns>
        private StorageNetwork CreateStorageNetwork(IDrawableNetSimSimulator simulator)
        {
            var network = new StorageNetwork
            {
                Clients =
                    simulator.Clients.Select(
                        c =>
                        new StorageClient()
                {
                    Id        = c.Id,
                    IsOffline = c.IsOffline,
                    Left      = c.Location.Left,
                    Top       = c.Location.Top
                }).ToArray(),
                Connections =
                    simulator.Connections.Select(
                        c =>
                        new StorageConnection()
                {
                    EndpointA = c.EndPointA.Id,
                    EndpointB = c.EndPointB.Id,
                    Id        = c.Id,
                    IsOffline = c.IsOffline,
                    Metric    = c.Metric
                }).ToArray()
            };

            return(network);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetSimVisualizer"/> class.
        /// </summary>
        /// <param name="simulator">The simulator.</param>
        /// <param name="drawCanvas">The draw canvas.</param>
        public NetSimVisualizer(IDrawableNetSimSimulator simulator, Canvas drawCanvas)
        {
            this.simulator     = simulator;
            this.drawCanvas    = drawCanvas;
            this.messageStates = new Dictionary <string, NetSimMessageTransmissionStep>();

            simulator.SimulatorUpdated += this.SimulatorUpdated;
        }
Exemple #3
0
        /// <summary>
        /// Saves the network.
        /// </summary>
        /// <param name="filepath">The file path.</param>
        /// <param name="simulator">The simulator.</param>
        public void SaveNetwork(string filepath, IDrawableNetSimSimulator simulator)
        {
            JsonSerializer serializer = new JsonSerializer();

            using (StreamWriter sw = new StreamWriter(filepath))
            {
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, this.CreateStorageNetwork(simulator));
                    writer.Flush();
                    sw.Flush();
                }
            }
        }