Пример #1
1
        static bool Files(IList<string> unparsed)
        {
            if (unparsed.Count > 2)
            {
                Console.Error.WriteLine("Too many arguments for [files]: {0}", String.Join(", ", unparsed.Select(s => String.Format("'{0}'", s))));
                Console.Error.WriteLine("Usage: vmc files <appname> <path>");
                return false;
            }
            if (unparsed.Count < 1)
            {
                Console.Error.WriteLine("Not enough arguments for [files]: {0}", String.Join(", ", unparsed.Select(s => String.Format("'{0}'", s))));
                Console.Error.WriteLine("Usage: vmc files <appname> <path (optional)>");
                return false;
            }

            string appname = unparsed[0];
            string path = string.Empty;
            if (unparsed.Count == 2)
                path = unparsed[1];

            IVcapClient vc = new VcapClient();
            byte[] output = vc.FilesSimple(appname, path, 0);
            if (false == output.IsNullOrEmpty())
            {
                Stream stdout = Console.OpenStandardOutput();
                stdout.Write(output, 0, output.Length);
                stdout.Flush();
            }
            return true;
        }
Пример #2
1
        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;
        }
Пример #3
0
        public ProviderResponse<Cloud> Connect(Cloud cloud)
        {
            ProviderResponse<Cloud> response = new ProviderResponse<Cloud>();
            Cloud local = cloud.DeepCopy();
            IVcapClient client = new VcapClient(local);

            try
            {
                VcapClientResult result = client.Login();
                if (!result.Success)
                    throw new Exception(result.Message);
                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;
            }
            return response;
        }
Пример #4
0
        static bool Update(IList<string> unparsed)
        {
            if (unparsed.Count != 2)
            {
                Console.Error.WriteLine("Usage: vmc update <appname> <path>");
                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;
        }
Пример #5
0
        static bool AddUser(IList<string> unparsed)
        {
            if (unparsed.Count != 0)
            {
                Console.Error.WriteLine("Too many arguments for [add_user]: {0}", String.Join(", ", unparsed.Select(s => String.Format("'{0}'", s))));
                Console.Error.WriteLine("Usage: vmc add-user");
                return false;
            }

            Console.Write("Email: ");
            string email = Console.ReadLine();

            Console.Write("Password: "******"Verify Password: "******"Creating New User: "******"OK");
                return true;
            }
            else
            {
                Console.Error.WriteLine("Passwords did not match!");
                return false;
            }
        }
Пример #6
0
        static bool Services(IList<string> unparsed)
        {
            IVcapClient vc = new VcapClient();
            IEnumerable<SystemService> systemServices = vc.GetSystemServices();
            if (false == systemServices.IsNullOrEmpty())
            {
                Console.WriteLine(systemHeader);
                foreach (SystemService s in systemServices)
                {
                    Console.WriteLine("{0}     {1}     {2}", s.Vendor, s.Version, s.Description);
                }
            }

            IEnumerable<ProvisionedService> provisionedServices = vc.GetProvisionedServices();
            if (false == provisionedServices.IsNullOrEmpty())
            {
                Console.WriteLine();
                Console.WriteLine(provisionedHeader);
                foreach (ProvisionedService s in provisionedServices)
                {
                    Console.WriteLine("{0}     {1}", s.Name, s.Vendor);
                }
            }

            return true;
        }
Пример #7
0
        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");
                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;
            }
        }
Пример #8
0
 public void Stop_App_As_User()
 {
     IVcapClient client = new VcapClient("http://api.ironfoundry.me");
     VcapClientResult rslt = client.Login("*****@*****.**", "password");
     Assert.True(rslt.Success);
     VcapUser user = client.GetUser("otheruser");
     client.ProxyAs(user);
     VcapClientResult stopRslt = client.Stop("appname");
 }
Пример #9
0
 static bool TestFiles(IList<string> unparsed)
 {
     string appname = unparsed[0];
     string path = unparsed[1];
     IVcapClient vc = new VcapClient();
     VcapFilesResult result = vc.Files(appname, path, 0);
     Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
     return true;
 }
Пример #10
0
 static bool TestStats(IList<string> unparsed)
 {
     string appname = unparsed[0];
     IVcapClient vc = new VcapClient();
     Application app = vc.GetApplication(appname);
     IEnumerable<StatInfo> result = vc.GetStats(app);
     Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
     return true;
 }
