Search This Blog

Saturday 30 January 2016

How cordova works?

Cordova invokes Web-View of your mobile OS.
Its like a web browsers.So it cannot actually directly talk to any of the native features.

But Cordova allows you to talk to most of the native features.
Cordova fills the gap by having a standard JS interface implementation.

In your Cordova plugin under www folder, there will be your JS interface file.
which has a method call cordova.exec()
ex:exports.coolMethod = function(arg0, success, error) {
    exec(success, error, "mytest1", "coolMethod", [arg0]);

where success is the call back for successful cordova plugin call,
           error is the call back for failure call,
           "mytest1" is the native class which plugin will call,
           "coolMethod" is my method name in my interface/class
           [arg0] is the argument array to pass to my method.

So from java script you are making a call to native class mentioned in your exec method.
corodova will do that for you.

platform support for cordova can be found here:
http://cordova.apache.org/docs/en/3.5.0/guide/support/index.html#Platform%20Support


How exactly Cordova does that i couldnt found in google.
http://ishanaba.com/blog/tag/how-cordova-works/

References:
https://blogs.oracle.com/mobile/entry/introduction_to_custom_cordova_plugin

Create Custom Cordova plugins using plugman

creating custom plugin is sometimes needed when working on hybrid apps.
creating a custom plugin manually is not so easy as it needs a
1. XML
2. JS interface

If we plugman, its very easy as plugman creates most of your XML and JS interface.
follow the steps below to create one:

1. Install Plugman
2. Create plugin with Plugman
3. Add a package.json to plugin
4. Add platforms
5. Edit your method name in JS and XML files
6. Install using plugman to check if everything is correct.

1. Install Plugman
using CLI it is quite easy to install any plugin.
use the following command to install plugman.

npm install -g plugman

2. Create plugin with Plugman

plugman create --name <pluginName> --plugin_id <pluginID> --plugin_version <version> [--path <directory>] [--variable NAME=VALUE]
ex:plugman create --name Super --plugin_id "org.super.cool" --plugin_version 0.0.0 --variable description="Awesome PLugin"

this will create a plugin.xml and src/, www/ folders required for your plugin.
3. Add a Package.json
Creates a package.json file in the plugin based on values from plugin.xml.
 plugman createpackagejson <directory>

4. Add platforms
plugman platform add --platform_name=ios
This will add the <platform> tags to the plugin.xml as well as create an ios/ source folder in src/

5. Edit your method name in JS and XML files
the above command creates a js entry with name coolMethod in js and xml files
edit them according to your needs.

change the method name and make sure that the name matches the name in your src class.

6. Install plugin to a project to verify
plugman install --platform ios --project /Users/praveenseela/Desktop/Team/Praveen/custom\ plugin/testprj/testprj/platforms/ios/ --plugin /Users/praveenseela/Desktop/Team/Praveen/custom\ plugin/SaveBase64 

install plugin specific to a platform of your cordova project

if everything is correct it will not throw any errors.

in your project js file, you should be call be able to call your method using:
cordova.plugins. SaveBase64.yourMethodName

this way using plugman the burden of creating xml and js interface is simplified.
References:

Tuesday 26 January 2016

Interesting and Useful Perl Operators/Commands/Operations

Declarations
my-for local variable declaration
# - Comment
@-Array
$-Scalar variable
eq- equals to operator for string operations
ne-not equals for string operators

Matching
=~ - contains or matches part of a string
ex:if($var=~/'$sometext'/)
{
}

!~ - doesnt contains or matches 
ex:
if($var=~/'$sometext'/)
{
}

~~  - to check if the variable is in an array
ex: $ModelText ~~ @CompletedModels

Replace:
s/match/replace/g
ex: s/a/b/g - will replace all occurrences of a with b

Loop
foreach my $a(@AnArray)
{
    #like all other foreach loops
}

Opening a File
my $filepath = "<urpath>";
open(varFileHandler,$filepath);
#opens the file and stores it handler to varFileHandler variable
seek(varFileHandler,0,0);
#to move the file handler to point to first line, first character
close(varFileHandler);
#close file
Open File for writing
open JSONOut,">$FilePath" or die "cant open json to write";

Working with CSV files
declare CSV package at the top.
use Text::CSV;
install it using PPM-Perl Package Manager.
in cmd, type: ppm install Text-CSV

then get the csv separator.
my $csv = Text::CSV->new({ sep_char => ',' });
then, parse
$csv->parse($TempLine)
then, split it
my @fields = $csv->fields();

Some Common useful operations in text processing:
remove beginning and trailing white spaces: $TempVar =~ s/^\s+|\s+$//g
remove special chars like \r \n: chomp($TempVar);

Functions
ex:
sub PrintJsonAttrib
{
    #print $_[0].$_[1];
    print JSONOut "\"".$_[0]."\"".":"."\"".$_[1]."\"".","."\n";
}

i am using this function to print out the 1 and 2nd argument of my function.
$_ - contains the arguments. its like argv array in c.

Call/Connect to SharePoint from C# with NLTM authentication

I need to call a rest service hosted in SharePoint 2010 from C# .Net.
SharePoint uses NLTM authentication. So basic authentication wont work.

Initially i tried using
1. HttpClient
2. WebRequest
3. HttpWebRequest

My trail codes:
//1----
                // validate cert by calling a function
                //ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
                var creds = new NetworkCredential("<domain\un>","Password");
                string myreq = @"{ProgramID:6}";
                String MyURI = new Uri("<myserviceurl>").ToString();
                WebRequest WReq = WebRequest.Create(MyURI);
                WReq.Method = "POST";
                WReq.Credentials = creds;
                    var res = WReq.GetResponse();
//2--------
string jsonRequest = "<myServiceUrl>";

                HttpWebRequest spRequest = (HttpWebRequest)HttpWebRequest.Create(jsonRequest);
                spRequest.Credentials = credCache;
                spRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";
                spRequest.Method = "POST";
                spRequest.Accept = "application/json; odata=verbose";
                HttpWebResponse endpointResponse = (HttpWebResponse)spRequest.GetResponse();
//3--------
                var handler = new HttpClientHandler{Credentials = creds};
               
                using(var http = new HttpClient(handler)){
                   
                    http.DefaultRequestHeaders.Clear();
                    http.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");
                    //http.DefaultRequestHeaders.Add("X-RequestDigest", digest);
                    http.DefaultRequestHeaders.Add("X-RequestDigest", "digest");
                    http.DefaultRequestHeaders.Add("X-HTTP-Method", "POST");

                    var mediaType = new MediaTypeHeaderValue("application/json");
                    //var jsonSerializerSettings = new JsonSerializerSettings();
                    //var jsonFormatter = new JsonNetFormatter(jsonSerializerSettings);
                    //var requestMessage = new HttpRequestMessage<T>(data, mediaType, new MediaTypeFormatter[] { jsonFormatter });
                    StringContent content = new StringContent(myreq);
                    content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");//, Encoding.UTF8, "application/json");
                    //content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                    //content.Headers.ContentLength = myreq.Length;

                   
                   
                    http.BaseAddress = new Uri("<serviceurl>");
                   
                    resp = http.PostAsync("serviceurl",content).Result;
                }

NOTHING ABOVE WORKED. ITS ALL CREDENTIALS PROBLEM.
The below has worked: using CredentialCache
//4--
                string json = "{\"ProgramID\":\"6\"}";
                HttpWebRequest req = WebRequest.Create(MyURI) as HttpWebRequest;
                req.Method = "POST";
                req.ContentType = "application/json";
                req.ContentLength = json.Length;
                
                CredentialCache credCache = new CredentialCache();
                credCache.Add(new Uri(MyURI), "NTLM", new NetworkCredential("<un>", "Password"));
                req.Credentials = credCache;
                using (StreamWriter requestStream =new StreamWriter(req.GetRequestStream()))
                {
                    requestStream.Write(json);
                    requestStream.Flush();
                    requestStream.Close();

                }

                HttpWebResponse myres = req.GetResponse() as HttpWebResponse;
                using (var streamReader = new StreamReader(myres.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();

                }

Saturday 16 January 2016

Host Domain from resgistrar any in GoDaddy

1.       Get GoDaddy Hosting IP
2.       Update above IP in DNS File zone on your other Godaddy Domain
3.       If your domain is from other seller, update the above IP in that DNS account. i.e. if you get it from bigrock, update IP in bigrock’s DNS record.
Steps:
                1.       To get IP of your hosting
a.        go to Domains -> Manage
b.      Your domain name-> DNS File zone.
c.       Under A (HOST) IP opposite to @ is your IP to point
d.      Your name servers will be at the bottom
Ex:ns57.domaincontrol.com etc..
2.       To update Hosting IP in Domain account records
a.       Go to domains in your account where you purchased your domain
b.      Click on that domain and click on DNS file zone there.
c.       In @ record, under actions click Edit.
d.      Enter the IP from your hosting account (from step 1)

e.      Finish and save changes.

Adding Domains to your GoDaddy's Hosting

For Hosting multiple websites under same hosting plan in Godaddy, you should have Deluxe or Unlimited account. With that follow the steps below to finish the set up:

For adding domains to your deluxe hosting account:
  •  Go to my hosting
  • Click on Web Hosting-> manage
  • Click on manage against your hosting account name cPanel (linux)
  • Under Domains-> Add Domains
  • Enter domain name and add FTP for easy upload of your files


After that you need to point that domain’s DNS to GoDaddy Hosting IP and URL (of your hosting account).