We know how important it is to share, share whatever comes to our minds no matter what it is for. We have released a new feature called “Social Connector”, this will allow our users to share content from their iKnode apps to Social Accounts, with the simplicity of 2 lines of code. Right now we are supporting Twitter and Facebook services, we allow our users to post tweets or content to the user Facebook feed.
It is also very easy to set this up, once you are in Command Center locate the section called “Social Connector”:
This will display on the right panel two buttons
Each of those buttons will begin the traditional authentication/authorization process, if you are already logged on those services you will just have to authorize our app, otherwise you will have to authenticate against the service first, what it is going to happen is that we are going to store your access tokens in your user storage, the collection will be called social media, so you can just look at it right away after you authorize iKnode to access your social accounts.
If you have multiple accounts, iKnode will handle that by naming your token records so you can choose which one to use in your apps. This is how the records will look like:
among other columns, you should see the ones shown below, of course you will a token string for each document (record) in the collection. What you should consider is the column name, on your apps you would refer to this tokens by the name, so let’s say if you wanted to post some random message to one of your twitter accounts, you would have to use the name of the token record to use, you can of couse edit the document and change the name to whatever you like, something that would make more sense to you than twitter1, twitter2, etc.
Now, how to use this? easy, take a look at the iKnode app shown below, your apps method ‘Shout’ will try to post a message (provided as a parameter) to facebook and twitter, we will make use of our twitter and facebook accounts, twitter1 and facebook1 respectively.
Of course you have to provide your own user id, you can take your user id from the profile section, just click your name on the top right corner of Command Center and you should see your user information, your user id should be the first field.
Copy as paste this app in the Command Center application editor, save, compile and execute to test! you should be able to see the text provided as a parameter to the Shout method in your Twitter and Facebook timelines with the string “!!” as a suffix.
A few weeks ago we were talking to an iKnode user which was trying to write a code generator. While trying to help solve the problem, we came up with a solution that ended up being a really cool feature. Apps that Write other Apps.
We were already writing a service to allow iKnode Apps to call others, but to Create, Compile and Publish Applications from an iKnode Application was an amazing idea which would give iKnode Apps a lot more power and flexibility. We went ahead to spec, design and implement the feature. And today, we unveil the Frankestein Feature as we like to call it.
The iKnode engine is already implemented as a set of Services which are only accessible from the inside of our network. When an iKnode application runs, it is running inside our network, so it made sense to just allow iKnode Apps to just call our services. We created a service in the assembly iKnode.Applications (which is used by ALL iKnode Applications) to simplify the call to our internal service, allowing the caller to Save, Publish and Execute iKnode Applications.
Programming Interface
The Service is called “iKnode.Applications.ApplicationService” (docs) and handles “Application” (docs) objects. The Application class represents an application for the service. Let’s look at the structure:
The ApplicationService is the class that allows the application to perform operations in the iKnode engine. The structure is defined below:
The important operations for the Application Service are:
Save
Allows the Application to be Saved. There is not compilation or validation of code. A ‘Saved’ application is considered in Draft mode, which means it cannot be executed. Use this method to store partial or drafts of an application.
Allows the Application to published. The Application is first saved, then compiled and then published so that it can be executed. If there is any compilation errors, and exception will be generated. A successfully published Application can be Executed.
We have built an example that covers all of the operations. Throughout this example we will class this Application “The Host”. The host’s main purpose is to create the Guest Application if it doesn’t exist, and then run it. But if the application already exists then it sohuld only execute it.
usingSystem;usingSystem.Text;usingiKnode.Applications;usingSystem.Collections.Generic;namespaceApplications{/// <summary>/// Defines the Application Service Test./// </summary> [Application]publicclassApplicationServiceTest{/// <summary>/// User Identifier./// </summary>privatestaticreadonlyGuidUserId=newGuid("YOUR_USERID");/// <summary>/// Tests the Application Service./// </summary>/// <returns>Trace Information.</returns>publicstringTestAppService(){stringappName="GuestApp";StringBuildertrace=newStringBuilder();ApplicationServicesvc=newApplicationService(UserId);Applicationapp=svc.GetByName(appName);if(app==null){trace.AppendLine("App was not found!");Guidid=this.CreateApplication(appName);trace.AppendLine("App '"+appName+"' created with Id - "+id);}else{trace.AppendLine("App '"+appName+"' found!");}trace.AppendLine("Application Executed: "+svc.Execute(appName,"Sum","{ a:'10', b:'20'}"));returntrace.ToString();}/// <summary>/// Creates an application with the selected name./// </summary>/// <param name="appName">Application Name</param>/// <returns>Application Identifier of the created application.</returns>privateGuidCreateApplication(stringappName){stringcontent=@"using System;using iKnode.Applications;[Application]public class GuestApp{ public Double Sum(Double a, Double b) { return a + b; }}";List<string>dependencies=newList<string>();Applicationapp=newApplication(appName,"Test Application",content,"1.0",dependencies);ApplicationServicesvc=newApplicationService(UserId);// Saves the App but no publish. Cannot be executed.if(!svc.Save(app)){returnGuid.Empty;}// Saves, Compiles and Publishes. If successful, then app can be executed.if(!svc.Publish(app)){returnGuid.Empty;}returnapp.Id;}}}
What the Host application does is create another application named “Test” which performs a “Sum” operation. We will refer to the generated application as the Guest. The code this new Application will have is:
Let’s test the Host application. Before executing the Host, this is how the Application Library looks like:
If we execute the application the first time, this is what we will see:
As we can see the application was not found by the Host application and created it before executing it. If we run it a second time, this is what we’ll see:
As we can see the guest application was found, so it was just executed. If we go to the Application Library we’ll see the GuestApp, just like any other application.
We hope you enjoy this new feature, we had a lot of fun writing it and coming up with applications to use it. Try it and let us know what you think.