Пример #1
0
        public void DeleteApplication()
        {
            var worker = new BackgroundWorker {
                WorkerReportsProgress = true
            };

            SetProgressTitle("Delete Application");
            worker.ProgressChanged += WorkerProgressChanged;
            worker.DoWork          += (s, e) =>
            {
                worker.ReportProgress(30, "Deleting Application: " + SelectedApplication.Name);
                ProviderResponse <bool> appResult = provider.Delete(SelectedApplication.DeepCopy(), Cloud.DeepCopy());
                if (!appResult.Response)
                {
                    worker.ReportProgress(-1, appResult.Message);
                    return;
                }
                e.Result = appResult.Response;
            };
            worker.RunWorkerCompleted += (s, e) =>
            {
                Application applicationToRemove =
                    Cloud.Applications.SingleOrDefault((i) => i.Name == SelectedApplication.Name);
                if (applicationToRemove != null)
                {
                    int index = Cloud.Applications.IndexOf(applicationToRemove);
                    Cloud.Applications.RemoveAt(index);
                }
                Messenger.Default.Send(new ProgressMessage(100, "Application Deleted."));
            };
            worker.RunWorkerAsync();
            Messenger.Default.Send(new NotificationMessageAction <bool>(Messages.Progress, c => { }));
        }
Пример #2
0
 private void RefreshSelectedApplication(Application application)
 {
     SelectedApplication.PropertyChanged           -= SelectedApplicationPropertyChanged;
     SelectedApplication.Resources.PropertyChanged -= SelectedApplicationPropertyChanged;
     SelectedApplication.Merge(application);
     SelectedApplication.PropertyChanged           += SelectedApplicationPropertyChanged;
     SelectedApplication.Resources.PropertyChanged += SelectedApplicationPropertyChanged;
 }
 public InstanceTreeViewItemViewModel(Instance instance, ApplicationTreeViewItemViewModel parentApplication)
     : base(parentApplication, true)
 {
     Messenger.Default.Send(new NotificationMessageAction<ICloudFoundryProvider>(
                                Messages.GetCloudFoundryProvider, p => provider = p));
     app = parentApplication.Application;
     this.instance = instance;
     dispatcher = Dispatcher.CurrentDispatcher;
 }
Пример #4
0
        public string GetLogs(Application argApp, ushort argInstance)
        {
            string logoutput = "";

            logoutput = "====stderr.log====\n";
            logoutput = logoutput + GetStdErrLog(argApp, argInstance);
            logoutput = logoutput + "\n====stdout.log====\n";
            logoutput = logoutput + GetStdOutLog(argApp, argInstance);
            logoutput = logoutput + "\n====startup.log====\n";
            logoutput = logoutput + GetStartupLog(argApp, argInstance);

            return logoutput;
        }
Пример #5
0
        public IEnumerable<StatInfo> GetStats(VcapUser user, Application app)
        {
            VcapRequest r = base.BuildVcapRequest(Constants.AppsResource, app.Name, "stats");
            IRestResponse response = r.Execute();
            var tmp = JsonConvert.DeserializeObject<SortedDictionary<int, StatInfo>>(response.Content);

            var rv = new List<StatInfo>();
            foreach (KeyValuePair<int, StatInfo> kvp in tmp)
            {
                StatInfo si = kvp.Value;
                si.ID = kvp.Key;
                rv.Add(si);
            }
            return rv.ToArrayOrNull();
        }
        public ApplicationTreeViewItemViewModel(Application application, CloudTreeViewItemViewModel parentCloud)
            : base(parentCloud, true)
        {
            Messenger.Default.Send(new NotificationMessageAction<ICloudFoundryProvider>(
                                       Messages.GetCloudFoundryProvider, p => provider = p));
            OpenApplicationCommand = new RelayCommand<MouseButtonEventArgs>(OpenApplication);
            StartApplicationCommand = new RelayCommand(StartApplication, CanStart);
            StopApplicationCommand = new RelayCommand(StopApplication, CanStop);
            RestartApplicationCommand = new RelayCommand(RestartApplication, CanStop);
            DeleteApplicationCommand = new RelayCommand(DeleteApplication);

            Application = application;
            Application.InstanceCollection.CollectionChanged += InstanceCollection_CollectionChanged;
            Dispatcher = Dispatcher.CurrentDispatcher;
        }
        /// <summary>
        /// This method get application record by pass ip parameter synchronously
        /// </summary>
        /// <param name="ip"></param>
        /// <returns>
        /// Return null or one record of application that IP field is equal to passed parameter
        /// </returns>
        public Application GetApplicationByIP(string ip)
        {
            if (string.IsNullOrWhiteSpace(ip) == true)
            {
                return(null);
            }

            Models.Application application =
                DbSet
                .Where(current => current.IP == ip)
                .FirstOrDefault()
                .Application
            ;

            return(application);
        }
