ورود

View Full Version : اضافه کردن شبکه های اجتماعی و یا ذخیره سازی ابری در کمتر از سی دقیقه به محصول (سایت ، اپلیکیشن) شما



baracudaProject
سه شنبه 12 فروردین 1393, 02:40 صبح
می توانید در کمتر از 30 دقیقه تا دهها سرویس آنلاین را با کمترین زحمت به وب ، محصول تحت ویندوز ، آی او اس .. در کلیه محیطهای دات نت (حتی ویندوز فون ) و شامارین (از جمله آندروید و آی او اس) خود اضافه کنید.

این مقاله که در کد پروجکت منتشر می گردد توضحیاتی در این مورد داده است :

شایان ذکر است امکان خرید قانونی این محصولات در ایران نیز از طریق ارسال پیام خصوصی برای این آی دی (بدون هزنیه اضافه و با هزینه تخفیف و قانونی) فراهم گردیده است. ، کلیه محصولات قانونی شرکتهای بزرگ تولید کننده کامپوننت به دلیل بخشی از محصولات آنها در حمهوری اسلامی ایران تولید می گردد فراهم گردیده است از جمله محصولات شرکت تی ام اس بلژیک و سایر شرکتها.
طریقه محاسبه قیمت محصول به یورو- تخفیف * قیمت روز یورو و یا دلار (برای محصولات کانادایی و آمریکای شمالی) می باشد.
کلیه محصولات از طریق شرکت مادر به شما ارایه می گردند.

http://www.tmssoftware.com/site/tmscloudnet.asp

how to add login with other services for your website
using TMS CloudPack.NET.
Introduction :
I tell you how to:
1- Add OAuth service login to your website or application.
2- Using AntiFreeze to avoid your GUI from freezing during network connections
3- Token Persistence and the usage of it

Online demos are available here:
www.tmssoftware.biz/cloudnetdemos

you can download trial and full demos source code here :

http://www.tmssoftware.com/site/tmscloudnet.asp

Most of developers, from Desktop to mobile applications to Web love to integrate social networks, online storages and other online services such as photo services in to their Website or application, question remains is it easy ? if you want to use original SDKS it is complex , you need to deal with many different syntax and some times some codes are complex to use or not working and even some services do not have a tested SDK for .net , but how about when you do have all of them in one low weight and small footprint from a longterm experienced Component seller?

In the article below , I do answer some of your questions, first one is how to add login with other services for your website. Also , meanwhile take a look at our roadmap which is possible to be added based on our customer interests, you must have over 35 different services in near future (maybe few motnhs) plus chat support for some of them, this is a great chance for both of side , customers and TMS to have such opportunity to have unique product.
This article:
In this article I tried to introduce how an Asp.Net application can use this component set within less than 30 minutes to create a login through multiple services, there are several issues which are described in next articles.
Share Data through multiple services
Load and store files in Cloud Storage with the same syntax
Note that in all environments such as ASP.NET , WebForms, WPF , Store Ready Applications or Winphone or Xamarin syntax will be used is the same , so , you don’t need to have special knowledge to use them and also, all components using unified design so, you can use them in the same way, use direct API or Wrapped ones, for example for paging you don’t need to write special code in most cases.

You need to do just few steps:

Add reference for TMS.Cloud and TMS.Cloud.Web assemblies to your project.
First you must add this two components to your webpage:

CloudCacheProvider
WebFormsOAuthPanel


After adding them you have two ways to do login , first scenario is with state (means holding data in cache and cookies) which works well with all components other than Flicker and twitter as they use OAUTH 1 which are must use stateless mode because of technical limitations, so, you can do StateLess

With Stateful option you have to set following property for CloudCacheProvider.
Expiry
Time of cache expiry in Seconds , default is 300 means cache will hold your data in 300 Seconds or 5 Minutes. You can change this value but in most cases default value works properly.

Now add a RadioButtonList to your page and add following items to that:
Facebook,LinkedIn,Google

And add a Button and change its caption to Login.

Add following using directives:
using TMS.Cloud.Facebook;
using TMS.Cloud.LinkedIn;
using TMS.Cloud.GoogleContacts;

implement following properties in your WebForm class:


private Facebook Facebook { get; set; }
private LinkedIn LinkedIn { get; set; }
private GoogleContacts GoogleContacts { get; set; }


Write following code in to your Page_Load event:
Facebook = CloudCacheProvider1.Factory<Facebook>("Facebook");
LinkedIn = CloudCacheProvider1.Factory<LinkedIn>("LinkedIn");
GoogleContacts = CloudCacheProvider1.Factory<GoogleContacts>("GoogleContacts");




