Exemplo 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);
        }
Exemplo n.º 2
0
        protected override ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            ResourceInfo             retVal  = new ResourceInfo();
            EmailStorageAbsolutePath absPath = ticket.AbsolutePath as EmailStorageAbsolutePath;

            if (absPath == null)
            {
                throw new ArgumentException("absPath");
            }

            EMailMessageRow row       = new EMailMessageRow(absPath.EmailMsgId);
            MemoryStream    memStream = new MemoryStream(row.EmlMessage.Length);

            memStream.Write(row.EmlMessage, 0, row.EmlMessage.Length);
            memStream.Position = 0;

            Pop3Message message         = new Pop3Message(memStream);
            int         attachmentIndex = absPath.EmailAttachmentIndex;

            Mediachase.IBN.Business.EMail.EMailMessageInfo.AttachmentData entry =
                EMailMessageInfo.GetAttachment(message.MimeEntries, ref attachmentIndex);

            if (entry != null)
            {
                retVal.AbsolutePath = ticket.ToString();
                retVal.Tag          = entry;
                retVal.Name         = entry.FileName;
                //Fix ET:26-11-2008 Solve trouble inconsistency Content-Type email attachment and file extension
                //try first get Content-Type by file extension
                retVal.ContentType = ContentTypeResolver.Resolve(Path.GetExtension(entry.FileName));
                if (String.IsNullOrEmpty(retVal.ContentType))
                {
                    //otherwise set ContentType as ContentType email attachment
                    retVal.ContentType = entry.ContentType;
                }
                retVal.ContentLength = entry.Data.Length;
                retVal.ParentName    = "root";
                DateTime created = Database.DBCommon.GetLocalDate(Security.CurrentUser.TimeZoneId, row.Created);
                retVal.Created  = created;
                retVal.Modified = created;
            }

            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the web dav URL.
        /// </summary>
        /// <param name="emailId">The email id.</param>
        /// <param name="emailAttachIndex">Index of the email attach.</param>
        /// <param name="withAuthToken">if set to <c>true</c> [with auth token].</param>
        /// <returns></returns>
        public static string GetEmailAtachWebDavUrl(int emailId, int emailAttachIndex, bool withAuthToken)
        {
            EMailMessageInfo emlInfo = EMailMessageInfo.Load(emailId);

            if (emlInfo.Attachments.Length <= emailAttachIndex)
            {
                throw new ArgumentException("emailAttachIndex");
            }

            AttachmentInfo attachInfo = emlInfo.Attachments[emailAttachIndex];

            EmailStorageAbsolutePath absPath = (EmailStorageAbsolutePath)WebDavAbsolutePath.CreateInstance(ObjectTypes.File_Incident);

            absPath.EmailMsgId           = emailId;
            absPath.EmailAttachmentIndex = emailAttachIndex;
            absPath.FileName             = attachInfo.FileName;

            return(GetWebDavUrl(absPath, withAuthToken));
        }