How to retrieve an image from an OData Service? - c#

I have an OData service (its System Center Orchestrator's web service if you must know ) that returns a BMP image if I query
http://localhost.com/Orchestrator2012/Orchestrator.svc/RunbookDiagrams(guid'882f767d-63bd-437c-b0c7-4051aac56176')/$value
So its basically saying, give me the RunbookDiagram with the Id 882f767d-63bd-437c-b0c7-4051aac56176
It renders it correctly in IE. But when I query it fom C# I'm not able to get the image data, but I do get all other data fields.
Now the documentation of the webservice says I need to use $value to return the query. But how do I use $value in the following OData query from C#
RunbookDiagram rbkdiag=orch.RunbookDiagrams.Where(
m => m.RunbookId ==runbookId
).SingleOrDefault();

Maybe the service is returning the images as media link entries?
You can check for this by viewing the xml returned from the server and look for m:HasStream="true"
If this is the case use GetReadStream on the context.
Check this astoriateam blog post for details.

Related

HTML to Note content

When I trying to write some HTML text to Note, I have error (I think because HTML have some prohibited tags):
Evernote.EDAM.Error.EDAMUserException
When I use the same HTML with:
ENNote.Content = ENNoteContentAdvanced.NoteContentWithSanitizedHTML(HTML);
it works fine.
But I need get notes by ID, for updating. And I am not understand how I can write correctly HTML to Note (in HTML I have tables), or catching ENNote by GUID.
UPD.
I writing service for synchronization Notes (EN) between Evernotes and Microsoft Exchange Appointments (MA). When user create/update EN, my service create/update MA. When user update MA (created from Evernote), my service update EN. For linking I use EN GUID (I store it in MA in extended property). So I can find EN with this code:
List<ExtendedProperty> guids = appointment.ExtendedProperties.Where(ap => ap.PropertyDefinition == guidProp).ToList();
if (guids.Count > 0)
{
string guid = (string)guids.First().Value;
Note sNote = store.GetNote(guid, true, false, false, false);
}
But when I trying to set EN content I have error:
Error code "ENML_VALIDATION"
Parameter = "Document is invalid: no grammar found"
I can't store ENNoteRef in MA, because it object, not string. So I need to find ENNote by GUID (not ENNoteRef), or some stuff to set HTML to Note.Content without loosing tables.
It would help if you provide more of your code that surrounds the ENNote.Content call so we have more context.
Given the code you've provided: once you've created the ENNote and its content using the NoteContentWithSanitizedHTML function, you're then adding the note to the Evernote service with something like the following, correct?
ENNoteRef myNoteRef = ENSession.SharedSession.UploadNote(ENNote, null);
When you do this, you get back a NoteRef object, which is a reference to an actual specific note in the Evernote service. The NoteRef object has a Guid property, which is what you're looking for.

how to do API calls of Kentico using ASP.NET MVC?

I'm struggling with API calls of Kentico forms using ASP.NET MVC, so that I can use AngularJS to display the return data (JSON format).
Specifically, my client is using Kentico on their server to create data using "Forms" on Kentico and I want to get the records stored in these forms via API calls using ASP.NET MVC. What I'm thinking is that in the general section of the "Forms", I see the "Form code name" showing that "Code name is a string identifier of the object that can be used by developers in API calls or URLs". But it seems to be there's no good example of it on internet. Keep trying to search it but no luck. I also tried to access data directly in SQL Server in which kentico stores the data. But the table's name that Kentico uses in SQL Server to store the data is different from the ones in "Forms" or "Custom tables" in Kentico.
Hope someone can show me how to do it and I really appreciate it. Thanks in advance.
There is a very good example in the official documentation of Kentico.
Please note that Forms have been renamed a few times in the past (they were called BizForms and On-Line forms) that's the reason why the code below references CMS.OnlineForms and uses BizFormInfoProvider. It might also very well be the reason why you didn't find any good example :)
The example below shows how to retrieve Form's definition (metadata), get all the data and iterate through it.
using CMS.OnlineForms;
using CMS.DataEngine;
using CMS.SiteProvider;
using CMS.Helpers;
...
// Gets the form info object for the 'ContactUs' form
BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("ContactUs", SiteContext.CurrentSiteID);
// Gets the class name of the 'ContactUs' form
DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
string className = formClass.ClassName;
// Loads the form's data
ObjectQuery<BizFormItem> data = BizFormItemProvider.GetItems(className);
// Checks whether the form contains any records
if (!DataHelper.DataSourceIsEmpty(data))
{
// Loops through the form's data records
foreach (BizFormItem item in data)
{
string firstNameFieldValue = item.GetStringValue("FirstName", "");
string lastNameFieldValue = item.GetStringValue("LastName", "");
// Perform any required logic with the form field values
// Variable representing a custom value that you want to save into the form data
object customFieldValue;
// Programatically assigns and saves a value for the form record's 'CustomField' field
item.SetValue("CustomField", customFieldValue);
item.SubmitChanges(false);
}
}
UPDATE:
The example above assumes that you're using the API from within the running Kentico instance. If you want to use Kentico API (DLLs) from an external application please follow the steps I described in another answer.
You also asked about the site identifier (siteId or siteName params of the BizFormInfoProvider.GetBizFormInfo() method). They refer to the SiteInfo object in Kentico (DB table CMS_Site). You can find site name if you navigate to Site->Edit site->General->Site code name.
If you don't want to use Kentico DLLs there is another option - using Kentico REST endpoint.

