Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Sunday, December 15, 2013

Microsoft Windows - Client Operating Systems - API unity


Why Microsoft needs three or more operating systems

   A common operating system core, with common APIs and capabilities, is inevitable, and it is logical. Microsoft might even start to use common branding, most likely with Windows Phone becoming just "Windows." But that doesn't mean that it won't actually have three operating systems. Windows on a phone will be different from Windows on a tablet—in much the same was as iOS on the iPhone is different from iOS on the iPad. The user interface will be tailored to the form factor, making the two close siblings but not identical.

This will result in Windows for ARM phones, Windows for ARM tablets, and Windows for x86/x64 PCs. One might even make a case for a fourth to be added into the mix: Windows for x86 phones.

More exotic is the Xbox One operating system. This has no branding of its own, as it's never decoupled from the Xbox One hardware


A completely different API? That’s a different OS !


The operating system that is meaningfully different is Windows Phone. Windows Phone 7 used Windows CE (Microsoft's lightweight, customizable, embedded operating system) as its kernel. At the time, Windows CE was Microsoft's only ARM-compatible operating system, and the company had considerable experience using it on smartphones (as it was also used in Windows Mobile). This seemed like a sensible decision. Third-party applications were built using a modified version of Silverlight with a .NET environment .


For Windows Phone 8, Microsoft wanted to use the NT kernel. The NT kernel is more capable and is where most of Microsoft's development effort is spent, so this made sense for the company (if not for end users). Since the development of Windows RT meant that the Windows software stack ran on ARM, there was no longer any reason to stick with Windows CE. Accordingly, Windows Phone 8 shares major parts with Windows 8, with low-level components such as the network stack and security infrastructure in common between the operating systems.

To support existing Windows Phone 7 apps, Windows Phone 8 included essentially the same Silverlight environment. New applications for Windows Phone 8, however, didn't use the Silverlight environment. They have a couple of options: a new .NET environment similar to the old Silverlight one (though this time built on the full .NET runtime and notably missing the XNA 3D graphics API that the Silverlight system supported) and native code C++ with Direct3D.

Significantly, Windows Phone apps can't use Windows' Win32 API. Nor can they use most of the new WinRT API.

Developers wanting to share code between their phone and tablet software aren't completely out of luck: it's possible to write .NET code that conforms to a common subset of functionality that's available on both Phone and regular Windows (producing what are called "Portable Class Libraries"). Windows Phone 8 also gives C++ developers access to a limited subset of the WinRT API (sometimes called WinPRT), and large parts of Direct3D. Sources speaking to Paul Thurrott claim that overall, there's about a 33 percent commonality between the phone and non-phone operating systems.

This makes Windows Phone 8 a strange orphan operating system. Windows Phone 8 has few APIs in common with either Windows or Windows RT, so while iOS and Android phone apps can also be used on iOS and Android tablets, Windows Phone apps are strictly for the phone alone !

Universal binariesMicrosoft is currently pushing the notion of universal binaries that would let developers create a single app that can run both on Windows RT and Windows Phone. Where Windows Phone 8 has 33 percent "API unity" with Windows RT, Windows Phone 8.1 will hit 77 percent.

Friday, October 28, 2011

Step 7 : POST data from JSON Android Client to WCF REST WebService

POST JSON data from an Android Client to a WCF RESTful WebService

The full Android.java source code is on Google Code :
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/

The full Eclipse Indigo 3.7 - Android  project zipped on Google Docs :
https://docs.google.com/leaf?id=0BzKVfKe--t_cMDU5OTU5MDQtNDQzOC00YjE3LTlhODgtYjE1ZDhmZWFmZjc1&hl=en_GB


All files of the WCF RESTful Web Service are also on Google Code :
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/RestService

The full Visual Web Developer project -  VWD  Express 2010 also on Google Docs :
https://docs.google.com/leaf?id=0BzKVfKe--t_cODIwZWE2M2QtZTUwMy00Yjg1LTljMjUtYTA3MGI4YmM5OGZm&hl=en_GB

First we tried to post XML formatted data to a WCF Web Service with FIDDLER ( step 5 ) :
http://pantestmb.blogspot.com/2011/10/pass-multiple-body-parameters-wcf-rest.html

Then tried to post JSON data to a WCF Web Service with FIDDLER ( step 6 ) :
http://pantestmb.blogspot.com/2011/10/wcf-rest-fiddler-json-request-body.html

Now , knowing that the WCF Web Service responds OK with both XML and JSON ,
we can take our simple sample project to the ANDROID Client Test :


http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/SavePerson.java

package net.learn2develop.AndroidViews;


import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
// import org.json.JSONObject;
import org.json.JSONStringer;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

public class SavePerson extends Activity {

private final static String SERVICE_URI = "http://192.168.61.3/RestServicePost/RestServiceImpl.svc";

@Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);
       // String plate = new String("test");
       // POST request to
            HttpPost request = new HttpPost(SERVICE_URI + "/json/adduser");
            request.setHeader("Accept", "application/json");
            request.setHeader("Content-type", "application/json");
         
            String not = new String(" ");
            try {
            // Build JSON string
            JSONStringer vehicle = new JSONStringer()
                .object()
                    .key("rData")
                        .object()
                            .key("details").value("bar|bob|b@h.us|why")
                        .endObject()
                    .endObject();
         
            StringEntity entity = new StringEntity(vehicle.toString());
         
            Toast.makeText(this, vehicle.toString() + "\n", Toast.LENGTH_LONG).show() ;
         
            request.setEntity(entity);
         
            // Send request to WCF service
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpResponse response = httpClient.execute(request);
            // Log.d("WebInvoke", "Saving : " + response.getStatusLine().getStatusCode());
            Toast.makeText(this, response.getStatusLine().getStatusCode() + "\n", Toast.LENGTH_LONG).show() ;
         
            }catch (Exception e) {
            not = "NOT ";
            }
         
            Toast.makeText(this, not + " OK ! " + "\n", Toast.LENGTH_LONG).show() ;
         
         

}  
}


