Ales Rosina's blog

shelastyle.net
Subscribe

Publishing NopCommerce 2.0 to Azure

So if you haven’t heard, NopCommerce is great open source project for e-commerce type sites. The latest version is rewritten in ASP.NET MVC, so you don’t need to bother with WebForms anymore.

I thought, that since it’s codebase was changed from 1.9 version it should also work very easily on Azure platform. But unfortunately that is not the case. If you take a close look at how nopCommerce works, you’ll see, that it needs write permissions for configuring connection string (actually it is stored in Settings.txt file in App_Data folder). I will not argue if that’s good or not, we just need to port it to Azure, that’s all :)

So for the first step, we need to deploy app on a local machine to get a full database. With a standard “Import and Export Data Wizard”, which you get with SQL Server installation, you can transfer database from local SQL Server instance to Azure based (read more on how to configure SQL Azure in this short tutorial). For more info on how to do a transfer, referrer to this great article on Microsoft TehNet Wiki.

So, when you’re done with configuring database, we’ll need to customize a bit NopCommerce. First of all, download version with source and open it in Visual Studio. You’ll need to have Azure SDK installed on your machine. You can add new empty Azure project in NopCommerce Solution and after it’s added, right click on Roles folder and choose Add>Web Role Project in solution. Add Nop.Web and that’s it for Azure configuration.

Now here comes tricky part – you need to include a few more folders in Nop.Web solution – that is folder Administration and folder Plugins. That’s because Visual Studio packages only folders included in project. After you’ve done that, you’ll also need to add a few more Refereces – try to build the project and check which references are missing.

One more thing before you’ll be able to upload to Azure – we need to change where Connection string is stored. I choose Web.config, where you need to add two new keys in appSettings section:

    <add key="DataProvider" value="sqlserver"/>
    <add key="DataConnectionString" value="Server=tcp:sth.database.windows.net,1433;
Database=nopcommerce;User ID=username@sth;Password=your_pwd;
Trusted_Connection=False;Encrypt=True;
"/>
and after that, you’ll also need to edit DataSettingsManager.cs (found in Data folder in Nop.Core project), where you’ll simply delete content of SaveSettings() function and replace LoadSettings() with:

public virtual DataSettings LoadSettings()
{
    var ret = new DataSettings();
    ret.DataProvider = ConfigurationManager.AppSettings["DataProvider"];
    ret.DataConnectionString = ConfigurationManager.AppSettings["DataConnectionString"];
    return ret;
}
And if you’re lucky enough, NopCommerce should be ready and published after Visual Studio does it’s magic of uploading/starting Azure instance.



   

author: Aleš Rosina | 6 Comments | Tags:
17
October
2011

Ads in Windows Phone applications

This weekend I had some spare time and following by a joke from a friend, I’ve made a very simple (and also very stupid) Windows Phone called “Easy Button”. It was also the first app I’ve published with my own AppHub account (previous ones – Mobitel Monitor and Ljubljana Bus were published in behalf of Microsoft Slovenia for a local competition). With that I do have access to all of the statistics, but more on that subject in a later post.

I’ve decided, that I’ll include some ads in my application, just to test things out. And also because I cannot sell apps with my account (read why in my previous post). So I’ve started to browse for ads providers – there are plenty, let me mention just a few:

First one is the most obvious and the most simple, but it useless for me, since I’m not from US. Moving right along to second one, which was also pretty good, since I can link it with my Google AdSense account. They are also providing official control for Windows Phone, so it was looking pretty cool. But… there’s a catch. Firstly, there are some technical issues with current implementation of this ad control and the worst part (for me as advertiser) – there are almost no ads for this platform and my region. With that, I’ve switched to the last one, that is AdDuplex.

This ad network allows me to show exchange ads for other apps on Windows Phone with some sponsored ads. This network is pretty new, created by Alan Mendelevich and allows my app some exposure within other apps. Like old “banner exchange” services for your own website popular about 5-6 years ago. But here’s a catch – you can also mark your app as “Monetized” which means, it will also show some commercial ads and can generate revenue. It’s not limited to a certain region (hooray for author!), payments are limited to a PayPal system.

