/// <summary>
        /// Gets the file locked user id.
        /// </summary>
        /// <param name="fileUrl">The file URL.</param>
        /// <returns></returns>
        public static UserLight GetFileLockedUserId(string fileUrl)
        {
            UserLight retVal = null;

            try
            {
                WebDavTicket          ticket   = WebDavUrlBuilder.GetWebDavTicket(fileUrl);
                WebDavAbstractFactory factory  = new WebDavAbstractFactory();
                WebDavPropertyStorage provider =
                    factory.Create <WebDavElementStorageProvider>(ticket.AbsolutePath.StorageType) as WebDavPropertyStorage;
                if (provider != null)
                {
                    WebDavElementInfo elInfo = provider.GetElementInfo(ticket.ToString());
                    foreach (ActiveLockElement activeLock in provider.GetActiveLocks(elInfo))
                    {
                        UserLight user = UserLight.Load(activeLock.Owner);
                        if (user != null)
                        {
                            retVal = user;
                            break;
                        }
                    }
                }
            }
            catch (System.Exception)
            {
            }

            return(retVal);
        }
        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 #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);
        }
Example #4
0
        protected CollectionInfo GetCollectionInfo(WebDavTicket ticket)
        {
            CollectionInfo retVal = new CollectionInfo();

            retVal.Name         = "root";
            retVal.Created      = DateTime.MinValue;
            retVal.Modified     = DateTime.MinValue;
            retVal.AbsolutePath = ticket.ToString();

            return(retVal);
        }
Example #5
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);
        }
Example #6
0
        protected virtual ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException("ticket");
            }
            MetaDataPlusAbsolutePath metaAbsPath = ticket.AbsolutePath as MetaDataPlusAbsolutePath;

            if (metaAbsPath == null)
            {
                throw new NullReferenceException("metaAbsPath");
            }

            ResourceInfo retVal = new ResourceInfo();
            MetaObject   obj    = MetaDataWrapper.LoadMetaObject(metaAbsPath.MetaObjectId, metaAbsPath.MetaObjectType);

            if (obj == null)
            {
                throw new NullReferenceException("obj");
            }

            MetaFile metaFile = (MetaFile)obj[metaAbsPath.MetaFieldName];

            if (metaFile != null)
            {
                retVal.AbsolutePath  = ticket.ToString();
                retVal.Tag           = new object[] { obj, metaFile, metaAbsPath };
                retVal.Name          = metaFile.Name;
                retVal.ContentType   = ContentTypeResolver.Resolve(Path.GetExtension(metaFile.Name));
                retVal.ContentLength = metaFile.Size;
                retVal.ParentName    = "root";
                retVal.Modified      = metaFile.LastWriteTime;
                retVal.Created       = metaFile.CreationTime;
            }

            return(retVal);
        }
Example #7
0
        protected override ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            MetaDataAbsolutePath metaAbsPath = ticket.AbsolutePath as MetaDataAbsolutePath;

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

            ResourceInfo retVal = new ResourceInfo();

            Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(metaAbsPath.FileUID);

            retVal.AbsolutePath  = ticket.ToString();
            retVal.Tag           = fileInfo;
            retVal.Name          = fileInfo.Name;
            retVal.ContentType   = ContentTypeResolver.Resolve(Path.GetExtension(fileInfo.Name));
            retVal.ContentLength = fileInfo.Length;
            retVal.ParentName    = "root";
            retVal.Modified      = DateTime.Now;
            retVal.Created       = DateTime.Now;

            return(retVal);
        }
Example #8
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;
        }
Example #9
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 #10
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;
        }
Example #11
0
        protected CollectionInfo GetCollectionInfo(WebDavTicket ticket)
        {
            CollectionInfo retVal = new CollectionInfo();

            retVal.Name = "root";
            retVal.Created = DateTime.MinValue;
            retVal.Modified = DateTime.MinValue;
            retVal.AbsolutePath = ticket.ToString();

            return retVal;
        }
Example #12
0
        protected override ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            MetaDataAbsolutePath metaAbsPath = ticket.AbsolutePath as MetaDataAbsolutePath;
            if (metaAbsPath == null)
                throw new ArgumentException("absPath");

            ResourceInfo retVal = new ResourceInfo();

            Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(metaAbsPath.FileUID);

            retVal.AbsolutePath = ticket.ToString();
            retVal.Tag = fileInfo;
            retVal.Name = fileInfo.Name;
            retVal.ContentType = ContentTypeResolver.Resolve(Path.GetExtension(fileInfo.Name));
            retVal.ContentLength = fileInfo.Length;
            retVal.ParentName = "root";
            retVal.Modified = DateTime.Now;
            retVal.Created = DateTime.Now;

            return retVal;
        }
Example #13
0
        protected virtual ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException("ticket");
            }
            MetaDataPlusAbsolutePath metaAbsPath = ticket.AbsolutePath as MetaDataPlusAbsolutePath;
            if (metaAbsPath == null)
            {
                throw new NullReferenceException("metaAbsPath");
            }

            ResourceInfo retVal = new ResourceInfo();
            MetaObject obj = MetaDataWrapper.LoadMetaObject(metaAbsPath.MetaObjectId, metaAbsPath.MetaObjectType);
            if (obj == null)
            {
                throw new NullReferenceException("obj");
            }

            MetaFile metaFile = (MetaFile)obj[metaAbsPath.MetaFieldName];

            if (metaFile != null)
            {
                retVal.AbsolutePath = ticket.ToString();
                retVal.Tag = new object[] { obj, metaFile, metaAbsPath};
                retVal.Name = metaFile.Name;
                retVal.ContentType = ContentTypeResolver.Resolve(Path.GetExtension(metaFile.Name));
                retVal.ContentLength = metaFile.Size;
                retVal.ParentName = "root";
                retVal.Modified = metaFile.LastWriteTime;
                retVal.Created = metaFile.CreationTime;
            }

            return retVal;
        }