Пример #1
0
        /// <summary>
        /// BeginInvoke方法执行完成后调用该异步委托回调方法
        /// </summary>
        /// <param name="iar">用于监视异步调用进度</param>
        private void IsZipComplete(IAsyncResult iar)
        {
            AsyncResult ar = (AsyncResult)iar;

            myZip = (AsycMyZipZipDir)ar.AsyncDelegate;
            myZip.EndInvoke(iar);
            Thread.Sleep(1000);
            //MessageBox.Show("压缩upload文件夹成功!");
            //isZipCompleteMark = true;
            fsUpload = new FileStream(ZipedFile, FileMode.Open, FileAccess.Read);

            myUploadFile = new AsycUploadFile(wcfclient.UpLoadFile);
            myUploadFile.BeginInvoke(fsUpload, new AsyncCallback(isUploadComplete), null);


            /*
             * //bool a = wcfclient.getBytes(bytes1);
             * fs.Read(bytes1, 0, bytes1.Length);
             * fs.Close();
             * fs.Dispose();
             * bool b = wcfclient.GetUpLoadBytes(bytes1, DateTime.Now, "upload");*/
        }
Пример #2
0
        /// <summary>
        /// 异步方式进行数据的更新
        /// </summary>
        private void StartUpdateDate()
        {
            ///创建同步历史记录
            createUpdateRecordXml();
            /// <summary>
            /// 新建WCF服务实例
            /// </summary>
            try
            {
                wcfclient = new DeskTopServiceClient();
            }
            catch (Exception ex)
            {
                LogHelper.LogWrite(ex.Message);
            }
            ///下载维护保养计划
            try
            {
                byte[] bytes = wcfclient.GetPlanList();
                if (!Directory.Exists(wcfdownloadpath))
                {
                    Directory.CreateDirectory(wcfdownloadpath);
                    using (FileStream wcfFile = new FileStream(wcfdownloadpath + "planList.xml", FileMode.Create))
                    {
                        wcfFile.Write(bytes, 0, bytes.Length);
                        wcfFile.Flush();
                    }
                }
                else
                {
                    //File.Delete(wcfdownloadpath + "planList.xml");
                    using (FileStream wcfFile = new FileStream(wcfdownloadpath + "planList.xml", FileMode.Create))
                    {
                        wcfFile.Write(bytes, 0, bytes.Length);
                        wcfFile.Flush();
                    }
                }
                Thread.Sleep(100);
                try
                {
                    portableDevices[0].CopyFolderToPad(lastObjDown, wcfdownloadpath + "planList.xml");
                }
                catch (Exception ex)
                {
                    LogHelper.LogWrite(ex);
                }
                n = n + 1;
                Thread.Sleep(100);
                //MessageBox.Show("下载维护保养计划成功!");
            }
            catch (Exception ex)
            {
                LogHelper.LogWrite(ex);
            }


            ///下载应急预案
            //int a=int.Parse(DateTime.now)
            try
            {
                byte[] bytes = wcfclient.EmergencyDetail(DateTime.Now.ToString("yyyy"), 505);
                if (!Directory.Exists(wcfdownloadpath))
                {
                    Directory.CreateDirectory(wcfdownloadpath);
                    using (FileStream wcfFile = new FileStream(wcfdownloadpath + "应急预案.pdf", FileMode.Create))
                    {
                        wcfFile.Write(bytes, 0, bytes.Length);
                        wcfFile.Flush();
                    }
                }
                else
                {
                    //File.Delete(wcfdownloadpath + "planList.xml");
                    using (FileStream wcfFile = new FileStream(wcfdownloadpath + "应急预案.pdf", FileMode.Create))
                    {
                        wcfFile.Write(bytes, 0, bytes.Length);
                        wcfFile.Flush();
                    }
                }
                Thread.Sleep(100);
                try
                {
                    portableDevices[0].CopyFolderToPad(lastObjDown, wcfdownloadpath + "应急预案.pdf");
                }
                catch (Exception ex)
                {
                    LogHelper.LogWrite(ex);
                }
                n = n + 1;
                Thread.Sleep(100);
            }
            catch (Exception ex)
            {
                LogHelper.LogWrite(ex);
            }

            ///异步方式下载备份备件信息
            try
            {
                myBackupEquip = new AsycBackupEquip(wcfclient.GetProduct);
                myBackupEquip.BeginInvoke(new AsyncCallback(IsDownBackupEquipCom), null);
            }
            catch (Exception ex)
            {
                LogHelper.LogWrite(ex);
            }

            //异步方式下载应急计划
            try
            {
                string currentYear    = DateTime.Now.ToString("yyyy");
                int    departMentName = 505;
                myEmergencyPlan = new AsycEmergencyPlan(wcfclient.EmergencyDetail);
                myEmergencyPlan.BeginInvoke(currentYear, departMentName, new AsyncCallback(IsEmergencyPlanCom), null);
            }
            catch (Exception ex)
            {
                LogHelper.LogWrite(ex);
            }

            int CompressionLevel = 9;

            try
            {
                myZip = new AsycMyZipZipDir(new ICharpZip().ZipDir);
                myZip.BeginInvoke(DirToZip, ZipedFile, CompressionLevel, new AsyncCallback(IsZipComplete), null);
            }
            catch (Exception ex)
            {
                LogHelper.LogWrite(ex);
            }

            ///异步方法下载设备台账信息
            try
            {
                myEquipInfo = new AsycEquipInfo(wcfclient.GetTZList);
                myEquipInfo.BeginInvoke(new AsyncCallback(IsDownEquipInfoComplete), null);
            }
            catch (Exception ex)
            {
                LogHelper.LogWrite(ex);
            }
        }