Right now I cannot talk about success about ads, I’ll write about that in about a month or so when there will be some data available. The only thing I would like to point out is download/ads impressions ratio – which is after 4 days on marketplace 404 downloads/64 impressions. I’m not sure if that means that only 6% of people opens downloaded app or is there any other stuff that I’ve missed. I’ll share that when I’ll get more data.



   

author: Aleš Rosina | No Comments | Tags:
17
August
2011

WP7 Marketplace from unsupported country

Featured in the Windows Phone Marketplace - 4t...

Image by jeffwilcox via Flickr

So, you’ve just created an awesome app for Windows Phone and you’re ready to submit it to Marketplace. You’ve fulfill all the Marketplace requirements, all you need to do is to register on AppHub portal to actually submit your super-cool app.
But … oh wait, you live in a “not-supported” country? Microsoft initially said: “Sorry folks, no go.” After a lot of “negative response” from community, Microsoft changed its viewpoint and now they are “working on more and more supported countries, in the meantime try some other options from our partners.”
So first, let’s take a look at how I managed to get an official AppHub account and the end I’ll mention some other options ways to publish your app.

If you read my blog, than you probably know, that I live in a small European country Slovenia. Since we’re too small to be bothered by Microsoft (even thought we have localization for all major Microsoft products, including Windows and Office), we’re not supported on Windows Phone platform.
I started with my DreamSpark account (which is valid for one year after I’ve finished my studies, so I just caught last months of this account :)), since there is no need to pay $100 yearly subscription fee for students . For registration to be completed you need to enter a valid address in one of the supported countries, so just for fun I entered UK and one random address in London (hint: there are a lot of stores in London) and I was registered. All I need was a conformation from GeoTrust, company which checks your information on behalf of Microsoft. OK, so I submitted one test app (student account is not verified until you submit your first app) and waited what will happen. After a day or two, I got an email, stating that I should send them a copy of a valid driving license or Passport. Damn. Battle lost, I guess I’ll have to find another way to submit apps. But after two weeks, when I nearly forgot about that (I was working on some other project, but that’s another story), I got a call from a US phone number. I picked a phone with a surprise “Hello?” and on the other end guy said to me: “Hi, this is Jeff from GeoTrust. I’m calling on behalf of Microsoft for your Marketplace verification.” At first I was “Ehm, what?” but it took me just second to realize, that I need to explain myself. I told him I was just testing out and I don’t live in UK, as I stated in AppHub account, actually I’m from Slovenia. The guy from GeoTrust just said “Ok … let me check something…” and after a few seconds of silence he said to me some very cool words: “So, Slovenia is member of European Union, right? Just send me copy of your ID document and we’ll see what we can do.” The first thing I did, when I got home (I was driving when this call happened) was to send them a copy of my ID. And that’s it, next day I got email stating “Congratulations, Ales Rosina. Welcome to the Windows Phone Marketplace developer program.”

There you have it, it’s my experience with AppHub account verification – I hope some of you may get it the same way. But – there are some drawbacks – with this account I’m able to publish only free apps, since for paid Microsoft wants me to send them UK VAT number (which I obviously don’t have). But publishing free apps is good enough for me, so I didn’t dig any further in this direction.

If this doesn't work for you, you have some other options – the most complicated is opening business in one of the supported countries. If that’s not what' you’re looking for (eg. you would like to submit an app or two and maybe get some bucks for them, but it’s just not your primary business) you can check Yalla Yalla apps, which is one of the best option for unsupported countries – at least that’s what community on the web is saying. More on that subject read on ailon’s blog in this two great posts:

- The state of Worldwide WP7 publishing after MIX11 and
- Windows Phone app publishing through Yalla apps

If you have any questions, just leave a comment!

Enhanced by Zemanta


   

