Example #1
0
        private void LawListCT_DownloadFileStart_Callback(Law_DownloadItemViewModel lawItem)
        {
            Func <LawRow, bool>        func = null;
            _003C_003Ec__DisplayClassb _003C_003Ec__DisplayClassb = new _003C_003Ec__DisplayClassb();

            _003C_003Ec__DisplayClassb.lawItem = lawItem;
            if (!base.Dispatcher.CheckAccess())
            {
                base.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_DownloadFileStart_Callback), _003C_003Ec__DisplayClassb.lawItem);
                return;
            }
            IEnumerable <LawRow> source = Enumerable.OfType <LawRow>(LawRowSP.Children);

            if (func == null)
            {
                func = new Func <LawRow, bool>(_003C_003Ec__DisplayClassb._003CLawListCT_DownloadFileStart_Callback_003Eb__9);
            }
            LawRow lawRow = Enumerable.FirstOrDefault(Enumerable.Where(source, func));

            if (lawRow != null)
            {
                lawRow.txtPercent.Text       = "0 %";
                lawRow.txtPercent.Foreground = Brushes.Black;
                lawRow.pb.Value      = 0.0;
                lawRow.pb.Foreground = Brushes.Orange;
                lawRow.pb.Background = Brushes.Black;
            }
        }
 private void DownloadProgressChanged(Law_DownloadItemViewModel lawItem)
 {
     if (lawItem != null && this.LawListCT_DownloadProgressChanged_Event != null)
     {
         this.LawListCT_DownloadProgressChanged_Event(lawItem);
     }
 }
 private void DownloadFileCompleted(Law_DownloadItemViewModel lawItem)
 {
     if (lawItem != null)
     {
         if (lawItem.StorageFileName.EndsWith(".update"))
         {
             lawItem.FileType = LawFileType.更新檔已下載完成;
             File.Move(lawItem.StorageFilePath, lawItem.StorageFilePath.Replace(".update", ""));
             lawItem.StorageFileName = lawItem.StorageFileName.Replace(".update", "");
         }
         else
         {
             lawItem.FileType = LawFileType.已下載完成;
         }
         UnzipTrigger(lawItem);
         if (this.LawListCT_DownloadFileCompleted_Event != null)
         {
             this.LawListCT_DownloadFileCompleted_Event(lawItem);
         }
         string text = "update  LawRow set AtDownloadFinished_XmlUpDate=@1\r\n                       , Link=@2,StorageFileName=@3\r\n                       , DownloadBytes=@4,TotalBytes=@5 where ID=@6 and UserID=@7";
         int    num  = MSCE.ExecuteNonQuery(text, lawItem.UpDate.ToString("yyyy/MM/dd HH:mm:ss"), lawItem.Link, lawItem.StorageFileName, lawItem.DownloadBytes.ToString(), lawItem.TotalBytes.ToString(), lawItem.ID, lawItem.UserID);
         if (num < 1)
         {
             LogTool.Debug(new Exception("DB失敗:" + text));
         }
     }
 }
Example #4
0
        private void LawListCT_DownloadProgressChanged_Callback(Law_DownloadItemViewModel lawItem)
        {
            Func <LawRow, bool>         func = null;
            _003C_003Ec__DisplayClass13 _003C_003Ec__DisplayClass = new _003C_003Ec__DisplayClass13();

            _003C_003Ec__DisplayClass.lawItem = lawItem;
            if (!base.Dispatcher.CheckAccess())
            {
                base.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_DownloadProgressChanged_Callback), _003C_003Ec__DisplayClass.lawItem);
                return;
            }
            IEnumerable <LawRow> source = Enumerable.OfType <LawRow>(LawRowSP.Children);

            if (func == null)
            {
                func = new Func <LawRow, bool>(_003C_003Ec__DisplayClass._003CLawListCT_DownloadProgressChanged_Callback_003Eb__11);
            }
            LawRow lawRow = Enumerable.FirstOrDefault(Enumerable.Where(source, func));

            if (lawRow != null)
            {
                lawRow.txtPercent.Text        = (int)_003C_003Ec__DisplayClass.lawItem.NowPercentage + " %";
                lawRow.pb.Value               = _003C_003Ec__DisplayClass.lawItem.NowPercentage;
                lawRow.btnDownload.Visibility = Visibility.Collapsed;
                lawRow.txtPercent.Visibility  = Visibility.Visible;
                lawRow.pb.Visibility          = Visibility.Visible;
            }
        }