http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/RestService/IRestServiceImpl.cs


      [OperationContract]
        [WebInvoke(Method = "POST",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "json/adduser")]
        PersonData AddJsonUser(RequestData rData);

In our simple example we create a JSONStringer object with "rData" key and "details" sub-key ;
      "rData" is the variable of the function "AddJsonUser" ;
"details" is the single property of the object "RequestData" :
 http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/RestService/RequestData.cs


    [DataContract(Namespace = "")]
    public class RequestData
    {
        [DataMember]
        public string details { get; set; }
    }





The string  "bar|bob|b@h.us|why" of the JSONStringer is hard-coded to simplify things ;
After being parsed - it ends up in the SQLS table "Users" : 





http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/RestService/RestServiceImpl.svc.cs
AddUser is the function triggered by the POST WCF Webservice
http://192.168.61.3/RestServicePost/RestServiceImpl.svc/json/adduser
with a JSON request body -  JSONStringer vehicle : 


        public PersonData AddUser(RequestData rData)
        {
            bool returnBool = false;

            var data = rData.details.Split('|');
            var response = new PersonData
            {
                Name = data[0],
                User = data[1],
                Email = data[2],
                Password = data[3]
            };

            SqlConnection dbConn = new SqlConnection(connStr);
            string sqlStr = "INSERT INTO users(username,name,email,password)
                          values('" + data[0] + "', '" + data[1] + "', '" + data[2] + "', '" + data[3] + "');";
            SqlCommand dbCommand = new SqlCommand(sqlStr, dbConn);
            try
            {
                dbConn.Open();
                if (dbCommand.ExecuteNonQuery() != 0)
                {
                    returnBool = true;
                }
                dbConn.Close();
            }
            catch
            {
                returnBool = false;
            }
            return response;
        }

        public PersonData AddJsonUser(RequestData rData)
        {
            return AddUser(rData);
        }



~ ~ ~


the SQL Server Database has only one table - Users :

