Descriptor of a binary resource.
Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        public static MemoryStream GetResourceAsStream(BinaryResourceDescriptor descriptor)
        {
            byte[] byteResource = GetResource(descriptor);

            return new MemoryStream(byteResource);

        }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
 //------------------------------------------------------------------------------------------------------------------------
 public BinaryResourceDescriptorTimelineInfo(Yodiwo.API.Plegma.BinaryResourceDescriptor desc)
 {
     BinaryResourceDescriptorKey = desc.Key;
     Name = desc.FriendlyName;
 }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        public static byte[] RedisDBFetchHandler(BinaryResourceDescriptor descriptor)
        {
            byte[] resource = null;

            // Fetch resource from redisDB location


            return resource;
        }
Exemplo n.º 7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="brd"></param>
 public void Update(BinaryResourceDescriptor brd) { }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="brd"></param>
 public void Update(BinaryResourceDescriptor brd)
 {
 }