public string ReadFileSeg(Stream stream, string companyID, string fileName, int fileLength, int totalSegments, int currentSegmentsIndex, int dataLength)
        {
            lock (_readOnly)
            {
                string result = "";
                if (totalSegments < currentSegmentsIndex)
                {
                    return("请求当前段号大于文件同段数");
                }

                byte[] buffer = ADFileCached.getInstance().ReadFileSegment(companyID, fileName, fileLength, totalSegments, currentSegmentsIndex);
                if (buffer == null)
                {
                    buffer = ADFileCached.getInstance().ReadFile(companyID, fileName);
                    if (buffer == null)
                    {
                        //没有找到缓存文件
                        WCFServiceProxy <IADFileService> _iTaskManageProxy = new WCFServiceProxy <IADFileService>();
                        buffer = _iTaskManageProxy.getChannel.DownLoad(companyID, fileName);
                        _iTaskManageProxy.Close();
                        ADFileCached.getInstance().SaveFile(buffer, companyID, fileName);
                    }
                    MemoryStream ms = new MemoryStream();

                    int bPos = (currentSegmentsIndex - 1) * 1024;
                    if ((bPos + 1024) > (fileLength - 1))
                    {
                        dataLength = fileLength - bPos;
                    }
                    else
                    {
                        dataLength = 1024;
                    }

                    ms.Write(buffer, bPos, dataLength);
                    buffer      = new byte[dataLength];
                    ms.Position = 0;
                    ms.Read(buffer, 0, dataLength);
                    ms.Close();
                    ADFileCached.getInstance().SaveFileSegment(buffer, companyID, fileName, fileLength, totalSegments, currentSegmentsIndex);
                }


                if (buffer != null)
                {
                    stream.Write(buffer, 0, buffer.Length);
                }
                else
                {
                    result = "读取文件段失败";
                }

                return(result);
            }
        }
Beispiel #2
0
        private void btnPublish_Click(object sender, EventArgs e)
        {
            WCFServiceProxy <IADPublishManager> _iTaskManageProxy = new WCFServiceProxy <IADPublishManager>();
            string result = _iTaskManageProxy.getChannel.ADPublish(Convert.ToInt64(this.txtAP.Value));

            _iTaskManageProxy.Close();
            if (result == "")
            {
                MessageBox.Show("发布完成");
            }
            else
            {
                MessageBox.Show("发布失败,原因:" + result);
            }
        }
Beispiel #3
0
 private void Heart()
 {
     //调度服务到数据中心的注册维护。
     while (isChecked)
     {
         Thread.Sleep(1000 * 5);
         if (this.isRegister)
         {
             try
             {
                 this._iDCSServiceProxy.getChannel.Heart(this.serviceNo);
             }
             catch
             {
                 isRegister = false;
                 contxt     = new InstanceContext(this);
                 if (_iDCSServiceProxy != null)
                 {
                     try
                     {
                         if (_iDCSServiceProxy.State != System.ServiceModel.CommunicationState.Faulted)
                         {
                             _iDCSServiceProxy.Close();
                         }
                     }
                     catch
                     {
                         _iDCSServiceProxy.Abort();
                     }
                 }
                 _iDCSServiceProxy = new WCFServiceProxy <IDCSService>(contxt);
             }
         }
         else
         {
             this.isRegister = Register();
         }
     }
 }
Beispiel #4
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            WCFServiceProxy <IADFileService> _iTaskManageProxy = new WCFServiceProxy <IADFileService>();

            System.IO.FileStream fs = System.IO.File.OpenRead(this.txtFile.Text);
            byte[] buffer           = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();
            string fileName = string.Format("{0}{1}{2}{3}", txtCompanyID.Text, txtDate.Text, txtOrder.Value.ToString().PadLeft(5, '0'), System.IO.Path.GetExtension(this.txtFile.Text));
            string result   = _iTaskManageProxy.getChannel.UpLoad(txtCompanyID.Text, fileName, buffer);

            _iTaskManageProxy.Close();
            if (result == "")
            {
                MessageBox.Show("上传完成。");
                this.txtOrder.Value++;
            }
            else
            {
                MessageBox.Show("上传失败,原因:" + result);
            }
        }