Example #5
0
        private void DownloadFileCompleted(Law_DownloadItemViewModel lawItem)
        {
            if (lawItem == null)
            {
                return;
            }


            if (lawItem.StorageFileName.EndsWith(".update"))
            {
                lawItem.FileType = LawFileType.更新檔已下載完成;
                //複寫原本的檔案
                File.Move(lawItem.StorageFilePath, lawItem.StorageFilePath.Replace(".update", ""));
                lawItem.StorageFileName = lawItem.StorageFileName.Replace(".update", "");
            }
            else
            {
                lawItem.FileType = LawFileType.已下載完成;
            }


            // 解壓縮,可以開thread去解壓縮,這樣就會直接下載下一個
            // 不過不要這樣做,因為nowItem會直接變成下一個下載物件,就不能判斷現在的下載狀態了
            // 因為使用者會隨時重新整理頁面
            //ThreadPool.QueueUserWorkItem(callback =>
            //{
            //    UnzipTrigger(lawItem);
            //});

            //解壓縮
            UnzipTrigger(lawItem);

            if (LawListCT_DownloadFileCompleted_Event != null)
            {
                LawListCT_DownloadFileCompleted_Event(lawItem);
            }

            string SQL = @"update  LawRow set AtDownloadFinished_XmlUpDate=@1
                       , Link=@2,StorageFileName=@3
                       , DownloadBytes=@4,TotalBytes=@5 where ID=@6 and UserID=@7";

            int success = MSCE.ExecuteNonQuery(SQL
                                               , lawItem.UpDate.ToString("yyyy/MM/dd HH:mm:ss")
                                               , lawItem.Link
                                               , lawItem.StorageFileName
                                               , lawItem.DownloadBytes.ToString()
                                               , lawItem.TotalBytes.ToString()
                                               , lawItem.ID
                                               , lawItem.UserID);

            if (success < 1)
            {
                LogTool.Debug(new Exception("DB失敗:" + SQL));
            }
        }
Example #6
0
        private void DownloadProgressChanged(Law_DownloadItemViewModel lawItem)
        {
            if (lawItem == null)
            {
                return;
            }

            //呼叫完成event並且在主執行序執行
            if (LawListCT_DownloadProgressChanged_Event != null)
            {
                LawListCT_DownloadProgressChanged_Event(lawItem);
            }
        }
Example #7
0
 public LawRow(string UserID, string UserName, string UserPWD, bool IsLastRow, LawDataLaw lawDataLaw, LawListCT_HangTheDownloadEvent_Function callback1, LawListCT_IsAllLawRowFinished_AddInitUIFinished_Function callback2, LawListCT_GetBookVMs_ByMeetingFileCate_Function callback3)
 {
     InitializeComponent();
     this.UserID     = UserID;
     this.UserName   = UserName;
     this.UserPWD    = UserPWD;
     this.IsLastRow  = IsLastRow;
     this.lawDataLaw = lawDataLaw;
     base.Loaded    += new RoutedEventHandler(LawRow_Loaded);
     LawListCT_HangTheDownloadEvent_Event = callback1;
     LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event = callback2;
     LawListCT_GetBookVMs_ByMeetingFileCate_Event          = callback3;
     lawItem = new Law_DownloadItemViewModel();
 }
Example #8
0
        private void LawListCT_UnZip_Callback(Law_DownloadItemViewModel lawItem)
        {
            Func <LawRow, bool>        func = null;
            _003C_003Ec__DisplayClass7 _003C_003Ec__DisplayClass = new _003C_003Ec__DisplayClass7();

            _003C_003Ec__DisplayClass.lawItem = lawItem;
            if (!base.Dispatcher.CheckAccess())
            {
                base.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_UnZip_Callback), _003C_003Ec__DisplayClass.lawItem);
                return;
            }
            IEnumerable <LawRow> source = Enumerable.OfType <LawRow>(LawRowSP.Children);

            if (func == null)
            {
                func = new Func <LawRow, bool>(_003C_003Ec__DisplayClass._003CLawListCT_UnZip_Callback_003Eb__5);
            }
            LawRow lawRow = Enumerable.FirstOrDefault(Enumerable.Where(source, func));

            if (lawRow == null)
            {
                return;
            }
            if (_003C_003Ec__DisplayClass.lawItem.FileType == LawFileType.更新檔解壓縮中)
            {
                lawRow.txtUpdatePercent.Text       = "100 %";
                lawRow.pbUpdate.Value              = lawRow.pb.Maximum;
                lawRow.txtUpdatePercent.Visibility = Visibility.Collapsed;
                lawRow.pbUpdate.Visibility         = Visibility.Collapsed;
                Storyboard storyboard = (Storyboard)lawRow.TryFindResource("sbUpdate");
                if (storyboard != null)
                {
                    storyboard.Begin();
                }
            }
            else
            {
                lawRow.txtPercent.Text       = "100 %";
                lawRow.pb.Value              = lawRow.pb.Maximum;
                lawRow.txtPercent.Visibility = Visibility.Collapsed;
                lawRow.pb.Visibility         = Visibility.Collapsed;
                Storyboard storyboard = (Storyboard)lawRow.TryFindResource("sb");
                if (storyboard != null)
                {
                    storyboard.Begin();
                }
            }
        }
