Exemple #1
0
        public void SetFirstSnapshot(PackedMemorySnapshot snapshot)
        {
            if (snapshot == null)
            {
                Debug.LogError("UIState.SetFirstSnapshot can't be called with null, if you meant to clear the open snapshots, call ClearAllOpenSnapshots");
                return;
            }
            history.Clear();
            if (FirstMode != null)
            {
                if (SecondMode != null)
                {
                    SecondMode.Clear();
                }
                SecondMode = FirstMode;
            }
            FirstMode = new SnapshotMode(DataRenderer, snapshot);

            // Make sure that the first mode is shown and that ModeChanged (fired by ShownMode if set to something different) is fired.
            if (CurrentViewMode != ViewMode.ShowFirst)
            {
                CurrentViewMode = ViewMode.ShowFirst;
            }
            else
            {
                ModeChanged(CurrentMode, CurrentViewMode);
            }
            ClearDiffMode();
        }
Exemple #2
0
 protected SnapshotMode(SnapshotMode copy)
     : base(copy)
 {
     m_RawSnapshot   = copy.m_RawSnapshot;
     m_RawSchema     = copy.m_RawSchema;
     ViewSchema      = copy.ViewSchema;
     SchemaToDisplay = copy.SchemaToDisplay;
     m_RawSchema.renderer.m_BaseRenderer.PrettyNamesOptionChanged += UpdateTableSelectionNames;
 }
Exemple #3
0
        /// <summary>
        /// Set operational mode of current snapshot
        /// </summary>
        /// <param name="mode">Operational mode that will be set</param>
        internal void SetMode(SnapshotMode mode)
        {
            if (_inSet != null)
            {
                _inSet.Snapshot.SetMode(mode);
            }

            if (_outSet != null)
            {
                _outSet.Snapshot.SetMode(mode);
            }
        }
Exemple #4
0
 void SetSnapshotMode(SnapshotMode snapshotMode)
 {
     if (this.SelectedSnapshotMode == SnapshotMode.None)
     {
         this.SelectedSnapshotMode = snapshotMode;
     }
     else
     {
         throw new ArgumentException("Only one snapshot mode can be set per execution. The snapshot mode is currently set to " +
                                     this.SelectedSnapshotMode);
     }
 }
Exemple #5
0
        /// <summary>
        /// Gets proper variant of algorithm factories for given snapshot mode.
        /// </summary>
        /// <param name="snapshotMode">The snapshot mode.</param>
        /// <returns>Reference to stored instance of algorithm factories.</returns>
        /// <exception cref="System.NotSupportedException">Unsupported snapshot mode</exception>
        public AlgorithmInstances GetAlgorithms(SnapshotMode snapshotMode)
        {
            switch (snapshotMode)
            {
            case SnapshotMode.MemoryLevel:
                return(MemoryAlgorithms);

            case SnapshotMode.InfoLevel:
                return(InfoAlgorithms);

            default:
                throw new NotSupportedException("Unsupported snapshot mode: " + snapshotMode);
            }
        }
Exemple #6
0
        public UIState()
        {
            FormattingOptions = new FormattingOptions();
            FormattingOptions.ObjectDataFormatter = new ObjectDataFormatter();
            var sizeDataFormatter = new Database.SizeDataFormatter();

            FormattingOptions.AddFormatter("size", sizeDataFormatter);
            // TODO add a format named "integer" that output in base 16,10,8,2
            //FormattingOptions.AddFormatter("integer", PointerFormatter);
            // TODO add a format named "pointer" that output in hex
            //FormattingOptions.AddFormatter("pointer", PointerFormatter);

            noMode = new SnapshotMode(FormattingOptions.ObjectDataFormatter, null);
        }
Exemple #7
0
 /// <summary>
 /// Constructs a new collector
 /// </summary>
 public SnapshotCollector(
     LoggingContext loggingContext,
     AbsolutePath snapshotFile,
     SnapshotMode snapshotMode,
     IReadOnlyCollection <string> commandLineArguments)
 {
     m_loggingContext       = loggingContext;
     m_snapshotFile         = snapshotFile;
     m_snapshotMode         = snapshotMode;
     m_environmentVariables = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
     m_mounts = new List <IMount>();
     m_files  = new ConcurrentBag <AbsolutePath>();
     m_commandLineArguments = commandLineArguments;
 }
Exemple #8
0
 public override BaseMode BuildViewSchemaClone(Database.View.ViewSchema.Builder builder)
 {
     Database.View.ViewSchema vs;
     vs = builder.Build(m_RawSchema);
     if (vs != null)
     {
         SnapshotMode copy = new SnapshotMode(this);
         copy.ViewSchema      = vs;
         copy.SchemaToDisplay = vs;
         copy.UpdateTableSelectionNames();
         return(copy);
     }
     return(null);
 }
