Пример #1
0
        public static void UpdateCloudScript(string titleId, List <CloudScriptFile> cloudScriptData, Action <bool> callback)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;
            var task = PlayFabAdminAPI.UpdateCloudScriptAsync(new UpdateCloudScriptRequest()
            {
                Files   = cloudScriptData,
                Publish = true
            })
                       .ContinueWith(
                (result) =>
            {
                PlayFabSettings.TitleId            = currentPlayFabTitleId;
                PlayFabSettings.DeveloperSecretKey = currentDevKey;
                if (result.Result.Error != null)
                {
                    //Console.WriteLine(PlayFabUtil.GetErrorReport(result.Result.Error));
                    callback(false);
                    return;
                }
                if (result.IsCompleted)
                {
                    callback(true);
                }
            });
        }
Пример #2
0
        public async Task <bool> UploadCloudScript()
        {
            if (string.IsNullOrEmpty(cloudScriptPath))
            {
                LogToFile("CloudScript File Path is Null ");
                return(true);
            }

            LogToFile("Uploading CloudScript...");
            var parsedFile = ParseFile(cloudScriptPath);

            if (parsedFile == null)
            {
                LogToFile("\tAn error occurred deserializing the CloudScript.js file.", ConsoleColor.Red);
                return(false);
            }

            var files = new List <CloudScriptFile>
            {
                new CloudScriptFile
                {
                    Filename     = "CloudScript.js",
                    FileContents = parsedFile
                }
            };

            var request = new UpdateCloudScriptRequest()
            {
                Publish = true,
                Files   = files
            };

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

            var updateCloudScriptTask = await PlayFabAdminAPI.UpdateCloudScriptAsync(request);

            //updateCloudScriptTask.Wait();

            if (updateCloudScriptTask.Error != null)
            {
                OutputPlayFabError("\tCloudScript Upload Error: ", updateCloudScriptTask.Error);
                return(false);
            }

            LogToFile("\tUploaded CloudScript!", ConsoleColor.Green);
            return(true);
        }
Пример #3
0
        private async Task <bool> CloudScript(string parsedFile, CancellationToken token)
        {
            if (parsedFile == null)
            {
                LogToFile("\tAn error occurred deserializing the CloudScript.js file.");
                return(false);
            }
            var files = new List <CloudScriptFile> {
                new CloudScriptFile
                {
                    Filename     = "CloudScript.js",
                    FileContents = parsedFile
                }
            };

            var request = new UpdateCloudScriptRequest()
            {
                Publish = true,
                Files   = files
            };

            if (IsCancellationRequest(token))
            {
                return(false);
            }
            var updateCloudScriptTask = await PlayFabAdminAPI.UpdateCloudScriptAsync(request);

            if (updateCloudScriptTask.Error != null)
            {
                OutputPlayFabError("\tCloudScript Upload Error: ", updateCloudScriptTask.Error);
                return(false);
            }

            LogToFile("\tUploaded CloudScript!");
            return(true);
        }
Пример #4
0
        async public static Task <bool> UpdateCloudScript(string titleId, List <CloudScriptFile> cloudScriptData)
        {
            var currentPlayFabTitleId = PlayFabSettings.TitleId;
            var currentDevKey         = PlayFabSettings.DeveloperSecretKey;

            var title = FindTitle(titleId);

            PlayFabSettings.TitleId            = titleId;
            PlayFabSettings.DeveloperSecretKey = title.SecretKey;
            var result = await PlayFabAdminAPI.UpdateCloudScriptAsync(new UpdateCloudScriptRequest()
            {
                Files   = cloudScriptData,
                Publish = true
            });

            PlayFabSettings.TitleId            = currentPlayFabTitleId;
            PlayFabSettings.DeveloperSecretKey = currentDevKey;
            if (result.Error != null)
            {
                Console.WriteLine(PlayFabUtil.GetErrorReport(result.Error));
                return(false);
            }
            return(true);
        }
Пример #5
0
        public void Publish(bool newVersion = false)
        {
            List <CloudScriptFile> files = new List <CloudScriptFile>();
            var dirPath = ToolSettings.RootPath;

            if (Directory.Exists(dirPath))
            {
                foreach (var filePath in Directory.GetFiles(dirPath))
                {
                    var    filename = Path.GetFileName(filePath);
                    string contents = string.Empty;
                    using (StreamReader sr = File.OpenText(filePath))
                    {
                        contents = sr.ReadToEnd();
                    }
                    CloudScriptFile csfile = new CloudScriptFile()
                    {
                        Filename     = filename,
                        FileContents = contents
                    };

                    //Get previous Revision of the CloudScript File if it exists.
                    var  revCsFile = _cloudScriptFiles.Find((csf) => { return(csf.Filename == filename); });
                    bool fileDirty = false;
                    if (revCsFile != null)
                    {
                        // File exists on playfab
                        if (revCsFile.FileContents != contents)
                        {
                            fileDirty = true;
                        }
                    }
                    else
                    {
                        fileDirty = true;
                    }

                    if (fileDirty)
                    {
                        var csfiles = new List <CloudScriptFile>();
                        csfiles.Add(csfile);
                        int?version = ToolSettings.CloudScriptVersion;
                        if (newVersion)
                        {
                            version = ToolSettings.CloudScriptVersion + 1;
                        }

                        PlayFabAdminAPI.UpdateCloudScriptAsync(new UpdateCloudScriptRequest()
                        {
                            Files   = csfiles,
                            Version = version
                        }).ContinueWith((result) =>
                        {
                            Console.WriteLine("test");
                            if (!result.IsFaulted && result.IsCompleted)
                            {
                                if (result.Result.Error != null)
                                {
                                    CommandManager.WriteAsync(string.Format("Error:{0}", result.Result.Error.ErrorMessage), ConsoleColor.Red);
                                }
                                else
                                {
                                    GetCloudScriptRevision(false);
                                    CommandManager.WriteAsync(string.Format("Publishing - {0}", filePath), ConsoleColor.Yellow);
                                }
                            }
                            else
                            {
                                CommandManager.WriteAsync("Error: Not Published", ConsoleColor.Red);
                            }
                        });
                    }
                    else
                    {
                        Console.WriteLine("Already Up to Date");
                    }
                }
            }
        }