예제 #1
0
 public void setProject(Project proj)
 {
     p = proj;
 }
예제 #2
0
 public RandomProjectData(Project proj)
 {
     rng = new Random();
     setProject(proj);
 }
        /// <summary>
        /// Updates this instance.
        /// </summary>
        /// <returns></returns>
        public bool Update()
        {
            if (Page.IsValid)
            {
                Globals.ProjectAccessType at = (rblAccessType.SelectedValue == "Public") ? Globals.ProjectAccessType.Public : Globals.ProjectAccessType.Private;
                IssueAttachmentStorageType attachmentStorageType = (AttachmentStorageType.SelectedValue == "2") ? IssueAttachmentStorageType.Database : IssueAttachmentStorageType.FileSystem;
                Project newProject = null;

                // get the current file
                HttpPostedFile uploadFile = ProjectImageUploadFile.PostedFile;
                HttpContext context = HttpContext.Current;

                // if there was a file uploaded
                if (uploadFile.ContentLength > 0)
                {
                    bool isFileOk = false;
                    string[] AllowedFileTypes = new string[3] { ".gif", ".png", ".jpg" };
                    string fileExt = System.IO.Path.GetExtension(uploadFile.FileName).ToLower();
                    string uploadedFileName = Path.GetFileName(uploadFile.FileName).ToLower();

                    foreach (string fileType in AllowedFileTypes)
                    {
                        string newfileType = fileType.Substring(fileType.LastIndexOf("."));
                        if (newfileType.CompareTo(fileExt) == 0)
                            isFileOk = true;
                    }

                    //file type is not valid
                    if (!isFileOk)
                    {
                        if (Log.IsErrorEnabled) Log.Error(string.Format(Logging.GetErrorMessageResource("InvalidFileType"), uploadedFileName));
                        return false;
                    }

                    //check for illegal filename characters
                    if (uploadedFileName.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) != -1)
                    {
                        if (Log.IsErrorEnabled) Log.Error(string.Format(Logging.GetErrorMessageResource("InvalidFileName"), uploadedFileName));
                        return false;
                    }

                    //if the file is ok save it.
                    if (isFileOk)
                    {
                        int fileSize = uploadFile.ContentLength;
                        byte[] fileBytes = new byte[fileSize];
                        System.IO.Stream myStream = uploadFile.InputStream;
                        myStream.Read(fileBytes, 0, fileSize);

                        ProjectImage projectImage = new ProjectImage(ProjectId, fileBytes, uploadedFileName, fileSize, uploadFile.ContentType);

                        // In High Security Mode, attachments can only go into the database.
                        if (SecurityModes.isHighSecurityMode())
                            attachmentStorageType = IssueAttachmentStorageType.Database;

                        newProject = new Project(ProjectId, txtName.Text.Trim(), ProjectCode.Text.Trim(), ProjectDescriptionHtmlEditor.Text.Trim(), ProjectManager.SelectedValue, string.Empty,
                        Page.User.Identity.Name, string.Empty, txtUploadPath.Text.Trim(), at, false, AllowAttachments.Checked, attachmentStorageType, string.Empty, chkAllowIssueVoting.Checked,
                        projectImage);

                    }
                }
                else
                {
                    // In High Security Mode, attachments can only go into the database.
                    if (SecurityModes.isHighSecurityMode())
                        attachmentStorageType = IssueAttachmentStorageType.Database;

                    newProject = new Project(ProjectId, txtName.Text.Trim(), ProjectCode.Text.Trim(), ProjectDescriptionHtmlEditor.Text.Trim(), ProjectManager.SelectedValue, string.Empty,
                        Page.User.Identity.Name, string.Empty, txtUploadPath.Text.Trim(), at, false, AllowAttachments.Checked, attachmentStorageType, string.Empty, chkAllowIssueVoting.Checked);

                }

                if (newProject.Save())
                {
                    ProjectId = newProject.Id;
                    return true;
                }
                else
                    lblError.Text = Logging.GetErrorMessageResource("SaveProjectError");

            }
            return false;
        }