private IHmeResource ResourceToHmeResource(Events.ResourceInfo resourceInfo, Resource resource) { IHmeResource hmeResource = null; lock (_resourceManager) { if (_resourceManager.TryGetHmeResource(resourceInfo.ResourceId, out hmeResource)) { return(hmeResource); } } if (resource.IsMusic) { hmeResource = new StreamedMusic(this, resource.Name, resourceInfo.ResourceId); } else if (resource.IsResourceType(ResourceType.Image)) { hmeResource = new ImageResource(this, resource.Name, resourceInfo.ResourceId); } else if (resource.IsResourceType(ResourceType.Sound)) { hmeResource = new Sound(this, resource.Name, resourceInfo.ResourceId); } else if (resource.IsResourceType(ResourceType.TrueTypeFont)) { hmeResource = new TrueTypeFontResource(this, resource.Name, resourceInfo.ResourceId); } else { hmeResource = new GenericResource(this, resource.Name, resourceInfo.ResourceId); } return(hmeResource); }
internal void OnResourceInfoReceived(Events.ResourceInfo resourceInfo) { if (resourceInfo.Status == (long)ResourceStatus.Error) { int errorCode; string value; if (!resourceInfo.Info.TryGetValue("error.code", out value) || !int.TryParse(value, out errorCode)) { errorCode = (int)ResourceErrorCode.Unknown; } string errorText; if (!resourceInfo.Info.TryGetValue("error.text", out errorText)) { errorText = string.Empty; } IHmeResource hmeResource = null; lock (_resourceManager) { Resource resource; if (_resourceManager.TryGetResource(resourceInfo.ResourceId, out resource)) { hmeResource = ResourceToHmeResource(resourceInfo, resource); } } EventHandler <ResourceErrorArgs> handler = ResourceErrorOccurred; if (handler != null) { handler(this, new ResourceErrorArgs(hmeResource, (ResourceErrorCode)errorCode, errorText)); } } else { IHmeResource hmeResource = null; lock (_resourceManager) { Resource resource; if (_resourceManager.TryGetResource(resourceInfo.ResourceId, out resource)) { hmeResource = ResourceToHmeResource(resourceInfo, resource); } } EventHandler <ResourceStateChangedArgs> handler = ResourceStateChanged; if (handler != null) { handler(this, new ResourceStateChangedArgs(hmeResource, (ResourceStatus)resourceInfo.Status, resourceInfo.Info)); } } }