Ejemplo n.º 1
0
        public JsonResult Upload(Guid id)
        {
            var tenantId = _userManager.CurrentUserTenantId;
            var file     = new UploadFileViewModel
            {
                File = Request.Form.Files.FirstOrDefault(),
                Id   = id,
            };
            var response = _fileManager.AddFile(file, tenantId ?? Guid.Empty);

            return(Json(response));
        }
Ejemplo n.º 2
0
        public IActionResult OnPost(File file)
        {
            _fileManager.AddFile(file);

            fileModels = GetAllRecords();
            return(Page());
        }
Ejemplo n.º 3
0
        public HttpResponseMessage CreateThumbnail(CreateThumbnailDTO dto)
        {
            IFileManager   _fileManager   = FileManager.Instance;
            IFolderManager _folderManager = FolderManager.Instance;

            IFileInfo _file = _fileManager.GetFile(dto.FileId);

            if (_file == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "File Not Found"));
                //return Json(new {Result = "error"});
            }
            IFolderInfo _folder = _folderManager.GetFolder(_file.FolderId);

            string ext = _file.Extension;

            if (!(ext.StartsWith(".")))
            {
                ext = "." + ext;
            }
            string sizedPhoto = _file.FileName.Replace(ext, "_" + dto.Width.ToString(CultureInfo.InvariantCulture) + "x" + dto.Height.ToString(CultureInfo.InvariantCulture) + ext);

            IFileInfo newPhoto = _fileManager.AddFile(_folder, sizedPhoto, _fileManager.GetFileContent(_file));

            sizedPhoto = ImageUtils.CreateImage(newPhoto.PhysicalPath, dto.Height, dto.Width);
            newPhoto   = _fileManager.UpdateFile(newPhoto);

            return(Request.CreateResponse(HttpStatusCode.OK, newPhoto.ToJson()));
        }
Ejemplo n.º 4
0
        private void Save_Click(object sender, EventArgs e)
        {
            if (GroupId > 0)
            {
                RoleController          roleController = new RoleController();
                Security.PortalSecurity ps             = new Security.PortalSecurity();
                txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoScripting);
                txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoMarkup);
                var roleInfo = roleController.GetRole(GroupId, PortalId);
                if (roleInfo != null)
                {
                    roleInfo.Description = txtDescription.Text;
                    roleInfo.IsPublic    = rdAccessTypePublic.Checked;
                    if (roleInfo.Settings.ContainsKey("URL"))
                    {
                        roleInfo.Settings["URL"] = Globals.NavigateURL(TabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() });
                    }
                    else
                    {
                        roleInfo.Settings.Add("URL", Globals.NavigateURL(TabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() }));
                    }
                    if (roleInfo.Settings.ContainsKey("ReviewMembers"))
                    {
                        roleInfo.Settings["ReviewMembers"] = chkMemberApproved.Checked.ToString();
                    }
                    else
                    {
                        roleInfo.Settings.Add("ReviewMembers", chkMemberApproved.Checked.ToString());
                    }
                    TestableRoleController.Instance.UpdateRoleSettings(roleInfo, true);
                    roleController.UpdateRole(roleInfo);

                    if (inpFile.PostedFile.ContentLength > 0)
                    {
                        IFileManager   _fileManager   = FileManager.Instance;
                        IFolderManager _folderManager = FolderManager.Instance;
                        var            rootFolderPath = PathUtils.Instance.FormatFolderPath(PortalSettings.HomeDirectory);

                        IFolderInfo groupFolder = _folderManager.GetFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                        if (groupFolder == null)
                        {
                            groupFolder = _folderManager.AddFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                        }
                        if (groupFolder != null)
                        {
                            var fileName = Path.GetFileName(inpFile.PostedFile.FileName);
                            var fileInfo = _fileManager.AddFile(groupFolder, fileName, inpFile.PostedFile.InputStream, true);
                            roleInfo.IconFile = "FileID=" + fileInfo.FileId;
                            roleController.UpdateRole(roleInfo);
                        }
                    }
                }
                Response.Redirect(Globals.NavigateURL(TabId, "", new String[] { "groupid=" + GroupId.ToString() }));
            }
        }