Example #9
0
        private void LawListCT_UnZip_Callback(Law_DownloadItemViewModel lawItem)
        {
            //先判斷是否要invoke
            if (this.Dispatcher.CheckAccess() == false)
            {
                // 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
                //this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action<Law_DownloadItemViewModel>(LawListCT_UnZip_Callback), lawItem);
                this.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_UnZip_Callback), lawItem);
            }
            else
            {
                LawRow lawRow = LawRowSP.Children.OfType <LawRow>().Where(x => x.lawDataLaw.ID.Equals(lawItem.ID)).FirstOrDefault();
                if (lawRow != null)
                {
                    Storyboard sb;
                    if (lawItem.FileType == LawFileType.更新檔解壓縮中)
                    {
                        //記得不要讓使用者開書
                        lawRow.txtUpdatePercent.Text       = "100 %";
                        lawRow.pbUpdate.Value              = lawRow.pb.Maximum;
                        lawRow.txtUpdatePercent.Visibility = Visibility.Collapsed;
                        lawRow.pbUpdate.Visibility         = Visibility.Collapsed;

                        sb = (Storyboard)lawRow.TryFindResource("sbUpdate");
                        if (sb != null)
                        {
                            sb.Begin();
                        }
                    }
                    else
                    {
                        lawRow.txtPercent.Text       = "100 %";
                        lawRow.pb.Value              = lawRow.pb.Maximum;
                        lawRow.txtPercent.Visibility = Visibility.Collapsed;
                        lawRow.pb.Visibility         = Visibility.Collapsed;

                        sb = (Storyboard)lawRow.TryFindResource("sb");
                        if (sb != null)
                        {
                            sb.Begin();
                        }
                    }
                }
            }
        }
 private void DownloadFileStart(Law_DownloadItemViewModel lawItem)
 {
     if (lawItem != null)
     {
         if (lawItem.StorageFileName.EndsWith(".update"))
         {
             lawItem.FileType = LawFileType.更新檔正在下載中;
         }
         else
         {
             lawItem.FileType = LawFileType.正在下載中;
         }
         if (this.LawListCT_DownloadFileStart_Event != null)
         {
             this.LawListCT_DownloadFileStart_Event(lawItem);
         }
     }
 }
Example #11
0
        private void UpdateToDB(Law_DownloadItemViewModel lawItem)
        {
//            if (fileItem == null)
//                return;
//            string SQL = @"update  FileRow set Url=@1,StorageFileName=@2
//                       , DownloadBytes=@3,TotalBytes=@4 where ID=@6 and UserID=@7 and MeetingID=@8";

//            int success = MSCE.ExecuteNonQuery(SQL
//                                               , fileItem.Url
//                                               , fileItem.StorageFileName
//                                               , fileItem.DownloadBytes.ToString()
//                                               , fileItem.TotalBytes.ToString()
//                                               , fileItem.ID
//                                               , fileItem.UserID
//                                               , fileItem.MeetingID);
//            if (success < 1)
//                LogTool.Debug(new Exception("DB失敗:" + SQL));
        }
Example #12
0
 public void AddItem(Law_DownloadItemViewModel lawItem)
 {
     lock (this)
     {
         if (lawItem == null)
         {
             return;
         }
         list.Add(lawItem);
         //LawDownloader lawDownloader = Singleton_LawDownloader.GetInstance();
         // 如果沒有在下載中
         if (this.downloaderType == DownloaderType.沒有任何檔案下載中)
         {
             //ThreadPool.QueueUserWorkItem(callback => { this.Start(); });
             Task.Factory.StartNew(() => this.Start(), TaskCreationOptions.LongRunning);
         }
     }
 }