author: Aleš Rosina | 7 Comments | Tags:
04
June
2011

Sharing to Facebook, Twitter and email in Windows Phone 7

Recently I needed to implement sharing capabilities for Facebook, Twitter and email in one Windows Phone app I’m currently working on. Just for fun I also added sharing through SMS messaging.

We are all aware of default sharing page, which is included in Pictures hub and allows you to share to various networks and applications, so I wanted to recreate this look also in my app (you can download it on my SkyDrive):

screen1        screen2

Sharing a link through email  is easy, just 4 lines of code:

EmailComposeTask email = new EmailComposeTask();
email.Subject = title;
email.Body = "Read all about it here: " +  link;
email.Show();

For sending SMS messages is totally same, just the object is SmsComposeTask and there is no title.  There are several more launchers and choosers in Microsoft.Phone.Tasks namespace, you can read more about that here.

OK, so for Facebook and Twitter there are some complications, since you need to implement oAuth protocol. Basically it means, that my app doesn’t know anything about user’s credentials, but for doing that, we need a little hacking with browser control.

For Facebook there is already Facebook Toolkit and from latest version there is also support for Windows Phone apps. So there is no surprises, you just need to implement a lot of code, just because there is a lot of ping-pong communication going on. But hey, that’s why I did this sample, so you won’t have to!

Twitter implementation is using some bits of code from Twitt – Windows Phone 7 Twitter App, which is basic Twitter app for demoing purposes, but it’s very solid and well build example.

UPDATE: I forgot to mention, that you need to create application in Facebook (go for more info here – you will need Facebook account for that). By doing that, you will get Application ID. Insert this string in Helpers/FacebookSettings.cs and you’re ready to go.

For Twitter is almost the same – go here (again, you will need Twitter account for that) and create browser application (it’s because I’m using same app in my web application), where you’ll get consumer key and consumer key secret (and some more keys, but they are not relevant for this case). Enter those into Helpers/TwitterSettings.cs.

So that’s that, tell me what you think and don’t forget to download sample code here.

 

Enhanced by Zemanta


   

author: Aleš Rosina | 15 Comments |
05
May
2011

Ljubljana Bus Windows Phone app

panorama

Ok, so here’s my second app for Windows Phone – Ljubljana Bus (remember the first one – Mobitel Monitor?) Since I live in Ljubljana and I’m pretty frequent user of public transportation I wanted to have an app, where I’ll have all the info I need to travel around. The main idea was, that I can check arrival time of a bus when I’m still at home/office/restaurant/etc. And since LPP (company responsible for public transportation in Ljubljana) does provide a website with information about arrival times of buses, it was pretty easy to show this info. Just parse website and show it in an app, that is :)

Anyway, for development I wanted to take advantage of MVVM pattern and all the tools Microsoft has provided. So I did customize Panorama control (there will be a blog post about that soon), use some MVVM (with some ugly HTML parsing methods), full usage of Blend and (you would never guess) Visual Studio. But I won’t go deep about development in this post, if you’re interested just put a comment, send me email or find me somewhere :)

Let me just mention, there are currently apps for Ljubljana public transport on all major platforms including iPhone by Matej Bukovinski, Android by Pia Režek and now even for Windows Phone by me :).
Application is currently waiting for submission on Marketplace, so I hope it will be online in a week or two. Application is available in Marketplace, download it here. But before that, check video I’ve posted to Youtube:


 


Oh, and by the way – thanks to Goran Petrasevic who allowed me to use his photo as background in this application. Check out his photos, they are just awesome! Thanks again!

UPDATE:



   

author: Aleš Rosina | 7 Comments | Tags:
02
May
2011

Simple error reporting on Windows Phone 7

NEW YORK - OCTOBER 11:  A person holds a new  ...

If you’re developer, you’re familiar with user reports as “your app just crashed.” And before you can find out what the user was doing, it can last for a few hours or even days. This is even worse on mobile applications – if user will get two or three unexpected crushes, he will simply throw your app away and download a new one (don’t fool yourself, that your app is the only one with one super-cool functionality) . So getting error reports from your app is crucial for user satisfaction.

