private void GetVideoFileList(string currentPath, List <VideoInfo> videoFilePathList) { if (Directory.GetFiles(currentPath).Length > 0) { string[] fileList = Directory.GetFiles(currentPath); for (int i = 0; i < fileList.Length; i++) { VideoInfo thumbnailInfo = new VideoInfo(); thumbnailInfo.VideoFullUrl = fileList[i]; thumbnailInfo.VideoName = Path.GetFileName(fileList[i]); // Nitin Start //thumbnailInfo.ThumbnailFilePath = Path.Combine(ClientHelper.GetClientThumbanailPath(), ThumbnailHelper.GetThumbnailFileName(ClientHelper.GetClientThumbanailPath(), ClientHelper.GetClassNameFromFullPath(currentPath), currentPath)); thumbnailInfo.ThumbnailFilePath = ThumbnailHelper.GetThumbnailFilePathByVideoPath(fileList[i]); // Nitin End videoFilePathList.Add(thumbnailInfo); } } else { string[] currentDirectoryList = Directory.GetDirectories(currentPath); for (int i = 0; i < currentDirectoryList.Length; i++) { GetVideoFileList(currentDirectoryList[i], videoFilePathList); } } }
private void AddRecomandatedVideos() { _mostRecommandedVideos.Clear(); Random random = new Random(); int[] randomVideoIndexList = Enumerable.Repeat <int>(-1, CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.Count).ToArray(); //new int[CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.Count]; int noOfIterations = 0; do { noOfIterations++; int newRandomNumber = random.Next(0, CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.Count - 1); if (randomVideoIndexList.Contains(newRandomNumber) == false) { _mostRecommandedVideos.Add(CommonAppStateDataHelper.ClientInfoObject.VideoInfoList[newRandomNumber]); randomVideoIndexList[newRandomNumber] = newRandomNumber; } }while ((_mostRecommandedVideos.Count < 5 && _mostRecommandedVideos.Count <= CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.Count) && noOfIterations < (CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.Count * 2)); if (_mostRecommandedVideos.Count < 5 && _mostRecommandedVideos.Count < CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.Count) { int intialCounterValue = _mostRecommandedVideos.Count == 0 ? 0 : _mostRecommandedVideos.Count - 1; for (int i = intialCounterValue; i < 5 && i < CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.Count; i++) { // int newRandomNumber = 0; if (randomVideoIndexList[i] < 0) { _mostRecommandedVideos.Add(CommonAppStateDataHelper.ClientInfoObject.VideoInfoList[i]); randomVideoIndexList[i] = i; } } } for (int i = 0; _mostRecommandedVideos != null && i < _mostRecommandedVideos.Count; i++) { // Nitin Start //ThumbnailInfo thumbInfo = new ThumbnailInfo(); //thumbInfo.FileName = _mostRecommandedVideos[i].VideoName; //thumbInfo.ThumbnailFilePath = Path.Combine(ClientHelper.GetClientThumbanailPath(), ThumbnailHelper.GetThumbnailFileName(ClientHelper.GetClientThumbanailPath(),_mostRecommandedVideos[i].ClassName, _mostRecommandedVideos[i].Book)); //thumbInfo.VideoFullUrl = _mostRecommandedVideos[i].VideoFullUrl; //_mostRecommandedVideosThumbList.Add(thumbInfo); _mostRecommandedVideos[i].ThumbnailFilePath = ThumbnailHelper.GetThumbnailFilePathByVideoPath(_mostRecommandedVideos[i].VideoFullUrl); // Nitin End } if (_mostRecommandedVideos != null && _mostRecommandedVideos.Count > 0) { AddVideoThumbnailControls(pnlRecomVideo, _mostRecommandedVideos, CtlMostWatchedVideo_Click); } }
private void AddMostWatchedVideos() { _mostWatchedVideos.Clear(); _mostWatchedVideos = CommonAppStateDataHelper.ClientInfoObject.VideoInfoList.OrderByDescending(k => k.WatchCount).Take(5).ToList <VideoInfo>(); for (int i = 0; _mostWatchedVideos != null && i < _mostWatchedVideos.Count; i++) { // Nitin Start //ThumbnailInfo thumbInfo = new ThumbnailInfo(); //thumbInfo.FileName = _mostWatchedVideos[i].VideoName; //thumbInfo.ThumbnailFilePath = Path.Combine(ClientHelper.GetClientThumbanailPath(), ThumbnailHelper.GetThumbnailFileName(ClientHelper.GetClientThumbanailPath(),_mostWatchedVideos[i].ClassName, _mostWatchedVideos[i].Book)); //thumbInfo.VideoFullUrl = _mostWatchedVideos[i].VideoFullUrl; //_mostWatchedVideosThumbList.Add(thumbInfo); _mostWatchedVideos[i].ThumbnailFilePath = ThumbnailHelper.GetThumbnailFilePathByVideoPath(_mostWatchedVideos[i].VideoFullUrl); // Nitin End } if (_mostWatchedVideos != null && _mostWatchedVideos.Count > 0) { AddVideoThumbnailControls(pnlMostWatchVideo, _mostWatchedVideos, CtlMostWatchedVideo_Click); } }
private void OnAfterAuthentication() { // Add mac address in firebase database. if (_firebaseRegInfo != null && _firebaseRegInfo.MacAddresses.Contains(_currentMacAddress) == false) { _firebaseRegInfo.MacAddresses.Add(_currentMacAddress); UpdateRegInfo(_firebaseRegInfo); } SessionInfo sessionInfo = new SessionInfo(); sessionInfo.StartTime = DateTime.Now; _clientInfo.LastAccessStartTime = DateTime.Now; _clientInfo.LastAccessEndTime = DateTime.Now; _clientInfo.SessionList.Add(sessionInfo); if (string.IsNullOrEmpty(_clientInfo.MacAddress)) { _clientInfo.MacAddress = _currentMacAddress; } for (int i = 0; i < _clientInfo.VideoInfoList.Count; i++) { if (Path.Combine(ClientHelper.GetClientRootPath(), _clientInfo.VideoInfoList[i].VideoRelativeUrl).Equals(_clientInfo.VideoInfoList[i].VideoFullUrl) == false) { _clientInfo.VideoInfoList[i].VideoFullUrl = Path.Combine(ClientHelper.GetClientRootPath(), _clientInfo.VideoInfoList[i].VideoRelativeUrl); // Nitin Start _clientInfo.VideoInfoList[i].ThumbnailFilePath = ThumbnailHelper.GetThumbnailFilePathByVideoPath(_clientInfo.VideoInfoList[i].VideoFullUrl); // Nitin End } } FileInfo clientInfoFileInfo = new FileInfo(ClientHelper.GetClientInfoFilePath()); try { clientInfoFileInfo.Attributes &= ~FileAttributes.Hidden; // this.ClientInfoObject.LastAccessStartTime = DateTime.UtcNow; Cryptograph.EncryptObject(_clientInfo, ClientHelper.GetClientInfoFilePath()); clientInfoFileInfo.Attributes |= FileAttributes.Hidden; } catch (Exception ex) { ExceptionHandler.HandleException(ex); throw; } finally { clientInfoFileInfo.Attributes |= FileAttributes.Hidden; } frmDashboard frm = new frmDashboard(); // frm.MdiParent = this.MdiParent; frm.ParentFormControl = this; frm.ClientInfoObject = CommonAppStateDataHelper.ClientInfoObject; CommonAppStateDataHelper.AddForm(this); frm.Show(); this.Hide(); CommonAppStateDataHelper.LoggedIn = true; }
private void CreateClientSchoolPackage() { string clientSchoolCodePath = ""; try { progressBar1.Visible = true; progressBar1.Value = 10; string schoolCode = txtSchoolCode.Text.Trim(); clientSchoolCodePath = Path.Combine(_clientDistributionRootPath, schoolCode); string clientVideoPath = ClientHelper.GetRegisteredSchoolPackageVideoPath(schoolCode, txtSchoolCity.Text.Trim()); // string clientThumbnailPath = ClientHelper.GetRegisteredSchoolPackageThumbnailPath(schoolCode); // Path.Combine(clientPacakgeFolderPath, "Thumbnails"); string clientVideoFolderName = ClientHelper.GetClientVideoFolderName(schoolCode, txtSchoolCity.Text.Trim()); List <VideoInfo> videoInfoList = new List <VideoInfo>(); #region Create Folder Structure // Create client distribution root folder. if (Directory.Exists(_clientDistributionRootPath) == false) { Directory.CreateDirectory(_clientDistributionRootPath); } // Define client pacakge root folder path i.e. school code if (Directory.Exists(clientSchoolCodePath) == false) { Directory.CreateDirectory(clientSchoolCodePath); } // Delete all old directory and files else if (Directory.Exists(clientSchoolCodePath)) { string[] oldClientFiles = Directory.GetDirectories(clientSchoolCodePath); for (int i = 0; i < oldClientFiles.Length; i++) { //System.IO.File.Delete(Path.Combine(clientSchoolCodeFolderPath, oldClientFiles[i])); System.IO.Directory.Delete(oldClientFiles[i], true); } oldClientFiles = Directory.GetFiles(clientSchoolCodePath); for (int i = 0; i < oldClientFiles.Length; i++) { System.IO.File.Delete(oldClientFiles[i]); } } progressBar1.Value = 25; //// Define client pacakge folder path i.e. pacakage //string clientPacakgeFolderPath = ClientHelper.GetClientRegistrationPackagePath(schoolCode); // Path.Combine(clientSchoolCodeFolderPath, "Package"); //if (Directory.Exists(clientPacakgeFolderPath) == false) //{ // Directory.CreateDirectory(clientPacakgeFolderPath); //} // Define client video folder path i.e. SchoolCode_City_LBFVideos if (Directory.Exists(clientVideoPath) == false) { Directory.CreateDirectory(clientVideoPath); } // Make client video folder hidden DirectoryInfo clientVideoFolderInfo = new DirectoryInfo(clientVideoPath); clientVideoFolderInfo.Attributes = FileAttributes.Hidden; //if (Directory.Exists(clientThumbnailPath) == false) //{ // Directory.CreateDirectory(clientThumbnailPath); //} //DirectoryInfo clientPackageThumbnailPathDirInfo = new DirectoryInfo(clientThumbnailPath); //clientPackageThumbnailPathDirInfo.Attributes = FileAttributes.Hidden; progressBar1.Value = 30; #endregion #region Copy Client Distribution if (Directory.Exists(ConfigHelper.ClientDistributionPath)) { string[] clientDistributionFiles = Directory.GetFiles(ConfigHelper.ClientDistributionPath); for (int i = 0; i < clientDistributionFiles.Length; i++) { string targetFilePath = Path.Combine(clientSchoolCodePath, Path.GetFileName(clientDistributionFiles[i])); System.IO.File.Copy(Path.Combine(ConfigHelper.ClientDistributionPath, clientDistributionFiles[i]), targetFilePath, true); if (_nonHiddenFiles.Contains(Path.GetFileName(targetFilePath).ToLower()) == false) { FileInfo targetFileInfo = new FileInfo(targetFilePath); targetFileInfo.Attributes = FileAttributes.Hidden; } } //// Create shortcut of exe. //WshShellClass shell = new WshShellClass(); //IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Path.Combine(clientSchoolCodeFolderPath, "LBSVideoLib.Client.exe.lnk")); //shortcut.TargetPath = Path.Combine(clientPacakgeFolderPath, "LBSVideoLib.Client.exe"); //// add Description of Short cut //shortcut.Description = "Run this exe to play LBF Video Library."; //// save it / create //shortcut.Save(); } else { MessageBox.Show("Unable to find client distribution on specified path.", "Error", MessageBoxButtons.OK); } progressBar1.Value = 45; for (int i = 0; i < chkListBooks.CheckedItems.Count; i++) { Book selectedBook = (chkListBooks.CheckedItems[i]) as Book; if (selectedBook.VideoList != null) { // string[] selectedBookVideos = Directory.GetFiles(selectedBook.BookId); foreach (string selectedBookVideo in selectedBook.VideoList) { string clientTargetVideoPath = Path.Combine(clientVideoPath, selectedBook.ClassName); string clientVideoRelativePath = Path.Combine(clientVideoFolderName, selectedBook.ClassName); if (Directory.Exists(clientTargetVideoPath) == false) { Directory.CreateDirectory(clientTargetVideoPath); } DirectoryInfo clientTargetVideoPathInfo = new DirectoryInfo(clientTargetVideoPath); clientTargetVideoPathInfo.Attributes = FileAttributes.Hidden; clientTargetVideoPath = Path.Combine(clientTargetVideoPath, selectedBook.SeriesName); clientVideoRelativePath = Path.Combine(clientVideoRelativePath, selectedBook.SeriesName); if (Directory.Exists(clientTargetVideoPath) == false) { Directory.CreateDirectory(clientTargetVideoPath); } clientTargetVideoPathInfo = new DirectoryInfo(clientTargetVideoPath); clientTargetVideoPathInfo.Attributes = FileAttributes.Hidden; clientTargetVideoPath = Path.Combine(clientTargetVideoPath, selectedBook.SubjectName); clientVideoRelativePath = Path.Combine(clientVideoRelativePath, selectedBook.SubjectName); if (Directory.Exists(clientTargetVideoPath) == false) { Directory.CreateDirectory(clientTargetVideoPath); } clientTargetVideoPathInfo = new DirectoryInfo(clientTargetVideoPath); clientTargetVideoPathInfo.Attributes = FileAttributes.Hidden; clientTargetVideoPath = Path.Combine(clientTargetVideoPath, selectedBook.BookName); clientVideoRelativePath = Path.Combine(clientVideoRelativePath, selectedBook.BookName); if (Directory.Exists(clientTargetVideoPath) == false) { Directory.CreateDirectory(clientTargetVideoPath); } clientTargetVideoPathInfo = new DirectoryInfo(clientTargetVideoPath); clientTargetVideoPathInfo.Attributes = FileAttributes.Hidden; if (Directory.Exists(clientTargetVideoPath) == false) { Directory.CreateDirectory(clientTargetVideoPath); } clientTargetVideoPathInfo = new DirectoryInfo(clientTargetVideoPath); clientTargetVideoPathInfo.Attributes = FileAttributes.Hidden; VideoInfo videoInfo = new VideoInfo(); videoInfo.VideoName = Path.GetFileName(selectedBookVideo); videoInfo.ClassName = selectedBook.ClassName; videoInfo.SeriesName = selectedBook.SeriesName; videoInfo.Subject = selectedBook.SubjectName; videoInfo.Book = selectedBook.BookName; clientTargetVideoPath = Path.Combine(clientTargetVideoPath, Path.GetFileName(selectedBookVideo)); clientVideoRelativePath = Path.Combine(clientVideoRelativePath, Path.GetFileName(selectedBookVideo)); //videoInfo.VideoFullUrl = clientTargetVideoPath; videoInfo.VideoFullUrl = clientVideoRelativePath; videoInfo.VideoRelativeUrl = clientVideoRelativePath; Cryptograph.EncryptFile(selectedBookVideo, clientTargetVideoPath); // Nitin Start 03-Sep // Copy thumbnail file string targetThumbnailFilePath = ThumbnailHelper.GetThumbnailDirectoryPathByVideoPath(clientTargetVideoPath); if (System.IO.File.Exists(targetThumbnailFilePath) == false) { if (Directory.Exists(targetThumbnailFilePath) == false) { Directory.CreateDirectory(targetThumbnailFilePath); } string sourceThumbnailFilePath = ThumbnailHelper.GetThumbnailFilePathByVideoPath(selectedBookVideo); targetThumbnailFilePath = Path.Combine(targetThumbnailFilePath, ThumbnailHelper.GetThumbnailFileNameByVideoPath(selectedBookVideo)); System.IO.File.Copy(sourceThumbnailFilePath, targetThumbnailFilePath, true); } // Nitin End 03-Sep FileInfo clientTargetVideoPathFileInfo = new FileInfo(clientTargetVideoPath); clientTargetVideoPathFileInfo.Attributes = FileAttributes.Hidden; videoInfoList.Add(videoInfo); } } } // Nitin Start //string[] subjectThumbnailFiles = Directory.GetFiles(ClientHelper.GetSubjectThumbnailSourcePath()); //for (int i = 0; i < subjectThumbnailFiles.Length; i++) //{ // string thumbnailFilePath = Path.Combine(clientThumbnailPath, Path.GetFileName(subjectThumbnailFiles[i])); // System.IO.File.Copy(subjectThumbnailFiles[i], thumbnailFilePath, true); // FileInfo thumbnailFilePathFileInfo = new FileInfo(thumbnailFilePath); // thumbnailFilePathFileInfo.Attributes = FileAttributes.Hidden; //} // Nitin End #endregion progressBar1.Value = 70; string newMemoNumber = GenerateNewMemoNumber(); // Save data on firebase RegInfoFB selectedClassList = SaveRegDataOnFireBase(newMemoNumber); string registeredSchoolInfo = Newtonsoft.Json.JsonConvert.SerializeObject(selectedClassList); // Nitin Start CreateRegisteredSchoolInfoFile(registeredSchoolInfo, schoolCode, txtSchoolCity.Text.Trim(), txtSchoolName.Text.Trim(), newMemoNumber); // Nitin End progressBar1.Value = 80; // Set client email, password and license date in client info class. ClientInfo clientInfo = new ClientInfo(); clientInfo.EmailId = txtEmailId.Text.ToLower().Trim(); clientInfo.Password = txtPwd.Text.Trim(); clientInfo.RegistrationDate = DateTime.Now; clientInfo.SessionStartDate = LicenseHelper.GetSessionStartDateBySessionString(cmbSchoolSession.SelectedItem.ToString()); clientInfo.SessionEndDate = LicenseHelper.GetSessionEndDateBySessionString(cmbSchoolSession.SelectedItem.ToString()); clientInfo.LastAccessEndTime = clientInfo.SessionStartDate; clientInfo.SessionString = cmbSchoolSession.SelectedItem.ToString(); clientInfo.SchoolId = this.txtSchoolCode.Text.Trim(); clientInfo.SchoolName = this.txtSchoolName.Text.Trim(); clientInfo.SchoolCity = txtSchoolCity.Text.Trim(); clientInfo.SelectedVideoDetails = selectedClassList.Classes; clientInfo.VideoInfoList = videoInfoList; clientInfo.MemoNumber = newMemoNumber; // Generate client info json file and encrypt it. string clientInfoFilePath = Path.Combine(clientSchoolCodePath, _clientInfoFileName); Cryptograph.EncryptObject(clientInfo, clientInfoFilePath); FileInfo clientInfoFileInfo = new FileInfo(clientInfoFilePath); clientInfoFileInfo.Attributes = FileAttributes.Hidden; progressBar1.Value = 99; //string clientInfoPlainText = Newtonsoft.Json.JsonConvert.SerializeObject(clientInfo); //sw = System.IO.File.CreateText(Path.Combine(ClientHelper.GetRegisteredSchoolInfoFilePath(), this.txtSchoolCode.Text.Trim() + "-Plain.txt")); //sw.Write(clientInfoPlainText); //sw.Flush(); //sw.Close(); progressBar1.Value = 100; progressBar1.Visible = false; // Copy client project bin folder to target location. MessageBox.Show("Registration completed successfully.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); InitializeRegistrationForm(); } catch (Exception ex) { // Delete all file on folder if (Directory.Exists(clientSchoolCodePath)) { // Delete created package folder inside school code System.IO.Directory.Delete(clientSchoolCodePath, true); } MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } finally { progressBar1.Visible = false; } }