Example #13
0
        private void LawListCT_DownloadFileCompleted_Callback(Law_DownloadItemViewModel lawItem)
        {
            Func <LawRow, bool>        func = null;
            _003C_003Ec__DisplayClassf _003C_003Ec__DisplayClassf = new _003C_003Ec__DisplayClassf();

            _003C_003Ec__DisplayClassf.lawItem = lawItem;
            if (!base.Dispatcher.CheckAccess())
            {
                base.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_DownloadFileCompleted_Callback), _003C_003Ec__DisplayClassf.lawItem);
                return;
            }
            IEnumerable <LawRow> source = Enumerable.OfType <LawRow>(LawRowSP.Children);

            if (func == null)
            {
                func = new Func <LawRow, bool>(_003C_003Ec__DisplayClassf._003CLawListCT_DownloadFileCompleted_Callback_003Eb__d);
            }
            LawRow lawRow = Enumerable.FirstOrDefault(Enumerable.Where(source, func));

            if (lawRow == null)
            {
                return;
            }
            if (_003C_003Ec__DisplayClassf.lawItem.FileType == LawFileType.更新檔已下載完成)
            {
                Storyboard storyboard = (Storyboard)lawRow.TryFindResource("sb");
                if (storyboard != null)
                {
                    storyboard.Stop();
                }
                lawRow.txtIsNew.Visibility = Visibility.Visible;
                return;
            }
            Storyboard storyboard2 = (Storyboard)lawRow.TryFindResource("sb");

            if (storyboard2 != null)
            {
                storyboard2.Stop();
            }
            lawRow.btnDownload.Visibility = Visibility.Collapsed;
            lawRow.btnOpen.Visibility     = Visibility.Visible;
            lawRow.btnDelete.Visibility   = Visibility.Visible;
            lawRow.txtIsNew.Visibility    = Visibility.Visible;
        }
Example #14
0
        private void LawListCT_UnZipError_Callback(Law_DownloadItemViewModel lawItem)
        {
            Func <LawRow, bool>        func = null;
            _003C_003Ec__DisplayClass3 _003C_003Ec__DisplayClass = new _003C_003Ec__DisplayClass3();

            _003C_003Ec__DisplayClass.lawItem = lawItem;
            if (!base.Dispatcher.CheckAccess())
            {
                base.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_UnZipError_Callback), _003C_003Ec__DisplayClass.lawItem);
                return;
            }
            IEnumerable <LawRow> source = Enumerable.OfType <LawRow>(LawRowSP.Children);

            if (func == null)
            {
                func = new Func <LawRow, bool>(_003C_003Ec__DisplayClass._003CLawListCT_UnZipError_Callback_003Eb__1);
            }
            LawRow lawRow = Enumerable.FirstOrDefault(Enumerable.Where(source, func));

            if (lawRow == null)
            {
                return;
            }
            if (_003C_003Ec__DisplayClass.lawItem.FileType == LawFileType.更新檔解壓縮失敗)
            {
                Storyboard storyboard = (Storyboard)lawRow.TryFindResource("sbUpdate");
                if (storyboard != null)
                {
                    storyboard.Stop();
                }
                lawRow.btnUpdate.Visibility = Visibility.Visible;
            }
            else
            {
                Storyboard storyboard = (Storyboard)lawRow.TryFindResource("sb");
                if (storyboard != null)
                {
                    storyboard.Stop();
                }
                lawRow.btnDownload.Visibility = Visibility.Visible;
            }
        }
Example #15
0
        private void LawListCT_UnZipError_Callback(Law_DownloadItemViewModel lawItem)
        {
            //先判斷是否要invoke
            if (this.Dispatcher.CheckAccess() == false)
            {
                // 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
                //this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,new Action<Law_DownloadItemViewModel>(LawListCT_UnZipError_Callback), lawItem);
                this.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_UnZipError_Callback), lawItem);
            }
            else
            {
                // 在Home的主視窗Show,不要在這裡Show
                //AutoClosingMessageBox.Show("解壓縮失敗");
                LawRow lawRow = LawRowSP.Children.OfType <LawRow>().Where(x => x.lawDataLaw.ID.Equals(lawItem.ID)).FirstOrDefault();
                if (lawRow != null)
                {
                    Storyboard sb;
                    if (lawItem.FileType == LawFileType.更新檔解壓縮失敗)
                    {
                        sb = (Storyboard)lawRow.TryFindResource("sbUpdate");
                        if (sb != null)
                        {
                            sb.Stop();
                        }

                        // 記得必須隱藏必須先做,才不會被看見
                        lawRow.btnUpdate.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        sb = (Storyboard)lawRow.TryFindResource("sb");
                        if (sb != null)
                        {
                            sb.Stop();
                        }

                        // 記得必須隱藏必須先做,才不會被看見
                        lawRow.btnDownload.Visibility = Visibility.Visible;
                    }
                }
            }
        }