Пример #11
0
        static bool Info(IList<string> unparsed)
        {
            if (unparsed.Count != 0)
            {
                Console.Error.WriteLine("Usage: vmc info");
                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 = PrettySize(info.Limits.Memory * 1024 * 1024);
                        string mem = PrettySize(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
            {
                Console.Error.WriteLine(String.Format("Error: {0}", rslt.Message));
            }

            return rslt.Success;
        }
Пример #12
0
        public void Test_Using_Host_And_IPAddress_Against_Local()
        {
            string ipStr = "172.21.114.11";
            string host = "api.vcap.me";

            var uri = new Uri("http://" + host);
            IPAddress ip;
            IPAddress.TryParse(ipStr, out ip);
            var client = new VcapClient(uri, ip);
            client.Login("*****@*****.**", "Password");
        }
Пример #13
0
        public void Test_Using_Host_And_IPAddress()
        {
            IPAddress ip = IPAddress.Parse("127.0.0.1");
            string host = "localhost";

            var context = StartWebServer();
            Assert.Equal(context.Request.Headers["host"], host);
            context.Response.OutputStream.Close();
            StopWebServer();

            var uri = new Uri("http://" + host);
            var client = new VcapClient(uri, ip, 12345);
            client.GetInfo();
        }
Пример #14
0
        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;
        }
Пример #15
0
 public ProviderResponse<bool> ChangePassword(Cloud cloud, string newPassword)
 {
     var response = new ProviderResponse<bool>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         client.ChangePassword(newPassword);
         response.Response = true;
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
Пример #16
0
        static bool BindService(IList<string> unparsed)
        {
            if (unparsed.Count != 2)
            {
                Console.Error.WriteLine("Usage: vmc bind-service <servicename> <appname>");
                return false;
            }

            string svcname = unparsed[0];
            string appname = unparsed[1];

            IVcapClient vc = new VcapClient();
            VcapClientResult rslt = vc.BindService(svcname, appname);
            return rslt.Success;
        }
Пример #17
0
 public ProviderResponse<bool> ChangePassword(Cloud cloud, string newPassword)
 {
     var response = new ProviderResponse<bool>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         var vcapResult = client.ChangePassword(newPassword);
         if (!vcapResult.Success)
             throw new Exception(vcapResult.Message);
         response.Response = true;
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
Пример #18
0
 public void Get_All_Users_And_Apps()
 {
     var client = new VcapClient("http://api.ironfoundry.me");
     VcapClientResult rslt = client.Login("*****@*****.**", "password");
     Assert.True(rslt.Success);
     var users = client.GetUsers();
     Assert.NotEmpty(users);
     foreach (var user in users)
     {
         Console.WriteLine("User: {0}", user.Email);
         client.ProxyAs(user);
         var apps = client.GetApplications();
         foreach (var app in apps)
         {
             Console.WriteLine("\t\tApp: {0}", app.Name);
         }
     }
 }
Пример #19
0
        public void Test_Using_Host_And_IPAddress()
        {
            string ipStr = "10.0.0.1";
            string host = "api.vcap.me";

            var uri = new Uri("http://" + host);
            IPAddress ip;
            IPAddress.TryParse(ipStr, out ip);
            var client = new VcapClient(uri, ip);
            VcapRequest infoRequest = client.GetRequestForTesting();

            RestClient restClient = infoRequest.Client;
            RestRequest restRequest = infoRequest.Request;

            Assert.Equal("http://" + ipStr, restClient.BaseUrl);
            Assert.Equal(host, infoRequest.RequestHostHeader);

            Assert.NotNull(restRequest.JsonSerializer);
            Assert.IsType<NewtonsoftJsonSerializer>(restRequest.JsonSerializer);
        }
Пример #20
0
 static bool Apps(IList<string> unparsed)
 {
     if (unparsed.Count != 0)
     {
         Console.Error.WriteLine("Too many arguments for [apps]");
         Console.Error.WriteLine("Usage: vmc apps");
         return false;
     }
     IVcapClient vc = new VcapClient();
     IEnumerable<Application> apps = vc.GetApplications();
     if (false == apps.IsNullOrEmpty())
     {
         foreach (Application a in apps)
         {
             Console.WriteLine("App name: {0} Instances: {1} State: {2} Services: {3}",
                 a.Name, a.RunningInstances, a.State, String.Join(", ", a.Services));
         }
     }
     return true;
 }
Пример #21
0
        public ProviderResponse<Cloud> Connect(Cloud cloud)
        {
            var response = new ProviderResponse<Cloud>();

            if (cloud.IsDataComplete)
            {
                Cloud local = cloud.DeepCopy();
                IVcapClient client = new VcapClient(local);
                try
                {
                    client.Login();
                    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.Response = null;
                    response.Message = ex.Message;
                }
            }
            else
            {
                response.Message = Resources.CloudFoundryProvider_ConnectIncompleteData_Message;
            }

            return response;
        }
Пример #22
0
        static bool Push(IList<string> unparsed)
        {
            if (unparsed.Count < 3 || unparsed.Count > 4)
            {
                Console.Error.WriteLine("Usage: vmc push <appname> <path> <url> [service] --instances N --mem MB");
                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;
        }
        private void PerformAction(string actionName, Project project, Cloud cloud, ProjectDirectories dir,
            Action<IVcapClient, DirectoryInfo> action)
        {
            var worker = new BackgroundWorker();

            Messenger.Default.Register<NotificationMessageAction<string>>(this,
                message =>
                {
                    if (message.Notification.Equals(Messages.SetProgressData))
                        message.Execute(actionName);
                });

            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 " + actionName));

                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 (process.ExitCode != 0)
                    {
                        string message = "Asp Compile Error";
                        if (false == String.IsNullOrEmpty(output))
                        {
                            message += ": " + output;
                        }
                        dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError(message))));
                        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);
                try
                {
                    client.Login();
                }
                catch (Exception e)
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Failure: " + e.Message))));
                    return;
                }

                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(75, "Sending to " + cloud.Url))));
                if (worker.CancellationPending) { args.Cancel = true; return; }

                try
                {
                    action(client, new DirectoryInfo(dir.DeployFromPath));
                }
                catch (Exception e)
                {
                    dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressError("Failure: " + e.Message))));
                    return;
                }
                dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send(new ProgressMessage(100, actionName + " complete."))));
            };

            worker.RunWorkerAsync();
            if (!window.ShowDialog().GetValueOrDefault())
            {
                worker.CancelAsync();
            }
        }