CREATE TABLE [dbo].[Users](
[UserName] [varchar](100) NOT NULL,
[Name] [varchar](100) NOT NULL,
[EMail] [varchar](100) NOT NULL,
[Password] [varchar](100) NOT NULL,


Thursday, August 4, 2011

Android Indigo : invalid command-line parameter



Android Emulator on Eclipse Indigo has an error like 
"invalid command-line parameter" :

 This post is about Eclipse Indigo Build id = 20110615-0604

[2011-08-04 18:13:32 - AndroidViews2] ------------------------------
[2011-08-04 18:13:32 - AndroidViews2] Android Launch!
[2011-08-04 18:13:32 - AndroidViews2] adb is running normally.
[2011-08-04 18:13:32 - AndroidViews2] Performing net.learn2develop.AndroidViews.ViewsActivity activity launch
[2011-08-04 18:13:32 - AndroidViews2] Automatic Target Mode: launching new emulator with compatible AVD 'avd_2.3'
[2011-08-04 18:13:32 - AndroidViews2] Launching a new emulator with Virtual Device 'avd_2.3'
[2011-08-04 18:13:37 - Emulator] invalid command-line parameter: Files\Android\android-sdk-windows\tools/emulator-arm.exe.
[2011-08-04 18:13:37 - Emulator] Hint: use '@foo' to launch a virtual device named 'foo'.
[2011-08-04 18:13:37 - Emulator] please use -help for more information


It seems that the error is caused by the SDK location path : 
C:\Program Files\Android\android-sdk-windows








This works on i386 : 
C:\Progra~1\Android\android-sdk-windows






After OK & Run : 




SDK location path on AMD64
C:\PROGRA~2\Android\android-sdk



Wednesday, June 29, 2011

Late Orders : Soap ASP.NET WebService & Android Ksoap2 Client

Here it is the source code and pictures from a sample application that exposes an ASP.NET 
SOAP webservice that is consumed in an Android Java Client ... 


How to load into Eclipse a project from Google.Code via subversion
How to add Android plugin to Eclipse Indigo


LateOrdersByZone extends ListActivity 


ViewsActivity : 
startActivity(new Intent(this, LateOrdersByZone.class));


Order[] allOrders;
Vector vectorOfStrings = new Vector();



int orderCount = vectorOfStrings.size();
String[] orderTimeStamps = new String[orderCount];
vectorOfStrings.copyInto(orderTimeStamps); 

setListAdapter(new ArrayAdapter(this,
                android.R.layout.simple_list_item_1 , orderTimeStamps));




http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/


Order
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/Order.java


LateOrdersByZone
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/LateOrdersByZone.java


Copy1OfLateOrdersByZone


Copy2OfLateOrdersByZone


Copy3OfLateOrdersByZone






ASP.NET WebService : Orders2a.asmx 









what we want to do in a few years ...


Wednesday, February 23, 2011

Web Service call with a String as a parameter

ASP.NET Web Service ( ASMX ) call from Android with a String parameter :

http://www.flickr.com/photos/24834074@N04/5469116121/sizes/l/in/photostream/

http://www.flickr.com/photos/24834074@N04/5469710588/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5469116261/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5469710484/sizes/l/in/photostream/


[WebMethod(Description = "Method to obtain Orders By Zone")]
public Order[] ReturnOrdersByZone(string theZone)
{

    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();

    string sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name , dbo.PersoanaFizica.Prenume as Surname, dbo.Zona.Denumire AS Zone, dbo.Persoana.Denumire AS Client , dbo.[Document].Control " +
" FROM dbo.[Document] INNER JOIN " +
" dbo.PersoanaFizica ON dbo.[Document].Utilizator_ID =
dbo.PersoanaFizica.PersoanaFizica_ID INNER JOIN " +
 " dbo.Persoana ON dbo.[Document].Persoana_ID = dbo.Persoana.PersoanaID INNER JOIN " +
 " dbo.Comanda ON dbo.[Document].DocumentID = dbo.Comanda.Comanda_ID INNER JOIN  " +
 " dbo.Utilizator ON dbo.[Document].Utilizator_ID = dbo.Utilizator.UtilizatorID INNER JOIN " +
                   " dbo.Zona ON dbo.Utilizator.ZonaID = dbo.Zona.Id " +
                   " WHERE  (dbo.Zona.Denumire LIKE" + "'%" + theZone + "%')" +
                   " ORDER BY Control DESC ";


    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);
    dbConn.Close();
    List list = new List();
    foreach (DataRow row in dt.Rows)
    {
        // Person target = Activator.CreateInstance();
        Order target = new Order();
        target.Name = row["Name"].ToString();
        target.Surname = row["Surname"].ToString();
        target.Zone = row["Zone"].ToString();
        target.Client = row["Client"].ToString();
        target.Control = row["Control"].ToString();
        list.Add(target);
    }
    return list.ToArray();
}

