private async Task <bool> StatisticDefination(string parsedFile, CancellationToken token)
        {
            var statisticDefinitions = JsonWrapper.DeserializeObject <List <PlayerStatisticDefinition> >(parsedFile);

            foreach (var item in statisticDefinitions)
            {
                if (IsCancellationRequest(token))
                {
                    return(false);
                }
                LogToFile("\tUploading: " + item.StatisticName);

                var request = new CreatePlayerStatisticDefinitionRequest()
                {
                    StatisticName         = item.StatisticName,
                    VersionChangeInterval = item.VersionChangeInterval,
                    AggregationMethod     = item.AggregationMethod
                };

                var createStatTask = await PlayFabAdminAPI.CreatePlayerStatisticDefinitionAsync(request);

                if (createStatTask.Error != null)
                {
                    if (createStatTask.Error.Error == PlayFabErrorCode.StatisticNameConflict)
                    {
                        LogToFile("\tStatistic Already Exists, Updating values: " + item.StatisticName);
                        var updateRequest = new UpdatePlayerStatisticDefinitionRequest()
                        {
                            StatisticName         = item.StatisticName,
                            VersionChangeInterval = item.VersionChangeInterval,
                            AggregationMethod     = item.AggregationMethod
                        };
                        if (IsCancellationRequest(token))
                        {
                            return(false);
                        }
                        var updateStatTask = await PlayFabAdminAPI.UpdatePlayerStatisticDefinitionAsync(updateRequest);

                        if (updateStatTask.Error != null)
                        {
                            OutputPlayFabError("\t\tStatistics Definition Error: " + item.StatisticName, updateStatTask.Error);
                        }
                        else
                        {
                            LogToFile("\t\tStatistics Definition:" + item.StatisticName + " Updated");
                        }
                    }
                    else
                    {
                        OutputPlayFabError("\t\tStatistics Definition Error: " + item.StatisticName, createStatTask.Error);
                    }
                }
                else
                {
                    LogToFile("\t\tStatistics Definition: " + item.StatisticName + " Created");
                }
            }
            return(true);
        }
Exemple #2
0
        public async Task <bool> UploadStatisticDefinitions()
        {
            if (string.IsNullOrEmpty(statsDefPath))
            {
                LogToFile("Player Statistics Definitions File Path is Null ");
                return(true);
            }


            LogToFile("Updating Player Statistics Definitions ...");
            var parsedFile = ParseFile(statsDefPath);

            var statisticDefinitions = JsonWrapper.DeserializeObject <List <PlayerStatisticDefinition> >(parsedFile);

            foreach (var item in statisticDefinitions)
            {
                LogToFile("\tUploading: " + item.StatisticName);

                var request = new CreatePlayerStatisticDefinitionRequest()
                {
                    StatisticName         = item.StatisticName,
                    VersionChangeInterval = item.VersionChangeInterval,
                    AggregationMethod     = item.AggregationMethod
                };

                if (token.IsCancellationRequested)
                {
                    return(true);
                }

                var createStatTask = await PlayFabAdminAPI.CreatePlayerStatisticDefinitionAsync(request);

                if (createStatTask.Error != null)
                {
                    if (createStatTask.Error.Error == PlayFabErrorCode.StatisticNameConflict)
                    {
                        LogToFile("\tStatistic Already Exists, Updating values: " + item.StatisticName,
                                  ConsoleColor.DarkYellow);
                        var updateRequest = new UpdatePlayerStatisticDefinitionRequest()
                        {
                            StatisticName         = item.StatisticName,
                            VersionChangeInterval = item.VersionChangeInterval,
                            AggregationMethod     = item.AggregationMethod
                        };

                        if (token.IsCancellationRequested)
                        {
                            return(true);
                        }

                        var updateStatTask = await PlayFabAdminAPI.UpdatePlayerStatisticDefinitionAsync(updateRequest);

                        //updateStatTask.Wait();
                        if (updateStatTask.Error != null)
                        {
                            OutputPlayFabError("\t\tStatistics Definition Error: " + item.StatisticName,
                                               updateStatTask.Error);
                        }
                        else
                        {
                            LogToFile("\t\tStatistics Definition:" + item.StatisticName + " Updated",
                                      ConsoleColor.Green);
                        }
                    }
                    else
                    {
                        OutputPlayFabError("\t\tStatistics Definition Error: " + item.StatisticName,
                                           createStatTask.Error);
                    }
                }
                else
                {
                    LogToFile("\t\tStatistics Definition: " + item.StatisticName + " Created", ConsoleColor.Green);
                }
            }

            return(true);
        }
Exemple #3
0
        private static bool UploadStatisticDefinitions()
        {
            if (string.IsNullOrEmpty(statsDefPath))
            {
                return(false);
            }

            LogToFile("Updating Player Statistics Definitions ...");
            var parsedFile = ParseFile(statsDefPath);

            var statisticDefinitions = JsonWrapper.DeserializeObject <List <PlayerStatisticDefinition> >(parsedFile);

            foreach (var item in statisticDefinitions)
            {
                LogToFile(string.Format("\tUploading: {0}", item.StatisticName));

                var request = new CreatePlayerStatisticDefinitionRequest()
                {
                    StatisticName         = item.StatisticName,
                    VersionChangeInterval = item.VersionChangeInterval,
                    AggregationMethod     = item.AggregationMethod
                };

                var createStatTask = PlayFabAdminAPI.CreatePlayerStatisticDefinitionAsync(request);
                createStatTask.Wait();

                if (createStatTask.Result.Error != null)
                {
                    if (createStatTask.Result.Error.Error == PlayFabErrorCode.StatisticNameConflict)
                    {
                        LogToFile(string.Format("\tStatistic Already Exists, Updating values: {0}", item.StatisticName), ConsoleColor.DarkYellow);
                        var updateRequest = new UpdatePlayerStatisticDefinitionRequest()
                        {
                            StatisticName         = item.StatisticName,
                            VersionChangeInterval = item.VersionChangeInterval,
                            AggregationMethod     = item.AggregationMethod
                        };

                        var updateStatTask = PlayFabAdminAPI.UpdatePlayerStatisticDefinitionAsync(updateRequest);
                        updateStatTask.Wait();
                        if (updateStatTask.Result.Error != null)
                        {
                            OutputPlayFabError("\t\tStatistics Definition Error: " + item.StatisticName, updateStatTask.Result.Error);
                        }
                        else
                        {
                            LogToFile(string.Format("\t\tStatistics Definition: {0} Updated ", item.StatisticName), ConsoleColor.Green);
                        }
                    }
                    else
                    {
                        OutputPlayFabError("\t\tStatistics Definition Error: " + item.StatisticName, createStatTask.Result.Error);
                    }
                }
                else
                {
                    LogToFile(string.Format("\t\tStatistics Definition: {0} Created ", item.StatisticName), ConsoleColor.Green);
                }
            }
            return(true);
        }