Exemple #9
0
        /// <summary>
        /// Stops the transaction and stores the results.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <exception cref="System.Exception">Trying to stop the same transaction twice</exception>
        public void StopTransaction(Snapshot snapshot)
        {
            if (stopwatch.IsRunning)
            {
                stopwatch.Stop();

                TransactionTime = stopwatch.Elapsed.TotalMilliseconds;
                EndMemory       = GC.GetTotalMemory(false);
                Mode            = snapshot.CurrentMode;
            }
            else
            {
                throw new Exception("Trying to stop the same transaction twice");
            }
        }
Exemple #10
0
        /// <summary>
        /// Set operational mode of current snapshot
        /// </summary>
        /// <param name="mode">Operational mode that will be set</param>
        public void SetMode(SnapshotMode mode)
        {
            checkFrozenState();

            if (CurrentMode == mode)
            {
                //there is nothing to change
                return;
            }

            _statistics.Report(Statistic.ModeSwitch);

            CurrentMode = mode;
            setMode(mode);
        }
Exemple #11
0
 public override BaseMode BuildViewSchemaClone(Database.View.ViewSchema.Builder builder)
 {
     Database.View.ViewSchema vs;
     using (Profiling.GetMarker(Profiling.MarkerId.BuildViewDefinitionFile).Auto())
     {
         vs = builder.Build(m_RawSchema);
     }
     if (vs != null)
     {
         SnapshotMode copy = new SnapshotMode(this);
         copy.ViewSchema      = vs;
         copy.SchemaToDisplay = vs;
         copy.UpdateTableSelectionNames();
         return(copy);
     }
     return(null);
 }
Exemple #12
0
        void PerformSnapshotOperation(SnapshotMode mode)
        {
            switch (mode)
            {
            case SnapshotMode.TakeSnapshot:
                this.PerformTakeSnapshot();
                break;

            case SnapshotMode.Restore:
                this.PerformRestoreSnapshot();
                break;

            case SnapshotMode.Delete:
                this.PerformDeleteSnapshot();
                break;
            }
        }
Exemple #13
0
 private Exception notSupportedMode(SnapshotMode currentMode)
 {
     return(new NotSupportedException("Current mode: " + currentMode));
 }
