예제 #1
0
        private void SaveFiles()
        {
            // create directory
            //HesterConsultants.Properties.Settings settings =
            //    HesterConsultants.Properties.Settings.Default;

            // job files virtual root
            string jobFilesRootVirtual = Settings.Default.JobFilesRoot;

            if (!jobFilesRootVirtual.EndsWith(@"/"))
            {
                jobFilesRootVirtual += @"/";
            }

            // get local path
            string jobFilesRootLocal = this.Server.MapPath(jobFilesRootVirtual);

            if (!jobFilesRootLocal.EndsWith(@"\"))
            {
                jobFilesRootLocal += @"\";
            }

            DirectoryInfo jobInFolder = Directory.CreateDirectory(jobFilesRootLocal + newJob.JobId.ToString() + @"\in"); // "in" for submitted files

            // six file upload controls
            for (int k = 1; k <= 6; k++)
            {
                FileUpload fu = (FileUpload)this.FindControl("file" + k.ToString());
                if (fu.HasFile)
                {
                    string filename = HesterConsultants.AppCode.SiteUtils.WindowsSafeFilename(fu.FileName);

                    // adjust filename if necessary
                    filename = HesterConsultants.AppCode.SiteUtils.ConflictFreeFilename(jobInFolder.FullName, filename, Settings.Default.FilenameAppendedDigitsMax);
                    string virtualPath = jobFilesRootVirtual + newJob.JobId.ToString() + @"/in/" + filename;

                    try
                    {
                        fu.SaveAs(jobInFolder.FullName + @"\" + filename);
                    }
                    catch (Exception ex)
                    {
                        ClientData.Current.LogErrorAndSendAlert(ex);
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to save file."));
                    }

                    //int jobFileId = ClientData.Current.InsertJobFile(newJob.JobId, filename, virtualPath, false, true);

                    //if (jobFileId == 0)
                    //    throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job file to database."));

                    JobFile jobFile = JobFile.InsertJobFile(newJob, filename, virtualPath, false, true);

                    if (jobFile == null)
                    {
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Job file is null."));
                    }
                }
            }
        }
예제 #2
0
        private void SaveFiles()
        {
            filesChanged = true;

            // get or create directory

            // virtual jobfiles root
            string jobFilesRootVirtual = Settings.Default.JobFilesRoot;

            if (!jobFilesRootVirtual.EndsWith(@"/"))
            {
                jobFilesRootVirtual += @"/";
            }

            // get local path
            string jobFilesRootLocal = this.Server.MapPath(jobFilesRootVirtual);

            // file upload controls
            for (int j = 0; j < 2; j++)
            {
                JobFile.JobFileType fileType;
                string whichFileControl;
                string whichDirectory;

                if (j == 0)
                {
                    fileType         = JobFile.JobFileType.Returned;
                    whichFileControl = "returnFile";
                    whichDirectory   = "out";
                }
                else if (j == 1)
                {
                    fileType         = JobFile.JobFileType.Working;
                    whichFileControl = "workingFile";
                    whichDirectory   = "working";
                }
                else
                {
                    fileType         = JobFile.JobFileType.Submitted;
                    whichFileControl = "submittedFile";
                    whichDirectory   = "in";
                }


                FileUpload fu = (FileUpload)this.FindControl(whichFileControl + "1");
                if (fu.HasFile)
                {
                    DirectoryInfo fileFolder = Directory.CreateDirectory(jobFilesRootLocal + @"\" + jobId.ToString() + @"\" + whichDirectory);

                    string filename = HesterConsultants.AppCode.SiteUtils.WindowsSafeFilename(fu.FileName);

                    // adjust filename if necessary
                    filename = HesterConsultants.AppCode.SiteUtils.ConflictFreeFilename(fileFolder.FullName, filename, Settings.Default.FilenameAppendedDigitsMax);

                    string virtualPath = jobFilesRootVirtual + jobId.ToString() + @"/" + whichDirectory + @"/" + filename;

                    // save file
                    try
                    {
                        fu.SaveAs(fileFolder.FullName + @"\" + filename);
                    }
                    catch (Exception ex)
                    {
                        ClientData.Current.LogErrorAndSendAlert(ex);
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to save file."));
                    }

                    JobFile jobFile = JobFile.InsertJobFile(curJob, filename, virtualPath, (fileType == JobFile.JobFileType.Returned), (fileType == JobFile.JobFileType.Submitted));

                    if (jobFile == null)
                    {
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Job file is null."));
                    }
                }
            }
        }