Example #16
0
        private void LawListCT_DownloadFileCompleted_Callback(Law_DownloadItemViewModel lawItem)
        {
            //先判斷是否要invoke
            if (this.Dispatcher.CheckAccess() == false)
            {
                // 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
                //this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action<Law_DownloadItemViewModel>(LawListCT_DownloadFileCompleted_Callback), lawItem);
                this.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_DownloadFileCompleted_Callback), lawItem);
            }
            else
            {
                LawRow lawRow = LawRowSP.Children.OfType <LawRow>().Where(x => x.lawDataLaw.ID.Equals(lawItem.ID)).FirstOrDefault();

                if (lawRow != null)
                {
                    if (lawItem.FileType == LawFileType.更新檔已下載完成)
                    {
                        Storyboard sb = (Storyboard)lawRow.TryFindResource("sb");
                        if (sb != null)
                        {
                            sb.Stop();
                        }

                        lawRow.txtIsNew.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        Storyboard sb = (Storyboard)lawRow.TryFindResource("sb");
                        if (sb != null)
                        {
                            sb.Stop();
                        }

                        lawRow.btnDownload.Visibility = Visibility.Collapsed;
                        lawRow.btnOpen.Visibility     = Visibility.Visible;
                        lawRow.btnDelete.Visibility   = Visibility.Visible;
                        lawRow.txtIsNew.Visibility    = Visibility.Visible;
                    }
                }
            }
        }
        public void AddItem(Law_DownloadItemViewModel lawItem)
        {
            Action action = null;

            lock (this)
            {
                if (lawItem != null)
                {
                    list.Add(lawItem);
                    if (downloaderType == DownloaderType.沒有任何檔案下載中)
                    {
                        TaskFactory factory = Task.Factory;
                        if (action == null)
                        {
                            action = new Action(_003CAddItem_003Eb__5);
                        }
                        factory.StartNew(action, TaskCreationOptions.LongRunning);
                    }
                }
            }
        }
Example #18
0
 private void StartNextFileItemDownload(Law_DownloadItemViewModel lawItem)
 {
     lock (this)
     {
         if (downloaderType == DownloaderType.停止)
         {
             //清空所有列表
             list.Clear();
         }
         // 設定成 沒有正在下載 和 沒有正在下載的物件
         lawItem        = null;
         downloaderType = DownloaderType.沒有任何檔案下載中;
         // 不同線程的回呼,不會造成Recursive堆疊上限
         // 如果不是停止就開始新的檔案物件下載
         //LawDownloader lawDownloader = Singleton_LawDownloader.GetInstance();
         if (this.downloaderType == DownloaderType.沒有任何檔案下載中)
         {
             //ThreadPool.QueueUserWorkItem(callback => { this.Start(); });
             Task.Factory.StartNew(() => this.Start(), TaskCreationOptions.LongRunning);
         }
     }
 }
Example #19
0
 private void LawListCT_DownloadProgressChanged_Callback(Law_DownloadItemViewModel lawItem)
 {
     //先判斷是否要invoke
     if (this.Dispatcher.CheckAccess() == false)
     {
         // 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
         //this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action<Law_DownloadItemViewModel>(LawListCT_DownloadProgressChanged_Callback), lawItem);
         this.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_DownloadProgressChanged_Callback), lawItem);
     }
     else
     {
         LawRow lawRow = LawRowSP.Children.OfType <LawRow>().Where(x => x.lawDataLaw.ID.Equals(lawItem.ID)).FirstOrDefault();
         if (lawRow != null)
         {
             lawRow.txtPercent.Text        = ((int)lawItem.NowPercentage).ToString() + " %";
             lawRow.pb.Value               = lawItem.NowPercentage;
             lawRow.btnDownload.Visibility = Visibility.Collapsed;
             lawRow.txtPercent.Visibility  = Visibility.Visible;
             lawRow.pb.Visibility          = Visibility.Visible;
         }
     }
 }
Example #20
0
 private void LawListCT_DownloadFileStart_Callback(Law_DownloadItemViewModel lawItem)
 {
     //先判斷是否要invoke
     if (this.Dispatcher.CheckAccess() == false)
     {
         // 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
         //this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action<Law_DownloadItemViewModel>(LawListCT_DownloadFileStart_Callback), lawItem);
         this.Dispatcher.BeginInvoke(new Action <Law_DownloadItemViewModel>(LawListCT_DownloadFileStart_Callback), lawItem);
     }
     else
     {
         LawRow lawRow = LawRowSP.Children.OfType <LawRow>().Where(x => x.lawDataLaw.ID.Equals(lawItem.ID)).FirstOrDefault();
         if (lawRow != null)
         {
             lawRow.txtPercent.Text       = "0 %";
             lawRow.txtPercent.Foreground = Brushes.Black;
             lawRow.pb.Value      = 0;
             lawRow.pb.Foreground = Brushes.Orange;
             lawRow.pb.Background = Brushes.Black;
         }
     }
 }