Exemple #14
0
 public UIState()
 {
     noMode = new SnapshotMode(DataRenderer, null);
 }
        /// <summary>
        /// Initializes a new Snapshot, with the specified Date it was Posted
        /// </summary>
        /// <param name="Snapshot">The snapshot source</param>
        public Snapshot(string Snapshot, IPAddress ServerIp = null)
        {
            // Set some internal variables
            this.ServerIp = ServerIp ?? IPAddress.Loopback;
            this.Players = new List<Player>();
            this.DataString = Snapshot.Trim();
            string[] Data = DataString.Split('\\');
            Snapshot = null;

            // Check for invalid snapshot string. All snapshots have at least 36 data pairs,
            // and has an Even number of data sectors.
            if (Data.Length < 36 || Data.Length % 2 != 0)
                throw new InvalidDataException("Snapshot does not contain at least 36 elements, or contains an odd number of elements");

            // Assign server name and prefix
            this.ServerPrefix = Data[0];
            this.ServerName = Data[1];

            // Determine if we are central update. the "cdb_update" variable must be the LAST sector in snapshot
            int Mode;
            if (Data[Data.Length - 2] == "cdb_update" && Int32.TryParse(Data[Data.Length - 1], out Mode) && Mode.InRange(1, 2))
            {
                this.SnapshotMode = (Mode == 2) ? SnapshotMode.Minimal : SnapshotMode.FullSync;
            }

            // Setup our data dictionary's. We use NiceDictionary so we can easily determine missing keys in the log file
            NiceDictionary<string, string> StandardData = new NiceDictionary<string, string>(16);
            NiceDictionary<string, string> PlayerData = new NiceDictionary<string, string>();
            Dictionary<int, int> KillData = new Dictionary<int, int>();

            // Wrap parsing Key/Value snapshot data in a try block!
            try
            {
                // Convert our standard data into key => value pairs
                for (int i = 2; i < Data.Length; i += 2)
                {
                    // Format: "DataKey_PlayerIndex". PlayerIndex is NOT the Player Id
                    string[] Parts = Data[i].Split('_');
                    if (Parts.Length == 1)
                    {
                        // Add to the Standard keys
                        StandardData.Add(Data[i], Data[i + 1]);

                        // Are we at the End of File? If so stop here
                        if (Parts[0] == "EOF")
                        {
                            // Make sure to save that last players stats!!
                            if (PlayerData.Count != 0)
                            {
                                AddPlayer(new Player(PlayerData, KillData));
                                PlayerData = null;
                                KillData = null;
                            }
                            break;
                        }
                    }

                    // If the item key is "pID", then we have a new player record
                    else if (Parts[0] == "pID")
                    {
                        // If we have data, complete this player and start anew
                        if (PlayerData.Count != 0)
                        {
                            AddPlayer(new Player(PlayerData, KillData));
                            PlayerData.Clear();
                            KillData.Clear();
                        }

                        // Add new PID
                        PlayerData.Add(Parts[0], Data[i + 1]);
                    }
                    else if (Parts[0] == "mvks") // Skip mvks... kill data only needs processed once (mvns)
                        continue;
                    else if (Parts[0] == "mvns") // Player kill data
                        KillData.Add(Int32.Parse(Data[i + 1]), Int32.Parse(Data[i + 3]));
                    else
                        PlayerData.Add(Parts[0], Data[i + 1]);
                }
            }
            catch (Exception e)
            {
                throw new InvalidDataException("Error assigning Key => value pairs. See InnerException", e);
            }

            // Make sure we have a completed snapshot
            if (!StandardData.ContainsKey("EOF"))
                throw new InvalidDataException("No End of File element was found, Snapshot assumed to be incomplete.");

            // Try and set internal GameResult variables
            try
            {
                // Server data
                this.ServerPort = Int32.Parse(StandardData["gameport"]);
                this.QueryPort = Int32.Parse(StandardData["queryport"]);

                // Map Data
                this.MapName = StandardData["mapname"];
                this.MapId = Int32.Parse(StandardData["mapid"]);
                this.RoundStartTime = (int)Convert.ToDouble(StandardData["mapstart"], CultureInfo.InvariantCulture.NumberFormat);
                this.RoundEndTime = (int)Convert.ToDouble(StandardData["mapend"], CultureInfo.InvariantCulture.NumberFormat);

                // Misc Data
                this.GameMode = Int32.Parse(StandardData["gm"]);
                this.Mod = StandardData["v"]; // bf2 mod replaced the version key, since we dont care the version anyways
                this.PlayersConnected = Int32.Parse(StandardData["pc"]);

                // Army Data... There is no RWA key if there was no winner...
                this.WinningTeam = Int32.Parse(StandardData["win"]); // Temp
                this.WinningArmyId = (StandardData.ContainsKey("rwa")) ? Int32.Parse(StandardData["rwa"]) : -1;
                this.Team1ArmyId = Int32.Parse(StandardData["ra1"]);
                this.Team1Tickets = Int32.Parse(StandardData["rs1"]);
                this.Team2ArmyId = Int32.Parse(StandardData["ra2"]);
                this.Team2Tickets = Int32.Parse(StandardData["rs2"]);
            }
            catch (Exception e)
            {
                throw new InvalidDataException("Error assigning GameResult variables. See InnerException", e);
            }

            // Wrap this in a try-catch block, because we want to be able to view GameResult
            // data, even if the database is offline
            try
            {
                // Dispose when done!
                using (StatsDatabase Driver = new StatsDatabase())
                {
                    // Check for custom map, with no ID (Not defined in Constants.py)
                    if (this.MapId == 99)
                    {
                        // Check for existing map data
                        var Rows = Driver.Query("SELECT id FROM mapinfo WHERE name=@P0", this.MapName);
                        if (Rows.Count == 0)
                        {
                            // Create new MapId. Id's 700 - 1000 are reserved for unknown maps in the Constants.py file
                            // There should never be more then 300 unknown map id's, considering 1001 is the start of KNOWN
                            // Custom mod map id's. If we are at 1000 now, then we are in trouble :S
                            this.MapId = Driver.ExecuteScalar<int>("SELECT COALESCE(MAX(id), 699) FROM mapinfo WHERE id BETWEEN 700 AND 999") + 1;
                            if (this.MapId == 1000)
                                throw new Exception("Maximum unknown custom mapid has been reached. Please add this map's mapid to the Constants.py");

                            // Insert map data, so we dont lose this mapid we generated
                            Driver.Execute("INSERT INTO mapinfo(id, name, custom) VALUES (@P0, @P1, @P2)", this.MapId, this.MapName, 1);
                        }
                        else
                            this.MapId = Int32.Parse(Rows[0]["id"].ToString());
                    }

                    // Set whether or not this data is already been processed. The OR condition is because i goofed in early updates
                    // and set the timestamp to the RoundStart instead of the RoundEnd like i should have
                    this.IsProcessed = Driver.ExecuteScalar<int>(
                        "SELECT COUNT(*) FROM round_history WHERE mapid=@P0 AND time=@P1 AND (timestamp=@P2 OR timestamp=@P3)",
                        this.MapId, this.RoundTime.Seconds, this.RoundEndTime, this.RoundStartTime
                    ) > 0;
                }
            }
            catch(DbConnectException)
            {
                this.IsProcessed = false;
            }

            // Indicate whether we are a custom map
            this.IsCustomMap = (this.MapId >= 700 || this.MapId == 99);
        }
Exemple #16
0
 /// <summary>
 /// Set snapshot into given operational mode. Mode can be switched multiple times during
 /// transaction. Operations are processed according to current mode.
 /// </summary>
 /// <param name="mode">Operational mode of snapshot</param>
 protected virtual void setMode(SnapshotMode mode)
 {
     //by default there is nothing to do - operational mode should be read from CurrentMode member
 }
Exemple #17
0
 protected override void ResetState()
 {
     base.ResetState();
     this.SelectedSnapshotMode = SnapshotMode.None;
 }