IMediaResources Interface
Provides the interface for working with MediaResources: Adding, Getting and/or Updating -ErpMedias.
Namespace: powerGate.Erp.Client\ Assembly: powerGate.Erp.Client.dll
Syntax
1 | public interface IMediaResources |
Properties
Type |
Name |
Description |
---|---|---|
EntitySet |
Gets the EntitySet of this MediaResources. |
Methods
Type |
Name |
Description |
---|---|---|
void |
GetErpMedia(Dictionary<string,object> keys, Stream stream) |
Downloads the Media Resource of an existing Media Link Entry (MLE) and writes it to the passed Stream. |
AddErpMedia(MediaCreateOptions options) |
Creates a new Media Link Entry (MLE) with the request body containing the Media Resource (MR) and the Content-Type header indicating its media type. In other words it will create a streamable entity (Media Link Entry) and upload it together with the specified file (Media Resource). |
|
void |
UpdateErpMedia(MediaUpdateOptions options) |
Updates the Media Resource of an existing Media Link Entry (MLE). |
Extension Methods
Type |
Name |
Description |
---|---|---|
AddErpMedia(Stream data, Dictionary<string,object> properties=null, string contentType = “application/octet-stream”) |
Overloaded. Creates a new Media Link Entry (MLE) with the request body containing the Media Resource (MR) using the specified parameter values. |
|
void |
UpdateErpMedia(Dictionary<string, object> keys, Stream data, string contentType = “application/octet-stream”) |
Overloaded. Updates the Media Resource of an existing Media Link Entry (MLE) using the specified parameter values. |
Exceptions
In case of an invalid request the above methods will throw a WebRequestException.
Remarks
The GetErpMedia(…) function copies the downloaded binary data into the passed Stream object, and therefore the Stream needs to be writable.
For Streams that support seeking, the position is automatically set to starting position in order to directly allow reading it’s content.
The CreateErpMedia(…) and UpdateErpMedia(…) functions reading and uploading the binary data from the passed Stream object, and therefore the Stream has to be readable.
Examples
In the following examples we are using public OData Services (http://services.odata.org) for demonstration purposes:
Download ErpMedia
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using System; using System.Collections.Generic; using System.IO; using powerGate.Erp.Client; namespace MediaResourcesSample { class Program { static void Main(string[] args) { using (var erpclient = new ErpClient()) { using (var service = erpclient.ConnectErp(new Uri("http://services.odata.org/V3/OData/OData.svc"))) { var advertisments = service.EntitySets["Advertisements"]; //Check if the EntitySet supports MediaResources if (advertisments.SupportsMediaResources) using(var downloadData = new FileStream(@"C:\Temp\DownloadedFile.txt", FileMode.Create,FileAccess.Write)) { //Download MediaResource advertisments.MediaResources.GetErpMedia(new Dictionary<string, object> { { "ID", Guid.Parse("db2d2186-1c29-4d1e-88ef-a127f521b9c6") } }, downloadData); } } } } } } |
Add a new ErpMedia
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | using System; using System.Collections.Generic; using System.IO; using powerGate.Erp.Client; namespace MediaResourcesSample { class Program { static void Main(string[] args) { using (var erpclient = new ErpClient()) { using (var service = erpclient.ConnectErp(new Uri("http://services.odata.org/V3/OData/OData.svc"))) { var advertisments = service.EntitySets["Advertisements"]; //Check if the EntitySet supports MediaResources if (advertisments.SupportsMediaResources) using(var uploadData = File.OpenRead(@"C:\Temp\TestMedia.txt")) { var mediaCreateOptions = new MediaCreateOptions { Data = uploadData , ContentType = "text/plain", Properties = new Dictionary<string, object> { { "Name", "My new Advertisment, Yeaahh!" } } }; //Create a new Media Link Entry with a MediaResource var newAdvertisment = advertisments.MediaResources.AddErpMedia(mediaCreateOptions); Console.Write("Advertisment ID: {0}", newAdvertisment["ID"]); } } } } } } |
Update existing ErpMedia
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | using System; using System.Collections.Generic; using System.IO; using powerGate.Erp.Client; namespace MediaResourcesSample { class Program { static void Main(string[] args) { using (var erpclient = new ErpClient()) { using (var service = erpclient.ConnectErp(new Uri("http://services.odata.org/V3/OData/OData.svc"))) { var advertisments = service.EntitySets["Advertisements"]; //Check if the EntitySet supports MediaResources if (advertisments.SupportsMediaResources) using(var uploadData = File.OpenRead(@"C:\Temp\TestMedia.txt")) { //Update MediaResource of Media Link Entry advertisments.MediaResources.UpdateErpMedia( keys: new Dictionary<string, object> { { "ID", Guid.Parse("f89dee73-af9f-4cd4-b330-db93c25ff3c7") } }, data: uploadData ); } } } } } } |
See also
Reference