Пример #24
0
 public ProviderResponse<bool> ValidateAccount(string serverUrl, string email, string password)
 {
     var response = new ProviderResponse<bool>();
     try
     {
         IVcapClient client = new VcapClient(serverUrl);
         client.Login(email, password);
         response.Response = true;
     }
     catch (Exception ex)
     {
         response.Response = false;
         response.Message = ex.Message;
     }
     return response;
 }
Пример #25
0
 public ProviderResponse<bool> UpdateApplication(Application app, Cloud cloud)
 {
     var response = new ProviderResponse<bool>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         client.UpdateApplication(app);
         response.Response = true;
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
Пример #26
0
 public ProviderResponse<bool> Update(Cloud cloud, Application app, string directoryToPushFrom)
 {
     var response = new ProviderResponse<bool>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         client.Update(app.Name, new System.IO.DirectoryInfo(directoryToPushFrom));
         response.Response = true;
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
Пример #27
0
 public ProviderResponse<bool> Push(Cloud cloud, string name, string url, ushort instances, string directoryToPushFrom, uint memory, string[] services)
 {
     var response = new ProviderResponse<bool>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         client.Push(name, url, instances, new System.IO.DirectoryInfo(directoryToPushFrom), memory, services);
         response.Response = true;
     }
     catch (Exception ex)
     {
         response.Response = false;
         response.Message = ex.Message;
     }
     return response;
 }
Пример #28
0
 public ProviderResponse<SafeObservableCollection<StatInfo>> GetStats(Cloud cloud, Application application)
 {
     var response = new ProviderResponse<SafeObservableCollection<StatInfo>>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         response.Response = new SafeObservableCollection<StatInfo>(client.GetStats(application));
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
Пример #29
0
 public ProviderResponse<IEnumerable<StatInfo>> GetStats(Application app, Cloud cloud)
 {
     var response = new ProviderResponse<IEnumerable<StatInfo>>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         response.Response = client.GetStats(app);
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
Пример #30
0
 public ProviderResponse<SafeObservableCollection<ProvisionedService>> GetProvisionedServices(Cloud cloud)
 {
     var response = new ProviderResponse<SafeObservableCollection<ProvisionedService>>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         response.Response = new SafeObservableCollection<ProvisionedService>(client.GetProvisionedServices());
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }