Exemple #1
0
    public static File_DownloadItemViewModel Gen(MeetingDataDownloadFileFile meetingDataDownloadFileFile, string UserID, string MeetingID)
    {
        File_DownloadItemViewModel file_DownloadItemViewModel = new File_DownloadItemViewModel();

        try
        {
            long      num       = 0L;
            long      num2      = 0L;
            int       num3      = 0;
            string    text      = "";
            int       num4      = 0;
            DataTable dataTable = MSCE.GetDataTable("SELECT ID,Url,StorageFileName,DownloadBytes,TotalBytes,FileVersion,FinishedFileVersion,EncryptionKey FROM FileRow where ID=@1 and UserID=@2 and MeetingID=@3", meetingDataDownloadFileFile.ID, UserID, MeetingID);
            if (dataTable.Rows.Count > 0)
            {
                dataTable.Rows[0]["ID"].ToString();
                dataTable.Rows[0]["Url"].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());
                int.Parse((dataTable.Rows[0]["FileVersion"].ToString().Equals("") || dataTable.Rows[0]["FileVersion"].ToString().Equals("0")) ? "1" : dataTable.Rows[0]["FileVersion"].ToString());
                num3 = int.Parse(dataTable.Rows[0]["FinishedFileVersion"].ToString().Equals("") ? "0" : dataTable.Rows[0]["FileVersion"].ToString());
                dataTable.Rows[0]["EncryptionKey"].ToString();
            }
            else
            {
                text = "INSERT INTO FileRow(ID,DownloadBytes,TotalBytes,UserID,MeetingID,DisplayFileName,FileVersion,EncryptionKey) \r\n                                                    VALUES(@1,0,0,@2,@3,@4,@5,@6)";
                num4 = MSCE.ExecuteNonQuery(text, meetingDataDownloadFileFile.ID, UserID, MeetingID, meetingDataDownloadFileFile.FileName, meetingDataDownloadFileFile.version.Equals("") ? "1" : meetingDataDownloadFileFile.version, (meetingDataDownloadFileFile.EncryptionKey == null) ? "" : meetingDataDownloadFileFile.EncryptionKey);
                if (num4 < 1)
                {
                    LogTool.Debug(new Exception("DB失敗: " + text));
                }
            }
            file_DownloadItemViewModel.MeetingID         = MeetingID;
            file_DownloadItemViewModel.ID                = meetingDataDownloadFileFile.ID;
            file_DownloadItemViewModel.UserID            = UserID;
            file_DownloadItemViewModel.FileName          = meetingDataDownloadFileFile.FileName;
            file_DownloadItemViewModel.Url               = meetingDataDownloadFileFile.Url;
            file_DownloadItemViewModel.AgendaID          = meetingDataDownloadFileFile.AgendaID;
            file_DownloadItemViewModel.EncryptionKey     = ((meetingDataDownloadFileFile.EncryptionKey == null) ? "" : meetingDataDownloadFileFile.EncryptionKey);
            file_DownloadItemViewModel.StorageFileFolder = Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.File_StorageFileFolder);
            string text2 = DateTime.Now.ToFileTime().ToString();
            try
            {
                Uri    uri      = new Uri(file_DownloadItemViewModel.Url);
                string fileName = Path.GetFileName(uri.LocalPath);
                if (!fileName.Equals("/"))
                {
                    text2 = fileName;
                }
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            file_DownloadItemViewModel.StorageFileName = string.Format("{0}_{1}_{2}_{3}", UserID, MeetingID, meetingDataDownloadFileFile.ID, text2);
            file_DownloadItemViewModel.UnZipFileFolder = Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.File_UnZipFileFolder);
            LogTool.Debug(ClickOnceTool.GetFilePath());
            file_DownloadItemViewModel.DownloadBytes = num;
            file_DownloadItemViewModel.TotalBytes    = num2;
            int result = 0;
            int.TryParse(meetingDataDownloadFileFile.version, out result);
            if (result < 1)
            {
                result = 1;
            }
            file_DownloadItemViewModel.FileVersion = result;
            if (num3 > 0 && file_DownloadItemViewModel.FileVersion > num3)
            {
                file_DownloadItemViewModel.CanUpdate = true;
            }
            if (File.Exists(file_DownloadItemViewModel.StorageFilePath))
            {
                if (num == 0)
                {
                    if (File.Exists(file_DownloadItemViewModel.StorageFilePath))
                    {
                        File.Delete(file_DownloadItemViewModel.StorageFilePath);
                    }
                    file_DownloadItemViewModel.DownloadBytes = 0L;
                    file_DownloadItemViewModel.TotalBytes    = 0L;
                    file_DownloadItemViewModel.FileType      = MeetingFileType.從未下載;
                }
                else if (num < num2)
                {
                    if (file_DownloadItemViewModel.CanUpdate)
                    {
                        file_DownloadItemViewModel.DownloadBytes = 0L;
                        file_DownloadItemViewModel.TotalBytes    = 0L;
                        file_DownloadItemViewModel.FileType      = MeetingFileType.已經下載過一次且可以更新版本的檔案_目前下載未完成;
                    }
                    else
                    {
                        file_DownloadItemViewModel.DownloadBytes = num;
                        file_DownloadItemViewModel.TotalBytes    = num2;
                        file_DownloadItemViewModel.FileType      = MeetingFileType.已下載過但是未完成的檔案;
                    }
                }
                else if (file_DownloadItemViewModel.CanUpdate)
                {
                    file_DownloadItemViewModel.DownloadBytes = 0L;
                    file_DownloadItemViewModel.TotalBytes    = 0L;
                    file_DownloadItemViewModel.FileType      = MeetingFileType.已經下載過一次且可以更新版本的檔案_目前下載已完成;
                }
                else
                {
                    file_DownloadItemViewModel.FileType = MeetingFileType.已下載完成;
                }
            }
            else
            {
                file_DownloadItemViewModel.DownloadBytes = 0L;
                file_DownloadItemViewModel.TotalBytes    = 0L;
                file_DownloadItemViewModel.FileType      = MeetingFileType.從未下載;
            }
            text = "update FileRow set DownloadBytes=@1,TotalBytes=@2,UserID=@3,MeetingID=@4,FileVersion=@5 where ID=@6";
            num4 = MSCE.ExecuteNonQuery(text, file_DownloadItemViewModel.DownloadBytes.ToString(), file_DownloadItemViewModel.TotalBytes.ToString(), UserID, MeetingID, file_DownloadItemViewModel.FileVersion.ToString(), file_DownloadItemViewModel.ID);
            if (num4 >= 1)
            {
                return(file_DownloadItemViewModel);
            }
            LogTool.Debug(new Exception("DB失敗: " + text));
            return(file_DownloadItemViewModel);
        }
        catch (Exception ex2)
        {
            LogTool.Debug(ex2);
            return(file_DownloadItemViewModel);
        }
    }
Exemple #2
0
        private void CallOpenBook(bool HasOpenFinishedFileVersion = false)
        {
            MouseTool.ShowLoading();
            try
            {
                Home Home_Window = Application.Current.Windows.OfType <Home>().FirstOrDefault();

                if (Home_Window.IsInSync == true && Home_Window.IsSyncOwner == false)
                {
                    AutoClosingMessageBox.Show("同步中需由主控人員進行操作");
                    return;
                }


                //

                string filePath = ClickOnceTool.GetFilePath();

                //string _bookPath = System.IO.Path.Combine(filePath, fileItem.UnZipFilePath);
                string UnZipFileFolder = PaperLess_Emeeting.Properties.Settings.Default.File_UnZipFileFolder;
                //string _bookPath = filePath + "\\" + UnZipFileFolder + "\\" + UserID + "\\" + MeetingID + "\\"+ fileItem.ID +"\\"+fileItem.FileVersion.ToString();
                // 等於上面那個路徑
                string _bookPath = fileItem.UnZipFilePath;

                // 從資料庫查詢上一次完成的檔案版本
                if (HasOpenFinishedFileVersion == true)
                {
                    DataTable dt = MSCE.GetDataTable("SELECT FinishedFileVersion FROM FileRow where ID=@1 and UserID=@2 and MeetingID=@3"
                                                     , meetingDataDownloadFileFile.ID
                                                     , UserID
                                                     , MeetingID);
                    if (dt.Rows.Count > 0)
                    {
                        _bookPath = filePath + "\\" + UnZipFileFolder + "\\" + UserID + "\\" + MeetingID + "\\" + fileItem.ID + "\\" + dt.Rows[0]["FinishedFileVersion"].ToString();
                    }
                }
                string _bookId    = fileItem.ID;
                string _account   = UserID;
                string _userName  = UserName;
                string _email     = UserEmail;
                string _meetingId = MeetingID;
                string _watermark = "";
                if (MeetingDataCT_GetWatermark_Event != null)
                {
                    _watermark = MeetingDataCT_GetWatermark_Event();
                }
                string _dbPath        = System.IO.Path.Combine(ClickOnceTool.GetDataPath(), PaperLess_Emeeting.Properties.Settings.Default.bookInfo_Path);
                bool   _isSync        = Home_Window.IsInSync;
                bool   _isSyncOwner   = Home_Window.IsSyncOwner;
                string _webServiceUrl = WsTool.GetUrl() + "/AnnotationUpload";
                string _socketMessage = "";


                SocketClient _socket   = null;
                SocketClient tmpSocket = Singleton_Socket.GetInstance(MeetingID, UserID, UserName, Home_Window.IsInSync);

                if (tmpSocket != null && tmpSocket.GetIsConnected() == true)
                {
                    _socket = tmpSocket;
                }

                //if (_socket.GetIsConnected() == false)
                //    _socket = null;
                //if (Home_Window.IsInSync == false)
                //    _socket = null;

                // 呼叫一個事件取得 BookVMs
                Dictionary <string, BookVM> cbBooksData = new Dictionary <string, BookVM>();
                if (MeetingDataCT_GetBookVMs_ByMeetingFileCate_Event != null)
                {
                    cbBooksData = MeetingDataCT_GetBookVMs_ByMeetingFileCate_Event(fileItem);
                }
                // debug
                //BooksData["cAF6-P"] = new BookVM("cAF6-P", filePath + "\\" + UnZipFileFolder + "\\" + UserID + "\\" + MeetingID + "\\" + "cAF6-P");
                //BooksData["cAF3-P"] = new BookVM("cAF3-P", filePath + "\\" + UnZipFileFolder + "\\" + UserID + "\\" + MeetingID + "\\" + "cAF3-P");

                Home_Window.CloseAllWindow("", true);

                switch (fileItem.FileCate)
                {
                case MeetingFileCate.電子書:

                    InitSyncCenter(_dbPath, _bookId, _account, _meetingId);

                    Task.Factory.StartNew(() =>
                    {
                        this.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            byte[] ReaderKey = new byte[1];

                            try
                            {
                                if (fileItem.EncryptionKey.Equals("") == false)
                                {
                                    ReaderKey = ReaderDecodeTool.GetReaderKey(fileItem.EncryptionKey);
                                }
                            }
                            catch (Exception ex)
                            {
                                LogTool.Debug(ex);
                            }
                            ReadWindow rw = new ReadWindow(cbBooksData, Home_Window.OpenBookFromReader, _bookPath, _bookId, _account
                                                           , _userName, _email, _meetingId
                                                           , _watermark, _dbPath, _isSync
                                                           , _isSyncOwner, _webServiceUrl, ReaderKey, _socketMessage, _socket);

                            //ReadWindow rw = new ReadWindow(cbBooksData, Home_Window.OpenBookFromReader, _bookPath, _bookId, _account
                            //                      , _userName, _email, _meetingId
                            //                      , _watermark, _dbPath, _isSync
                            //                      , _isSyncOwner, _webServiceUrl, _socketMessage, _socket);
                            rw.FolderID = this.FolderID;
                            rw.WindowStyle = WindowStyle.None;
                            rw.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            rw.WindowState = WindowState.Maximized;
                            if (PaperLess_Emeeting.Properties.Settings.Default.AssemblyName.Contains("TPI4F") == true)
                            {
                                //rw.WindowStyle = WindowStyle.SingleBorderWindow;
                            }
                            rw.Show();
                        }));
                    });


                    break;

                case MeetingFileCate.Html5投影片:
                    _bookPath = _bookPath + @"\" + new FileInfo(Directory.GetFiles(_bookPath)[0]).Name;

                    InitSyncCenter(_dbPath, _bookId, _account, _meetingId);

                    Task.Factory.StartNew(() =>
                    {
                        this.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            HTML5ReadWindow Html5rw = new HTML5ReadWindow(cbBooksData, Home_Window.OpenBookFromReader, _bookPath, _bookId, _account
                                                                          , _userName, _email, _meetingId
                                                                          , _watermark, _dbPath, _isSync
                                                                          , _isSyncOwner, _webServiceUrl, _socketMessage, _socket);
                            Html5rw.FolderID = this.FolderID;
                            Html5rw.WindowStyle = WindowStyle.None;
                            Html5rw.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            Html5rw.WindowState = WindowState.Maximized;
                            if (PaperLess_Emeeting.Properties.Settings.Default.AssemblyName.Contains("TPI4F") == true)
                            {
                                //Html5rw.WindowStyle = WindowStyle.SingleBorderWindow;
                            }
                            Html5rw.Show();
                        }));
                    });


                    break;

                case MeetingFileCate.影片檔:
                    _bookPath = _bookPath + @"\" + new FileInfo(Directory.GetFiles(_bookPath)[0]).Name;

                    Task.Factory.StartNew(() =>
                    {
                        this.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            MVWindow mvWindow = new MVWindow(cbBooksData, Home_Window.OpenBookFromReader, _bookPath, _bookId);
                            mvWindow.WindowStyle = WindowStyle.None;
                            mvWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            mvWindow.WindowState = WindowState.Maximized;
                            if (PaperLess_Emeeting.Properties.Settings.Default.AssemblyName.Contains("TPI4F") == true)
                            {
                                //mvWindow.WindowStyle = WindowStyle.SingleBorderWindow;
                            }
                            mvWindow.Show();
                        }));
                    });

                    break;
                }

                if (Home_Window.IsInSync == true && Home_Window.IsSyncOwner == true)
                {
                    SocketClient socketClient = Singleton_Socket.GetInstance(MeetingID, UserID, UserName, Home_Window.IsInSync);
                    Task.Factory.StartNew(() =>
                    {
                        if (socketClient != null && socketClient.GetIsConnected() == true)
                        {
                            string OB = "{\"bookId\":\"" + meetingDataDownloadFileFile.ID + "\",\"cmd\":\"R.OB\"}";
                            socketClient.broadcast(OB);
                        }
                        else
                        {
                            //AutoClosingMessageBox.Show("同步伺服器尚未啟動,請聯絡議事管理員開啟同步");
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }

            MouseTool.ShowArrow();
        }