Esempio n. 1
0
        /// <summary>
        /// Gets the web dav URL by WebDavTicket.
        /// </summary>
        /// <param name="ticket">The ticket.</param>
        /// <returns></returns>
        public static string GetWebDavUrl(string ticket)
        {
            string       retVal       = string.Empty;
            WebDavTicket webDavTicket = WebDavTicket.Parse(ticket);

            //Попытаемся определить имя файла
            if (String.IsNullOrEmpty(webDavTicket.AbsolutePath.FileName))
            {
                if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_FileStorage)
                {
                    FileStorageAbsolutePath fsAbsPath = webDavTicket.AbsolutePath as FileStorageAbsolutePath;
                    if (fsAbsPath != null)
                    {
                        FileStorage fs = new FileStorage();
                        Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = fs.GetFile(fsAbsPath.UniqueId);
                        if (fileInfo != null)
                        {
                            webDavTicket.AbsolutePath.FileName = fileInfo.Name;
                        }
                    }
                }
                else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaData)
                {
                    MetaDataAbsolutePath mdAbsPath = webDavTicket.AbsolutePath as MetaDataAbsolutePath;
                    if (mdAbsPath != null)
                    {
                        Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(mdAbsPath.FileUID);
                        webDavTicket.AbsolutePath.FileName = fileInfo.Name;
                    }
                }
                else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaDataPlus)
                {
                    MetaDataPlusAbsolutePath mdpAbsPath = webDavTicket.AbsolutePath as MetaDataPlusAbsolutePath;
                    if (mdpAbsPath != null)
                    {
                        Mediachase.MetaDataPlus.MetaObject obj = MetaDataWrapper.LoadMetaObject(mdpAbsPath.MetaObjectId, mdpAbsPath.MetaObjectType);
                        MetaFile mf = obj[mdpAbsPath.MetaFieldName] as MetaFile;
                        if (mf != null)
                        {
                            webDavTicket.AbsolutePath.FileName = mf.Name;
                        }
                    }
                }
                else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_Incident)
                {
                    EmailStorageAbsolutePath emlAbsPath = webDavTicket.AbsolutePath as EmailStorageAbsolutePath;
                    if (emlAbsPath != null)
                    {
                        EMailMessageInfo emlInfo    = EMailMessageInfo.Load(emlAbsPath.EmailMsgId);
                        AttachmentInfo   attachInfo = emlInfo.Attachments[emlAbsPath.EmailAttachmentIndex];
                        webDavTicket.AbsolutePath.FileName = attachInfo.FileName;
                    }
                }
            }

            retVal = GetWebDavUrl(webDavTicket.AbsolutePath, true);


            return(retVal);
        }
Esempio n. 2
0
        public static string GetFileStorageWebDavUrl(int fileId, int historyId, string fileName, bool withAuthToken, Uri baseUri)
        {
            FileStorageAbsolutePath absPath = (FileStorageAbsolutePath)WebDavAbsolutePath.CreateInstance(ObjectTypes.File_FileStorage);

            absPath.UniqueId  = fileId;
            absPath.FileName  = fileName;
            absPath.HistoryId = historyId;
            //Do not allow server edit for history file versions
            return(GetWebDavUrl(absPath, withAuthToken, historyId == -1, baseUri));
        }
Esempio n. 3
0
        protected ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            FileStorageAbsolutePath absPath = ticket.AbsolutePath as FileStorageAbsolutePath;

            if (absPath == null)
            {
                throw new ArgumentException("ticket.AbsolutePath is null.");
            }

            ResourceInfo result = new ResourceInfo();

            Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = null;

            //Получаем оригинальный файл
            using (IDataReader reader = Mediachase.IBN.Database.ControlSystem.DBFile.GetById(Security.CurrentUser.TimeZoneId, absPath.UniqueId))
            {
                if (reader.Read())
                {
                    fileInfo = new Mediachase.IBN.Business.ControlSystem.FileInfo(reader);
                }
            }

            if (fileInfo == null)
            {
                throw new HttpException(404, "Not found");
            }

            FileHistoryInfo historyInfo = null;

            //Поддержка версий
            if (absPath.IsHistory)
            {
                foreach (FileHistoryInfo history in fileInfo.GetHistory())
                {
                    if (history.Id == absPath.HistoryId)
                    {
                        historyInfo = history;
                        break;
                    }
                }
            }

            DummyFileInfoWrapper dummyInfo = new DummyFileInfoWrapper(fileInfo, historyInfo);

            result.AbsolutePath  = ticket.ToString();
            result.Tag           = dummyInfo;
            result.Name          = dummyInfo.Name;
            result.ContentType   = dummyInfo.ContentType;
            result.ContentLength = dummyInfo.Length;
            result.ParentName    = "root";
            result.Modified      = dummyInfo.Modified;
            result.Created       = dummyInfo.Created;

            return(result);
        }