private static ResourceInfo GetResourceInfoFromPropertyRow(WebDavStorageElementPropertiesRow propertyRow)
        {
            if (propertyRow == null)
            {
                throw new ArgumentNullException("propertyRow");
            }
            ResourceInfo          retVal  = null;
            WebDavAbstractFactory factory = new WebDavAbstractFactory();

            //For MetaData stored int hash for Guid value is not possible restore back from hash to Guid
            if ((ObjectTypes)propertyRow.ObjectTypeId != ObjectTypes.File_MetaData)
            {
                WebDavElementStorageProvider provider = factory.Create <WebDavElementStorageProvider>(propertyRow.ObjectTypeId);
                WebDavAbsolutePath           absPath  = WebDavAbsolutePath.CreateInstance((ObjectTypes)propertyRow.ObjectTypeId);
                absPath.UniqueId = propertyRow.ObjectId;
                absPath.FileName = "file";
                WebDavTicket ticket = WebDavTicket.CreateInstance(ePluginToken.webdav, Guid.Empty, absPath);
                try
                {
                    retVal = provider.GetElementInfo(ticket.ToString()) as ResourceInfo;
                }
                catch (Exception)
                {
                }
            }
            return(retVal);
        }
Example #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));
        }
Example #3
0
        /// <summary>
        /// Gets the web dav URL.
        /// </summary>
        /// <param name="fileInfo">The file info.</param>
        /// <param name="withAuthToken">if set to <c>true</c> [with auth token].</param>
        /// <returns></returns>
        public static string GetMetaDataWebDavUrl(Mediachase.Ibn.Data.Meta.FileInfo fileInfo, bool withAuthToken)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException("fileInfo");
            }

            MetaDataAbsolutePath absPath = (MetaDataAbsolutePath)WebDavAbsolutePath.CreateInstance(ObjectTypes.File_MetaData);

            absPath.FileUID  = fileInfo.FileUID;
            absPath.FileName = fileInfo.Name;

            return(GetWebDavUrl(absPath, withAuthToken));
        }
Example #4
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));
        }
Example #5
0
        /// <summary>
        /// Gets the web dav URL.
        /// </summary>
        /// <param name="metaObjectId">The meta object id.</param>
        /// <param name="metaClassName">Name of the meta class.</param>
        /// <param name="metaFieldName">Name of the meta field.</param>
        /// <param name="withAuthToken">if set to <c>true</c> [with auth token].</param>
        /// <returns></returns>
        public static string GetMetaDataPlusWebDavUrl(Mediachase.MetaDataPlus.MetaObject mo, string metaField, bool withAuthToken)
        {
            MetaFile mf = mo[metaField] as MetaFile;

            if (mf == null)
            {
                throw new ArgumentException(metaField + " is not a MetaFile");
            }

            MetaDataPlusAbsolutePath absPath = (MetaDataPlusAbsolutePath)WebDavAbsolutePath.CreateInstance(ObjectTypes.File_MetaDataPlus);

            absPath.MetaFieldName  = metaField;
            absPath.MetaObjectId   = mo.Id;
            absPath.MetaObjectType = mo.MetaClass.Name;
            absPath.UniqueId       = mo.Id;
            absPath.FileName       = mf.Name;

            return(GetWebDavUrl(absPath, withAuthToken));
        }
Example #6
0
        internal static string GetWebDavUrl(WebDavAbsolutePath absPath, bool withAuthToken,
                                            bool detectServerEdit, Uri baseUrl)
        {
            if (absPath == null)
            {
                throw new ArgumentNullException("absPath");
            }
            if (baseUrl == null)
            {
                throw new ArgumentNullException("baseUrl");
            }

            Guid?  authToken       = null;
            bool?  bWebDavTurnOn   = PortalConfig.UseWebDav;
            string applicationPath = baseUrl.AbsolutePath;

            if (HttpContext.Current != null)
            {
                //try get cached token
                authToken       = (Guid?)HttpContext.Current.Items[AUTH_TOKEN_CACHE_NAME];
                applicationPath = HttpContext.Current.Request.ApplicationPath;
                applicationPath = applicationPath.TrimEnd('/');
            }

            ePluginToken pluginToken = ePluginToken.files;

            //Determine server editing
            if (detectServerEdit)
            {
                if (bWebDavTurnOn.HasValue && bWebDavTurnOn.Value && ContentTypeResolver.IsWebDAVSupportedExtension(Path.GetExtension(absPath.FileName)))
                {
                    pluginToken = ePluginToken.webdav;
                }
            }
            //Формировать authToken only for webdav resources
            if (pluginToken == ePluginToken.webdav)
            {
                //Использовать из кеша если нет то сгенерировать новый
                if (authToken == null)
                {
                    //authToken = withAuthToken ? WebDavAuthHelper.MakeAuthSession(true, absPath.StorageType, absPath.UniqueId) : Guid.Empty;
                    authToken = withAuthToken ? WebDavAuthHelper.MakeAuthSession(true, ObjectTypes.File_FileStorage, 0) : Guid.Empty;
                    if (HttpContext.Current != null && authToken != Guid.Empty)
                    {
                        //add to cache auth token
                        HttpContext.Current.Items[AUTH_TOKEN_CACHE_NAME] = authToken;
                    }
                }
            }
            else if (pluginToken == ePluginToken.files)
            {
                //never add auth token to file plugin token resources
                authToken = Guid.Empty;
            }

            WebDavTicket ticket     = WebDavTicket.CreateInstance(pluginToken, authToken.Value, absPath);
            UriBuilder   uriBuilder = new UriBuilder();

            uriBuilder.Scheme = baseUrl.Scheme;
            uriBuilder.Port   = baseUrl.Port;
            uriBuilder.Host   = baseUrl.Host;


            uriBuilder.Path = applicationPath + ticket.ToString();

            //Outer url to redirect page only for webdav access type
            if (ticket.PluginToken == ePluginToken.webdav && !withAuthToken)
            {
                uriBuilder.Path = applicationPath + AUTH_REDIRECT_PAGE;
                string webDavTicket = ticket.ToString("A");
                //Remove file name from ticket
                uriBuilder.Query = AUTH_TICKET_PARAM_NAME + String.Format("={0}", webDavTicket);
            }

            ////FileName = System.Web.HttpUtility.UrlPathEncode(FileName);

            return(Uri.EscapeUriString(uriBuilder.Uri.ToString()));
        }
Example #7
0
 internal static string GetWebDavUrl(WebDavAbsolutePath absPath, bool withAuthToken, bool detectServerEdit)
 {
     return(GetWebDavUrl(absPath, withAuthToken, true, HttpContext.Current.Request.Url));
 }
Example #8
0
 internal static string GetWebDavUrl(WebDavAbsolutePath absPath, bool withAuthToken)
 {
     return(GetWebDavUrl(absPath, withAuthToken, true));
 }