Set Key/Secrets or other options:
You have two options, one is set them by OAuth.CFG or directly in your code, each OAuth Component have Authenticator property and you can use that to load your Application settings:
Sample:
Facebook.Authenticator.LoadSettings(); //to load with default settings (OAuth.Cfg)
Or :
Facebook.Authenticator.XmlFileName

And even you can set XPath for your component , by default Xpath is equal to Component Name, a sample file is below:

<?xml version="1.0"?>
<oauth>
<dropbox>
<key></key>
<secret>xxxxxxxxxxxxxx</secret>
<callback>xxxxxxxxxxxxxx </callback>
</dropbox>
<onedrive>
<key>xxxxxxxxxxxxxx</key>
<secret>xxxxxxxxxxxxxx</secret>
<callback>xxxxxxxxxxxxxx</callback>
</onedrive>
<googledrive>
<key> xxxxxxxxxxxxxx </key>
<secret> xxxxxxxxxxxxxx </secret>
<callback> xxxxxxxxxxxxxx </callback>
</googledrive>
<box>
<key> xxxxxxxxxxxxxx </key>
<secret> xxxxxxxxxxxxxx </secret>
<callback> xxxxxxxxxxxxxx </callback>
</box>
</oauth>


Also you can have your settings simply by loading this values by LoadSettings method.
Now you have all three services available in your page.
When you use Stateful this made some advantages for you in design main things is you can do all of your jobs in one place.
In Stateful you need to set ViewState enabled for the page.
OAuthWebFormsPanel.OpenMode:
You can do authentication a page in NewWindow,Popup or Redirect , all three options available to let your development easier, but note that NewWindow or popup might have problems with some devices such as tablets or might be blocked by popup blockers.

Next step:
Each OAuthWebFormsPanel should be connected to only one component at once, so you can do this simply as below:

Component.Authenticator.OAuthPanel = OAuthWebFormsPanel1;
When you use multiple components in one page you can do it in two ways, one is using switch like code below (in your Page_Load event)
switch (RadioButtonList1.SelectedIndex)
{
case 0:
Facebook.Authenticator.OAuthPanel = OAuthWebFormsPanel1;
break;
case 1:
LinkedIn.Authenticator.OAuthPanel = OAuthWebFormsPanel1;
break;
case 2:
GoogleContacts.Authenticator.OAuthPanel = OAuthWebFormsPanel1;
break;
}

In your login button you can write code below:

protected void Button1_Click(object sender, EventArgs e){
switch (RadioButtonList1.SelectedIndex)
{
case 0:
Facebook.Open();
break;
case 1:
LinkedIn.Open();
break;
case 2:
GoogleContacts.Open();
break;
}


}

By running Open method , system will run required codes to let you do authentication.



Stateless design:
Stateless is another option you do have , to use it , you must set OAuthWebFormsPanel OpenMode property to Redirect, and StatelessRedirection = true , this option let you to redirect to other page but for each Component you need to create a Login Redirect Page for example , Facebook.aspx and just drop a the two key components , CloudCacheProvider,OAuthWebFormsPanel and then create an instance from your CloudCompoennt and connect that to your OAuthWebFormsPanel component like code below:

FaceBook.Authenticatot.OAuthPanel = OAuthWebFormsPanel1;

Whats next:

Each component have an AfterOpen event, just set that event to your designated component for example facebook,
Facebook.AfterOpen = AfterOpenEvent ;


In AfterOpen event you can write your own code to use the component , as all components are using asynchronouse method to be authenticated you need to write your code access inside this event,

If you want to do a login only for each service simply use component.UserProfile property as most of components have this property as well and then use their Id (which is String value most of times) plus @ with name of component , this can create a unique Id for each login for example:

341234422@twitter and then specify it to a database field and store a record for the person, also you can collect some information from the service (for example user screen name or more etc ) from the service he is logged in through that , if it is first time for his login you can add a record for him and sign him up through that and later times , you can read that record and update it if required.


AntiFreeze:
How to stop your program from freezing during network actions?

For Winforms/WPF/Store Ready/Winphone you have a component named AntiFreeze that permit your program continue working during your application connecting to the network, you have two ways , one is do that inside a thread or if you don’t like to do that you can set an AntiFreeze you can set component.AntiFreeze value to the related type to your Application, first add a reference to Cloud.[YourProjectType] library ,then add or create instance of one the following components :
WinFormsAntiFreeze
WPFAnfiFreeze
StoreReadyAntiFreeze
WinphoneAntiFreeze
This can let your application work during the transfer and GUI will continue working, system uses a mechanism that let system work thread safe , so, your requests will be processed in a task list , to avoid GUI from sending more commands through available UI elements such as buttons you can set ShowWaitingPanel to true which show a waiting panel to user and disable other functionalities , meanwhile user can see your system is trying to send data to network, this is popular for easy single thread development.