Пример #8
0
        /// <summary>
        /// This method get application record by pass url parameter synchronously
        /// </summary>
        /// <param name="url"></param>
        /// <returns>
        /// Return null or one record of application that url field is equal to passed parameter
        /// </returns>
        public Models.Application GetApplicationByURL(string url)
        {
            if (string.IsNullOrWhiteSpace(url) == true)
            {
                return(null);
            }

            Models.Application application =
                DbSet
                .Where(current => current.Url == url)
                .FirstOrDefault()
                .Application
            ;

            return(application);
        }
Пример #9
0
 public void ExecutePrint(StudentExt objStudent)
 {
     //1.定义一个Excel工作簿
     Microsoft.Office.Interop.Excel.Application excelApp = new Application();
     //2.获取已创建好的工作簿路径
     string excelBookPath = Environment.CurrentDirectory + "\\StudentInfo.xls";
     //3.将现有工作簿加入已定义的工作簿集合
     excelApp.Workbooks.Add(excelBookPath);
     //4.获取第一个工作表
     Worksheet objSheet = (Worksheet)excelApp.Worksheets[1];
     //5.在当前Excel中写入数据
     if (objStudent.StuImage.Length != 0)
     {
         //将图片保存在指定的位置
         Image objImage = (Image)new
             StudentManager.SerializeObjectToString().DeserializeObject(objStudent.StuImage);
         if (File.Exists(Environment.CurrentDirectory + "\\Student.jpg"))
             File.Delete(Environment.CurrentDirectory + "\\Student.jp");
         else
         {
             //保存图片到系统目录(当前会保存到debug或者release文件夹中)
             objImage.Save(Environment.CurrentDirectory + "\\Student.jpg");
             //将图片插入到Excel中
             objSheet.Shapes.AddPicture(Environment.CurrentDirectory + "\\Student.jpg", MsoTriState.msoFalse, MsoTriState.msoTrue, 10, 50, 70, 80);
             //使用完毕后删除保存的图片
             File.Delete(Environment.CurrentDirectory + "\\Student.jpg");
         }
     }
     //写入其他数据
     objSheet.Cells[4, 4] = objStudent.StudentId;
     objSheet.Cells[4, 6] = objStudent.StudentName;
     objSheet.Cells[4, 8] = objStudent.Gender;
     objSheet.Cells[6, 4] = objStudent.ClassName;
     objSheet.Cells[6, 6] = objStudent.PhoneNumber;
     objSheet.Cells[8, 4] = objStudent.StudentAddress;
     //6.打印预览
     excelApp.Visible = true;
     excelApp.Sheets.PrintPreview(true);
     //7.释放对象
     excelApp.Quit();
     System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);//释放
     excelApp = null;
 }
Пример #10
0
        /// <summary>
        /// This method get application record by pass url parameter asynchronously
        /// </summary>
        /// <param name="url"></param>
        /// <returns>
        /// Return null or one record of application that url field is equal to passed parameter
        /// </returns>
        public virtual async Task <Application> GetApplicationByURLAsync(string url)
        {
            if (string.IsNullOrWhiteSpace(url) == true)
            {
                return(null);
            }

            Models.Application application = null;
            await System.Threading.Tasks.Task.Run(() =>
            {
                application =
                    DbSet
                    .Where(current => current.Url == url)
                    .FirstOrDefault()
                    .Application
                ;
            });

            return(application);
        }
Пример #11
0
 public IEnumerable<StatInfo> GetStats(Application argApp)
 {
     return GetStats(null, argApp);
 }
Пример #12
0
 public IEnumerable<ExternalInstance> GetInstances(Application app)
 {
     var info = new InfoHelper(proxyUser, credMgr);
     return info.GetInstances(app);
 }
Пример #13
0
 public void UpdateApplication(Application app)
 {
     var helper = new AppsHelper(proxyUser, credMgr);
     helper.UpdateApplication(app);
 }
Пример #14
0
 public string GetLogs(Application app, ushort instanceNumber)
 {
     var info = new InfoHelper(proxyUser, credMgr);
     return info.GetLogs(app, instanceNumber);
 }
Пример #15
0
 public void Delete(Application application)
 {
     var r = BuildVcapJsonRequest(Method.DELETE, Constants.APPS_PATH, application.Name);
     r.Execute();
 }
Пример #16
0
 public void Restart(Application app)
 {
     var helper = new AppsHelper(proxyUser, credMgr);
     helper.Restart(app);
 }
