예제 #1
0
        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);
        }
예제 #2
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()));
        }