Now, let’s see how we can achieve this on Windows Phone 7. First of all, we must take into consideration how to get reports – we could use email, we could use some web service to post error reports or just store it locally and forgot about it. Sure, the last option is pretty much the same as if we didn’t have any reports and the second is also not very reliable (maybe user has no data coverage at a time of crash, maybe he’s running app in airplane mode or even a web service is down) so the only simple option is sending by email. So let’s take a look at that option.

I’m using this kind of approach in my apps with a button “report errors” in about page. This approach is widely used (eg. it’s used in Twitter and Facebook app), so I guess users are willing to use it. Let me just warn you here, that even if you have this error reporting implemented, you should still use try-catch blocks on risky parts of code.

In this example (you can download sample project here) we are going to use IsolatedStorage and Phone Task for sending email.

Firstly, in WP7 apps you can find App.xaml with codebihind in App.xaml.cs where we’ll do most of the work. In this file (which is generated by Visual Studio) you can find event called Application_UnhandledException, where you shoud add this code:

private void Application_UnhandledException(object sender, 
ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // An unhandled exception has occurred; break into the debugger System.Diagnostics.Debugger.Break(); } else { try { using (IsolatedStorageFile file =
IsolatedStorageFile.GetUserStoreForApplication()) { using (StreamWriter sw = new
StreamWriter(file.OpenFile("error_log",
FileMode.Append, FileAccess.Write))) { sw.WriteLine("{0}\n{1}\n{2}\n------------------\n",
DateTime.Now.ToString(),
e.ExceptionObject.Message,
e.ExceptionObject.StackTrace); } } } catch (IsolatedStorageException ex) { } } }


Now we just need to add a button for sending reports, where we will implement sending email:

private void buttonSendError_Click(object sender, RoutedEventArgs e)
{
    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
    {

        if (!file.FileExists("error_log"))
        {
            MessageBox.Show("Yeah, there are no errors!");
            return;
        }
        try
        {
            string errorLog = "";
            using (StreamReader reader = new 
StreamReader(file.OpenFile("error_log", FileMode.Open, FileAccess.Read))) { errorLog = reader.ReadToEnd(); Microsoft.Phone.Tasks.EmailComposeTask em = new EmailComposeTask(); em.To = "your.reporting@email.com"; em.Subject = "my super cool app has crashed! :("; em.Body = errorLog; em.Show(); } file.DeleteFile("error_log"); } catch (IsolatedStorageException ex) { } } }


And we’re done! This will open up user’s new email dialog. One downturn of send emails is, that you cannot test this in emulator, only on real device.

That’s it! If you have any comments, leave them bellow or just download sample project here.

Enhanced by Zemanta


   

author: Aleš Rosina | 4 Comments | Tags: , , ,
23
March
2011

Windows Phone 7 app tips: drawing my location on a map

Winodws Phone 7 MapsI’m starting a series of useful tips and some tricks about Windows Phone 7. I hope I will have time to post some tips on a regular basis :)
In the first one we will take a look at how to create a simple map app with this little diamond for current location in Maps application.

If you are in a hurry, here’s an article sample download.

Before we go deep into Visual Studio, we need to create Bing Maps account for API usage. This step is very simple, just go to this site, login (or create account if you don’t have one), fill in form and you’ll get API key.
Once we did this, open Visual Studio and create WP7 project. Drag a button and map control on page, and paste API key into CredentialsProvider property. Now let’s dig into some XAML code – map control should looks like this:

<my:Map Height="498" CredentialsProvider="your_api_key" HorizontalAlignment="Left" 
Margin="0,6,0,0" Name="map1" VerticalAlignment="Top" Width="468"> <my:MapItemsControl x:Name="mapControl" /> </my:Map>


 
After that, we need to draw diamond-shaped-pinpoint:

