/// <summary> /// /// </summary> /// <returns></returns> public static BinaryResourceDescriptor CreateDescriptor(byte[] resource, eBinaryResourceLocationType locationType, object locationDescriptor) { BinaryResourceDescriptor descriptor = new BinaryResourceDescriptor(); try { // Construct descriptor if (locationType.Equals(eBinaryResourceLocationType.Http)) { var locDesc = locationDescriptor as HttpLocationDescriptor; descriptor.LocationDescriptorJson = (new HttpLocationDescriptor { Uri = locDesc.Uri }).ToJSON(); // Use Dropbox's REST API to upload resource } else if (locationType.Equals(eBinaryResourceLocationType.RedisDB)) { var locDesc = locationDescriptor as RedisDBLocationDescriptor; descriptor.LocationDescriptorJson = (new RedisDBLocationDescriptor()).ToJSON(); } } catch (Exception ex) { descriptor = null; DebugEx.Assert(ex, "Error constructing descriptor for specified resource"); } return descriptor; }
public static MemoryStream GetResourceAsStream(BinaryResourceDescriptor descriptor) { byte[] byteResource = GetResource(descriptor); return new MemoryStream(byteResource); }
/// <summary> /// Get resource based on given descriptor /// </summary> /// <param name="descriptor"></param> /// <returns></returns> public static byte[] GetResource(BinaryResourceDescriptor descriptor) { byte[] resource = null; try { if (FetchHandlers.ContainsKey(descriptor.LocationType)) { resource = FetchHandlers[descriptor.LocationType](descriptor); } else { DebugEx.TraceError("No handler for resource descriptor of type: " + descriptor.LocationType.ToString()); } } catch (Exception ex) { DebugEx.Assert(ex, "Error getting resource from specified resource descriptor"); } return resource; }
//------------------------------------------------------------------------------------------------------------------------ public BinaryResourceDescriptorTimelineInfo(Yodiwo.API.Plegma.BinaryResourceDescriptor desc) { BinaryResourceDescriptorKey = desc.Key; Name = desc.FriendlyName; }
public static byte[] HttpFetchHandler(BinaryResourceDescriptor descriptor) { byte[] resource = null; // Fetch resource from HTTP location try { var uri = (descriptor.LocationDescriptor as HttpLocationDescriptor).Uri; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (Stream stream = response.GetResponseStream()) using (var ms = new MemoryStream()) { int count = 0; do { byte[] buf = new byte[1024]; count = stream.Read(buf, 0, 1024); ms.Write(buf, 0, count); } while (stream.CanRead && count > 0); resource = ms.ToArray(); } } catch (Exception ex) { DebugEx.Assert(ex, "Error fetching resource from specified HTTP location"); } return resource; }
public static byte[] RedisDBFetchHandler(BinaryResourceDescriptor descriptor) { byte[] resource = null; // Fetch resource from redisDB location return resource; }
/// <summary> /// /// </summary> /// <param name="brd"></param> public void Update(BinaryResourceDescriptor brd) { }