Example #21
0
        private void DownloadFileStart(Law_DownloadItemViewModel lawItem)
        {
            if (lawItem == null)
            {
                return;
            }

            if (lawItem.StorageFileName.EndsWith(".update"))
            {
                lawItem.FileType = LawFileType.更新檔正在下載中;
            }
            else
            {
                lawItem.FileType = LawFileType.正在下載中;
            }

            //呼叫完成event並且在主執行序執行
            if (LawListCT_DownloadFileStart_Event != null)
            {
                LawListCT_DownloadFileStart_Event(lawItem);
            }
        }
        private void StartNextFileItemDownload(Law_DownloadItemViewModel lawItem)
        {
            Action action = null;

            lock (this)
            {
                if (downloaderType == DownloaderType.停止)
                {
                    list.Clear();
                }
                lawItem        = null;
                downloaderType = DownloaderType.沒有任何檔案下載中;
                if (downloaderType == DownloaderType.沒有任何檔案下載中)
                {
                    TaskFactory factory = Task.Factory;
                    if (action == null)
                    {
                        action = new Action(_003CStartNextFileItemDownload_003Eb__2);
                    }
                    factory.StartNew(action, TaskCreationOptions.LongRunning);
                }
            }
        }
        private void UnzipTrigger(Law_DownloadItemViewModel lawItem)
        {
            if (lawItem == null)
            {
                return;
            }
            if (lawItem.FileType == LawFileType.已下載完成)
            {
                lawItem.FileType = LawFileType.解壓縮中;
            }
            else
            {
                lawItem.FileType = LawFileType.更新檔解壓縮中;
            }
            bool flag = false;

            if (this.LawListCT_UnZip_Event != null)
            {
                this.LawListCT_UnZip_Event(lawItem);
            }
            try
            {
                UnZipTool unZipTool = new UnZipTool();
                flag = unZipTool.UnZip(lawItem.StorageFilePath, lawItem.UnZipFilePath, "", true);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            if (flag)
            {
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.FileType = LawFileType.已下載完成;
                }
                else
                {
                    lawItem.FileType = LawFileType.更新檔已下載完成;
                }
                return;
            }
            if (lawItem.FileType == LawFileType.解壓縮中)
            {
                lawItem.DownloadBytes  = 0L;
                lawItem.TotalBytes     = 0L;
                lawItem.LastPercentage = 0.0;
                if (File.Exists(lawItem.StorageFilePath))
                {
                    File.Delete(lawItem.StorageFilePath);
                }
                string text = "update  LawRow set AtDownloadFinished_XmlUpDate=@1\r\n                                           , Link=@2,StorageFileName=@3\r\n                                           , DownloadBytes=@4,TotalBytes=@5 where ID=@6 and UserID=@7";
                int    num  = MSCE.ExecuteNonQuery(text, lawItem.UpDate.ToString("yyyy/MM/dd HH:mm:ss"), lawItem.Link, lawItem.StorageFileName, lawItem.DownloadBytes.ToString(), lawItem.TotalBytes.ToString(), lawItem.ID, lawItem.UserID);
                if (num < 1)
                {
                    LogTool.Debug(new Exception("DB失敗:" + text));
                }
            }
            if (lawItem.FileType == LawFileType.解壓縮中)
            {
                lawItem.FileType = LawFileType.解壓縮失敗;
                if (this.LawListCT_UnZipError_Event != null)
                {
                    this.LawListCT_UnZipError_Event(lawItem);
                }
                if (this.Home_UnZipError_Event != null)
                {
                    this.Home_UnZipError_Event(string.Format("{0} {1}", Settings.Default.LawButtonName, Enum.GetName(typeof(LawFileType), LawFileType.解壓縮失敗)));
                }
                lawItem.FileType = LawFileType.從未下載;
            }
            else
            {
                lawItem.FileType = LawFileType.更新檔解壓縮失敗;
                if (this.LawListCT_UnZipError_Event != null)
                {
                    this.LawListCT_UnZipError_Event(lawItem);
                }
                if (this.Home_UnZipError_Event != null)
                {
                    this.Home_UnZipError_Event(string.Format("檔名: {0},{1}", Settings.Default.LawButtonName, Enum.GetName(typeof(LawFileType), LawFileType.更新檔解壓縮失敗)));
                }
                lawItem.FileType = LawFileType.更新檔未下載;
            }
        }
Example #24
0
        private Dictionary <string, App_Code.ViewModel.BookVM> LawListCT_GetBookVMs_ByMeetingFileCate_Callback(Law_DownloadItemViewModel lawItem)
        {
            Dictionary <string, BookVM> BookVMs = new Dictionary <string, BookVM>();

            IEnumerable <LawRow> LawRowS = LawRowSP.Children.OfType <LawRow>().Where(x => x.lawItem.FileCate == lawItem.FileCate && x.lawItem.DownloadBytes != 0 && x.lawItem.DownloadBytes >= x.lawItem.TotalBytes);
            string filePath        = ClickOnceTool.GetFilePath();
            string UnZipFileFolder = PaperLess_Emeeting.Properties.Settings.Default.File_UnZipFileFolder;
            string baseBookPath    = filePath + "\\" + UnZipFileFolder + "\\" + UserID;

            if (LawRowS != null)
            {
                foreach (LawRow item in LawRowS)
                {
                    BookVMs[item.lawItem.Name] = new BookVM(item.lawItem.ID, baseBookPath + "\\" + item.lawItem.ID, lawItem.FileCate);
                }
            }

            return(BookVMs);
        }
