Beispiel #1
0
        public static void SaveNewScore(int score)
        {
            var appReader     = new ApplicationDataReader <HighScoreData>();
            var highScoreData = appReader.LoadData(highScoreDataFilePath);

            if (highScoreData != null)
            {
                var scores = highScoreData.GetScores();

                for (int i = 0; i < scores.Length; i++)
                {
                    if (score > scores[i])
                    {
                        scores[i] = score;
                        break;
                    }
                }

                highScoreData.SetScores(scores.OrderByDescending(x => x).ToArray());
            }
            else
            {
                var scores = new int[10];
                scores[0]     = score;
                highScoreData = new HighScoreData();
                highScoreData.SetScores(scores);
            }

            appReader.SaveData(highScoreData, highScoreDataFilePath);
        }
        public static bool HasSfxOn()
        {
            var appReader = new ApplicationDataReader <AudioData>();
            var data      = appReader.LoadData(audioDataFilePath);

            return(data.isSfxOn);
        }
        public static void SetMusic(bool musicStatus)
        {
            var appReader = new ApplicationDataReader <AudioData>();
            var data      = appReader.LoadData(audioDataFilePath);

            data.isMusicOn = musicStatus;
            appReader.SaveData(data, audioDataFilePath);
        }
        public static void SetSfx(bool sfxStatus)
        {
            var appReader = new ApplicationDataReader <AudioData>();
            var data      = appReader.LoadData(audioDataFilePath);

            data.isSfxOn = sfxStatus;
            appReader.SaveData(data, audioDataFilePath);
        }
Beispiel #5
0
        public static void SavePlayerStatus(PlayerStatusData playerStatusData = null)
        {
            var appDataReader = new ApplicationDataReader <PlayerStatusData>();

            if (playerStatusData == null)
            {
                playerStatusData = appDataReader.LoadData(playerDataFilePath);
            }
            appDataReader.SaveDataAsync(playerStatusData, playerDataFilePath);
        }
        public static void CreateInitialLoad()
        {
            var       appReader = new ApplicationDataReader <AudioData>();
            AudioData data      = new AudioData()
            {
                isMusicOn = true, isSfxOn = true
            };

            appReader.SaveData(data, audioDataFilePath);
        }
Beispiel #7
0
        public void IncreaseTimesUserHasPlayed()
        {
            var ratingRequestService = new RatingRequestService();
            var request = GetLastRequestData();


            request.timesUserHasPlayed++;

            var appReader = new ApplicationDataReader <RatingRequest>();

            appReader.SaveDataAsync(request, ratingRequestDataFilePath);
        }
Beispiel #8
0
        public RatingRequest GetLastRequestData()
        {
            var appReader   = new ApplicationDataReader <RatingRequest>();
            var requestData = appReader.LoadData(ratingRequestDataFilePath);

            if (requestData == null)
            {
                requestData = new RatingRequest();
            }

            return(requestData);
        }
        public static void SaveTimeExperience(float timeExperience)
        {
            var appReader = new ApplicationDataReader <PlayerExperienceData>();
            var data      = appReader.LoadData(playerDataFilePath);

            if (data == null)
            {
                data = new PlayerExperienceData();
            }
            data.InsertGameDuration(timeExperience);
            appReader.SaveDataAsync(data, playerDataFilePath);
        }
Beispiel #10
0
        public unsafe void TestApplicationDataReaderParseDateTime()
        {
            var datetime = DateTime.UtcNow;
            var filetime = datetime.ToFileTimeUtc();

            // DateTime object was incorrectly used. This is needed to handle bad traces from bug #6590047
            var applicationDataReader = new ApplicationDataReader((IntPtr)(int *)&datetime);

            Assert.AreEqual(datetime, applicationDataReader.ReadFileTime());

            applicationDataReader = new ApplicationDataReader((IntPtr)(int *)&filetime);
            Assert.AreEqual(datetime, applicationDataReader.ReadFileTime());
        }
