public static void GitVersioningCloud(this ICakeContext cakeContext, string projectDirectory = ".", GitVersioningCloudSettings settings = null) { var fullProjectDirectory = (new DirectoryInfo(projectDirectory)).FullName; string directoryName = Path.GetDirectoryName(Assembly.GetAssembly(typeof(GitVersioningAliases)).Location); if (string.IsNullOrWhiteSpace(directoryName)) { throw new InvalidOperationException("Could not locate the Cake.GitVersioning library"); } settings ??= new GitVersioningCloudSettings(); var cloudCommand = new CloudCommand(Console.Out, Console.Error); cloudCommand.SetBuildVariables( fullProjectDirectory, settings.Metadata, settings.Version, settings.CISystem?.ToString(), settings.AllVariables, settings.CommonVariables, settings.AdditionalVariables, false ); }
//[System.Web.Services.Protocols.SoapHeader("Authentication")] public CloudResults Execute(CloudCommand command) { var results = new CloudResults(); var messages = new List <string>(); try { if (command.Action == CloudAction.Delete) { messages.Add(Delete(command.UserControllers)); messages.Add(Delete(command.UserGames)); } else { messages.Add(Upsert(command.UserControllers)); messages.Add(Upsert(command.UserGames)); } results.ErrorMessage = string.Join("\r\n", messages.Where(x => !string.IsNullOrEmpty(x))); } catch (Exception ex) { results.ErrorCode = 1; results.ErrorMessage = ex.Message; } return(results); }
/// <summary> /// Submit changed data to the cloud. /// </summary> Exception Execute <T>(CloudAction action) { var ws = new WebServiceClient(); ws.Url = SettingsManager.Options.InternetDatabaseUrl; CloudResults result = null; try { var citems = data.Where(x => x.Action == action); var items = citems.Select(x => x.Item).OfType <T>().ToList(); if (items.Count > 0) { var command = new CloudCommand(); command.Action = action; if (typeof(T) == typeof(UserGame)) { command.UserGames = items as List <UserGame>; } else if (typeof(T) == typeof(UserController)) { command.UserControllers = items as List <UserController>; } // Add secure credentials. var rsa = new JocysCom.ClassLibrary.Security.Encryption("Cloud"); if (string.IsNullOrEmpty(rsa.RsaPublicKeyValue)) { var username = rsa.RsaEncrypt("username"); var password = rsa.RsaEncrypt("password"); ws.SetCredentials(username, password); } result = ws.Execute(command); if (result.ErrorCode > 0) { queueTimer.SleepTimer.Interval = 5 * 60 * 1000; return(new Exception(result.ErrorMessage)); } foreach (var item in citems) { data.Remove(item); } } } catch (Exception ex) { // Sleep for 5 minutes; queueTimer.SleepTimer.Interval = 5 * 60 * 1000; return(ex); } return(null); }
/// <summary> /// Submit changed data to the cloud. /// </summary> void Execute <T>(CloudAction action) { MainForm.Current.LoadingCircle = true; var ws = new WebServiceClient(); ws.Url = MainForm.Current.OptionsPanel.InternetDatabaseUrlComboBox.Text; CloudResults result = null; try { var items = data.Where(x => x.Action == action).Select(x => x.Item).OfType <T>().ToList(); if (items.Count > 0) { var command = new CloudCommand(); command.Action = action; if (typeof(T) == typeof(Game)) { command.Games = items as List <Game>; } else if (typeof(T) == typeof(UserController)) { command.UserControllers = items as List <UserController>; } // Add secure credentials. var rsa = new JocysCom.ClassLibrary.Security.Encryption("Cloud"); if (string.IsNullOrEmpty(rsa.RsaPublicKeyValue)) { var username = rsa.RsaEncrypt("username"); var password = rsa.RsaEncrypt("password"); ws.SetCredentials(username, password); } result = ws.Execute(command); MainForm.Current.SetHeaderBody(result.ErrorCode == 0 ? MessageBoxIcon.Information : MessageBoxIcon.Error, result.ErrorMessage); } } catch (Exception ex) { var error = ex.Message; if (ex.InnerException != null) { error += "\r\n" + ex.InnerException.Message; } MainForm.Current.SetHeaderBody(MessageBoxIcon.Error, error); } }
private static int OnCloudCommand(string project, IReadOnlyList <string> metadata, string version, string ciSystem, bool allVars, bool commonVars, IReadOnlyList <string> define) { string searchPath = GetSpecifiedOrCurrentDirectoryPath(project); if (!Directory.Exists(searchPath)) { Console.Error.WriteLine("\"{0}\" is not an existing directory.", searchPath); return((int)ExitCodes.NoGitRepo); } var additionalVariables = new Dictionary <string, string>(); if (define is not null) { foreach (string def in define) { string[] split = def.Split(new char[] { '=' }, 2); if (split.Length < 2) { Console.Error.WriteLine($"\"{def}\" is not in the NAME=VALUE syntax required for cloud variables."); return((int)ExitCodes.BadCloudVariable); } if (additionalVariables.ContainsKey(split[0])) { Console.Error.WriteLine($"Cloud build variable \"{split[0]}\" specified more than once."); return((int)ExitCodes.DuplicateCloudVariable); } additionalVariables[split[0]] = split[1]; } } try { var cloudCommand = new CloudCommand(Console.Out, Console.Error); cloudCommand.SetBuildVariables(searchPath, metadata, version, ciSystem, allVars, commonVars, additionalVariables, AlwaysUseLibGit2); } catch (CloudCommand.CloudCommandException ex) { Console.Error.WriteLine(ex.Message); // map error codes switch (ex.Error) { case CloudCommand.CloudCommandError.NoCloudBuildProviderMatch: return((int)ExitCodes.NoCloudBuildProviderMatch); case CloudCommand.CloudCommandError.DuplicateCloudVariable: return((int)ExitCodes.DuplicateCloudVariable); case CloudCommand.CloudCommandError.NoCloudBuildEnvDetected: return((int)ExitCodes.NoCloudBuildEnvDetected); default: Report.Fail($"{nameof(CloudCommand.CloudCommandError)}: {ex.Error}"); return(-1); } } return((int)ExitCodes.OK); }