Tuesday, February 15, 2011

PersonPassport4.asmx - Simple webservice : INSERT UPDATE DELETE

Web Service C#.NET :
DB.SQL.TABLE as ARRAY
Android Client Consumer


From SOAP to WCF REST without LINQ : small and easy steps

PersonPassport2.asmx
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/PersonPassport2.asmx
http://jtelmon.googlecode.com/svn/trunk/AndroidViews/PersonPassport2.asmx

Building XML Web Services Using C# and ASP.NET



CREATE DATABASE minipassport 
GO 

CREATE TABLE Users ( 
UserName varchar (10) Primary Key NOT NULL , 
Name varchar (50) NOT NULL , 
EMail varchar (100) NOT NULL , 
Password varchar (10) NOT NULL 
) ON PRIMARY 
GO


http://www.flickr.com/photos/24834074@N04/5446222119/sizes/l/
http://www.flickr.com/photos/24834074@N04/5446222063/sizes/l/
http://www.flickr.com/photos/24834074@N04/5446839620/sizes/l/

http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport/src/passport/bimbim/in/MainLP2.java
http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport/src/passport/bimbim/in
http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport

<%@ WebService class = "PersonPassport2" Language="C#" Debug = "true"%>

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;


public class Person

{

    private string _name = string.Empty;
    private string _user_name = string.Empty;
    private string _eMaiL = string.Empty;
    private string _password = string.Empty;

  public Person() {}




    public string Name

    {

        get { return _name; }

        set { _name = value; }

    }

   
        public string Password

    {

        get { return _password; }

        set { _password = value; }

    }

   
   
    public string UserName

    {

        get { return _user_name; }

        set { _user_name = value; }

    }

    public string EMail

    {

        get { return _eMaiL; }

        set { _eMaiL = value; }

    }

        

}

public class PersonPassport2 : WebService
{
const string connStr = "server=localhost;uid=sa;pwd=kash;database=minipassport";

[WebMethod(Description = "Method to Authenticate Users")]
public bool Authenticate(string username, string password)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select password from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();

bool returnBool;
if (dbReader.Read())
{
if (dbReader[0].ToString()==password)
{
returnBool = true;
}
else
{
returnBool = false;
}
}
else
{
returnBool=false;
}
dbReader.Close();
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Add User")]
public bool AddUser(string username, string password, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "INSERT INTO users(username,password,name,email) values('" + username + "', '" + password + "', '" + name + "', '" + email + "');";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
returnBool=true;
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Delete User")]
public bool DeleteUser(string username)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "DELETE FROM users where username = '" + username +"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Edit User Information")]
public bool EditUser(string username, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET username = '" + username +"',name = '"+name+"',email= '"+email+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Change User Password")]
public bool ChangePassword(string username, string password)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET password = '"+password+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Obtain User Name")]
public string ReturnName(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select Name from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain User Email Address")]
public string ReturnEmail(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select email from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain All User Info")]
public DataSet ReturnAll()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataSet ds = new DataSet();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(ds, "users");
    dbConn.Close();
    return ds;
}

[WebMethod(Description = "Method to obtain All User Info")]
public Person[] ReturnArray()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);   
    dbConn.Close();
    List list = new List();
    foreach(DataRow row in dt.Rows) {
        // Person target = Activator.CreateInstance();
        Person target = new Person();
        target.Name = row["Name"].ToString();
        target.UserName = row["UserName"].ToString();
        target.EMail = row["EMail"].ToString();
        target.Password = row["Password"].ToString();
        // DataColumnAttribute.Bind(row,target);
        list.Add(target);
    }
    return list.ToArray();
}


 [WebMethod]
    public Person GetSingle()
    {
        Person person = new Person();
        person.Name = "bimbim.in";
        //person.Age = 30;
        //person.Dob = new System.DateTime(1980, 01, 15);
        //person.Salary = 50000f;
        return person;
    }

[WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

}











Dumped Database can be downloaded at :
https://docs.google.com/leaf?id=0BzKVfKe--t_cYjAzOTk5YmEtNjk1ZS00ZTcxLWIzMDgtYTMwMTVlMTQwZDVi&hl=en_GB