/// <summary> /// Konstruktor /// </summary> /// <param name="fileName"></param> /// <param name="itemKey"></param> /// <param name="packKey"></param> /// <param name="sizeType"></param> /// <param name="contentType"></param> internal DataResourceItem(string fileName, string itemKey, string packKey, ResourceImageSizeType sizeType, ResourceContentType contentType) { FileName = fileName; ItemKey = itemKey; PackKey = packKey; ContentType = contentType; SizeType = sizeType; _Content = null; _ContentLoaded = false; }
/// <summary> /// Vrací true, pokud dodaný typ obsahu podporuje uvádění velikosti v názvu zdroje (souboru). Typicky jde o obrázky. /// </summary> /// <param name="contentType"></param> /// <returns></returns> private static bool ContentTypeSupportSize(ResourceContentType contentType) { switch (contentType) { case ResourceContentType.Bitmap: case ResourceContentType.Vector: case ResourceContentType.Icon: case ResourceContentType.Cursor: return(true); } return(false); }
/// <summary> /// Konstruktor /// </summary> /// <param name="content"></param> /// <param name="fileBegin"></param> /// <param name="fileLength"></param> /// <param name="itemKey"></param> /// <param name="packKey"></param> /// <param name="sizeType"></param> /// <param name="contentType"></param> public DataResourceItem(byte[] content, long fileBegin, int fileLength, string itemKey, string packKey, ResourceImageSizeType sizeType, ResourceContentType contentType) { FileName = null; ItemKey = itemKey; PackKey = packKey; SizeType = sizeType; ContentType = contentType; _Content = new byte[fileLength]; if (fileLength > 0) { Array.Copy(content, fileBegin, _Content, 0, fileLength); } _ContentLoaded = true; }
/// <summary> /// Z dodaného jména souboru určí příponu, podle ní detekuje typ obsahu (dá do out parametru) a detekovanou příponu odřízne (včetně tečky). /// Vrátí true, pokud nějakou příponu detekoval a odřízl (tedy <paramref name="contentType"/> je jiný než None). /// Vrátí false, když je vstup prázdný, nebo bez přípony nebo s neznámou příponou, pak příponu neodřízne. /// <para/> /// Například pro vstup: "C:/Images/Button-24x24.png" detekuje <paramref name="contentType"/> = <see cref="ResourceContentType.Bitmap"/>, /// a v ref parametru <paramref name="name"/> ponechá: "C:/Images/Button-24x24". /// <para/> /// Tato metoda se typicky volá před metodou <see cref="RemoveSizeTypeBySuffix(ref string, out ResourceImageSizeType)"/>, protože tady se řeší a odřízne přípona, a následně se tam řeší suffix jména souboru. /// </summary> /// <param name="name"></param> /// <param name="contentType"></param> private static bool RemoveContentTypeByExtension(ref string name, out ResourceContentType contentType) { contentType = ResourceContentType.None; if (String.IsNullOrEmpty(name)) { return(false); } name = name.TrimEnd(); string extension = System.IO.Path.GetExtension(name).ToLower(); contentType = DxComponent.GetContentTypeFromExtension(extension); if (contentType != ResourceContentType.None) { name = name.Substring(0, name.Length - extension.Length); } return(contentType != ResourceContentType.None); }
/// <summary> /// Récupère une ressource à partir d'une URL absolue. Utilise un caching afin qu'une /// même ressource ne soit pas traitée deux fois. /// </summary> /// <param name="url"></param> /// <returns></returns> private Resource GetResource(Uri url, ResourceContentType initialContentType) { Resource resource; Uri urlWithoutSessionId = url.WithoutSession(); if (!Resources.TryGetValue(urlWithoutSessionId.AbsoluteUri, out resource)) { lock (_lock) { if (!Resources.TryGetValue(urlWithoutSessionId.AbsoluteUri, out resource)) { resource = new Resource(urlWithoutSessionId, ResourceBehavior.Ignore); resource.ContentType = initialContentType; IBehaviorRule behaviorRule = _behaviorRules.GetBehaviorRule(resource); resource.Behavior = behaviorRule == null ? ResourceBehavior.Ignore : behaviorRule.Behavior; Resources.Add(urlWithoutSessionId.AbsoluteUri, resource); Context.Resources.Add(resource); // En fonction du behavior et de la limitation de ressource, on décide // si une ressource devra être traitée ou non. if (resource.Behavior != ResourceBehavior.Ignore && (!_limitResources.HasValue || _limitResources > 0)) { if (_limitResources.HasValue) { _limitResources--; } behaviorRule.TargetBucket.QueueItem(resource); resource.CurrentBucket = behaviorRule.TargetBucket.Name; } else { resource.Status = ResourceStatus.Ignored; resource.CurrentBucket = null; } } } } return(resource); }
/// <summary> /// Vrátí obecné jméno zdroje z dodaného plného jména zdroje (oddělí velikost a typ souboru podle suffixu a přípony). /// Pro vstupní text např. "Noris/pic/AddressDelete-32x32.png" vrátí "Noris/pic/AddressDelete" /// a nastaví <paramref name="sizeType"/> = <see cref="ResourceImageSizeType.Large"/>; /// a <paramref name="contentType"/> = <see cref="ResourceContentType.Bitmap"/>. /// </summary> /// <param name="name"></param> /// <param name="sizeType"></param> /// <param name="contentType"></param> /// <returns></returns> public static string GetPackKey(string name, out ResourceImageSizeType sizeType, out ResourceContentType contentType) { string packKey = GetItemKey(name); sizeType = ResourceImageSizeType.None; contentType = ResourceContentType.None; if (!String.IsNullOrEmpty(packKey) && !packKey.Contains("«")) { if (RemoveContentTypeByExtension(ref packKey, out contentType) && ContentTypeSupportSize(contentType)) { RemoveSizeTypeBySuffix(ref packKey, out sizeType); } } return(packKey); }
string ISystemAdapter.GetResourcePackKey(string name, out ResourceImageSizeType sizeType, out ResourceContentType contentType) { return(DataResources.GetPackKey(name, out sizeType, out contentType)); }