public bool Download(OnlineKernel tObject)
        {
            Request.Method = Method.POST;
            Request.AddJsonBody(tObject);
            Request.Resource = string.Format("api/{0}/Download/", Resource);
            var response = _apiRequest.Execute <ApiBoolResponseDTO>(Request);

            return(response != null && response.Value);
        }
        public bool DownloadKernel(OnlineKernel onlineKernel)
        {
            if (SettingServices.ServerIsClusterPrimary)
            {
                foreach (var tftpServer in new SecondaryServerServices().GetAllWithTftpRole())
                {
                    var result = new APICall(new SecondaryServerServices().GetToken(tftpServer.Name))
                                 .ServiceAccountApi.DownloadOnlineKernel(onlineKernel);
                    if (!result)
                    {
                        return(false);
                    }
                }
            }

            return(WebDownload(onlineKernel));
        }
Example #3
0
        protected void btnDownload_OnClick(object sender, EventArgs e)
        {
            var control = sender as Control;

            if (control != null)
            {
                var onlineKernel = new OnlineKernel();
                var gvRow        = (GridViewRow)control.Parent.Parent;
                onlineKernel.BaseVersion = gvRow.Cells[2].Text;
                onlineKernel.FileName    = gvRow.Cells[0].Text;
                if (onlineKernel.BaseVersion != null)
                {
                    var result = Call.OnlineKernelApi.Download(onlineKernel);
                    EndUserMessage = result ? "Successfully Downloaded Kernel" : "Could Not Download Kernel";
                }
            }
            PopulateKernels();
        }
        private bool WebDownload(OnlineKernel onlineKernel)
        {
            var baseUrl = "http://files.clonedeploy.org/kernels/";

            using (var wc = new WebClient())
            {
                try
                {
                    wc.DownloadFile(new Uri(baseUrl + onlineKernel.BaseVersion + "/" + onlineKernel.FileName),
                                    SettingServices.GetSettingValue(SettingStrings.TftpPath) + "kernels" +
                                    Path.DirectorySeparatorChar + onlineKernel.FileName);
                    return(true);
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                    return(false);
                }
            }
        }
 public ApiBoolResponseDTO Download(OnlineKernel onlineKernel)
 {
     return(new ApiBoolResponseDTO {
         Value = _onlineKernelServices.DownloadKernel(onlineKernel)
     });
 }