Ejemplo n.º 5
0
        public File <int, int> Add(IFolder parent, Stream body, string fileName, bool ensureUniqueName)
        {
            if (ensureUniqueName)
            {
                fileName = FindUniqueFileName(parent, fileName);
            }
            var dnnFolder = _dnnFolders.GetFolder(parent.AsDnn().SysId);
            var dnnFile   = _dnnFiles.AddFile(dnnFolder, Path.GetFileName(fileName), body);

            return(GetFile(dnnFile.FileId));
        }
Ejemplo n.º 6
0
        public File <int, int> Add(IFolder parent, Stream body, string fileName, bool ensureUniqueName)
        {
            var callLog = Log.Call <File <int, int> >($"..., ..., {fileName}, {ensureUniqueName}");

            if (ensureUniqueName)
            {
                fileName = FindUniqueFileName(parent, fileName);
            }
            var dnnFolder = _dnnFolders.GetFolder(parent.AsDnn().SysId);
            var dnnFile   = _dnnFiles.AddFile(dnnFolder, Path.GetFileName(fileName), body);

            return(callLog("ok", GetFile(dnnFile.FileId)));
        }
Ejemplo n.º 7
0
        // Upload entire file
        private void UploadWholeFile(HttpContextBase context, ICollection <FilesStatus> statuses)
        {
            for (var i = 0; i < context.Request.Files.Count; i++)
            {
                var file = context.Request.Files[i];
                if (file == null)
                {
                    continue;
                }

                var fileName = Path.GetFileName(file.FileName);

                try
                {
                    var userFolder = _folderManager.GetUserFolder(UserInfo);

                    //todo: deal with the case where the exact file name already exists.
                    var fileInfo = _fileManager.AddFile(userFolder, fileName, file.InputStream, true);
                    var fileIcon = Entities.Icons.IconController.IconURL("Ext" + fileInfo.Extension, "32x32");
                    if (!File.Exists(context.Server.MapPath(fileIcon)))
                    {
                        fileIcon = Entities.Icons.IconController.IconURL("File", "32x32");
                    }
                    statuses.Add(new FilesStatus
                    {
                        success       = true,
                        name          = fileName,
                        extension     = fileInfo.Extension,
                        type          = fileInfo.ContentType,
                        size          = file.ContentLength,
                        progress      = "1.0",
                        url           = FileManager.Instance.GetUrl(fileInfo),
                        thumbnail_url = fileIcon,
                        message       = "success",
                        id            = fileInfo.FileId,
                    });
                }
                catch (InvalidFileExtensionException)
                {
                    statuses.Add(new FilesStatus
                    {
                        success = false,
                        name    = fileName,
                        message = "File type not allowed."
                    });
                }
            }
        }
Ejemplo n.º 8
0
        private string DealUploadedFile(string shortFileName, string fullFileName, Dictionary <string, string> customParams)
        {
            int    systemID     = customParams["SystemID"].ToInt32();
            string moduleCode   = customParams["ModuleCode"];
            string categoryCode = customParams["CategoryCode"];
            string masterID     = customParams["MasterID"];

            string fileName = shortFileName;
            string fileType = Path.GetExtension(shortFileName);

            byte[] fileContent = null;
            using (FileStream fs = File.Open(fullFileName, FileMode.Open))
            {
                using (BinaryReader reader = new BinaryReader(fs))
                {
                    fs.Seek(0L, SeekOrigin.Begin);
                    fileContent = reader.ReadBytes((int)fs.Length);
                }
            }

            ConnectionStringSettings connstr = ConfigurationManager.ConnectionStrings["SparkServiceDesk_FileManagerConnectionString"];
            DBOperator db = DBOperatorFactory.GetDBOperator(connstr);

            IFileManager fileManager = FileManagerFactory.CreateFileManager("DEFAULT");

            fileManager.DB = db;

            //add by qianbin
            bool overWrite = false;

            if (customParams.ContainsKey("OverWrite"))
            {
                overWrite = customParams["OverWrite"].ToBoolean(false);
            }
            if (overWrite)
            {
                List <SimpleFileModel> list = fileManager.GetSimpleFileModel(systemID, moduleCode, categoryCode, masterID);
                foreach (SimpleFileModel innerSfm in list)
                {
                    fileManager.DeleteFile(innerSfm.FileID);
                }
            }
            //end add

            SimpleFileModel sfm = fileManager.AddFile(systemID, moduleCode, categoryCode, masterID, fileName, fileType, fileContent, FileState.Saved);

            return(sfm.FileID.ToString());
        }
