Esempio n. 1
0
        protected void PageLoad()
        {
            File file;

            try
            {
                ShareLink = Request[UrlConstant.DocUrlKey] ?? "";
                WithLink  = !string.IsNullOrEmpty(ShareLink);

                var fileId = WithLink ? (object)-1 : Request[UrlConstant.FileId];
                FileNew = !string.IsNullOrEmpty(Request[UrlConstant.New]) && Request[UrlConstant.New] == "true";
                var ver = string.IsNullOrEmpty(Request[UrlConstant.Version]) ? -1 : Convert.ToInt32(Request[UrlConstant.Version]);

                file = DocumentUtils.GetServiceParams(false, fileId, ver, FileNew, ShareLink, out DocParams);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return;
                //var urlRedirect = Request.UrlReferrer == null
                //                      ? PathProvider.StartURL
                //                      : Request.UrlReferrer.ToString();

                //Response.Redirect(urlRedirect + "#" + UrlConstant.Error + "/" + HttpUtility.UrlEncode(ex.Message));
            }

            if (!FileUtility.UsingHtml5(file.Title, false))
            {
                Server.Transfer("viewer.aspx", true);
            }

            Title = file.Title;

            DocParams.Type = MobileDetector.IsRequestMatchesMobile(Context) ? "mobile" : "desktop";
            if (MobileDetector.IsRequestMatchesMobile(Context))
            {
                DocParams.FolderUrl = string.Empty;
            }

            DocKeyForTrack = DocumentUtils.GetDocKey(file.ID, -1, DateTime.MinValue);

            Global.DaoFactory.GetTagDao().RemoveTags(Tag.New(SecurityContext.CurrentAccount.ID, file));

            FilesActivityPublisher.OpenEditorFile(file);
        }
Esempio n. 2
0
        protected void PageLoad()
        {
            var file = new File();

            try
            {
                ShareLink = Request[UrlConstant.DocUrlKey] ?? "";
                WithLink  = !string.IsNullOrEmpty(ShareLink);

                var fileId = WithLink ? (object)-1 : Request[UrlConstant.FileId];
                FileNew = !string.IsNullOrEmpty(Request[UrlConstant.New]) && Request[UrlConstant.New] == "true";

                file = DocumentUtils.GetServiceParams(true, fileId, 0, FileNew, ShareLink, out DocParams);
            }
            catch (Exception ex)
            {
                Response.Redirect(PathProvider.BaseVirtualPath + "docviewer.aspx" + "?" + Request.QueryString + "#" + UrlConstant.Error + "/" + HttpUtility.UrlEncode(ex.Message));
            }

            if (!FileUtility.UsingHtml5(file.Title))
            {
                Server.Transfer("editor.aspx", true);
            }

            Title = file.Title;

            DocParams.Type = MobileDetector.IsRequestMatchesMobile(Context) ? "mobile" : "desktop";

            DocKeyForTrack = DocumentUtils.GetDocKey(file.ID, -1, DateTime.MinValue);

            using (var tagDao = Global.DaoFactory.GetTagDao())
            {
                tagDao.RemoveTags(Tag.New(SecurityContext.CurrentAccount.ID, file));
            }

            FilesActivityPublisher.OpenEditorFile(file);

            FileLocker.Add(file.ID);
        }