Beispiel #11
0
        static PlayerStatusData CreateInitialPlayerStatus(ApplicationDataReader <PlayerStatusData> appDataReader)
        {
            PlayerStatusData playerData = new PlayerStatusData(0, 1, 1);

            //player always owns the first ship by default
            playerData.GetOwnedShipsIDs().Add(1);

            playerData.IncreaseDashUpgrade();

            appDataReader.SaveDataAsync(playerData, playerDataFilePath);
            SavePlayerStatus(playerData);

            return(playerData);
        }
        private void ProcessServicePackageInactiveEvent(
            EventRecord eventRecord,
            string taskName,
            string eventName,
            EtwEventTimestamp eventTimestamp,
            bool implicitlyInactive)
        {
            ApplicationDataReader reader = new ApplicationDataReader(
                eventRecord.UserData,
                eventRecord.UserDataLength);

            // Verify event version
            int eventVersion = reader.ReadInt32();

            if (eventVersion > MaxServicePackageDeactivatedEventVersion)
            {
                Utility.TraceSource.WriteError(
                    TraceType,
                    "Unexpected version {0} encountered for event name {1}. Event will be ignored.",
                    eventVersion,
                    eventName);
                return;
            }

            // Get the node name
            string nodeName = reader.ReadUnicodeString();

            // Get the application instance ID
            string appInstanceId = reader.ReadUnicodeString();

            // Get the service package name
            string servicePackageName = reader.ReadUnicodeString();

            Utility.TraceSource.WriteInfo(
                TraceType,
                "ETW event received. Task {0}, event {1}, node name: {2}, application instance ID: {3}, service package name: {4}.",
                taskName,
                eventName,
                nodeName,
                appInstanceId,
                servicePackageName);

            // Delete record from service package table
            this.RemoveServicePackageHandler(nodeName, appInstanceId, servicePackageName, eventTimestamp, true, implicitlyInactive);
        }
Beispiel #13
0
        public void SaveNewRequest(bool userHasClickedToRate)
        {
            var request = GetLastRequestData();

            if (!userHasClickedToRate)
            {
                request.timesUserHastPostponedRequest++;
            }

            request.userHasClickedToRate = userHasClickedToRate;
            request.lastDayRequest       = DateTime.Today.Day;
            request.lastMonthRequest     = DateTime.Today.Month;
            request.lastYearRequest      = DateTime.Today.Year;

            var appReader = new ApplicationDataReader <RatingRequest>();

            appReader.SaveDataAsync(request, ratingRequestDataFilePath);
        }
Beispiel #14
0
        public static PlayerStatusData LoadPlayerStatus()
        {
            var appDataReader = new ApplicationDataReader <PlayerStatusData>();

            if (!HasPlayerDataFile())
            {
                PlayerStatusData playerData = CreateInitialPlayerStatus(appDataReader);
                _playerDataInstance = playerData;
                return(_playerDataInstance);
            }

            if (_playerDataInstance == null)
            {
                _playerDataInstance = appDataReader.LoadData(playerDataFilePath);
            }

            return(_playerDataInstance);
        }
