Exemplo n.º 1
0
        /// <summary>
        /// Processes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        public void Process(FolderElement element)
        {
            element.Card = cardName;
            BlobInfo blobInfo = element.GetBlobInfo();

            if (blobInfo != null)
            {
                BlobStorageProvider provider = BlobStorage.Providers[blobInfo.Provider];
                if (provider != null)
                {
                    using (Stream stream = provider.ReadStream(blobInfo))
                    {
                        try
                        {
                            Image img = Image.FromStream(stream);
                            element.Properties["Width"].Value  = img.Width;
                            element.Properties["Height"].Value = img.Height;
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the element by path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public static FolderElement[] GetElementsByPath(string path)
        {
            FolderElement[] retVal = null;
            char            delim  = '/';

            string[] folderParts = path.Split(new char[] { delim });

            //Incorrect path
            if (folderParts.Length == 0)
            {
                return(retVal);
            }

            string rootFolderName = folderParts[0];

            FilterElement filter =
                new FilterElement("Name", FilterElementType.Equal, rootFolderName);

            Folder[] folders = Folder.List(filter);
            if (folders.Length != 0)
            {
                Folder rootFolder = folders[0];
                rootFolder = FindFolderByPattern(rootFolder, rootFolder.Name, delim,
                                                 String.Join(delim.ToString(), folderParts));
                if (rootFolder != null)
                {
                    FilterElement filterElem =
                        new FilterElement("ParentId", FilterElementType.Equal,
                                          rootFolder.PrimaryKeyId.Value);
                    retVal = FolderElement.List(filterElem);
                }
            }

            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Copies the specified folder element.
        /// </summary>
        /// <param name="folderElement">The folder element.</param>
        /// <param name="newParentId">The parent id.</param>
        public static void Copy(FolderElement folderElement, int parentId)
        {
            FolderElement newElement = null;

            BlobInfo blobInfo    = folderElement.GetBlobInfo();
            BlobInfo blobInfoNew = (BlobInfo)blobInfo.Clone();

            blobInfoNew.Uid = Guid.NewGuid();

            BlobStorageProvider provider = BlobStorage.Providers[folderElement.BlobStorageProvider];

            using (Stream srcStream = provider.ReadStream(blobInfo))
            {
                using (Stream dstStream = provider.CreateStream(blobInfoNew))
                {
                    BlobStreamHelper.WriteToStream(dstStream, srcStream, 0, srcStream.Length);
                    provider.CommitStream(blobInfoNew);
                }
            }

            newElement         = (FolderElement)folderElement.Clone();
            newElement.BlobUid = blobInfoNew.Uid;
            newElement.Save();

            Move(newElement, parentId);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the specified parent id.
        /// </summary>
        /// <param name="parentId">The parent id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="srcStream">The SRC stream.</param>
        /// <returns></returns>
        public static FolderElement Create(int parentId, string fileName,
                                           Stream srcStream, Guid progressUid)
        {
            FolderElement retVal   = new FolderElement();
            BlobInfo      blobInfo = new BlobInfo(Guid.NewGuid());

            retVal.ParentId = parentId;

            //Try recognize provider from config setings
            BlobStorageProvider provider = BlobStorage.Provider;
            String providerName;
            String contentType = Mediachase.Ibn.Blob.ContentTypeResolver.ContentType.ResolveByPath(fileName);
            long   fileSize    = srcStream.Length;

            if (TryRecognizeStorageProvider(retVal, fileName, contentType,
                                            fileSize, out providerName))
            {
                provider = BlobStorage.Providers[providerName];
            }

            blobInfo.FileName    = fileName;
            blobInfo.Provider    = provider.Name;
            blobInfo.Created     = DateTime.UtcNow;
            blobInfo.ContentSize = fileSize;
            blobInfo.ContentType = contentType;
            //Content type assigned by provider

            //Save blob info to storage
            using (Stream dstStream = provider.CreateStream(blobInfo))
            {
                //BlobStreamHelper.WriteToStream(dstStream, srcStream, 0, fileSize);
                WriteToStream(dstStream, srcStream, 0, fileSize, progressUid);
            }

            provider.CommitStream(blobInfo);

            retVal.BlobStorageProvider = provider.Name;
            retVal.BlobUid             = blobInfo.Uid;
            retVal.Created             = DateTime.UtcNow;
            retVal.Name = blobInfo.FileName;
            if (retVal.Properties.Contains("ContentSize"))
            {
                retVal.Properties["ContentSize"].Value = (Int32)blobInfo.ContentSize;
            }
            if (retVal.Properties.Contains("ContentType"))
            {
                retVal.Properties["ContentType"].Value = blobInfo.ContentType;
            }

            //try
            IFolderElementExtension folderEl = GetCfgFolderElementExtension(blobInfo);

            if (folderEl != null)
            {
                folderEl.Process(retVal);
            }

            retVal.Save();
            return(retVal);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Tries the recognize storage provider.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="contentType">Type of the content.</param>
        /// <param name="fileSize">Size of the file.</param>
        /// <param name="providerName">Name of the provider.</param>
        /// <returns></returns>
        public static bool TryRecognizeStorageProvider(FolderElement element, string fileName,
                                                       String contentType, long fileSize,
                                                       out String providerName)
        {
            string profileName = String.Empty;

            return(TryRecognizeStorageProvider(element, fileName, contentType, fileSize, out providerName, out profileName));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Copies the specified folder id.
        /// </summary>
        /// <param name="folderId">The folder id.</param>
        /// <param name="parentId">The parent id.</param>
        public static void CopyRecursive(int folderId, int parentId)
        {
            Folder srcFolder = new Folder(folderId);
            Folder newFolder = (Folder)srcFolder.Clone();

            newFolder.Save();
            Move(newFolder, parentId);

            parentId = (int)newFolder.PrimaryKeyId.Value;

            TreeNode[] nodes = TreeManager.GetChildNodes(GetAssignedMetaClass(), folderId);
            foreach (TreeNode node in nodes)
            {
                CopyRecursive(node.ObjectId, parentId);
            }

            FolderElement[] elements = FolderElement.List <FolderElement>(FolderElement.GetAssignedMetaClass(), new FilterElement[] { new FilterElement("ParentId", FilterElementType.Equal, folderId) });
            foreach (FolderElement element in elements)
            {
                FolderElement.Copy(element, parentId);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Deletes the specified folder element.
 /// </summary>
 /// <param name="folderElement">The folder element.</param>
 public static void Delete(FolderElement folderElement)
 {
     folderElement.Delete();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Deletes the specified folder element id.
        /// </summary>
        /// <param name="folderElementId">The folder element id.</param>
        public static void Delete(int folderElementId)
        {
            FolderElement folderElement = new FolderElement(folderElementId);

            Delete(folderElement);
        }
Exemplo n.º 9
0
 public FolderElement()
     : base(FolderElement.GetAssignedMetaClass())
 {
 }
Exemplo n.º 10
0
        /// <summary>
        /// Copies the specified folder element id.
        /// </summary>
        /// <param name="folderElementId">The folder element id.</param>
        /// <param name="parentId">The parent id.</param>
        public static void Copy(int folderElementId, int parentId)
        {
            FolderElement folderElement = new FolderElement(folderElementId);

            Copy(folderElement, parentId);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Moves the specified folder element.
 /// </summary>
 /// <param name="folderElement">The folder element.</param>
 /// <param name="newParentId">The new parent id.</param>
 public static void Move(FolderElement folderElement, int newParentId)
 {
     folderElement.ParentId = newParentId;
     folderElement.Save();
 }
Exemplo n.º 12
0
        /// <summary>
        /// Moves the specified folder element id.
        /// </summary>
        /// <param name="folderElementId">The folder element id.</param>
        /// <param name="newParentId">The new parent id.</param>
        public static void Move(int folderElementId, int newParentId)
        {
            FolderElement folderElement = new FolderElement(folderElementId);

            Move(folderElement, newParentId);
        }
Exemplo n.º 13
0
 public static FolderElement[] List(Mediachase.Ibn.Data.FilterElementCollection filters, Mediachase.Ibn.Data.SortingElementCollection sorting, int start, int count)
 {
     return(MetaObject.List <FolderElement>(FolderElement.GetAssignedMetaClass(), filters, sorting, start, count));
 }
Exemplo n.º 14
0
 public FolderElement(PrimaryKeyId primaryKeyId)
     : base(FolderElement.GetAssignedMetaClass(), primaryKeyId)
 {
 }
Exemplo n.º 15
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            string libPath = HttpUtility.UrlDecode(context.Request.Url.AbsolutePath);
            string appPath = context.Request.ApplicationPath;

            appPath = appPath.TrimEnd(new char[] { '/' });

            if (!String.IsNullOrEmpty(appPath))
            {
                libPath = libPath.Substring(appPath.Length + 1);
            }

            int index = libPath.LastIndexOf('/');

            if (index != -1)
            {
                String elemName = libPath.Substring(index + 1);
                //remove iis extension from element name
                elemName = elemName.Substring(0, elemName.LastIndexOf('.'));
                libPath  = libPath.Substring(0, index);
                FolderElement[] elements = FolderElement.GetElementsByPath(libPath);

                if (elements != null)
                {
                    foreach (FolderElement element in elements)
                    {
                        /*
                         * if (provider is PublicDiskStorageProvider)
                         *  downloadProfile = BaseBlobProfile.GetAccessProfileByCfgName("iis");
                         * */

                        if (elemName.Equals(element.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            try
                            {
                                //"open" - is DonwloadProfile in Web.config
                                BaseBlobProfile downloadProfile = BaseBlobProfile.GetAccessProfileByCfgName("open");

                                //If public disk provider then redirect
                                BlobStorageProvider provider = BlobStorage.Providers[element.BlobStorageProvider];

                                BlobInfo blobInfo     = element.GetBlobInfo();
                                string   profileName  = String.Empty;
                                string   providerName = String.Empty;
                                if (FolderElement.TryRecognizeStorageProvider(element, blobInfo.FileName, blobInfo.ContentType, blobInfo.ContentSize, out providerName, out profileName))
                                {
                                    if (!String.IsNullOrEmpty(profileName))
                                    {
                                        downloadProfile = BaseBlobProfile.GetAccessProfileByCfgName(profileName);
                                    }
                                }

                                String filterName = context.Request[FolderElement.filterParam];

                                //Download filter impl
                                if (!String.IsNullOrEmpty(filterName))
                                {
                                    DownloadFilterBase filter = DownloadFilterBase.GetFilterByCfgName(filterName);
                                    if (filter != null)
                                    {
                                        filter.Initialize(context.Request.Params);
                                        //subscribe to filter event
                                        downloadProfile.FilterEvent += filter.ProcessFilter;
                                    }
                                }

                                //Begin download
                                downloadProfile.ProcessRequest(context, blobInfo);
                            }
                            catch (BlobDownloadException e)
                            {
                                if (e.Code == 204) //No content
                                {
                                    context.Response.ClearContent();
                                    context.Response.AddHeader("Content-Length", "0");
                                }
                                //throw new HttpException(e.Code, e.Message);
                                context.Response.StatusCode        = e.Code;
                                context.Response.StatusDescription = e.Message;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Tries the recognize provider.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="contentType">Type of the content.</param>
        /// <param name="fileSize">Size of the file.</param>
        /// <param name="providerName">Name of the provider.</param>
        /// <param name="profileName">Name of the profile.</param>
        /// <returns></returns>
        public static bool TryRecognizeStorageProvider(FolderElement element, string fileName,
                                                       String contentType, long fileSize,
                                                       out String providerName, out string profileName)
        {
            providerName = String.Empty;
            profileName  = String.Empty;
            FileLibraryLocationSection section = (FileLibraryLocationSection)
                                                 ConfigurationManager.GetSection(folderElementLocationsCfgName);

            if (section != null)
            {
                FileLibraryLocationCollection            locations = section.Locations;
                Dictionary <String, LocationRuleElement> matchList =
                    new Dictionary <string, LocationRuleElement>();

                string hierarhy = element.GetElementPath("\\");
                foreach (FileLibraryLocationElement location in locations)
                {
                    bool   wildcard     = location.Path.EndsWith(wildCardChar);
                    string locationPath = wildcard == true?
                                          location.Path.Substring(0, location.Path.IndexOf(wildCardChar))
                                              : location.Path;

                    if (hierarhy.Equals(locationPath,
                                        StringComparison.InvariantCultureIgnoreCase) ||
                        ((wildcard == true) && (hierarhy.StartsWith(locationPath, StringComparison.InvariantCultureIgnoreCase))))
                    {
                        LocationRuleCollections rules = location.LocationRules;

                        foreach (LocationRuleElement rule in rules)
                        {
                            bool found = true;

                            if (!String.IsNullOrEmpty(rule.Extension))
                            {
                                found = fileName.EndsWith(rule.Extension,
                                                          StringComparison.InvariantCultureIgnoreCase) ? found : false;
                            }

                            if (!String.IsNullOrEmpty(rule.MimeType))
                            {
                                found = contentType.Equals(rule.MimeType,
                                                           StringComparison.InvariantCultureIgnoreCase) ? found : false;
                            }

                            if (!String.IsNullOrEmpty(rule.MaxSize))
                            {
                                String regExpPat = @"(?<size>[0-9]+)\s*(?<unit>Kb|Mb|Gb)?";
                                Regex  regExp    = new Regex(regExpPat, RegexOptions.IgnoreCase);
                                Match  sizeMatch = regExp.Match(rule.MaxSize);
                                if (sizeMatch.Success)
                                {
                                    long   maxSize = Convert.ToInt64(sizeMatch.Groups["size"].Value);
                                    string unit    = sizeMatch.Groups["unit"].Value;
                                    if (!String.IsNullOrEmpty(unit))
                                    {
                                        if (unit.Equals("Kb", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            maxSize *= 1024;
                                        }
                                        else if (unit.Equals("Mb", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            maxSize *= 1048576;
                                        }
                                        else if (unit.Equals("Gb", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            maxSize *= 1073741824;
                                        }
                                    }

                                    found = fileSize >= maxSize ? found : false;
                                }
                            }

                            if ((found == true) || (String.IsNullOrEmpty(rule.MaxSize) &&
                                                    String.IsNullOrEmpty(rule.MimeType) &&
                                                    String.IsNullOrEmpty(rule.MaxSize)))
                            {
                                matchList.Add(location.Path, rule);
                                break;
                            }
                        }
                    }
                }

                if (matchList.Count != 0)
                {
                    //get location element with max depth
                    int    maxDepth = -1;
                    String maxKey   = String.Empty;
                    foreach (String key in matchList.Keys)
                    {
                        int depth = key.Split(new Char[] { '\\' }).Length;
                        if (depth > maxDepth)
                        {
                            maxDepth = depth;
                            maxKey   = key;
                        }
                    }
                    providerName = matchList[maxKey].StorageProvider;
                    profileName  = matchList[maxKey].DownloadProfile;
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 17
0
 public FolderElement(CustomTableRow row, MetaObjectOptions options)
     : base(FolderElement.GetAssignedMetaClass(), row, options)
 {
 }
Exemplo n.º 18
0
 public FolderElement(CustomTableRow row)
     : base(FolderElement.GetAssignedMetaClass(), row)
 {
 }
Exemplo n.º 19
0
 public FolderElement(PrimaryKeyId primaryKeyId, MetaObjectOptions options)
     : base(FolderElement.GetAssignedMetaClass(), primaryKeyId, options)
 {
 }
Exemplo n.º 20
0
 public static int GetTotalCount(params FilterElement[] filters)
 {
     return(MetaObject.GetTotalCount(FolderElement.GetAssignedMetaClass(), filters));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Processes the specified element.
 /// </summary>
 /// <param name="element">The element.</param>
 public void Process(FolderElement element)
 {
     element.Card = cardName;
 }
Exemplo n.º 22
0
 public static FolderElement[] List(params Mediachase.Ibn.Data.FilterElement[] filters)
 {
     return(MetaObject.List <FolderElement>(FolderElement.GetAssignedMetaClass(), filters));
 }
Exemplo n.º 23
0
 public FolderElement(MetaObjectOptions options)
     : base(FolderElement.GetAssignedMetaClass(), options)
 {
 }
Exemplo n.º 24
0
 public static FolderElement[] List()
 {
     return(MetaObject.List <FolderElement>(FolderElement.GetAssignedMetaClass()));
 }
Exemplo n.º 25
0
 public static FolderElement[] List(params Mediachase.Ibn.Data.SortingElement[] sorting)
 {
     return(MetaObject.List <FolderElement>(FolderElement.GetAssignedMetaClass(), sorting));
 }