Skip to main content

Windows Live - SkyDrive

Windows LIVE series:
Astazi o sa vorbim despre cum putem accesa SkyDrive.
Pentru a putea avea acces la datele pe care un user le are pe SkyDrive este nevoie ca la logare sa setam scopul "wl.skydrive". Avand setat acest scope o sa putem accesa orice informatie pe care userul o are pe SkyDrive.
WL.init({ client_id: {idClient}, redirect_uri: {ourRedirectUrl} });
WL.login(
{ "scope": "wl.skydrive" },
function (response) {
if (response.status == "connected") {
alert("Utilizator conectat");
}
else {
alert("Autentificare esuata");
}
});
Dupa ce utilizatorul s-a logat tot ce ne-a mai ramas este sa apelam API-ul care il avem la dispozitie. Fiecare element care ne vine dupa o interogare o sa contina date precum tipul ementului( daca e folder sau fisier - ce tip de fisier), nume fisier, id, dimensiune etc. Aceste informatii sunt foarte asemanatoare cu cele pe care le avem cand suntem intr-un director de pe disk-ul local. Din JS pentru a aduce toate elementele din root trebuie sa facem urmatorul apel:
 WL.api({ path: ""/me/skydrive/files", method: "GET" }, onGetRootItemsComplete);
function onGetRootItemsComplete(response) {
if (response.error) {
alert("A aparut o eroare");
return;
}
var items = response.data;
var foundFolder = 0;
for (var i = 0; i < items.length; i++)
{
// item[i].type - tipul fisierului. Valore este "fo-lder" daca elementul este un folder
// daca ar fi un fisier aceast camp ar avea valoarea "file"
// item[i].name - numele la element
// item[i].id - id unic a elementului din SkyDrive
}
}

O sa avem nevoie de id, daca vrem de exemplu sa facem download la continutul unui fisier.
Pentru a putea vedea toate folderele, albumele de poze si fisierele din root a unui user pe de Skydrive e nevoie sa facem un request cu path-ul setat spre: me/skydrive/files
Pentru a accesa fisierele unui folder este nevoie sa apelam urmatorul path: {folderId}/files . Exact la fel se face daca vrem sa aducem pozele dintr-un albul: {album_id}/files.
Dar cum putem sa adaugam un nou folder pe SkyDrive. Pentru acest lucru avem nevoie de numele la folder, o scurta descriere si locatia unde dorim sa il adaugam. Mai jos puteti gasi un exemplu in C#:
Dictionary<string, object> newFolderData = new Dictionary<string, object>();
folderData.Add("NewFolderName", "New folder description");
LiveConnectClient liveConnectClient = new LiveConnectClient(session);
liveConnectClient.PostCompleted +=
new EventHandler<LiveOperationCompletedEventArgs>(CreateFolderPostCompleted);
client.PostAsync("me/skydrive/files/BaseFolder", newFolderData);
...
void CreateFolderPostCompleted(object sender, LiveOperationCompletedEventArgs e)
{
// Daca e.Error este diferit de NULL, atunci actiunea nu s-a terminat cu succes.
}
Daca in al doilea exemplu am vazut cum putem itera printr-un folder, acuma va propun sa download un fisier de pe SkyDrive. Odata ce avem id-ul la fisierul pe care vrem sa il copiem local, e nevoie sa apelam direct metoda download din JS sau DownloadAsync din C#. Pentru exemplul de mai jos am ales tot varianta C#:
client.DownloadCompleted +=
new EventHandler<LiveDownloadCompletedEventArgs>(OnFileDownloadCompleted);
client.DownloadAsync("file.{id_fisier}/content");
...
void OnFileDownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
{
// e.Result o sa contina fisierul nostru.
// Nu uitati sa faceti close la Result, deoarece este un stream: e.Result.Close();
}
Dupa cum am putut vedea prin intermediul API-ului este foarte simplu sa lucram cu SkyDrive. Nu uitati ca SkyDrive nu permite prin intermediul API-ului upload-ul la orice fel de fisiere. Asigurativa inainte sa faceti upload ca fisierul vostru este suportat. Din interfata web puteti uploada orice fel de fisiere.
Fisierele care se pot copia pe SkyDrive prin intermediul API sunt:
  • PDF, txt + fisiere Office precum Word, Excell, etc
  • poze in orice format supotat de Windows
  • audio doar in format wav
  • video in format wmv sau H.264
Orice tip de fisier poate sa fie adaugat din brower de exemplu. Trebuie tinut cont ca, chiar daca din API manipulam datele unui user( schimba vizibilitatea unui fisier), nu putem sa restrictionam accesul la fisere a.i. userul sa nu le poata accesa.

Comments

Popular posts from this blog

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Run native .NET application in Docker (.NET Framework 4.6.2)

Scope
The main scope of this post is to see how we can run a legacy application written in .NET Framework in Docker.

Context
First of all, let’s define what is a legacy application in our context. By a legacy application we understand an application that runs .NET Framework 3.5 or higher in a production environment where we don’t have any more the people or documentation that would help us to understand what is happening behind the scene.
In this scenarios, you might want to migrate the current solution from a standard environment to Docker. There are many advantages for such a migration, like:

Continuous DeploymentTestingIsolationSecurity at container levelVersioning ControlEnvironment Standardization
Until now, we didn’t had the possibility to run a .NET application in Docker. With .NET Core, there was support for .NET Core in Docker, but migration from a full .NET framework to .NET Core can be costly and even impossible. Not only because of lack of features, but also because once you…