Beispiel #1
0
        /// <summary>
        /// Initializes the logging of a new Simulation
        /// </summary>
        /// <param name="destination">Where to save the data</param>
        /// <param name="disease">The Disease used in the Simulation</param>
        public void Initialize(string destination, Disease disease, int mapX, int mapY, int simintervall, int snapintervall, long duration)
        {
            _simInfo = SimulationInfo.InitializeFromRuntime(disease, mapX, mapY, simintervall, snapintervall, duration);

            _target = destination;
            _snapshots = new Queue<TickSnapshot>();

            _writer = new SnapshotWriter();
            _writer.QueueEmptied += (s, e) => WriterQueueEmpty.Raise(s, e);
            _writer.SnapshotWritten += (s, e) => SnapshotWritten.Raise(s, e);
            TookSnapshot += _writer.Recieve;
        }
Beispiel #2
0
        /// <summary>
        /// Opens a new .sim File and restores the contents to Runtime;
        /// Only one can be opened at a time
        /// </summary>
        /// <param name="path">The path where the file is located</param>
        public void OpenSimFile(string path)
        {
            if (_currentArchive != null)
                _currentArchive.Dispose();

            if (File.Exists(path))
                _currentArchive = ZipFile.Open(path, ZipArchiveMode.Read);
            else
                throw new FileNotFoundException("File not found!");

            ZipArchiveEntry first = null;
            Entries = new List<string>();

            foreach (ZipArchiveEntry entry in _currentArchive.Entries) // Reading all entries
                if (!entry.Name.Equals("header")) // All except header...
                    Entries.Add(entry.Name);

            long minEntry = Entries.Min(x => long.Parse(x.Split('_')[0]));
            first = _currentArchive.Entries.Where(
                    x => !x.Name.Equals("header") &&
                    int.Parse(x.Name.Split('_')[0]) == minEntry
                    ).First();

            try // If there's no header, the file is corrupt // yeah, with two r's
            {
                byte[] file = _currentArchive.GetEntry("header").ToByteArray(); // Reading Header
                SimInfo = SimulationInfo.InitializeFromFile(file);
            }
            catch (Exception e)
            {
                throw new SimFileCorruptException("The Header was not found!", e);
            }

            _creator = new MapCreator(SimInfo.MapX, SimInfo.MapY);
            _creator.setTarget(Path.GetDirectoryName(path)); // Setting Default Destination

            LoadedSnapshot = null;

            if (first == null) // If there's no first Snapshot, the file corrupt, no sense in empty logs
                throw new SimFileCorruptException("No first Snapshot found!");

            byte[] temp = first.ToByteArray();// Reading first Snap to initialize Maxima
            TickSnapshot tick = TickSnapshot.InitializeFromFile(temp);
            _creator.InitializeMaxima(tick);
            WriteMessage(first.Name + " is first. Initializing...");
            LoadedSnapshot = tick; // First Snaphsot stays loaded
            Entries.Sort();
        }