static bool Update(IList <string> unparsed) { // TODO match ruby argument parsing if (unparsed.Count != 2) { Console.Error.WriteLine("Usage: vmc update <appname> <path>"); // TODO usage statement standardization return(false); } string appname = unparsed[0]; string path = unparsed[1]; DirectoryInfo di = null; if (Directory.Exists(path)) { di = new DirectoryInfo(path); } else { Console.Error.WriteLine(String.Format("Directory '{0}' does not exist.")); return(false); } IVcapClient vc = new VcapClient(); VcapClientResult rv = vc.Update(appname, di); if (false == rv.Success) { Console.Error.WriteLine(rv.Message); } return(rv.Success); }
static bool Passwd(IList <string> unparsed) { if (unparsed.Count != 0) { Console.Error.WriteLine("Too many arguments for [change_password]: {0}", String.Join(", ", unparsed.Select(s => String.Format("'{0}'", s)))); Console.Error.WriteLine("Usage: vmc passwd"); // TODO usage statement standardization return(false); } IVcapClient vc = new VcapClient(); VcapClientResult rslt = vc.Info(); Info info = rslt.GetResponseMessage <Info>(); Console.WriteLine("Changing password for '{0}'", info.User); Console.Write("New Password: "******"Verify Password: "******"Passwords did not match!"); return(false); } }
static bool Info(IList <string> unparsed) { // TODO match ruby argument parsing if (unparsed.Count != 0) { Console.Error.WriteLine("Usage: vmc info"); // TODO usage statement standardization return(false); } IVcapClient vc = new VcapClient(); VcapClientResult rslt = vc.Info(); if (rslt.Success) { var info = rslt.GetResponseMessage <Info>(); if (result_as_json || result_as_rawjson) { if (result_as_rawjson) { Console.WriteLine(info.RawJson); } if (result_as_json) { Console.WriteLine(JsonConvert.SerializeObject(info, Formatting.Indented)); } } else { Version ver = Assembly.GetExecutingAssembly().GetName().Version; Console.WriteLine(String.Format(Resources.Vmc_InfoDisplay_1_Fmt, info.Description, info.Support, vc.CurrentUri, info.Version, ver)); if (false == info.User.IsNullOrEmpty()) { Console.WriteLine(String.Format(Resources.Vmc_InfoDisplay_2_Fmt, info.User)); } if (null != info.Usage && null != info.Limits) { string tmem = pretty_size(info.Limits.Memory * 1024 * 1024); string mem = pretty_size(info.Usage.Memory * 1024 * 1024); Console.WriteLine(String.Format(Resources.Vmc_InfoDisplay_3_Fmt, mem, tmem, info.Usage.Services, info.Limits.Services, info.Usage.Apps, info.Limits.Apps)); } } } else { // TODO standardize errors Console.Error.WriteLine(String.Format("Error: {0}", rslt.Message)); } return(rslt.Success); }
static bool DeleteService(IList <string> unparsed) { if (unparsed.Count != 1) { Console.Error.WriteLine("Usage: vmc delete-service <servicename>"); return(false); } string svcname = unparsed[0]; IVcapClient vc = new VcapClient(); VcapClientResult rslt = vc.DeleteService(svcname); return(rslt.Success); }
public ProviderResponse <Cloud> Connect(Cloud cloud) { var response = new ProviderResponse <Cloud>(); if (cloud.IsDataComplete) { Cloud local = cloud.DeepCopy(); IVcapClient client = new VcapClient(local); try { VcapClientResult result = client.Login(); if (false == result.Success) { response.Response = null; response.Message = result.Message; } else { local.AccessToken = client.CurrentToken; var applications = client.GetApplications(); var provisionedServices = client.GetProvisionedServices(); var availableServices = client.GetSystemServices(); local.Applications.Synchronize(new SafeObservableCollection <Application>(applications), new ApplicationEqualityComparer()); local.Services.Synchronize(new SafeObservableCollection <ProvisionedService>(provisionedServices), new ProvisionedServiceEqualityComparer()); local.AvailableServices.Synchronize(new SafeObservableCollection <SystemService>(availableServices), new SystemServiceEqualityComparer()); foreach (Application app in local.Applications) { var instances = GetInstances(local, app); if (instances.Response != null) { app.InstanceCollection.Synchronize(new SafeObservableCollection <Instance>(instances.Response), new InstanceEqualityComparer()); } } response.Response = local; } } catch (Exception ex) { response.Message = ex.Message; } } else { response.Message = Resources.CloudFoundryProvider_ConnectIncompleteData_Message; } return(response); }
static bool CreateService(IList <string> unparsed) { if (unparsed.Count != 2) { Console.Error.WriteLine("Usage: vmc create-service <service> <servicename>"); // TODO usage statement standardization return(false); } string svc = unparsed[0]; string svcname = unparsed[1]; IVcapClient vc = new VcapClient(); VcapClientResult rslt = vc.CreateService(svc, svcname); return(rslt.Success); }
static bool UnbindService(IList <string> unparsed) { if (unparsed.Count != 2) { Console.Error.WriteLine("Usage: vmc unbind-service <servicename> <appname>"); return(false); } string svcname = unparsed[0]; string appname = unparsed[1]; IVcapClient vc = new VcapClient(); VcapClientResult rslt = vc.UnbindService(svcname, appname); return(rslt.Success); }
static bool UnbindService(IList <string> unparsed) { // TODO match ruby argument parsing if (unparsed.Count != 2) { Console.Error.WriteLine("Usage: vmc unbind-service <servicename> <appname>"); // TODO usage statement standardization return(false); } string svcname = unparsed[0]; string appname = unparsed[1]; IVcapClient vc = new VcapClient(); VcapClientResult rslt = vc.UnbindService(svcname, appname); return(rslt.Success); }
public VcapClientResult Login(string argEmail, string argPassword) { VcapClientResult rv; var r = new VcapJsonRequest(credMgr, Method.POST, Constants.USERS_PATH, argEmail, "tokens"); r.AddBody(new { password = argPassword }); RestResponse response = r.Execute(); if (response.Content.IsNullOrEmpty()) { rv = new VcapClientResult(false, Resources.Vmc_NoContentReturned_Text); } else { var parsed = JObject.Parse(response.Content); string token = parsed.Value<string>("token"); credMgr.RegisterToken(token); rv = new VcapClientResult(); } return rv; }
static bool Push(IList <string> unparsed) { // TODO match ruby argument parsing if (unparsed.Count < 3 || unparsed.Count > 4) { Console.Error.WriteLine("Usage: vmc push <appname> <path> <url> [service] --instances N --mem MB"); // TODO usage statement standardization return(false); } string appname = unparsed[0]; string path = unparsed[1]; string fqdn = unparsed[2]; string[] serviceNames = null; if (unparsed.Count == 4) { serviceNames = new[] { unparsed[3] }; } DirectoryInfo di = null; if (Directory.Exists(path)) { di = new DirectoryInfo(path); } else { Console.Error.WriteLine(String.Format("Directory '{0}' does not exist.")); return(false); } IVcapClient vc = new VcapClient(); VcapClientResult rv = vc.Push(appname, fqdn, instances, di, memoryMB, serviceNames); if (false == rv.Success) { Console.Error.WriteLine(rv.Message); } return(rv.Success); }
static bool Target(IList <string> unparsed) { string url = command_url; if (false == unparsed.IsNullOrEmpty()) { url = unparsed[0]; } IVcapClient vc = new VcapClient(); VcapClientResult rslt = vc.Target(url); if (rslt.Success) { Console.WriteLine(String.Format(Resources.Vmc_TargetDisplay_Fmt, rslt.Message)); } else { Console.WriteLine(String.Format(Resources.Vmc_TargetNoSuccessDisplay_Fmt, rslt.Message)); } return(rslt.Success); }
public VcapClientResult Target(Uri argUri = null) { VcapClientResult rv; if (null == argUri) { // Just return current target rv = new VcapClientResult(false, credMgr.CurrentTarget.AbsoluteUriTrimmed()); } else { // "target" does the same thing as "info", but not logged in // considered valid if name, build, version and support are all non-null // without argument, displays current target VcapRequest r = base.BuildVcapRequest(false, argUri, Constants.INFO_PATH); Info info = r.Execute<Info>(); bool success = false; if (null != info) { success = false == info.Name.IsNullOrWhiteSpace() && false == info.Build.IsNullOrWhiteSpace() && false == info.Version.IsNullOrWhiteSpace() && false == info.Support.IsNullOrWhiteSpace(); } if (success) { credMgr.SetTarget(argUri); credMgr.StoreTarget(); } rv = new VcapClientResult(success, credMgr.CurrentTarget.AbsoluteUriTrimmed()); } return rv; }
static bool DeleteUser(IList <string> unparsed) { if (unparsed.Count != 1) { Console.Error.WriteLine("Too many arguments for [delete_user]: {0}", String.Join(", ", unparsed.Select(s => String.Format("'{0}'", s)))); Console.Error.WriteLine("Usage: vmc delete-user <user>"); return(false); } string email = unparsed[0]; Console.WriteLine("Deleting user '{0}' will also delete all applications and services for this user.", email); Console.Write("Do you want to do this? [yN] "); string input = Console.ReadLine(); if (input == "y") { Console.Write("Deleting User '{0}' ... ", email); IVcapClient vc = new VcapClient(); VcapClientResult result = vc.DeleteUser(email); Console.WriteLine("OK"); } return(true); }
public VcapClientResult CreateService(string argServiceName, string argProvisionedServiceName) { VcapClientResult rv; IEnumerable<SystemService> services = GetSystemServices(); if (services.IsNullOrEmpty()) { rv = new VcapClientResult(false); } else { SystemService svc = services.FirstOrDefault(s => s.Vendor == argServiceName); if (null == svc) { rv = new VcapClientResult(false); } else { // from vmc client.rb var data = new { name = argProvisionedServiceName, type = svc.Type, tier = "free", vendor = svc.Vendor, version = svc.Version, }; var r = new VcapJsonRequest(credMgr, Method.POST, Constants.SERVICES_PATH); r.AddBody(data); RestResponse response = r.Execute(); rv = new VcapClientResult(); } } return rv; }
public VcapClientResult Stop(string applicationName) { VcapClientResult rv; Application app = GetApplication(applicationName); if (app.IsStopped) { rv = new VcapClientResult(true); } else { app.Stop(); UpdateApplication(app); rv = new VcapClientResult(true); } return rv; }
public VcapClientResult Push(string name, string deployFQDN, ushort instances, DirectoryInfo path, uint memoryMB, string[] provisionedServiceNames, string framework, string runtime) { VcapClientResult rv; if (path == null) { rv = new VcapClientResult(false, "Application local location is needed"); } else if (deployFQDN == null) { rv = new VcapClientResult(false, "Please specify the url to deploy as."); } else if (framework == null) { rv = new VcapClientResult(false, "Please specify application framework"); } else { if (AppExists(name)) { rv = new VcapClientResult(false, String.Format(Resources.AppsHelper_PushApplicationExists_Fmt, name)); } else { /* * Before creating the app, ensure we can build resource list */ var resources = new List<Resource>(); ulong totalSize = addDirectoryToResources(resources, path, path.FullName); var manifest = new AppManifest { Name = name, Staging = new Staging { Framework = framework, Runtime = runtime }, Uris = new string[] { deployFQDN }, Instances = instances, Resources = new AppResources { Memory = memoryMB }, }; var r = new VcapJsonRequest(credMgr, Method.POST, Constants.APPS_PATH); r.AddBody(manifest); RestResponse response = r.Execute(); uploadAppBits(name, path); Application app = GetApplication(name); app.Start(); r = new VcapJsonRequest(credMgr, Method.PUT, Constants.APPS_PATH, name); r.AddBody(app); response = r.Execute(); bool started = isStarted(app.Name); if (started && false == provisionedServiceNames.IsNullOrEmpty()) { foreach (string svcName in provisionedServiceNames) { var servicesHelper = new ServicesHelper(credMgr); servicesHelper.BindService(svcName, app.Name); } } rv = new VcapClientResult(started); } } return rv; }
public VcapClientResult Update(string name, DirectoryInfo path) { VcapClientResult rv; if (path == null) { rv = new VcapClientResult(false, "Application local location is needed"); } else { uploadAppBits(name, path); Application app = GetApplication(name); Restart(app); rv = new VcapClientResult(); } return rv; }
private void PerformAction(string action, Project project, Cloud cloud, ProjectDirectories dir, Func <IVcapClient, DirectoryInfo, VcapClientResult> function) { var worker = new BackgroundWorker(); Messenger.Default.Register <NotificationMessageAction <string> >(this, message => { if (message.Notification.Equals(Messages.SetProgressData)) { message.Execute(action); } }); var window = new ProgressDialog(); var dispatcher = window.Dispatcher; var helper = new WindowInteropHelper(window); helper.Owner = (IntPtr)(dte.MainWindow.HWnd); worker.WorkerSupportsCancellation = true; worker.DoWork += (s, args) => { if (worker.CancellationPending) { args.Cancel = true; return; } Messenger.Default.Send(new ProgressMessage(0, "Starting " + action)); if (worker.CancellationPending) { args.Cancel = true; return; } if (!Directory.Exists(dir.StagingPath)) { dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(10, "Creating Staging Path")))); Directory.CreateDirectory(dir.StagingPath); } if (worker.CancellationPending) { args.Cancel = true; return; } if (Directory.Exists(dir.DeployFromPath)) { dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(10, "Creating Precompiled Site Path")))); Directory.Delete(dir.DeployFromPath, true); } if (worker.CancellationPending) { args.Cancel = true; return; } dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(30, "Preparing Compiler")))); VsWebSite.VSWebSite site = project.Object as VsWebSite.VSWebSite; if (site != null) { site.PreCompileWeb(dir.DeployFromPath, true); } else { string frameworkPath = (site == null) ? project.GetFrameworkPath() : String.Empty; if (worker.CancellationPending) { args.Cancel = true; return; } string objDir = Path.Combine(dir.ProjectDirectory, "obj"); if (Directory.Exists(objDir)) { Directory.Delete(objDir, true); // NB: this can cause precompile errors } var process = new System.Diagnostics.Process() { StartInfo = new ProcessStartInfo() { FileName = Path.Combine(frameworkPath, "aspnet_compiler.exe"), Arguments = String.Format("-nologo -v / -p \"{0}\" -f -u -c \"{1}\"", dir.ProjectDirectory, dir.DeployFromPath), CreateNoWindow = true, ErrorDialog = false, UseShellExecute = false, RedirectStandardOutput = true } }; if (worker.CancellationPending) { args.Cancel = true; return; } dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(40, "Precompiling Site")))); process.Start(); string output = process.StandardOutput.ReadToEnd(); process.WaitForExit(); if (false == String.IsNullOrEmpty(output)) { dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Asp Compile Error: " + output)))); return; } } dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(50, "Logging in to Cloud Foundry")))); if (worker.CancellationPending) { args.Cancel = true; return; } var client = new VcapClient(cloud); VcapClientResult result = client.Login(); if (result.Success == false) { dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Failure: " + result.Message)))); return; } dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(75, "Sending to " + cloud.Url)))); if (worker.CancellationPending) { args.Cancel = true; return; } result = function(client, new DirectoryInfo(dir.DeployFromPath)); if (result.Success == false) { dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Failure: " + result.Message)))); return; } dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(100, action + " complete.")))); }; worker.RunWorkerAsync(); if (!window.ShowDialog().GetValueOrDefault()) { worker.CancelAsync(); } }
static bool Login(IList <string> unparsed) { bool failed = true; ushort tries = 0; while (failed && tries < 3) { string email = command_email; if (false == unparsed.IsNullOrEmpty()) { email = unparsed[0]; } if (prompt_ok && email.IsNullOrWhiteSpace()) { Console.Write(Resources.Vmc_EmailPrompt_Text); email = Console.ReadLine(); } string password = command_password; if (prompt_ok && password.IsNullOrWhiteSpace()) { Console.Write(Resources.Vmc_PasswordPrompt_Text); password = readPassword(); } Console.WriteLine(); if (email.IsNullOrWhiteSpace()) { Console.Error.WriteLine(Resources.Vmc_NeedEmailPrompt_Text); return(false); } if (password.IsNullOrWhiteSpace()) { Console.Error.WriteLine(Resources.Vmc_NeedPasswordPrompt_Text); return(false); } IVcapClient vc = new VcapClient(); try { VcapClientResult rslt = vc.Login(email, password); if (rslt.Success) { Console.WriteLine(String.Format(Resources.Vmc_LoginSuccess_Fmt, vc.CurrentUri)); failed = false; } else { Console.Error.WriteLine(String.Format(Resources.Vmc_LoginFail_Fmt, vc.CurrentUri)); } } catch (Exception e) { Console.Error.WriteLine(String.Format(Resources.Vmc_LoginError_Fmt, vc.CurrentUri, e.Message)); } ++tries; } return(false == failed); }