<phone:PhoneApplicationPage.Resources>
<
ControlTemplate x:Key="pinMyLoc" TargetType="my:Pushpin">
<
Grid Height="26" Width="26" Margin="-13,-13,0,0" RenderTransformOrigin="0.5,0.5"> <Grid.RenderTransform> <CompositeTransform Rotation="-45"/> </Grid.RenderTransform> <Rectangle Fill="Black" HorizontalAlignment="Center"
Margin="0" Stroke="White" VerticalAlignment="Center"
Height="26" Width="26"/> <Ellipse HorizontalAlignment="Center" Height="16" Margin="0"
VerticalAlignment="Center" Fill="Yellow" Width="16"/> </Grid>
  </ControlTemplate>
</
phone:PhoneApplicationPage.Resources>


Notice that we did put this into PhoneApplication.Resources, since this is easier and you can create multiple pushpins with different templates.
Now, let’s move to C# coding – first we need to start GeoCoordinateWatcher and wait for it to return current location (remember, on WP7 every long call is async call):

private void button1_Click(object sender, RoutedEventArgs e)
{
    if (loc == null)
    {
        loc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
        loc.StatusChanged += loc_StatusChanged;
    }
    if (loc.Status == GeoPositionStatus.Disabled)
    {
        loc.StatusChanged -= loc_StatusChanged;
        MessageBox.Show("Location services must be enabled on your phone.");
        return;
    }
    loc.Start();
}

We are also checking, if positioning service is enabled on user’s phone(remember, user can turn on or off this feature!). All that has left is to create event listener, where we fill mapcontrol with one item – our custom pinpoint:

void loc_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{

    if (e.Status == GeoPositionStatus.Ready)
    {
        Pushpin p = new Pushpin();
        p.Template = this.Resources["pinMyLoc"] as ControlTemplate;
        p.Location = loc.Position.Location;
        mapControl.Items.Add(p);
        map1.SetView(loc.Position.Location, 17.0);
        loc.Stop();
    }
}

So there you have it – simple location aware application with map. And to add just one little hint: you can also remove Bing logo on the map – just set LogoVisibility property to Collapsed. There you have it, very easy and simple app example, which you can download here.

   

author: Aleš Rosina | 5 Comments |
15
March
2011

Windows Phone 7 presentation at MobileMonday

NEW YORK - OCTOBER 11: A person holds a new Wi...

I just had a presentation about Windows Phone 7 on (very cool) event MobileMonday Slovenia, which is held every month in Ljubljana’s local cyber-geek-place called Cyberpipe.
In this presentation I’ve covered basics about WP7, how the user interface is structured with some basic technical details.
I’ve shown a quick demo on how to develop and design a very simple app calling some external web service.
Just to quickly recap what I’ve done in demo:
Calling external service with adding Service Reference (which is also included in zip file – download from my skydrive) and showing async calls to service. After that, we’ve also seen some design stuff – that is, how to use Expression Blend for changing basic functionalities and creating animations.

We’ve also discussed how to publish apps on Marketplace and how to monetize them.

That’s that and check also my slides, maybe you’ll find them useful:

View more presentations from Ales Rosina
 
Enhanced by Zemanta


   

author: Aleš Rosina | 1 Comment | Tags: , ,
01
March
2011

Converting DateTime object to byte array in C# (and the opposite)

Pict0079

This post will be short but sweet – how can we convert DateTime object found in .NET to a smaller amount of data, e.g. 4B?
OK, first question – why the hell would anybody wanting that? Well, in my case it’s working with some external hardware where every byte of storage counts. So why using too much space for date? I needed only date without time, so 4B is enough space. And since I was working with external hardware, I was working with raw bytes.

Anyway, here’s the code:

