Exemplo n.º 1
0
        private void OnFileDownloadReq(Datagram datagram)
        {
            FileDownloadReq req = datagram.UnSerialData <FileDownloadReq>();

            string path = FileRootPath + "\\" + datagram.Sender.ToString();

            path += ("" == req.Path ? "" : req.Path + "\\") + req.Name;
            Download download    = new Download(path);
            Guid     download_id = Guid.NewGuid();

            if (FileCache.TryAdd(download_id, download))
            {
                FileDownloadRes res = new FileDownloadRes
                {
                    DownloadID = download_id,
                    Size       = (int)download.Length
                };
                datagram.DataType    = DatagramType.Client;
                datagram.MessageType = CloudDatagramDefine.FileDownloadRes;

                datagram.Datas = res.ToByteArray();
                if (!Send(datagram.ToByteArray()))
                {
                    Notify(IKXTServer.LogLevel.Error, "数据发送异常");
                    Close();
                }
            }
            else
            {
                download.Close();
            }
        }
Exemplo n.º 2
0
        void IDataSender.FileDownload(Guid request_id, FileDownloadReq req)
        {
            Datagram datagram = new Datagram
            {
                DataType    = DatagramType.Cloud,
                MessageType = CloudDatagramDefine.FileDownloadReq,
                RequestID   = request_id,
                Datas       = req.ToByteArray()
            };

            if (!Send(datagram))
            {
                RunningDatas.InfoNotify("网络连接失败 请重启软件后重试");
            }
        }