示例#1
0
 public void BeginDownload(ServerFileInfo serverInfo)
 {
     mDownLoadMgr = new NewFileSystem.FileDownloadManager();
     mDownLoadMgr.Init();
     mDownLoadMgr.BeginSynchronize(serverInfo, delegate() {
         mPersistentFileListDic = new Dictionary <string, FileDetailInfo>(mDownLoadMgr.GetPersistentFileList());
         Dictionary <string, FileDetailInfo> streamingFileListDic = mDownLoadMgr.GetStreamingFileList();
         if (null != streamingFileListDic)
         {
             mStreamingFileListDic = new Dictionary <string, FileDetailInfo>(streamingFileListDic);
         }
         mDownLoadMgr.Destroy();
         mDownLoadMgr = null;
         GameMain.Instance.EventMgr.PostObjectEvent(EventId.DownLoadFinish, null);
     });
 }
示例#2
0
    protected void ServerFileDelete_Click(object sender, EventArgs e)
    {
        //需要对该页面有执行权限
        if (!WebUtil.CheckPrivilege(WebConfig.FunctionUpdateServerDispenseFiles, OpType.EXECUTE, Session))
        {
            Response.Redirect(WebConfig.PageNotEnoughPrivilege, true);
        }

        LinkButton link     = sender as LinkButton;
        int        delId    = int.Parse(link.ID.Substring(10));
        string     fileName = (ServerFileList.Rows[delId + 1].Cells[1].Controls[1] as Literal).Text;
        //string fileName = ServerFileList.Rows[delId + 1].Cells[1].Text;
        ServerFileInfo file = ftpServer.GetServerFileInfo(fileName);

        if (ftpServer != null && file != null)
        {
            if (file.Directory)
            {
                if (ftpServer.RemoveDir(ftpServer.RootUri + file.Name + "/"))
                {
                    LabelOpMsg.Text = StringDef.Processing;
                }
                else
                {
                    LabelOpMsg.Text = (StringDef.OperationFail + ftpServer.Result);
                }
            }
            else
            {
                LabelOpMsg.Text = StringDef.Processing;
                if (ftpServer.DeleteFile(fileName))
                {
                    LabelOpMsg.Text = StringDef.Processing;
                }
                else
                {
                    LabelOpMsg.Text = (StringDef.OperationFail + ftpServer.Result);
                }
            }

            ftpServer.ListFile();
        }
    }
示例#3
0
        /// <summary>
        /// 加载文件信息
        /// </summary>
        /// <returns></returns>
        public static async Task <ServerFileInfo> LoadServerInfoAsync(string url)
        {
            var       httpClient = HttpClientFactory.Instance.GetHttpClient(url);
            Stopwatch stopwatch  = new Stopwatch();

            stopwatch.Start();
            HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);

            if (httpResponseMessage.IsSuccessStatusCode == false)
            {
                throw new Exception(httpResponseMessage.ReasonPhrase);
            }
            stopwatch.Stop();
            Console.WriteLine($"Get responseHeadersRead {stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            var contentLength = httpResponseMessage.Content.Headers.ContentLength;
            var isResumable   = contentLength.HasValue && contentLength.Value > 0;//await IsResumable(url);

            stopwatch.Stop();
            Console.WriteLine($"Get isResumable {stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            var downloadContent = await httpResponseMessage.Content.ReadAsStreamAsync();

            stopwatch.Stop();
            Console.WriteLine($"Get downloadContent {stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();
            var serverFileInfo = new ServerFileInfo
            {
                Name            = httpResponseMessage.Content.Headers?.ContentDisposition?.FileName ?? httpResponseMessage.RequestMessage.RequestUri.Segments.LastOrDefault(),
                MediaType       = httpResponseMessage.Content.Headers.ContentType.MediaType,
                Size            = httpResponseMessage.Content.Headers.ContentLength.GetValueOrDefault(),
                Extension       = httpResponseMessage.Content.Headers.ContentType.MediaType.GetFileExtension(),
                IsResumable     = isResumable,
                DownloadContent = downloadContent,
                TotalReadBytes  = 0
            };

            stopwatch.Stop();
            Console.WriteLine($"Get serverFileInfo {stopwatch.ElapsedMilliseconds}");
            return(serverFileInfo);
        }
示例#4
0
 protected void LinkButtonDeleteServerFile_Click(object sender, EventArgs e)
 {
     try
     {
         if (server != null)
         {
             //需要对该页面有执行权限
             if (!WebUtil.CheckPrivilege(WebConfig.FunctionUpdateServerUpdateServerState, OpType.EXECUTE, Session))
             {
                 Response.Redirect(WebConfig.PageNotEnoughPrivilege, true);
             }
             LinkButton lb = sender as LinkButton;
             if (lb != null)
             {
                 string        path       = ViewState[ParamPath] as string;
                 StringBuilder msgBuilder = new StringBuilder();
                 foreach (DataGridItem item in DataGridServerFileList.Items)
                 {
                     CheckBox checkBox = item.Cells[0].FindControl("CheckBoxServerFile") as CheckBox;
                     if (checkBox != null && checkBox.Checked)
                     {
                         LinkButton linkButtonFile = item.Cells[1].FindControl("LinkButtonViewDir") as LinkButton;
                         if (linkButtonFile != null)
                         {
                             string fileName = linkButtonFile.Text;
                             if (fileName != null && fileName.Length != 0)
                             {
                                 ServerFileInfo file = server.GetServerFileInfo(fileName);
                                 if (file != null)
                                 {
                                     if (file.Directory)
                                     {
                                         if (server.RemoveDir(server.RootUri + path + file.Name + WebConfig.UpdateServerPathDelimiter))
                                         {
                                             Thread.Sleep(DeleteServerFileDelayTime);
                                             msgBuilder.Append(string.Format("{0}[{1}]<br />", server.Result, file.Name));
                                         }
                                         else
                                         {
                                             msgBuilder.Append(string.Format("[删除目录[{0}]失败]{1}<br />", file.Name, server.Result));
                                         }
                                     }
                                     else
                                     {
                                         if (server.DeleteFile(path + fileName))
                                         {
                                             Thread.Sleep(DeleteServerFileDelayTime);
                                             msgBuilder.Append(string.Format("{0}[{1}]<br />", server.Result, file.Name));
                                         }
                                         else
                                         {
                                             msgBuilder.Append(string.Format("[删除文件[{0}]失败]{1}<br />", file.Name, server.Result));
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 Message.Text += msgBuilder.Length == 0 ? StringDef.OperationSucceed : msgBuilder.ToString();
                 Message.Text += "<br />";
                 ListServerFiles();
                 Thread.Sleep(RefreshServerFilesDelayTime);
                 GetServerFileList();
             }
         }
     }
     catch (Exception ex)
     {
         FSEye.Util.DebugLog(ex.ToString());
     }
 }