Tokens Persistence:
Most of times you need to save your login information to a file to let users continue using your system next time they open your application, most of our components to support Google , Yahoo and Microsoft have RefreshToken support, this will let you to save your Login information and then later, load them and let user to continue working without going for login steps, also, when your Login session is expired system automatically will try to obtain new Tokens to let users continue working:

To do that , first you must you must get and store your Tokens in AfterOpen Event:
To get Encrypted Tokens as string you use one of the following methods:
string tokens= Component.Authenticator.GetTokens()
Component.Authenticator.SaveTokensToFile(fileName) ;
Component.Authenticator.SaveTokensToStream(Stream) ;
also you can change your encryption key using this property:
Component.Authenticator.EncryptionKey=”M321132H3 2h13h”;

To load them , before Opening the component you must load your tokens:

Component.Authenticator.SetTokens(tokens)
Component.Authenticator.LoadTokensFromFile(fileNam e);
Component.Authenticator.LoadTokensFromStream (Stream);

System, will renew the token in required cases for example it they are expired, meanwhile you can renew that your self using :
Component.Authenticator.RefreshTokens();


Watching your job progress:
You have several events they let you to watch your action progress, these are important especially when you have large size of transfer for example sending or receiving files:

private void storage_WorkingProgress(object sender, HttpWorkType workType, HttpRequestContext requestContext, long workCount, long contentLength)
{
if (contentLength > 0)
{
SetMaximum((int)contentLength);
SetMinimum(0);
SetValue((int)workCount);

SetText("progress: " + workCount + "/" + contentLength);
}
}

You have several other events they can help you to have more control about your component:

BeforeHttpRequest(object sender, HttpRequestContext requestContext, ref bool handled)
Fires before you send a request to server , you can deny the request and handle it by your manual code but you must set handled to true, any mistake in writing a code can made your component malfunctioning

AfterHttpRequest(object sender, HttpRequestContext requestContext)
Fires after you send a request and request process is done:

AfterOpen(object sender, ref bool handled)
Fires after authentication is done, you can run your manual code and then stop component from loading Account information for logged in user by sending handled to true, this can stop your component from working in some cases.

BeforeOpen(object sender, ref bool handled)
Fires before component opening or authentication process, you can avoid system from running normal code by set handled to true, this can made your component malfunctioning if your code is not written properly.


BeginWork(object sender)
EndWork(object sender)

These two events starts before and after system send and then receive the response.


Error(object sender, CloudResponse response, System.IO.Stream content, ref bool handled)
This event is critical in some cases, system throw an exception when it do not succeed to do a request, you can handle them here, all of components handle the error by processing incoming data and translate them and then throw an exception through incoming fields depends on which component or service you are using, but you can handle this manually too, note that if you set handled to true such as other events system will stop running default actions but also, this can made your component malfunctioning if you do not implement your code properly.




These are one of the many thing we implemented here , it need a lot of time till we introduce all of them but I will try to tell you more about the design and great architecture we have in this component set. I can to say we did a great job by architecture and design we did.
You can find some compare below, if there are no real competitor in this arena but there are some solutions , this is an easy way to see where is the advantages :
CloudPack.Net Other systems or Open SDKs
Unified design X
OAuth Support for Winforms X X
OAuth Support for WPF X
OAuth Support for ASP.NET X X
OAuth Support for Store Ready X
OAuth Support for WindowsPhone X
Token Persistence X Partially
Support for 20 Services in small footprint (under 1Mb) X
Easy and fast setup architecture X

Also , you have only full implementation of vFormats here, such as vCard , vCalendar , plus, you have support for WebDav, and the size of Assembly is under 1Megabytes.

Now, do you believe this great but small footprint can do some magic for you?

In next article I will define more about Structure and design of this system, where I am saying we did strong architecture with a lot of effort, it is a selfish word if I says we did an Art of software Engineering but believe me, this is truth to say that so!


Roadmap:

We do have a plan for support all known services as we have in other versions, even we have a support for chat services etc, so , you don’t have to worry about future of product, product is coming with full source code and also, we have a support for all known .net project types such as MCV.NET , ASP.NET , WPF, WinForms , Store Ready(Modern and windows 8) , Windows Phone , Xamarin and Mono and product have a version that support Delphi to develop native code for IOS / Android/Windows (an edition named Cloudpack Studio)