Esempio n. 3
0
        protected override void Do()
        {
            if (_files.Count == 0)
            {
                return;
            }

            var parent = FolderDao.GetFolder(_parentId);

            if (parent == null)
            {
                throw new Exception(FilesCommonResource.ErrorMassage_FolderNotFound);
            }
            if (!FilesSecurity.CanCreate(parent))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }
            if (parent.RootFolderType == FolderType.TRASH)
            {
                throw new Exception(FilesCommonResource.ErrorMassage_ImportToTrash);
            }
            if (!string.IsNullOrEmpty(parent.ProviderName))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
            }

            var to = FolderDao.GetFolder(_folderName, _parentId);

            if (to == null)
            {
                to = new Folder
                {
                    FolderType     = FolderType.DEFAULT,
                    ParentFolderID = _parentId,
                    Title          = _folderName
                };
                to.ID = FolderDao.SaveFolder(to);
            }

            foreach (var f in _files)
            {
                if (Canceled)
                {
                    return;
                }
                try
                {
                    long size;
                    using (var stream = _docProvider.GetDocumentStream(f.ContentLink, out size))
                    {
                        if (stream == null)
                        {
                            throw new Exception("Can not import document " + f.ContentLink + ". Empty stream.");
                        }

                        if (SetupInfo.MaxUploadSize < size)
                        {
                            throw FileSizeComment.FileSizeException;
                        }

                        var folderId = to.ID;
                        var pos      = f.Title.LastIndexOf('/');
                        if (0 < pos)
                        {
                            folderId = GetOrCreateHierarchy(f.Title.Substring(0, pos), to);
                            f.Title  = f.Title.Substring(pos + 1);
                        }

                        f.Title = Global.ReplaceInvalidCharsAndTruncate(f.Title);
                        var file = new File
                        {
                            Title         = f.Title,
                            FolderID      = folderId,
                            ContentLength = size,
                            ContentType   = "application/octet-stream",
                        };

                        var conflict = FileDao.GetFile(file.FolderID, file.Title);
                        if (conflict != null)
                        {
                            if (_overwrite)
                            {
                                file.ID      = conflict.ID;
                                file.Version = conflict.Version + 1;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        if (size <= 0L)
                        {
                            using (var buffered = stream.GetBuffered())
                            {
                                size = buffered.Length;

                                if (SetupInfo.MaxUploadSize < size)
                                {
                                    throw FileSizeComment.FileSizeException;
                                }

                                file.ContentLength = size;
                                try
                                {
                                    file = FileDao.SaveFile(file, buffered);
                                }
                                catch (Exception error)
                                {
                                    FileDao.DeleteFile(file.ID);
                                    throw error;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                file = FileDao.SaveFile(file, stream);
                            }
                            catch (Exception error)
                            {
                                FileDao.DeleteFile(file.ID);
                                throw error;
                            }
                        }

                        if (conflict != null)
                        {
                            Global.PublishUpdateDocument(file.ID);
                        }
                        else
                        {
                            FilesActivityPublisher.UploadFile(FileDao.GetFile(file.ID));
                        }
                    }
                }
                catch (Exception error)
                {
                    Error = error;
                }
                finally
                {
                    ProgressStep();
                }
            }
        }
Esempio n. 4
0
        private static void CreateFile(HttpContext context)
        {
            var template  = context.Request[UrlConstant.Template];
            var fileTitle = context.Request[UrlConstant.FileTitle] ?? context.Request["title"];

            using (var fileDao = Global.DaoFactory.GetFileDao())
                using (var folderDao = Global.DaoFactory.GetFolderDao())
                {
                    var folder = folderDao.GetFolder(Global.FolderMy);
                    if (folder == null)
                    {
                        throw new HttpException((int)HttpStatusCode.NotFound, FilesCommonResource.ErrorMassage_FolderNotFound);
                    }
                    if (!Global.GetFilesSecurity().CanCreate(folder))
                    {
                        throw new HttpException((int)HttpStatusCode.Forbidden, FilesCommonResource.ErrorMassage_SecurityException_Create);
                    }

                    var storeTemp = Global.GetStoreTemplate();

                    var lang = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).GetCulture().TwoLetterISOLanguageName;

                    var templatePath = DocumentUtils.TemplateDocPath + lang + "/";
                    if (!storeTemp.IsDirectory(templatePath))
                    {
                        templatePath = DocumentUtils.TemplateDocPath + "default/";
                    }

                    string       templateName;
                    const string fileExt = ".docx";

                    if (string.IsNullOrEmpty(template))
                    {
                        //For ThirdParty use original file type
                        templateName = ("imaginary" + (FileUtility.UsingHtml5(fileExt) ? "html5" : string.Empty))
                                       + fileExt;

                        templatePath = templateName;
                    }
                    else
                    {
                        templateName  = template + fileExt;
                        templatePath += templateName;

                        if (!storeTemp.IsFile(templatePath))
                        {
                            templatePath  = DocumentUtils.TemplateDocPath + "default/";
                            templatePath += templateName;
                        }
                    }

                    if (string.IsNullOrEmpty(fileTitle))
                    {
                        fileTitle = templateName;
                    }
                    else
                    {
                        fileTitle = fileTitle + fileExt;
                    }
                    var file = new File
                    {
                        Title         = Global.ReplaceInvalidCharsAndTruncate(fileTitle),
                        ContentLength = storeTemp.GetFileSize(templatePath),
                        ContentType   = MimeMapping.GetMimeMapping(fileTitle),
                        ConvertedType = ".zip",
                        FolderID      = folder.ID
                    };

                    using (var stream = storeTemp.IronReadStream("", templatePath, 10))
                    {
                        file = fileDao.SaveFile(file, stream);
                    }

                    FilesActivityPublisher.CreateFile(fileDao.GetFile(file.ID));

                    context.Response.Redirect(CommonLinkUtility.GetFileWebEditorUrl(file.ID));
                }
        }