Ejemplo n.º 9
0
        private void Create_Click(object sender, EventArgs e)
        {
            RoleController roleController = new RoleController();

            Security.PortalSecurity ps = new Security.PortalSecurity();
            txtGroupName.Text = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoScripting);
            txtGroupName.Text = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoMarkup);

            txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoScripting);
            txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoMarkup);
            if (roleController.GetRoleByName(PortalId, txtGroupName.Text) != null)
            {
                lblInvalidGroupName.Visible = true;
                return;
            }


            var modRoles = new List <RoleInfo>();
            var modUsers = new List <UserInfo>();

            foreach (ModulePermissionInfo modulePermissionInfo in ModulePermissionController.GetModulePermissions(ModuleId, TabId))
            {
                if (modulePermissionInfo.PermissionKey == "MODGROUP" && modulePermissionInfo.AllowAccess)
                {
                    if (modulePermissionInfo.RoleID > int.Parse(Globals.glbRoleNothing))
                    {
                        modRoles.Add(roleController.GetRole(modulePermissionInfo.RoleID, PortalId));
                    }
                    else if (modulePermissionInfo.UserID > Null.NullInteger)
                    {
                        modUsers.Add(UserController.GetUserById(PortalId, modulePermissionInfo.UserID));
                    }
                }
            }

            var roleInfo = new RoleInfo()
            {
                PortalID     = PortalId,
                RoleName     = txtGroupName.Text,
                Description  = txtDescription.Text,
                SecurityMode = SecurityMode.SocialGroup,
                Status       = RoleStatus.Approved,
                IsPublic     = rdAccessTypePublic.Checked
            };
            var userRoleStatus = RoleStatus.Pending;

            if (GroupModerationEnabled)
            {
                roleInfo.Status = RoleStatus.Pending;
                userRoleStatus  = RoleStatus.Pending;
            }
            else
            {
                userRoleStatus = RoleStatus.Approved;
            }

            var objModulePermissions = new ModulePermissionCollection(CBO.FillCollection(DataProvider.Instance().GetModulePermissionsByModuleID(ModuleId, -1), typeof(ModulePermissionInfo)));

            if (ModulePermissionController.HasModulePermission(objModulePermissions, "MODGROUP"))
            {
                roleInfo.Status = RoleStatus.Approved;
                userRoleStatus  = RoleStatus.Approved;
            }
            roleInfo.RoleGroupID = DefaultRoleGroupId;

            roleInfo.RoleID = roleController.AddRole(roleInfo);
            roleInfo        = roleController.GetRole(roleInfo.RoleID, PortalId);

            var groupUrl = Globals.NavigateURL(GroupViewTabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() });

            if (groupUrl.StartsWith("http://") || groupUrl.StartsWith("https://"))
            {
                const int startIndex = 8;                 // length of https://
                groupUrl = groupUrl.Substring(groupUrl.IndexOf("/", startIndex, StringComparison.InvariantCultureIgnoreCase));
            }
            roleInfo.Settings.Add("URL", groupUrl);

            roleInfo.Settings.Add("GroupCreatorName", UserInfo.DisplayName);
            roleInfo.Settings.Add("ReviewMembers", chkMemberApproved.Checked.ToString());

            TestableRoleController.Instance.UpdateRoleSettings(roleInfo, true);
            if (inpFile.PostedFile != null && inpFile.PostedFile.ContentLength > 0)
            {
                IFileManager   _fileManager   = FileManager.Instance;
                IFolderManager _folderManager = FolderManager.Instance;
                var            rootFolderPath = PathUtils.Instance.FormatFolderPath(PortalSettings.HomeDirectory);

                IFolderInfo groupFolder = _folderManager.GetFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                if (groupFolder == null)
                {
                    groupFolder = _folderManager.AddFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                }
                if (groupFolder != null)
                {
                    var fileName = Path.GetFileName(inpFile.PostedFile.FileName);
                    var fileInfo = _fileManager.AddFile(groupFolder, fileName, inpFile.PostedFile.InputStream, true);
                    roleInfo.IconFile = "FileID=" + fileInfo.FileId;
                    roleController.UpdateRole(roleInfo);
                }
            }

            var notifications = new Notifications();


            roleController.AddUserRole(PortalId, UserId, roleInfo.RoleID, userRoleStatus, true, Null.NullDate, Null.NullDate);
            if (roleInfo.Status == RoleStatus.Pending)
            {
                //Send notification to Group Moderators to approve/reject group.
                notifications.AddGroupNotification(Constants.GroupPendingNotification, GroupViewTabId, ModuleId, roleInfo, UserInfo, modRoles, modUsers);
            }
            else
            {
                //Send notification to Group Moderators informing of new group.
                notifications.AddGroupNotification(Constants.GroupCreatedNotification, GroupViewTabId, ModuleId, roleInfo, UserInfo, modRoles, modUsers);

                //Add entry to journal.
                GroupUtilities.CreateJournalEntry(roleInfo, UserInfo);
            }

            Response.Redirect(Globals.NavigateURL(GroupViewTabId, "", new String[] { "groupid=" + roleInfo.RoleID.ToString() }));
        }
        // Upload entire file
        private void UploadWholeFile(HttpContextBase context, ICollection <FilesStatus> statuses)
        {
            for (var i = 0; i < context.Request.Files.Count; i++)
            {
                var file = context.Request.Files[i];
                if (file == null)
                {
                    continue;
                }

                var fileName = CleanUpFileName(Path.GetFileName(file.FileName));


                if (IsAllowedExtension(fileName))
                {
                    string uploadfolder = "OpenContent/Files/" + ActiveModule.ModuleID;

                    if (!string.IsNullOrEmpty(context.Request.Form["uploadfolder"]))
                    {
                        uploadfolder = context.Request.Form["uploadfolder"];
                    }
                    var userFolder = _folderManager.GetFolder(PortalSettings.PortalId, uploadfolder);
                    if (userFolder == null)
                    {
                        userFolder = _folderManager.AddFolder(PortalSettings.PortalId, uploadfolder);
                    }
                    int    suffix       = 0;
                    string baseFileName = Path.GetFileNameWithoutExtension(fileName);
                    string extension    = Path.GetExtension(fileName);
                    var    fileInfo     = _fileManager.GetFile(userFolder, fileName);
                    while (fileInfo != null)
                    {
                        suffix++;
                        fileName = baseFileName + "-" + suffix + extension;
                        fileInfo = _fileManager.GetFile(userFolder, fileName);
                    }
                    fileInfo = _fileManager.AddFile(userFolder, fileName, file.InputStream, true);
                    var fileIcon = IconController.IconURL("Ext" + fileInfo.Extension, "32x32");
                    if (!File.Exists(context.Server.MapPath(fileIcon)))
                    {
                        fileIcon = IconController.IconURL("File", "32x32");
                    }
                    statuses.Add(new FilesStatus
                    {
                        success       = true,
                        name          = fileName,
                        extension     = fileInfo.Extension,
                        type          = fileInfo.ContentType,
                        size          = file.ContentLength,
                        progress      = "1.0",
                        url           = fileInfo.ToUrl().RemoveCachebuster(),
                        thumbnail_url = fileIcon,
                        message       = "success",
                        id            = fileInfo.FileId,
                    });
                }
                else
                {
                    statuses.Add(new FilesStatus
                    {
                        success = false,
                        name    = fileName,
                        message = "File type not allowed."
                    });
                }
            }
        }