AngularJS .Net WebAPI Upload image and save to database (MSSQL)

I'm trying to upload an Image(can be bind to a model with a data type byte[]) from UI and save it in the database.
I'm using AngularJS connecting it to .NET WebAPI and saving it to MSSSQL Server
I cant find a good example using these technologies.
Question:
What approach is better to use? like ng-upload, FormData, ArrayBuffer, convert image to byte, etc. and how will you catch it from WebAPI?
Thanks!
I'm working on this feature these days. I share my experience (obviously it can be improved).
The key components I use are:
angular-file-upload
.NET ImageResizer: for resizing original image for thumbnails (excellent work by Nathanael Jones)
the stack is:
Angular.js Image Uploader
As I said, I use angular-file-uploader. There's no so much to add to the official documentation, but my uploader configuration is:
$scope.uploader = $fileUploader.create({
scope: $scope,
url: DisciturSettings.apiUrl + 'User/Image',
queueLimit: 1,
formData: [{ UserId: AuthService.user.userid }],
headers: AuthService.getTokenHeader()
});
In order to send the user id to the http request and to grant the access to the authorized route
WebApi 2 Action
The service does the main work. Here is the code.
As you can see, in this phase, I do two resizings of the image passed (one for the user profile picture and the other for user thumbnail picture). Besides this, I convert the byte[] in string and prepare the string for next retrievals. Doing this I prepend this part "data:image/gif;base64,", so, in the next entity readings (through EntityFramework) I don't have to manipulate the result anymore and I can put them directly in angular template:
<img ng-src="{{local.user.image}}" />
Obviously It can be made differently, but that's my case.
Database
At the moment I simply use nvarchar for storing images.
It's my first try so it can be improved for sure (if you have hints, don't hesitate).

Bloomberg API - get list of government bonds

When hitting KENGB <Govt> <GO> on the Bloomberg terminal I get list of all Kenya government bonds.
How do I get this list through Bloomberg API? Or list of their tickers?
(I download PX_LAST prices and historical prices for various securities regularly, so I am pretty familiar with service "//blp/refdata" and request "ReferenceDataRequest" ... but cannot figure out how to retrieve list of securities (and its tickers) programmatically)
try to take a look at this:
http://www.openbloomberg.com/content/uploads/sites/2/2013/04/blpapi-developers-guide.pdf
at page 77 it explains which service you must call to have Government Bonds.
this is teh c++ code:
Service govtService = session.getService("//blp/instruments");
Request request = govtService.createRequest("govtListRequest");
request.asElement().setElement("partialMatch", true);
request.asElement().setElement("query", "T*");// this plus the previous line permits to retrieve all the thicker that begins with T
request.asElement().setElement("ticker", "LANG_OVERRIDE_NONE");
request.asElement().setElement("maxResults", 10);
sendRequest(request, session);
The only way I know to get a list of securities via API v3 is to use the EQS API where you set up an EQS screen and then use the API to get the matching securities. Not sure if this lets you achieve the same result you get from security search on the Terminal.

Bloomberg API - using .Net API to get the FUT_CHAIN on an underlying security

I am trying to query the Bloomberg API (.Net) to get the future chain on an underlying security. Preferably, I would be able to get the list of futures for a given date in the past.
The equivalent operation in Excel using the worksheet formula API would be the following:-
=BDS("ERA COMDTY","FUT_CHAIN","CHAIN_DATE=20120103",
"INCLUDE_EXPIRED_CONTRACTS=Yes")
I looked at a large number of online resources, and I don't seem to be getting anywhere.
For the v3 API, you need to use request overrides.
Request request = refDataService.createRequest("ReferenceDataRequest");
request.append("securities", "ERA Comdty");
request.append("fields","FUT_CHAIN");
Element overrides = request.getElement("overrides");
Element override1 = overrides.appendElement();
override1.setElement("fieldId", "CHAIN_DATE");
override1.setElement("value", "20120103");
Element override2 = overrides.appendElement();
override2.setElement("fieldId", "INCLUDE_EXPIRED_CONTRACTS);
verride2.setElement("value", 'Y');
session.sendRequest(request);

Categories