コード例 #1
0
        public string StarterFilesXML(System.Guid guid)
        {
            try
            {
                DataSet     ds              = new DataSet();
                string      downloadRoot    = SharedSupport.AddBackSlashToDirectory(System.Web.HttpContext.Current.Request.MapPath(String.Empty, Constants.ASSIGNMENTMANAGER_DOWNLOAD_DIRECTORY, true));
                string      storageLocation = String.Empty;
                AssignmentM assign          = AssignmentM.Load(_assignmentID);
                storageLocation = SharedSupport.AddBackSlashToDirectory(assign.StorageDirectory + Constants.STARTER_PROJECT_PATH);

                //add unique guid to download path
                downloadRoot = downloadRoot + SharedSupport.AddBackSlashToDirectory(guid.ToString());

                DatabaseCall dbc = new DatabaseCall("Assignments_GetFiles", DBCallType.Select);
                dbc.AddParameter("@AssignmentID", _assignmentID);
                dbc.Fill(ds);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string source      = String.Empty;
                    string destination = String.Empty;

                    string filename = ds.Tables[0].Rows[i]["FileName"].ToString().Trim();
                    filename    = filename.Replace(@"\", @"/");
                    source      = SharedSupport.RemoveIllegalFilePathCharacters(storageLocation + filename);
                    destination = SharedSupport.RemoveIllegalFilePathCharacters(downloadRoot + filename);
                    //check to see if destination directory exists
                    string destinationDir = destination.Substring(0, destination.LastIndexOf("\\") + 1);
                    if (!Directory.Exists(destinationDir))
                    {
                        Directory.CreateDirectory(destinationDir);
                    }
                    //check if file is there
                    if (System.IO.File.Exists(source))
                    {
                        System.IO.File.Copy(source, destination, true);
                    }
                    else
                    {
                        throw new System.IO.FileNotFoundException(SharedSupport.GetLocalizedString("Assignment_UploadedFileNotFound"));
                    }

                    if (filename.StartsWith(@"/"))
                    {
                        ds.Tables[0].Rows[i]["FileName"] = guid + filename;
                    }
                    else
                    {
                        ds.Tables[0].Rows[i]["FileName"] = guid + @"/" + filename;
                    }
                }
                return(ds.GetXml());
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
コード例 #2
0
        public bool SubmitStarter(string xmlFileListing, string pathGuid)
        {
            if (this.IsValid)
            {
                bool submitSuccess = true;
                try
                {
                    System.Data.DataSet    dsXmlFileListing = new System.Data.DataSet();
                    System.IO.StringReader reader           = new System.IO.StringReader(xmlFileListing);
                    try
                    {
                        System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(reader);
                        dsXmlFileListing.ReadXml(xmlReader);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(SharedSupport.GetLocalizedString("UploadDownload_UnableToCopyToServer"), ex);
                    }

                    this.ClearStarter();

                    string uploadPath = SharedSupport.AddBackSlashToDirectory(System.Web.HttpContext.Current.Request.MapPath(String.Empty, Constants.ASSIGNMENTMANAGER_UPLOAD_DIRECTORY, true));
                    uploadPath += SharedSupport.AddBackSlashToDirectory(pathGuid);

                    string destinationPath = SharedSupport.AddBackSlashToDirectory(this.StorageDirectory + Constants.STARTER_PROJECT_PATH);

                    try
                    {
                        //Clear old directory
                        if (Directory.Exists(destinationPath))
                        {
                            Directory.Delete(destinationPath, true);
                        }
                        Directory.CreateDirectory(destinationPath);
                    }
                    catch
                    {
                    }

                    //Save all files and relative paths to assignmentfile table
                    for (int i = 0; i < dsXmlFileListing.Tables[0].Rows.Count; i++)
                    {
                        string filename = dsXmlFileListing.Tables[0].Rows[i]["FileName"].ToString();
                        if (filename.StartsWith(@"\") || filename.StartsWith(@"/"))
                        {
                            filename = filename.Remove(0, 1);
                        }
                        string sourceFile      = String.Empty;
                        string destinationFile = String.Empty;
                        sourceFile      = SharedSupport.RemoveIllegalFilePathCharacters(uploadPath + filename);
                        destinationFile = SharedSupport.RemoveIllegalFilePathCharacters(destinationPath + filename);
                        //check to make sure the target directory exists
                        string targetDirectory = destinationFile.Substring(0, destinationFile.LastIndexOf("\\"));
                        if (!Directory.Exists(targetDirectory))
                        {
                            Directory.CreateDirectory(targetDirectory);
                        }

                        //check if file is there
                        if (System.IO.File.Exists(sourceFile))
                        {
                            System.IO.File.Copy(sourceFile, destinationFile, true);
                        }
                        else
                        {
                            throw new System.IO.FileNotFoundException(SharedSupport.GetLocalizedString("Assignment_UploadedFileNotFound"));
                        }

                        this.AddFile(filename);
                    }
                    try
                    {
                        Directory.Delete(uploadPath, true);
                    }
                    catch
                    {
                    }

                    // Send new Starter project notice.
                    if (_sendNewProject && SharedSupport.UsingSmtp)
                    {
                        string[] AssignmentName = new string[] { _shortName };
                        string   subject        = SharedSupport.GetLocalizedString("Notification_UpdatedProjectSubject", AssignmentName);
                        string   body           = SharedSupport.GetLocalizedString("Notification_UpdatedProjectBody", AssignmentName);
                        MessageM.sendEmailMessageToCourse(subject, body, String.Empty, _courseId);
                    }
                }
                catch (Exception ex)
                {
                    SharedSupport.HandleError(ex);
                    submitSuccess = false;
                }

                if (submitSuccess)
                {
                    this.StarterProjectFlag = true;
                    this.Update();
                }
                return(submitSuccess);
            }
            else
            {
                return(false);
            }
        }