Пример #17
0
 public void Restart(Application applicationName)
 {
     Stop(applicationName);
     Start(applicationName);
 }
 public ProviderResponse<VcapFilesResult> GetFiles(Cloud cloud, Application application, string path, ushort instanceId)
 {
     var response = new ProviderResponse<VcapFilesResult>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         var result = client.Files(application.Name, path, instanceId);
         response.Response = result;
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
 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;
 }
 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;
 }
 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;
 }
 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;
 }
        public ProviderResponse<IEnumerable<Instance>> GetInstances(Cloud cloud, Application app)
        {
            var response = new ProviderResponse<IEnumerable<Instance>>();
            try
            {
                IVcapClient client = new VcapClient(cloud);
                var stats = client.GetStats(app);
                var instances = new SafeObservableCollection<Instance>();
                if (stats != null)
                {

                    foreach (var stat in stats)
                    {
                        var instance = new Instance()
                                       {
                                           Id = stat.ID,
                                           State = stat.State
                                       };
                        if (stat.Stats != null)
                        {
                            instance.Cores = stat.Stats.Cores;
                            instance.MemoryQuota = stat.Stats.MemQuota/1048576;
                            instance.DiskQuota = stat.Stats.DiskQuota/1048576;
                            instance.Host = stat.Stats.Host;
                            instance.Parent = app;
                            instance.Uptime = TimeSpan.FromSeconds(Convert.ToInt32(stat.Stats.Uptime));

                            if (stat.Stats.Usage != null)
                            {
                                instance.Cpu = stat.Stats.Usage.CpuTime/100;
                                instance.Memory = Convert.ToInt32(stat.Stats.Usage.MemoryUsage)/1024;
                                instance.Disk = Convert.ToInt32(stat.Stats.Usage.DiskUsage)/1048576;
                            }
                        }
                        instances.Add(instance);
                    }
                }
                response.Response = instances;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }
            return response;
        }
Пример #24
0
 public string GetStdOutLog(Application argApp, ushort argInstance)
 {
     var r = base.BuildVcapRequest(Constants.AppsResource, argApp.Name, argInstance, "files/logs/stdout.log");
     return r.Execute().Content;
 }
Пример #25
0
 public void Stop(Application application)
 {
     application.Stop();
     UpdateApplication(application);
 }
Пример #26
0
 public IEnumerable<StatInfo> GetStats(Application app)
 {
     var info = new InfoHelper(proxyUser, credMgr);
     return info.GetStats(app);
 }
 public ProviderResponse<Application> GetApplication(Application app, Cloud cloud)
 {
     var response = new ProviderResponse<Application>();
     try
     {
         IVcapClient client = new VcapClient(cloud);
         response.Response = client.GetApplication(app.Name);
         var instancesResponse = this.GetInstances(cloud, app);
         if (instancesResponse.Response != null)
             response.Response.InstanceCollection.Synchronize(new SafeObservableCollection<Instance>(instancesResponse.Response),new InstanceEqualityComparer());
     }
     catch (Exception ex)
     {
         response.Message = ex.Message;
     }
     return response;
 }
Пример #28
0
 public void Start(Application application)
 {
     application.Start();
     UpdateApplication(application);
     if (!IsStarted(application.Name, 180))
     {
         throw new VcapException("Failed to start application.");
     }
 }
Пример #29
0
 private void RefreshSelectedApplication(Application application)
 {
     SelectedApplication.PropertyChanged -= SelectedApplicationPropertyChanged;
     SelectedApplication.Resources.PropertyChanged -= SelectedApplicationPropertyChanged;
     SelectedApplication.Merge(application);
     SelectedApplication.PropertyChanged += SelectedApplicationPropertyChanged;
     SelectedApplication.Resources.PropertyChanged += SelectedApplicationPropertyChanged;
 }
Пример #30
0
        public void UpdateApplication(Application application)
        {
            var r = BuildVcapJsonRequest(Method.PUT, Constants.APPS_PATH, application.Name);
            r.AddBody(application);
            var response = r.Execute<VcapResponse>();

            if (response != null && !string.IsNullOrEmpty(response.Description))
            {
                throw new VcapException(response.Description);
            }
        }
Пример #31
0
 public string GetStdErrLog(Application argApp, ushort argInstance)
 {
     var r = base.BuildVcapRequest(Constants.APPS_PATH, argApp.Name, argInstance, "files/logs/stderr.log");
     return r.Execute().Content;
 }
Пример #32
0
 public IEnumerable<Crash> GetAppCrash(Application app)
 {
     var r = base.BuildVcapRequest(Constants.APPS_PATH, app.Name, "crashes");
     return r.Execute<Crash[]>();
 }
Пример #33
0
 public void GetFiles(Application argApp, ushort argInstance)
 {
     throw new NotImplementedException();
 }
Пример #34
0
 public IEnumerable<ExternalInstance> GetInstances(Application argApp)
 {
     var r = base.BuildVcapRequest(Constants.AppsResource, argApp.Name, "instances");
     var instances = r.Execute<Dictionary<string, ExternalInstance>>();
     return instances.Values.ToArrayOrNull();
 }
Пример #35
0
 public void Stop(Application app)
 {
     var helper = new AppsHelper(proxyUser, credMgr);
     helper.Stop(app);
 }