private bool Check_ImportUsersXSD() { string strFile = ""; try { strFile = ConfigurationSettings.AppSettings["ImportUsersXSD"].ToString(); strFile = WebTool.MapToPhysicalPath(strFile); this.Check_CanReadFile(strFile); this.AddMessage(true, "Import Users XSD" + "<BR>" + strFile, "File Exists/Readable"); return(true); } catch (Exception ex) { this.AddMessage(false, "Import Users XSD" + "<BR>" + strFile, ex.Message); return(false); } }
private bool Check_ErrorLogFileName() { string strFile = ""; try { strFile = ConfigurationSettings.AppSettings["ErrorLogFileName"].ToString(); strFile = WebTool.MapToPhysicalPath(strFile); this.Check_CanWriteFile(strFile); this.AddMessage(true, "Error Log File Name" + "<BR>" + strFile, "File Exists/Writable"); return(true); } catch (Exception ex) { this.AddMessage(false, "Error Log File Name" + "<BR>" + strFile, ex.Message); return(false); } }
private bool Check_UploadedFilePath() { string strDirectory = ""; try { // Construct the path on the web server where the uploaded files will be written strDirectory = ConfigurationSettings.AppSettings["UploadedFilePath"].ToString(); strDirectory = WebTool.MapToPhysicalPath(strDirectory); this.Check_ReadWriteFileToDirectory(strDirectory); this.AddMessage(true, "Uploaded File Path" + "<BR>" + strDirectory, "Directory Exists/Writable"); return(true); } catch (Exception ex) { this.AddMessage(false, "Uploaded File Path" + "<BR>" + strDirectory, ex.Message); return(false); } }
private bool Check_ToolBookDestinationDirectory() { string strDirectory = ""; try { // Construct the path on the web server where the Toolbook files will be placed strDirectory = ConfigurationSettings.AppSettings["ImportToolBookDestinationDirectory"].ToString(); strDirectory = WebTool.MapToPhysicalPath(strDirectory); this.Check_ReadWriteFileToDirectory(strDirectory); this.AddMessage(true, "ToolBook Destination Directory" + "<BR>" + strDirectory, "Directory Exists/Writable"); return(true); } catch (Exception ex) { this.AddMessage(false, "ToolBook Destination Directory" + "<BR>" + strDirectory, ex.Message); return(false); } }
} // UploadToolBokkContent /// <summary> /// This method handles the uploading of data from the xml file to the sql server database /// </summary> private void UploadScormContent() { int intModuleID; // The current Module ID int intCourseID; // The current Course ID Module objModule; // Used to access the Module Details DataTable dtbModule; // Datatable containing Module Details DirectoryInfo dirNewContentSource; // Directory info about the source directory DirectoryInfo dirNewContentDestination; // Directory info about the destination directory DirectoryInfo dirNewContentDestination2; // Directory info about the destination directory DirectoryInfo dirOldContentDestination; // Directory info about the destination directory string strContentType; // The content type, Quiz or a Lesson string strUploadType; // The Upload Type, a correction or an update string strNewContentDestination; // string strOldContentDestination; // string strFilename = ""; string strQFS = ""; // Retrieve the Module ID from the query string and Course ID from the database intModuleID = int.Parse(Request.QueryString["ModuleID"].ToString()); // Get module details objModule = new Module(); dtbModule = objModule.GetModule(intModuleID, UserContext.UserData.OrgID); intCourseID = int.Parse(dtbModule.Rows[0]["CourseID"].ToString()); // Verify that the ASP.NET user has the necessary permission to the content // destination folder before beginning content upload string strContentDestinationTest = ConfigurationSettings.AppSettings["ImportSCORMDestinationDirectory"] + "/Test"; DirectoryInfo dirContentDestinationTest = new DirectoryInfo(WebTool.MapToPhysicalPath(strContentDestinationTest)); try { // Try to create a test folder, will throw an IOException if insufficient permissions dirContentDestinationTest.Create(); // Tidy up dirContentDestinationTest.Delete(true); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; } String LaunchPoint; // LaunchPoint = txtLocation.Text; //Code by joseph //if (LaunchPoint.Contains("launchpage.html")) //{ // string strContentDestinationNew = ConfigurationSettings.AppSettings["ImportSCORMDestinationDirectory"];// +"/AdaptiveFiles"; // DirectoryInfo dirContentDestination = new DirectoryInfo(WebTool.MapToPhysicalPath(strContentDestinationNew)); // strNewContentDestination = strContentDestinationNew + "/" + intCourseID + "/" + intModuleID.ToString(); // if (!System.IO.Directory.Exists(dirContentDestination + "\\" + intCourseID + "\\" + intModuleID)) // { // System.IO.Directory.CreateDirectory(dirContentDestination + "\\" + intCourseID + "\\" + intModuleID); // string strContentDestination = dirContentDestination + "\\" + intCourseID + "\\" + intModuleID.ToString(); // // // System.IO.File.Copy(strContentDestination, strNewContentDestination, true); // } // else // { // string strContentDestination = dirContentDestination + "/" + intCourseID + "/" + intModuleID.ToString(); // // // } //} //else //{ //end try { // Create a directory info object for the specified path LaunchPoint = txtLocation.Text; dirNewContentSource = dirContentDestinationTest; if (LaunchPoint.Contains("launchpage.html")) { LaunchPoint = LaunchPoint.Split('/')[0].ToString(); FileInfo LessonLaunchPoint = new FileInfo(Server.MapPath("/General/") + "Scorm/Publishing/" + LaunchPoint); strFilename = "launchpage.html"; dirNewContentSource = new DirectoryInfo(LessonLaunchPoint.Directory.FullName + "/" + LaunchPoint.Split('/')[0].ToString()); LaunchPoint = txtLocation.Text; } else { LaunchPoint = LaunchPoint.Substring(0, LaunchPoint.IndexOf("?")); FileInfo LessonLaunchPoint = new FileInfo(Server.MapPath("/General/") + "Scorm/Publishing/" + LaunchPoint); strFilename = LessonLaunchPoint.Name; dirNewContentSource = new DirectoryInfo(LessonLaunchPoint.Directory.FullName); LaunchPoint = txtLocation.Text; } strQFS = LaunchPoint.Substring(LaunchPoint.IndexOf("?") + 5, LaunchPoint.Length - LaunchPoint.IndexOf("?") - 5); LaunchPoint = LaunchPoint.Substring(0, LaunchPoint.IndexOf("?")); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; return; } // Check that the supplied path exists if (dirNewContentSource.Exists) { // Construct the path on the web server where the new SCORM files will be placed strNewContentDestination = ConfigurationSettings.AppSettings["ImportSCORMDestinationDirectory"].ToString(); strNewContentDestination += "/" + intCourseID.ToString() + "/" + intModuleID.ToString(); if (!LaunchPoint.Contains("launchpage.html")) { strNewContentDestination += "/" + "lesson"; } // Construct the path on the web server where the OLD SCORM files will be moved to (if they exist) strOldContentDestination = ConfigurationSettings.AppSettings["ImportSCORMDestinationDirectory"].ToString(); strOldContentDestination += "/Superseded/" + intCourseID.ToString() + "/" + intModuleID.ToString(); if (!LaunchPoint.Contains("launchpage.html")) { strOldContentDestination += "/" + "lesson"; } strOldContentDestination = WebTool.MapToPhysicalPath(strOldContentDestination); //strNewContentDestination = txtLocation.Text; //strNewContentDestination = WebTool.MapToPhysicalPath(strNewContentDestination); // Ensure the destination directory on the web server exists dirNewContentDestination2 = new DirectoryInfo(WebTool.MapToPhysicalPath(strNewContentDestination)); if (dirNewContentDestination2.Exists) { // Delete the contents of the current content destination folder try { dirOldContentDestination = new DirectoryInfo(strOldContentDestination); dirOldContentDestination.Create(); dirNewContentDestination2.MoveTo(strOldContentDestination + "/" + DateTime.Now.Ticks); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; return; } } dirNewContentDestination = new DirectoryInfo(WebTool.MapToPhysicalPath(strNewContentDestination)); // Copy the source Toolbook files into the destination directory try { // Create the content destination folder dirNewContentDestination.Create(); // Copy the Toolbook files to the required destination on the web server WebTool.CopyDirectory(dirNewContentSource.FullName, dirNewContentDestination.FullName); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; new ErrorHandler.ErrorLog(ex, Bdw.Application.Salt.Data.ErrorLevel.High, "UploadToolbookContent.aspx", "UploadContent", "dirNewContentDestination.Create()"); return; } try { string contentdest; if (LaunchPoint.Contains("launchpage.html")) { contentdest = strNewContentDestination + "/shared/" + strFilename; } else { contentdest = strNewContentDestination + "/" + strFilename; } using (StoredProcedure sp = new StoredProcedure("prcSCORMimport", // StoredProcedure.CreateInputParam("@intLessonID", SqlDbType.Int, intLessonID), StoredProcedure.CreateInputParam("@intModuleID", SqlDbType.Int, intModuleID), // StoredProcedure.CreateInputParam("@strToolbookID", SqlDbType.VarChar,50, strToolbookID), // StoredProcedure.CreateInputParam("@strToolLocation", SqlDbType.VarChar, 100, strNewContentDestination + "/" + strFilename),By Joseph StoredProcedure.CreateInputParam("@strToolLocation", SqlDbType.VarChar, 100, contentdest), StoredProcedure.CreateInputParam("@strQFSLocation", SqlDbType.VarChar, 100, strNewContentDestination + "/" + strQFS), // StoredProcedure.CreateInputParam("@strToolLocation", SqlDbType.VarChar, 100, dirNewContentDestination.FullName + "/" + strFilename), StoredProcedure.CreateInputParam("@DatePublished", SqlDbType.DateTime, dirNewContentSource.LastWriteTime), StoredProcedure.CreateInputParam("@intUserID", SqlDbType.VarChar, 1000, UserContext.UserID), StoredProcedure.CreateInputParam("@SCORMsource", SqlDbType.VarChar, 100, LaunchPoint) ) ) { sp.ExecuteNonQuery(); } } catch (Exception) { throw; } // Display a success message this.lblMessage.Text = ResourceManager.GetString("LessonUpload"); this.lblMessage.CssClass = "SuccessMessage"; } else { this.lblMessage.Text = String.Format(ResourceManager.GetString("lblMessage5"), Request.ServerVariables["SERVER_NAME"]);//"The specified physical path does not exist on " + Request.ServerVariables["SERVER_NAME"]; this.lblMessage.CssClass = "WarningMessage"; return; } //} } // UploadScormContent
/// <summary> /// This method handles the uploading of data from the xml file to the sql server database /// </summary> private void UploadTBkContent() { int intModuleID; // The current Module ID int intCourseID; // The current Course ID Module objModule; // Used to access the Module Details DataTable dtbModule; // Datatable containing Module Details DirectoryInfo dirNewContentSource; // Directory info about the source directory DirectoryInfo dirNewContentDestination; // Directory info about the destination directory ImportToolbook objImport; // Used to perform the actual import DataSet dstImportResults; // Dataset containing the import results string strContentType; // The content type, Quiz or a Lesson string strUploadType; // The Upload Type, a correction or an update string strNewContentDestination; // // Retrieve the Module ID from the query string and Course ID from the database intModuleID = int.Parse(Request.QueryString["ModuleID"].ToString()); // Get module details objModule = new Module(); dtbModule = objModule.GetModule(intModuleID, UserContext.UserData.OrgID); intCourseID = int.Parse(dtbModule.Rows[0]["CourseID"].ToString()); // Verify that the ASP.NET user has the necessary permission to the content // destination folder before beginning content upload string strContentDestinationTest = ConfigurationSettings.AppSettings["ImportToolBookDestinationDirectory"] + "/Test"; DirectoryInfo dirContentDestinationTest = new DirectoryInfo(WebTool.MapToPhysicalPath(strContentDestinationTest)); try { // Try to create a test folder, will throw an IOException if insufficient permissions dirContentDestinationTest.Create(); // Tidy up dirContentDestinationTest.Delete(true); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; } try { // Create a directory info object for the specified path dirNewContentSource = new DirectoryInfo(txtLocation.Text); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; return; } // Check that the supplied path exists if (dirNewContentSource.Exists) { try { CheckForContent(); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; return; } // Create an ImportToolbook object to import the content in the XML file string strXMLFile = dirNewContentSource.FullName + @"\" + ConfigurationSettings.AppSettings["ImportToolBookXMLFileName"].ToString(); string strXSDFile = WebTool.MapToPhysicalPath(ConfigurationSettings.AppSettings["ToolBookXSD"]); objImport = new ImportToolbook(strXMLFile, strXSDFile, ConfigurationSettings.AppSettings["XMLNamespace"]); objImport.ModuleID = intModuleID; objImport.CourseID = intCourseID; objImport.UserID = UserContext.UserID; // Preview the XML to determine the content and upload type try { dstImportResults = objImport.Preview(); } catch (Exception ex) { this.lblMessage.Text = ResourceManager.GetString("lblMessage1") + Environment.NewLine + ex.Message; this.lblMessage.CssClass = "WarningMessage"; return; } switch (dstImportResults.Tables.Count) { case 2: // XML file loaded successfully strUploadType = dstImportResults.Tables[0].Rows[0].ItemArray[0].ToString(); strContentType = dstImportResults.Tables[0].Rows[0].ItemArray[1].ToString(); break; case 1: // Error condition - could be that a correction has been rejected this.lblMessage.Text = ResourceManager.GetString("lblMessage2") + " " + dstImportResults.Tables[0].Rows[0].ItemArray[0].ToString(); this.lblMessage.CssClass = "WarningMessage"; return; default: // Unknown error condition this.lblMessage.Text = ResourceManager.GetString("lblMessage3"); this.lblMessage.CssClass = "WarningMessage"; return; } // Construct the path on the web server where the Toolbook files will be placed strNewContentDestination = ConfigurationSettings.AppSettings["ImportToolBookDestinationDirectory"].ToString(); strNewContentDestination += "/" + intCourseID.ToString() + "/" + intModuleID.ToString(); strNewContentDestination += "/" + strContentType; // The import procedure just needs to the logical path, not the physical if (radInfoPath.Checked) { objImport.ToolbookLocation = strNewContentDestination + @"/default.aspx"; } if (radToolbook.Checked) { objImport.ToolbookLocation = strNewContentDestination + @"/ie4/index.html"; } strNewContentDestination = WebTool.MapToPhysicalPath(strNewContentDestination); //check for qfs // If the upload is a lesson, verify that the Quick facts sheet is present // if ( (strContentType.ToUpper() == "LESSON") && (dirNewContentSource.GetFiles(m_strQuickFactSheetFile).Length == 0) ) // { // // The Quick facts sheet does not exist // this.lblMessage.Text += "Error uploading new content: '" + dirNewContentSource.FullName + @"\" + m_strQuickFactSheetFile + "' does not exist"; // this.lblMessage.CssClass = "WarningMessage"; // return; // } // Load the content into the database try { dstImportResults = objImport.Load(); } catch (Exception ex) { ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex, ErrorLevel.High, "UploadToolBookContent.aspx.cs", "UploadContent", ex.Message); this.lblMessage.Text = ResourceManager.GetString("lblMessage4");//"Unknown error uploading new content."; this.lblMessage.CssClass = "WarningMessage"; return; } if (dstImportResults.Tables.Count != 2) { // Error condition this.lblMessage.Text = ResourceManager.GetString("lblMessage5");//"Error uploading new content."; this.lblMessage.CssClass = "WarningMessage"; return; } // Ensure the destination directory on the web server exists dirNewContentDestination = new DirectoryInfo(strNewContentDestination); if (dirNewContentDestination.Exists) { // Delete the contents of the current content destination folder try { dirNewContentDestination.Delete(true); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; return; } } // Copy the source Toolbook files into the destination directory try { // Create the content destination folder dirNewContentDestination.Create(); // Copy the Toolbook files to the required destination on the web server WebTool.CopyDirectory(dirNewContentSource.FullName, dirNewContentDestination.FullName); } catch (Exception ex) { this.lblMessage.Text = ex.Message; this.lblMessage.CssClass = "WarningMessage"; new ErrorHandler.ErrorLog(ex, Bdw.Application.Salt.Data.ErrorLevel.High, "UploadToolbookContent.aspx", "UploadContent", "dirNewContentDestination.Create()"); return; } // Display a success message switch (strContentType) { case "quiz": this.lblMessage.Text = ResourceManager.GetString("QuizUpload"); break; case "lesson": this.lblMessage.Text = ResourceManager.GetString("LessonUpload"); break; } this.lblMessage.CssClass = "SuccessMessage"; } else { this.lblMessage.Text = String.Format(ResourceManager.GetString("lblMessage5"), Request.ServerVariables["SERVER_NAME"]);//"The specified physical path does not exist on " + Request.ServerVariables["SERVER_NAME"]; this.lblMessage.CssClass = "WarningMessage"; return; } } // UploadToolBokkContent
private void UploadAdaptiveContent() { int intModuleID; // The current Module ID int intCourseID; // The current Course ID Module objModule; // Used to access the Module Details DataTable dtbModule; // Datatable containing Module Details DirectoryInfo dirNewContentSource; // Directory info about the source directory DirectoryInfo dirNewContentDestination; // Directory info about the destination directory DirectoryInfo dirNewContentDestination2; // Directory info about the destination directory DirectoryInfo dirOldContentDestination; // Directory info about the destination directory string strContentType; // The content type, Quiz or a Lesson string strUploadType; // The Upload Type, a correction or an update string strNewContentDestination; // string strOldContentDestination; // string strFilename = ""; string strQFS = ""; // Retrieve the Module ID from the query string and Course ID from the database intModuleID = int.Parse(Request.QueryString["ModuleID"].ToString()); // Get module details objModule = new Module(); dtbModule = objModule.GetModule(intModuleID, UserContext.UserData.OrgID); intCourseID = int.Parse(dtbModule.Rows[0]["CourseID"].ToString()); FileInfo zip = new FileInfo(inputFile.PostedFile.FileName); strFilename = inputFile.PostedFile.FileName.ToString(); string strContentDestinationNew = ConfigurationSettings.AppSettings["ImportSCORMDestinationDirectory"];// +"/AdaptiveFiles"; DirectoryInfo dirContentDestination = new DirectoryInfo(WebTool.MapToPhysicalPath(strContentDestinationNew)); strNewContentDestination = strContentDestinationNew + "/" + intCourseID + "/" + intModuleID.ToString(); if (!System.IO.Directory.Exists(dirContentDestination + "\\" + intCourseID + "\\" + intModuleID)) { System.IO.Directory.CreateDirectory(dirContentDestination + "\\" + intCourseID + "\\" + intModuleID); string strContentDestination = dirContentDestination + "\\" + intCourseID + "\\" + intModuleID.ToString(); using (ZipFile zipRead = ZipFile.Read(inputFile.PostedFile.InputStream)) { zipRead.ExtractAll(strContentDestination, ExtractExistingFileAction.OverwriteSilently); } } else { string strContentDestination = dirContentDestination + "/" + intCourseID + "/" + intModuleID.ToString(); using (ZipFile zipRead = ZipFile.Read(inputFile.PostedFile.InputStream)) { zipRead.ExtractAll(strContentDestination, ExtractExistingFileAction.OverwriteSilently); } } try { using (StoredProcedure sp = new StoredProcedure("prcSCORMimportAdaptive", // StoredProcedure.CreateInputParam("@intLessonID", SqlDbType.Int, intLessonID), StoredProcedure.CreateInputParam("@intModuleID", SqlDbType.Int, intModuleID), // StoredProcedure.CreateInputParam("@strToolbookID", SqlDbType.VarChar,50, strToolbookID), StoredProcedure.CreateInputParam("@strToolLocation", SqlDbType.VarChar, 100, strNewContentDestination + "/imsmanifest.xml"), //StoredProcedure.CreateInputParam("@strQFSLocation", SqlDbType.VarChar, 100, strNewContentDestination + "/" + strQFS), // StoredProcedure.CreateInputParam("@strToolLocation", SqlDbType.VarChar, 100, dirNewContentDestination.FullName + "/" + strFilename), //StoredProcedure.CreateInputParam("@DatePublished", SqlDbType.DateTime, dirNewContentSource.LastWriteTime), StoredProcedure.CreateInputParam("@intUserID", SqlDbType.VarChar, 1000, UserContext.UserID) //StoredProcedure.CreateInputParam("@SCORMsource", SqlDbType.VarChar, 100, LaunchPoint) ) ) { sp.ExecuteNonQuery(); } } catch (Exception) { throw; } }