Beispiel #15
0
        private Dictionary <string, string> ConvertEventToKvp(EventRecord eventRecord, EventDefinition eventDefinition)
        {
            var keyValueDictionary = new Dictionary <string, string>();

            try
            {
                var dataReader = new ApplicationDataReader(eventRecord.UserData, eventRecord.UserDataLength);

                foreach (FieldDefinition fieldDef in eventDefinition.Fields)
                {
                    string propertyValue = null;
                    switch (fieldDef.Type)
                    {
                    case FieldDefinition.FieldType.UnicodeString:
                    {
                        propertyValue = dataReader.ReadUnicodeString();
                        break;
                    }

                    case FieldDefinition.FieldType.AnsiString:
                    {
                        propertyValue = dataReader.ReadAnsiString();
                        break;
                    }

                    case FieldDefinition.FieldType.Boolean:
                    {
                        propertyValue = dataReader.ReadBoolean().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.UInt8:
                    {
                        propertyValue = dataReader.ReadUInt8().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.UInt16:
                    {
                        propertyValue = dataReader.ReadUInt16().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.UInt32:
                    {
                        unchecked
                        {
                            propertyValue = dataReader.ReadUInt32().ToString();
                        }
                        break;
                    }

                    case FieldDefinition.FieldType.UInt64:
                    {
                        unchecked
                        {
                            propertyValue = dataReader.ReadUInt64().ToString();
                        }
                        break;
                    }

                    case FieldDefinition.FieldType.Int8:
                    {
                        propertyValue = dataReader.ReadInt8().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.Int16:
                    {
                        propertyValue = dataReader.ReadInt16().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.Int32:
                    {
                        propertyValue = dataReader.ReadInt32().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.Int64:
                    {
                        propertyValue = dataReader.ReadInt64().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.HexInt32:
                    {
                        unchecked
                        {
                            propertyValue = dataReader.ReadUInt32().ToString();
                        }
                        break;
                    }

                    case FieldDefinition.FieldType.HexInt64:
                    {
                        unchecked
                        {
                            propertyValue = dataReader.ReadUInt64().ToString();
                        }
                        break;
                    }

                    case FieldDefinition.FieldType.Float:
                    {
                        propertyValue = dataReader.ReadFloat().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.Double:
                    {
                        propertyValue = dataReader.ReadDouble().ToString();
                        break;
                    }

                    case FieldDefinition.FieldType.DateTime:
                    {
                        propertyValue = dataReader.ReadFileTime().ToString("yyyy-dd-M--HH-mm-ss");
                        break;
                    }

                    case FieldDefinition.FieldType.Guid:
                    {
                        propertyValue = dataReader.ReadGuid().ToString();
                        break;
                    }

                    default:
                    {
                        this.traceSource.WriteError(
                            logSourceId,
                            "Event of type {0}.{1} has an unsupported field of type {2}.",
                            eventDefinition.TaskName,
                            eventDefinition.EventName,
                            fieldDef.Type);
                        break;
                    }
                    }

                    if (propertyValue != null)
                    {
                        keyValueDictionary[fieldDef.Name] = propertyValue;
                    }
                }
            }
            catch (Exception e)
            {
                this.traceSource.WriteError(
                    logSourceId,
                    "Failed to get all the fields of event of type {0}.{1}. Exception info: {2}.",
                    eventDefinition.TaskName,
                    eventDefinition.EventName,
                    e);

                return(null);
            }

            // our Platform event can't have a field names TimeStamp today. Still keeping this check till we add a unit test for that.
            if (!keyValueDictionary.ContainsKey(TimeStampFieldName))
            {
                keyValueDictionary.Add(TimeStampFieldName, DateTime.FromFileTimeUtc(eventRecord.EventHeader.TimeStamp).ToString(TimeStampFormat));
            }

            return(keyValueDictionary);
        }
        // returns an object that would be either a string or a double, or null if failed
        private static object GetEtwEventRecordValue(ApplicationDataReader reader, FieldDefinition fieldDef, string logSourceId)
        {
            object value = null;

            switch (fieldDef.Type)
            {
            case FieldDefinition.FieldType.UnicodeString:
                value = reader.ReadUnicodeString();
                break;

            case FieldDefinition.FieldType.AnsiString:
                value = reader.ReadAnsiString();
                break;

            case FieldDefinition.FieldType.Boolean:
                value = reader.ReadBoolean() ? "true" : "false";
                break;

            case FieldDefinition.FieldType.UInt8:
                value = (double)reader.ReadUInt8();
                break;

            case FieldDefinition.FieldType.UInt16:
                value = (double)reader.ReadUInt16();
                break;

            case FieldDefinition.FieldType.UInt32:
                value = (double)reader.ReadUInt32();
                break;

            case FieldDefinition.FieldType.UInt64:
                value = (double)reader.ReadUInt64();
                break;

            case FieldDefinition.FieldType.Int8:
                value = (double)reader.ReadInt8();
                break;

            case FieldDefinition.FieldType.Int16:
                value = (double)reader.ReadInt16();
                break;

            case FieldDefinition.FieldType.Int32:
                value = (double)reader.ReadInt32();
                break;

            case FieldDefinition.FieldType.Int64:
                value = (double)reader.ReadInt64();
                break;

            case FieldDefinition.FieldType.HexInt32:
                value = (double)reader.ReadUInt32();
                break;

            case FieldDefinition.FieldType.HexInt64:
                value = (double)reader.ReadUInt64();
                break;

            case FieldDefinition.FieldType.Float:
                value = (double)reader.ReadFloat();
                break;

            case FieldDefinition.FieldType.Double:
                value = (double)reader.ReadDouble();
                break;

            case FieldDefinition.FieldType.DateTime:
                value = reader.ReadFileTime().ToString();
                break;

            case FieldDefinition.FieldType.Guid:
                value = reader.ReadGuid().ToString();
                break;

            default:
                Utility.TraceSource.WriteError(
                    logSourceId,
                    "Unsupported field of type {0}.",
                    fieldDef.Type);
                break;
            }

            return(value);
        }
        public static bool ReadFieldsFromEventRecord(
            EventRecord eventRecord,
            EventDefinition eventDefinition,
            TraceAggregationConfig traceAggregationConfig,
            out List <KeyValuePair <string, double> > numericalFields,
            out List <KeyValuePair <string, string> > stringFields,
            out string diffFieldValueString,
            string logSourceId)
        {
            numericalFields      = new List <KeyValuePair <string, double> >();
            stringFields         = new List <KeyValuePair <string, string> >();
            diffFieldValueString = string.Empty;

            // Figure out how many fields the event has
            int fieldCount = eventDefinition.Fields.Count;

            if (0 == fieldCount)
            {
                Utility.TraceSource.WriteError(
                    logSourceId,
                    "No fields found in event of type {0}.{1}.",
                    eventDefinition.TaskName,
                    eventDefinition.EventName);
                return(false);
            }

            // Get the field names and values
            try
            {
                ApplicationDataReader reader = new ApplicationDataReader(
                    eventRecord.UserData,
                    eventRecord.UserDataLength);

                foreach (FieldDefinition fieldDef in eventDefinition.Fields)
                {
                    var fieldValue = TelemetryUtility.GetEtwEventRecordValue(reader, fieldDef, logSourceId);
                    if (traceAggregationConfig.FieldsAndAggregationConfigs.ContainsKey(fieldDef.Name))
                    {
                        if (null != fieldValue)
                        {
                            if (fieldValue is string)
                            {
                                stringFields.Add(new KeyValuePair <string, string>(fieldDef.Name, (string)fieldValue));
                            }
                            else
                            {
                                if (fieldValue is double)
                                {
                                    numericalFields.Add(new KeyValuePair <string, double>(fieldDef.Name, (double)fieldValue));
                                }
                                else
                                {
                                    Utility.TraceSource.WriteError(
                                        logSourceId,
                                        "Unexpected field value type read. TaskName : {0}, EventName : {1}, FieldName : {2}, FieldType : {3}",
                                        eventDefinition.TaskName,
                                        eventDefinition.EventName,
                                        fieldDef.Name,
                                        fieldDef.Type.ToString());
                                }
                            }
                        }
                    }

                    // look if field is the differentiator field
                    if (traceAggregationConfig.DifferentiatorFieldName == fieldDef.Name)
                    {
                        if (null != fieldValue)
                        {
                            diffFieldValueString = fieldValue.ToString();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Utility.TraceSource.WriteError(
                    logSourceId,
                    "Failed to get all the fields of event of type {0}.{1}. Exception info: {2}.",
                    eventDefinition.TaskName,
                    eventDefinition.EventName,
                    e);
                return(false);
            }

            return(true);
        }
        public static PlayerExperienceData LoadTimeExperience()
        {
            var appReader = new ApplicationDataReader <PlayerExperienceData>();

            return(appReader.LoadData(playerDataFilePath));
        }
Beispiel #19
0
        public static int GetHighestScore()
        {
            var appReader = new ApplicationDataReader <HighScoreData>();

            return(appReader.LoadData(highScoreDataFilePath).GetHighestScore());
        }
        public static bool HasAudioData()
        {
            var appReader = new ApplicationDataReader <AudioData>();

            return(appReader.LoadData(audioDataFilePath) != null);
        }
        private void ProcessServicePackageActiveEvent(EventRecord eventRecord, string taskName, string eventName, EtwEventTimestamp eventTimestamp, int maxVersion)
        {
            ApplicationDataReader reader = new ApplicationDataReader(
                eventRecord.UserData,
                eventRecord.UserDataLength);

            // Verify event version
            int eventVersion = reader.ReadInt32();

            if (eventVersion > maxVersion)
            {
                Utility.TraceSource.WriteError(
                    TraceType,
                    "Unexpected version {0} encountered for event name {1}. Event will be ignored.",
                    eventVersion,
                    eventName);
                return;
            }

            // Get the node name
            string nodeName = reader.ReadUnicodeString();

            // Get the root directory for the run layout
            string runLayoutRoot = reader.ReadUnicodeString();

            // Get the application instance ID
            string appInstanceId = reader.ReadUnicodeString();

            // Get the application rollout version
            string appRolloutVersion = reader.ReadUnicodeString();

            // Get the service package name
            string servicePackageName = reader.ReadUnicodeString();

            // Get the service package rollout version
            string serviceRolloutVersion = reader.ReadUnicodeString();

            // Create a record for the application data table
            ServicePackageTableRecord record = new ServicePackageTableRecord(
                nodeName,
                appInstanceId,
                appRolloutVersion,
                servicePackageName,
                serviceRolloutVersion,
                runLayoutRoot,
                default(DateTime));

            Utility.TraceSource.WriteInfo(
                TraceType,
                "ETW event received. Task {0}, event {1}, node name: {2}, application instance ID: {3}, application rollout version: {4}, service package name: {5}, service rollout version: {6}.",
                taskName,
                eventName,
                nodeName,
                record.ApplicationInstanceId,
                record.ApplicationRolloutVersion,
                record.ServicePackageName,
                record.ServiceRolloutVersion);

            // Add or update record in service package table
            this.AddOrUpdateServicePackageHandler(
                nodeName,
                appInstanceId,
                eventTimestamp.Timestamp,
                servicePackageName,
                record,
                eventTimestamp,
                true);
        }