Ejemplo n.º 1
0
 /// <summary>
 /// 判断是否下载设备台账信息成功
 /// </summary>
 /// <param name="iar"></param>
 private void IsDownEquipInfoComplete(IAsyncResult iar)
 {
     //string wcfdownloadpath = @"D:\download\";
     byte[] bytes;
     try
     {
         AsyncResult ar = (AsyncResult)iar;
         myEquipInfo = (AsycEquipInfo)ar.AsyncDelegate;
         bytes       = myEquipInfo.EndInvoke(iar);
         if (!Directory.Exists(wcfdownloadpath))
         {
             Directory.CreateDirectory(wcfdownloadpath);
             FileStream wcfFile = new FileStream(wcfdownloadpath + "EquipInfo.xml", FileMode.Create);
             wcfFile.Write(bytes, 0, bytes.Length);
             wcfFile.Flush();
             wcfFile.Close();
             wcfFile.Dispose();
         }
         else
         {
             if (File.Exists(wcfdownloadpath + "EquipInfo.xml"))
             {
                 File.Delete(wcfdownloadpath + "EquipInfo.xml");
             }
             FileStream wcfFile = null;
             try
             {
                 wcfFile = new FileStream(wcfdownloadpath + "EquipInfo.xml", FileMode.Create);
                 wcfFile.Write(bytes, 0, bytes.Length);
                 wcfFile.Flush();
             }
             catch (Exception ex)
             {
                 LogHelper.LogWrite(ex);
             }
             finally
             {
                 wcfFile.Close();
                 wcfFile.Dispose();
             }
         }
         try
         {
             portableDevices[0].CopyFolderToPad(lastObjDown, wcfdownloadpath + "EquipInfo.xml");
         }
         catch (Exception ex)
         {
             LogHelper.LogWrite(ex);
         }
         n = n + 1;
         Thread.Sleep(100);
         //MessageBox.Show("下载设备台账信息XML成功!");
     }
     catch (Exception ex)
     {
         LogHelper.LogWrite(ex);
     }
 }
Ejemplo n.º 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);
            }
        }