public bool Loop() { while (_state == States.Working) { } PackageManagerService.SetState(MainPackageStates.Idle); return(false); }
public bool Loop() { if (_state != States.Exit) { return(false); } _state = States.None; PackageManagerService.SetState(MainPackageStates.Idle); //Returning true will exit the program. return(true); }
private void Execute() { switch (_state) { case States.TitleData: #region Update Title Data Keys if (!_titleData.FromProcessed) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Getting Title Data from: " + _commandArgs.FromTitleId); PlayFabService.GetTitleData(_commandArgs.FromTitleId, (success, result) => { if (!success || result.Data.Count == 0) { Console.WriteLine("No Title Data found, skipping"); SetNextState(); } else { Console.WriteLine("Title Data Keys Found: " + result.Data.Count.ToString()); _titleData.Data = result.Data; _titleData.FromProcessed = true; } }); } if (!_titleData.ToProcessed && _titleData.FromProcessed) { if (_titleData.Data.Count == 0) { _titleData.ToProcessed = true; SetNextState(); break; } var kvp = _titleData.Pop(); Console.WriteLine("Saving Title Data from: " + _commandArgs.FromTitleId + " To: " + _commandArgs.ToTitleId); PlayFabService.UpdateTitleData(_commandArgs.ToTitleId, kvp, (success) => { if (!success) { Console.WriteLine("Save Title Data Failed, skipping"); SetNextState(); } }); } #endregion break; case States.TitleInternalData: #region Update Title Internal Data Keys if (!_titleInternalData.FromProcessed) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Getting Title Interal Data from: " + _commandArgs.FromTitleId); PlayFabService.GetTitleInternalData(_commandArgs.FromTitleId, (success, result) => { if (!success || result.Data.Count == 0) { Console.WriteLine("No Title Internal Data found, skipping"); SetNextState(); } else { Console.WriteLine("Title Internal Data Keys Found: " + result.Data.Count.ToString()); _titleInternalData.Data = result.Data; _titleInternalData.FromProcessed = true; } }); } if (!_titleInternalData.ToProcessed && _titleInternalData.FromProcessed) { if (_titleInternalData.Data.Count == 0) { _titleInternalData.ToProcessed = true; SetNextState(); break; } var kvp = _titleInternalData.Pop(); Console.WriteLine("Saving Title Interal Data from: " + _commandArgs.FromTitleId + " To: " + _commandArgs.ToTitleId); PlayFabService.UpdateTitleInternalData(_commandArgs.ToTitleId, kvp, (success) => { if (!success) { Console.WriteLine("Save Title Interal Data Failed, skipping"); SetNextState(); } }); } #endregion break; case States.Currency: #region Update Currency Types if (!_currencyData.FromProcessed) { Console.WriteLine("Getting Currency Types Data from: " + _commandArgs.FromTitleId); PlayFabService.GetCurrencyData(_commandArgs.FromTitleId, (success, vcData) => { if (!success || vcData.Count == 0) { Console.WriteLine("Error Fetching Currency Type Data, skipping"); SetNextState(); return; } _currencyData.Data = vcData; _currencyData.FromProcessed = true; }); } if (!_currencyData.ToProcessed && _currencyData.FromProcessed) { if (_currencyData.Data == null) { _currencyData.ToProcessed = true; SetNextState(); break; } PlayFabService.UpdateCurrencyData(_commandArgs.ToTitleId, _currencyData.Data, (success) => { if (!success) { Console.WriteLine("Save Title Data Failed."); _cts.Cancel(); } _currencyData.Data = null; }); } #endregion break; case States.CloudScript: #region Update CloudScript File if (!_cloudScriptData.FromProcessed) { Console.WriteLine("Getting CloudScript Data from: " + _commandArgs.FromTitleId); PlayFabService.GetCloudScript(_commandArgs.FromTitleId, (success, data) => { if (!success || data.Count == 0) { Console.WriteLine("Error Fetching CloudScript Data, skipping."); SetNextState(); return; } _cloudScriptData.Data = data; _cloudScriptData.FromProcessed = true; }); } if (!_cloudScriptData.ToProcessed && _cloudScriptData.FromProcessed) { if (_cloudScriptData.Data == null) { _cloudScriptData.ToProcessed = true; SetNextState(); break; } Console.WriteLine("Updating CloudScript on Title: " + _commandArgs.ToTitleId); PlayFabService.UpdateCloudScript(_commandArgs.ToTitleId, _cloudScriptData.Data, (success) => { //if (!success) //{ // Console.WriteLine("Save CloudScript Failed."); // _cts.Cancel(); //} _cloudScriptData.Data = null; }); } #endregion break; case States.Files: #region Update Content Files //Start by creating a temp directory var path = AppDomain.CurrentDomain.BaseDirectory + "temp"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!_cdnData.FromProcessed) { PlayFabService.GetContentList(_commandArgs.FromTitleId, (success, data) => { if (!success) { Console.WriteLine("Error Fetching CloudScript Data, skipping"); SetNextState(); return; } _cdnData.Data = data; _cdnData.FromProcessed = true; }); } if (!_cdnData.ToProcessed && _cdnData.FromProcessed) { if (_cdnData.Data.Count == 0 && _cdnData.FileList.Count == 0) { _cdnData.ToProcessed = true; _cdnData.Data = null; _cdnData.FileList = null; Directory.Delete(path, true); SetNextState(); break; } if (_cdnData.Data.Count > 0) { var isDone = false; PlayFabService.DownloadFile(_commandArgs.FromTitleId, path, _cdnData.popData(), (success, filePath, data) => { if (success) { _cdnData.FileList.Add(new CdnFileDataMigration.UploadFile() { Data = data, FilePath = filePath }); } isDone = true; }); do { //block until done. } while (!isDone); break; } if (_cdnData.Data.Count == 0 && _cdnData.FileList.Count > 0) { var isUploadDone = false; PlayFabService.UploadFile(_commandArgs.ToTitleId, _cdnData.popFileList(), (success) => { isUploadDone = true; }); do { //Block until this file upload is done. } while (!isUploadDone); } } #endregion break; case States.Catalogs: #region Update Catalog if (_catalogData.FromProcessed && _catalogData.ToProcessed) { SetNextState(); break; } if (!_catalogData.FromProcessed) { //TODO: Make this support multiple catalogs Console.WriteLine("Getting Catalog Data for Main Catalog only"); PlayFabService.GetCatalogData(_commandArgs.FromTitleId, (success, catalogVersion, catalog) => { if (!success) { Console.WriteLine("Error Fetching CloudScript Data, skipping"); SetNextState(); } _catalogData.Data = catalog; _catalogData.CatalogVersion = catalogVersion; _catalogData.FromProcessed = true; }); } if (!_catalogData.ToProcessed && _catalogData.FromProcessed) { Console.WriteLine("Updating Catalog on Title: " + _commandArgs.ToTitleId); PlayFabService.UpdateCatalogData(_commandArgs.ToTitleId, _catalogData.CatalogVersion, true, _catalogData.Data, (success) => { if (!success) { Console.WriteLine("Save Catalog Failed, skipping."); SetNextState(); } _catalogData.Data = null; _catalogData.CatalogVersion = null; _catalogData.ToProcessed = true; }); } #endregion break; case States.Stores: #region Update Stores if (_storeData.IsComplete) { _storeData.Data = null; _storeData.MarketingModel = null; _storeData.StoreId = null; _storeData.CatalogVersion = null; SetNextState(); break; } if (!_storeData.FromProcessed) { if (_storeData.StoreList.Count == 0) { SetNextState(); break; } var currentStoreId = _storeData.popStoreId(); Console.WriteLine("Getting Store Data for StoreID: " + currentStoreId); PlayFabService.GetStoreData(_commandArgs.FromTitleId, currentStoreId, (success, catalogVersion, storeId, marketingModel, store) => { if (!success) { Console.WriteLine("Error Fetching Store Data, Skipping."); SetNextState(); } _storeData.FromProcessed = true; _storeData.Data = store; _storeData.CatalogVersion = catalogVersion; _storeData.StoreId = storeId; _storeData.MarketingModel = marketingModel; }); } if (!_storeData.ToProcessed && _storeData.FromProcessed) { var currentStoreId = _storeData.StoreId; PlayFabService.UpdateStoreData(_commandArgs.ToTitleId, _storeData.StoreId, _storeData.CatalogVersion, _storeData.MarketingModel, _storeData.Data, (success) => { if (!success) { Console.WriteLine("Save Store Failed, Skipping."); SetNextState(); } _storeData.Data = null; _storeData.CatalogVersion = null; if (_storeData.StoreList.Count == 0) { _storeData.ToProcessed = true; _storeData.IsComplete = true; } else { _storeData.ToProcessed = false; _storeData.FromProcessed = false; } }); } #endregion break; case States.DropTables: #region Update Drop Tables if (_droptableData.FromProcessed && _droptableData.ToProcessed) { SetNextState(); break; } if (!_droptableData.FromProcessed) { //TODO: Make this support multiple catalogs Console.WriteLine("Getting Drop Table Data for Main Catalog only"); PlayFabService.GetDropTableData(_commandArgs.FromTitleId, (success, catalog) => { if (!success) { Console.WriteLine("Error Fetching CloudScript Data, skipping"); SetNextState(); } _droptableData.Data = new Queue <List <RandomResultTable> >(); Dictionary <string, RandomResultTableListing> listing = new Dictionary <string, RandomResultTableListing>(catalog); List <RandomResultTable> thisList = new List <RandomResultTable>(); foreach (var v in listing) { bool referencesDropTable = false; foreach (var item in v.Value.Nodes) { if (item.ResultItemType == ResultTableNodeType.TableId) { referencesDropTable = true; break; } } if (!referencesDropTable) { RandomResultTable table = new RandomResultTable(); table.TableId = v.Value.TableId; table.Nodes = v.Value.Nodes; thisList.Add(table); } } if (thisList.Count != 0) { while (true) { _droptableData.Data.Enqueue(thisList); foreach (var item in thisList) //remove from pending list { listing.Remove(item.TableId); } //Add any references List <RandomResultTable> nextList = new List <RandomResultTable>(); foreach (var item in listing) { bool referencesCurrent = false; foreach (var node in item.Value.Nodes) { if (node.ResultItemType == ResultTableNodeType.TableId && thisList.Any(x => x.TableId == node.ResultItem)) { referencesCurrent = true; break; } } if (referencesCurrent) { RandomResultTable table = new RandomResultTable(); table.TableId = item.Value.TableId; table.Nodes = item.Value.Nodes; nextList.Add(table); } } if (nextList.Count == 0) { break; } thisList = nextList; } } _droptableData.FromProcessed = true; }); } if (!_droptableData.ToProcessed && _droptableData.FromProcessed) { Console.WriteLine("Updating Drop Tables on Title: " + _commandArgs.ToTitleId); PlayFabService.UpdateDropTableData(_commandArgs.ToTitleId, _droptableData.Data.Dequeue(), (success) => { if (!success) { Console.WriteLine("Save Catalog Failed, skipping."); SetNextState(); } //_catalogData.Data = null; //_catalogData.CatalogVersion = null; if (_droptableData.Data.Count == 0) { _droptableData.Data = null; _droptableData.ToProcessed = true; } }); } #endregion break; case States.Complete: Console.WriteLine("Migration Complete."); Console.ForegroundColor = ConsoleColor.White; PackageManagerService.SetState(MainPackageStates.Idle); _cts.Cancel(); break; } }
public bool Loop() { var waitForLogin = false; switch (_state) { case States.WaitForUsername: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(""); Console.WriteLine("Username:"******""); Console.WriteLine("Password:"******""); Console.WriteLine("2FA Token:"); break; case States.Login: waitForLogin = true; PlayFabService.Login(_username, _password, _2faToken, (success, devKey) => { if (!success) { PackageManagerService.SetState(MainPackageStates.Idle); _state = States.Idle; waitForLogin = false; return; } _DeveloperClientToken = devKey; Console.ForegroundColor = ConsoleColor.White; _state = States.GetStudios; Loop(); waitForLogin = false; }); break; case States.GetStudios: waitForLogin = true; PlayFabService.GetStudios(_DeveloperClientToken, (success) => { PackageManagerService.SetState(MainPackageStates.Idle); _state = States.Idle; waitForLogin = false; }); break; case States.Idle: default: break; } //TODO: Paul Help? do { //Block util login call is done. } while (waitForLogin); return(false); }
static void Main(string[] args) { _args = args; _lineSb = new StringBuilder(); //Parse Args and determine if this is a CLI or Console mode. if (args.Length > 0 && !_argsRead) { _isCLI = true; foreach (var a in args) { _lineSb.Append(a + " "); } _line = _lineSb.ToString(); _argsRead = true; _args = new string[0]; } else { _readLine = true; _argsRead = true; } //Init PlayFab Service Settings PlayFabService.Init(); //Load Settings File PlayFabService.Load(); //Out put to screen some fancy playfab jazz Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.Green; Console.Write(".oO={ "); Console.ForegroundColor = ConsoleColor.White; Console.Write("PlayFab Power Tools CLI"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(" }=Oo."); Console.ForegroundColor = ConsoleColor.White; //if this is a console app then we want to show them how to get help. if (!_isCLI) { Console.WriteLine(""); Console.WriteLine("Type: 'Help' for a list of commands"); Console.WriteLine(""); Console.Write(">"); } else { Console.WriteLine(""); Console.WriteLine(""); } //Load all the packages that process commands var type = typeof(iStatePackage); var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => type.IsAssignableFrom(p) && p.Name != "iStatePackage"); //foreach package we need to register with Package Manager foreach (var t in types) { var packageType = (iStatePackage)Activator.CreateInstance(t); packageType.RegisterMainPackageStates(packageType); } //get the correct package for the state we are in _currentPackage = PackageManagerService.GetPackage(); //This is the main program loop. do { //if we are a console app, read the command that is entered. if (_args.Length == 0 && _readLine) { if (!_isTypedTextHidden) { //Read the line input from the console. _line = Console.ReadLine(); } else { //Read the line in a different way. ConsoleKeyInfo key; do { key = Console.ReadKey(true); if (key.Key != ConsoleKey.Enter) { var s = string.Format("{0}", key.KeyChar); _lineSb.Append(s); } } while (key.Key != ConsoleKey.Enter); _line = _lineSb.ToString(); } } //Set read line to true, not it will only be false if we came from a CLI. _readLine = true; var loopReturn = false; if (PackageManagerService.IsIdle()) { //If we are idle then we want to check for commands. PackageManagerService.SetState(_line); _currentPackage = PackageManagerService.GetPackage(); _isTypedTextHidden = _currentPackage.SetState(_line); loopReturn = _currentPackage.Loop(); } else { //If we are not idle, then we want to process the _line for arguments. //get the correct package for the state we are in _currentPackage = PackageManagerService.GetPackage(); //process the package state _isTypedTextHidden = _currentPackage.SetState(_line); //do package loop, which contains logic to do stuff. loopReturn = _currentPackage.Loop(); } //if this is a CLI then we just want to exit. if (!_isCLI) { //Prompt or exit. if (!loopReturn) { Console.Write(">"); } else { _line = null; } } else { _line = null; } } while (_line != null); //Always save before we completely exit. PlayFabService.Save(); }
public bool Loop() { HelpService.ShowHelp(); PackageManagerService.SetState(MainPackageStates.Idle); return(false); }