Ejemplo n.º 11
0
        private void Save_Click(object sender, EventArgs e)
        {
            if (GroupId > 0)
            {
                Security.PortalSecurity ps = Security.PortalSecurity.Instance;

                txtGroupName.Text   = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoScripting);
                txtGroupName.Text   = ps.InputFilter(txtGroupName.Text, Security.PortalSecurity.FilterFlag.NoMarkup);
                txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoScripting);
                txtDescription.Text = ps.InputFilter(txtDescription.Text, Security.PortalSecurity.FilterFlag.NoMarkup);

                var roleInfo = RoleController.Instance.GetRoleById(PortalId, GroupId);
                if (roleInfo != null)
                {
                    if (txtGroupName.Visible) //if this is visible assume that we're editing the groupname
                    {
                        if (txtGroupName.Text != roleInfo.RoleName)
                        {
                            if (RoleController.Instance.GetRoleByName(PortalId, txtGroupName.Text) != null)
                            {
                                lblInvalidGroupName.Visible = true;
                                return;
                            }
                        }
                    }

                    if (!roleInfo.IsSystemRole)
                    {
                        roleInfo.RoleName = txtGroupName.Text;
                    }

                    roleInfo.Description = txtDescription.Text;
                    roleInfo.IsPublic    = rdAccessTypePublic.Checked;

                    if (roleInfo.Settings.ContainsKey("ReviewMembers"))
                    {
                        roleInfo.Settings["ReviewMembers"] = chkMemberApproved.Checked.ToString();
                    }
                    else
                    {
                        roleInfo.Settings.Add("ReviewMembers", chkMemberApproved.Checked.ToString());
                    }

                    RoleController.Instance.UpdateRoleSettings(roleInfo, true);
                    RoleController.Instance.UpdateRole(roleInfo);

                    if (inpFile.PostedFile.ContentLength > 0)
                    {
                        IFileManager   _fileManager   = FileManager.Instance;
                        IFolderManager _folderManager = FolderManager.Instance;
                        var            rootFolderPath = PathUtils.Instance.FormatFolderPath(PortalSettings.HomeDirectory);

                        IFolderInfo groupFolder = _folderManager.GetFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                        if (groupFolder == null)
                        {
                            groupFolder = _folderManager.AddFolder(PortalSettings.PortalId, "Groups/" + roleInfo.RoleID);
                        }
                        if (groupFolder != null)
                        {
                            var fileName = Path.GetFileName(inpFile.PostedFile.FileName);
                            var fileInfo = _fileManager.AddFile(groupFolder, fileName, inpFile.PostedFile.InputStream, true);
                            roleInfo.IconFile = "FileID=" + fileInfo.FileId;
                            RoleController.Instance.UpdateRole(roleInfo);
                        }
                    }

                    //Clear Roles Cache
                    DataCache.RemoveCache("GetRoles");
                }

                Response.Redirect(Globals.NavigateURL(TabId, "", new String[] { "groupid=" + GroupId.ToString() }));
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add new document version
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> AddNewDocumentVersionAsync(AddNewVersionDocumentViewModel model)
        {
            var result      = new ResultModel();
            var userRequest = await _userManager.GetCurrentUserAsync();

            if (!userRequest.IsSuccess)
            {
                result.Errors.Add(new ErrorModel {
                    Message = "User not found"
                });
                result.IsSuccess = false;
                return(result);
            }
            var user = userRequest.Result;

            var document = await _documentContext.Documents.FirstOrDefaultAsync(x => x.Id == model.DocumentId);

            if (document == null)
            {
                result.Errors.Add(new ErrorModel {
                    Message = "document not fount"
                });
                result.IsSuccess = false;
                return(result);
            }


            Guid?fileId = null;

            if (model.File != null)
            {
                fileId = FileManager.AddFile(new UploadFileViewModel {
                    File = model.File
                }, user.Id).Result;
            }

            var newDocumentVersion = new DocumentVersion
            {
                DocumentId     = model.DocumentId,
                FileStorageId  = fileId,
                IsArhive       = false,
                Comments       = model.Comments,
                OwnerId        = user.Id,
                IsMajorVersion = model.IsMajorVersion,
                FileName       = model.File?.FileName ?? "",
                Url            = model.Url,
            };

            var lastVersion = await GetLastDocVersion(model.DocumentId);

            if (model.IsMajorVersion)
            {
                newDocumentVersion.VersionNumber = (int)lastVersion + 1;
            }
            else
            {
                newDocumentVersion.VersionNumber = lastVersion + 0.1;
            }

            await _documentContext.DocumentVersions.AddAsync(newDocumentVersion);

            result = await _documentContext.PushAsync();

            result.Result = newDocumentVersion.Id;
            return(result);
        }