Example #25
0
        private void InitSelectDB()
        {
            DataTable     dataTable = new DataTable();
            LawDownloader instance  = Singleton_LawDownloader.GetInstance();

            lawItem = instance.GetInList(lawDataLaw.ID);
            if (lawItem != null)
            {
                return;
            }
            DateTime dateTime = DateTime.Parse("2010/01/01");
            long     num      = 0L;
            long     num2     = 0L;

            dataTable = MSCE.GetDataTable("SELECT ID,AtDownloadFinished_XmlUpDate,Link,StorageFileName,DownloadBytes,TotalBytes FROM LawRow where ID=@1 and UserID=@2", lawDataLaw.ID, UserID);
            if (dataTable.Rows.Count > 0)
            {
                dataTable.Rows[0]["ID"].ToString();
                dateTime = (DateTime)dataTable.Rows[0]["AtDownloadFinished_XmlUpDate"];
                dataTable.Rows[0]["Link"].ToString();
                dataTable.Rows[0]["StorageFileName"].ToString();
                num  = long.Parse(dataTable.Rows[0]["DownloadBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["DownloadBytes"].ToString());
                num2 = long.Parse(dataTable.Rows[0]["TotalBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["TotalBytes"].ToString());
            }
            else
            {
                string text = "INSERT INTO LawRow(ID,AtDownloadFinished_XmlUpDate,DownloadBytes,TotalBytes,UserID) \r\n                                                    VALUES(@1,'2010/01/01',0,0,@2)";
                int    num3 = MSCE.ExecuteNonQuery(text, lawDataLaw.ID, UserID);
                if (num3 < 1)
                {
                    LogTool.Debug(new Exception("DB失敗: " + text));
                }
            }
            lawItem        = new Law_DownloadItemViewModel();
            lawItem.ID     = lawDataLaw.ID;
            lawItem.UserID = UserID;
            DateTime result;

            DateTime.TryParse(lawDataLaw.UpDate, out result);
            lawItem.UpDate = result;
            lawItem.Name   = lawDataLaw.Name;
            lawItem.Link   = lawDataLaw.Link;
            lawItem.Status = (LawDataStatus)Enum.Parse(typeof(LawDataStatus), lawDataLaw.Status);
            string baseDirectory         = AppDomain.CurrentDomain.BaseDirectory;
            string law_StorageFileFolder = Settings.Default.Law_StorageFileFolder2;

            lawItem.StorageFileFolder = Path.Combine(baseDirectory, law_StorageFileFolder);
            string arg = DateTime.Now.ToFileTime().ToString();

            try
            {
                Uri    uri      = new Uri(lawItem.Link);
                string fileName = Path.GetFileName(uri.LocalPath);
                if (!fileName.Equals("/"))
                {
                    arg = fileName;
                }
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            lawItem.StorageFileName = string.Format("{0}_{1}_{2}", UserID, lawDataLaw.ID, arg);
            lawItem.UnZipFileFolder = Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.Law_UnZipFileFolder);
            if (num == 0 || num < num2)
            {
                if (File.Exists(lawItem.StorageFilePath))
                {
                    File.Delete(lawItem.StorageFilePath);
                }
                lawItem.DownloadBytes = 0L;
                lawItem.TotalBytes    = 0L;
                lawItem.FileType      = LawFileType.從未下載;
            }
            else if (TimeSpan.Compare(new TimeSpan(result.Ticks), new TimeSpan(dateTime.Ticks)) > 0)
            {
                lawItem.StorageFileName += ".update";
                lawItem.DownloadBytes    = 0L;
                lawItem.TotalBytes       = 0L;
                lawItem.FileType         = LawFileType.更新檔未下載;
            }
            else
            {
                lawItem.FileType = LawFileType.已下載完成;
            }
        }
 public bool _003CGetInList_003Eb__11(Law_DownloadItemViewModel x)
 {
     return(x.ID.Equals(lawDataLaw_ID));
 }
 public bool _003CPause_003Eb__b(Law_DownloadItemViewModel x)
 {
     return(x.ID.Equals(lawItem_ID));
 }
Example #28
0
        private Dictionary <string, BookVM> LawListCT_GetBookVMs_ByMeetingFileCate_Callback(Law_DownloadItemViewModel lawItem)
        {
            _003C_003Ec__DisplayClass19 _003C_003Ec__DisplayClass = new _003C_003Ec__DisplayClass19();

            _003C_003Ec__DisplayClass.lawItem = lawItem;
            Dictionary <string, BookVM> dictionary = new Dictionary <string, BookVM>();
            IEnumerable <LawRow>        enumerable = Enumerable.Where(Enumerable.OfType <LawRow>(LawRowSP.Children), new Func <LawRow, bool>(_003C_003Ec__DisplayClass._003CLawListCT_GetBookVMs_ByMeetingFileCate_Callback_003Eb__18));
            string filePath             = ClickOnceTool.GetFilePath();
            string file_UnZipFileFolder = Settings.Default.File_UnZipFileFolder;
            string str = filePath + "\\" + file_UnZipFileFolder + "\\" + UserID;

            if (enumerable != null)
            {
                foreach (LawRow item in enumerable)
                {
                    dictionary[item.lawItem.Name] = new BookVM(item.lawItem.ID, str + "\\" + item.lawItem.ID, _003C_003Ec__DisplayClass.lawItem.FileCate);
                }
                return(dictionary);
            }
            return(dictionary);
        }
Example #29
0
        private void UnzipTrigger(Law_DownloadItemViewModel lawItem)
        {
            if (lawItem == null)
            {
                return;
            }

            if (lawItem.FileType == LawFileType.已下載完成)
            {
                lawItem.FileType = LawFileType.解壓縮中;
            }
            else //LawFileType.更新檔已下載完成
            {
                lawItem.FileType = LawFileType.更新檔解壓縮中;
            }


            bool success = false;

            if (LawListCT_UnZip_Event != null)
            {
                LawListCT_UnZip_Event(lawItem);
            }

            try
            {
                UnZipTool uz = new UnZipTool();
                success = uz.UnZip(lawItem.StorageFilePath, lawItem.UnZipFilePath, "", true);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
                // 解壓縮失敗
            }

            // 解壓縮成功
            if (success == true)
            {
                // 一般檔案解壓縮中
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.FileType = LawFileType.已下載完成;
                }
                else // 更新檔解壓縮中
                {
                    lawItem.FileType = LawFileType.更新檔已下載完成;
                }
            }
            else // 解壓縮失敗
            {
                // 一般檔案解壓縮失敗
                // 只有一般檔案解壓縮失敗才要寫DB
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.DownloadBytes  = 0;
                    lawItem.TotalBytes     = 0;
                    lawItem.LastPercentage = 0;

                    if (File.Exists(lawItem.StorageFilePath) == true)
                    {
                        File.Delete(lawItem.StorageFilePath);
                    }
                    //寫DB
                    string SQL        = @"update  LawRow set AtDownloadFinished_XmlUpDate=@1
                                           , Link=@2,StorageFileName=@3
                                           , DownloadBytes=@4,TotalBytes=@5 where ID=@6 and UserID=@7";
                    int    successNum = MSCE.ExecuteNonQuery(SQL
                                                             , lawItem.UpDate.ToString("yyyy/MM/dd HH:mm:ss")
                                                             , lawItem.Link
                                                             , lawItem.StorageFileName
                                                             , lawItem.DownloadBytes.ToString()
                                                             , lawItem.TotalBytes.ToString()
                                                             , lawItem.ID
                                                             , lawItem.UserID);

                    if (successNum < 1)
                    {
                        LogTool.Debug(new Exception("DB失敗:" + SQL));
                    }
                }
                else
                {
                    // 更新檔解壓縮失敗
                    // 不寫DB
                }

                // 一般檔案解壓縮失敗
                if (lawItem.FileType == LawFileType.解壓縮中)
                {
                    lawItem.FileType = LawFileType.解壓縮失敗;
                    if (LawListCT_UnZipError_Event != null)
                    {
                        LawListCT_UnZipError_Event(lawItem);
                    }

                    if (Home_UnZipError_Event != null)
                    {
                        Home_UnZipError_Event(string.Format("{0} {1}"
                                                            , PaperLess_Emeeting.Properties.Settings.Default.LawButtonName
                                                            , Enum.GetName(typeof(LawFileType), LawFileType.解壓縮失敗)));
                    }
                    lawItem.FileType = LawFileType.從未下載;
                }
                else // 更新的檔案解壓縮失敗
                {
                    lawItem.FileType = LawFileType.更新檔解壓縮失敗;
                    if (LawListCT_UnZipError_Event != null)
                    {
                        LawListCT_UnZipError_Event(lawItem);
                    }

                    if (Home_UnZipError_Event != null)
                    {
                        Home_UnZipError_Event(string.Format("檔名: {0},{1}"
                                                            , PaperLess_Emeeting.Properties.Settings.Default.LawButtonName
                                                            , Enum.GetName(typeof(LawFileType), LawFileType.更新檔解壓縮失敗)));
                    }
                    lawItem.FileType = LawFileType.更新檔未下載;
                }
            }
        }
 private void UpdateToDB(Law_DownloadItemViewModel lawItem)
 {
 }