public static byte[] DateTo4BytesString(DateTime date)
{
    string tmpDate = date.Year.ToString("D4") + date.Month.ToString("D2") 
+ date.Day.ToString("D2"); return BitConverter.GetBytes(Convert.ToUInt32(tmpDate)); } public static DateTime BytesStringToDate(byte[] byteDate) { if(byteDate.Length != 4) return new DateTime(); string tmpDate = BitConverter.ToUInt32(byteDate, 0).ToString(); return new DateTime(Convert.ToInt32(tmpDate.Substring(0,4)),
Convert.ToInt32(tmpDate.Substring(4,2)),
Convert.ToInt32(tmpDate.Substring(6,2))); }


There is only one remark  - this works only for dates in period between 1.1.1000 and 31.12.9999. If it’s lower, we would get 3B of data and if it’s higher than 9999 we would get 5B of data, which would fail in second function. I’m pretty sure, that in 7989 years nobody will be using this application (if humans will be still here anyway :) ) for identification and date storing. And since I’m not aware of no person ever getting to the age of 1010 years, lower boundary is also OK.

So there you have it, date in 4B in C#. How cool is that, huh? :)
Enhanced by Zemanta


   

author: Aleš Rosina | 3 Comments |
15
November
2010

Using SalesForce.com in your C# application

Image representing Salesforce as depicted in C...

We are working on some cool app, that is handling tasks and meetings a little bit different and more contextual. You can check that on mativy.com and try it out.
Anyway, basic idea is also, that all tasks in organization (or team) is handled on one place, so we needed importing from different services. Today I’ll show you how to get all tasks from SalesForce.com account.
If you are not aware, SalesForce.com is one of the leading online CRM solutions used by many big companies (Starbucks, Qualcomm, Siemens, etc.), so if you are developing software like ours, you need to take into account those “big guys”. Anyway, SalesForce.com is offering huge development platform, called Force.com (flashback: Luke, use The Force) which offers API access to all of the features of SalesForce.com.
First thing, you need to create a developer account on developer.force.com, which brings you to fully functional interface, but meant only for testing purposes. You need to obtain security token via: Setup > Personal Information > Security token and save it somewhere, you’ll need it later.
Second thing, go to App Setup > Develop > API and download Enterprise WSDL (right click on Generate Enterprise WSDL).
Third thing, generate some test data (in this example, we need some tasks).
Now open Visual Studio, create one project (I did a simple Console App, just for demo) and put downloaded WSDL file into solution folder.
After opening solution, add a web reference (right click on References > Add Service Reference > Advanced > Add Web Reference) to this WSDL file (enter physical path to file). You’ll get some parsing error, saying that this is not valid WSDL file, but just ignore that and click Add Reference.
That’s it with clicking part, now let’s digg into code:

SforceService binding = new SforceService();
binding.Timeout = 60000;
string un = "your@email.com", pw = "YourPassword", token = "security_token";
LoginResult loginResult = binding.login(un, pw + token);
binding.Url = loginResult.serverUrl;
binding.SessionHeaderValue = new SessionHeader();
binding.SessionHeaderValue.sessionId = loginResult.sessionId;
GetUserInfoResult userInfo = loginResult.userInfo;

This is used for logging into SalesForce API with your developer account and getting some basic info about your account. When we’re logged in, we can start getting all the data we need. In this example, we’ll just get all the tasks and select only few properties (as you can see in example below, we took AccountId, Description and Subject )of Task object. All available properties and functions of Task object can be found in API documentation.
For querying data you need to use SOQL (SalesForce Object Query Language), which is actually stripped down version of normal SQL.
QueryResult qr = null;
binding.QueryOptionsValue = new QueryOptions();
binding.QueryOptionsValue.batchSize = 3;
binding.QueryOptionsValue.batchSizeSpecified = true;
qr = binding.query("select AccountId, Description, Subject from Task");
for (int i = 0; i < qr.size; i++)
{
    Console.WriteLine((qr.records[i] as Task).Subject);
}


That’s it! Very simple and straight forward solution, so if you need to access any data from salesforce.com, that’s the way you can do it in C#.

You can download the whole demo project here on my skydrive.
Enhanced by Zemanta


   

author: Aleš Rosina | 2 Comments | Tags: , , ,
15
October
2010