Friday, November 19, 2010

Silverlight compressed binary serialization

So... I did my first Silverlight app - very good fun (although there was a fair amount of head scratching too!)

As part of this app I needed to send some fairly chunky bits of data to the client. To do this I used http://whydoidoit.com/silverlight-serializer/ and http://slsharpziplib.codeplex.com/

On the server (in an offline process) the code that generated my compressed files looked like:

            using (var f = File.Create(zipFileName))
            {
                using (var zipOut = new ZipOutputStream(f))
                {
                    ZipEntry entry = new ZipEntry("stuff");
                    var toStore = Serialization.SilverlightSerializer.Serialize(myClass);
                    entry.DateTime = DateTime.Now;
                    entry.Size = toStore.Length;
                    zipOut.PutNextEntry(entry);
                    zipOut.Write(toStore, 0, toStore.Length);
                    zipOut.Finish();
                    zipOut.Close();
                }
            }

And in the Silverlight client the code looked like:

        public void LoadFrom(Uri url)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.BeginGetResponse(new AsyncCallback(ReadCallback), request);
        }

        private void ReadCallback(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
            using (ZipInputStream zipIn = new ZipInputStream(response.GetResponseStream()))
            {
                ZipEntry entry;
                if ((entry = zipIn.GetNextEntry()) != null)
                {
                    var myClass = Serialization.SilverlightSerializer.Deserialize<TheClass>(zipIn);
                    if (myClass == null)
                    {
                        MessageBox.Show("Some error has occurred - unable to read data - sorry!");
                        return;
                    }

                    Dispatcher.BeginInvoke(() =>
                        {
                           // do stuff with myClass here
                        });
                }
            }
        }

It all worked surprisingly well :)

Thursday, November 18, 2010

More problems with SQL Azure backup


you can backup SQL Azure using
CREATE DATABASE [newName] *BUG HERE* COPY OF [oldName]

However, recently I've just hit lots of problems with doing this on "The CREATE DATABASE statement must be the only statement in the batch."

Sadly I don't seem to be able to get past this... I think it's something to do with names? Certainly it's an odd (and probably misleading) message... Anyways... I'll use the other backup method instead...

NEWSFLASH!!!!
The problem was my typo...

The statement is not:
CREATE DATABASE [newName] COPY OF [oldName]

Instead it is:
CREATE DATABASE [newName] AS COPY OF [oldName]

Doh! (although top marks to SQL Azure for the error message)

Tuesday, November 16, 2010

A look at some Silverlight control libraries

As I start serious Silverlight development for the first time, I've been looking at and evaluating some of the control libraries out there.

Why? Well, because they contain huge amounts of slick, useful, QA'd functionality which will accelerate my development - so they represent superb *value* for money.

Here are some of my notes so far:
  • Telerik - have a huge set of controls including rich text editing, super framework libraries (like containers and transitions), and lots and lots of charting. I've attended a couple of their webinars and clearly they've got good functionality now, plus lots more coming every quarter.
  • Infragistics - a fairly large set of functionality again including grids, menus and a docking framework
  • Dundas - seems to be mainly focussed on Business Intelligence (BI) dashboards - so lots of charts.
  • Actipro - a much smaller set of functionality focussed around an MsDev like code editor.
So far... I'm tempted to buy Telerik with the intention of using:
- the charting - especially the lovely sparklines :)
- the grid - everyone needs one eventually!
- the overall framework stuff - especially as they use MVVM everywhere.

I will install the trial version soon and then come back with more feedback.

Tuesday, November 02, 2010

Serialising Enums with Newtonsoft JSON.Net

For a while... I was using this serializer:

public class JsonEnumConverter<T> : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(T);
}

public override void WriteJson(JsonWriter writer, object
value, JsonSerializer serializer)
{
writer.WriteValue(((T)value).ToString());
}

public override object ReadJson(JsonReader reader, Type
objectType, object existingValue, JsonSerializer serializer)
{
return Enum.Parse(typeof(T), reader.Value.ToString());
}
}

This allowed me to serialize/deserialize using attributes like:

[JsonObject]
public class MyClass
{
[JsonConverter(typeof(SerializationUtils.JsonEnumConverter<DateTimeTestFormat>))]
public DateTimeTestFormat DateTimeTestFormat { get; set; }
}

However, eventually I worked out that I could just use a more general
solution - and that I could pass that in to the top-level JsonConvert
methods:

public class GeneralJsonEnumConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType.IsEnum;
}

public override void WriteJson(JsonWriter writer, object
value, JsonSerializer serializer)
{
writer.WriteValue(value.ToString());
}

public override object ReadJson(JsonReader reader, Type
objectType, object existingValue, JsonSerializer serializer)
{
return Enum.Parse(objectType, reader.Value.ToString());
}
}

Much easier... :)

Monday, November 01, 2010

Some practical experience of GPS battery life for Sports Tracking apps

On Navmi/RunSat, I got asked:

>> What's the impact on the battery when doing frequent GPS resolutions?

The answer is battery life varies dependent on phone...

On an iPhone you have to really mess about to improve battery life -
the only way of doing it on older phones is to start playing out audio
(e.g. a playlist) - then you can turn the screen off but still keep
your app alive and capturing GPS.

On my WM6.5 Omnia II, it's easy to keep the app/GPS alive but to save
some power. If I do that and still monitor the GPS, then up to 6 hours
battery life is OK - so pretty good.

On a Bada Wave, there's a SYSTEM_SERVICE level call to make so that
the app can carries on even when the screen is off - locked I can
manage 3-4 hours easy - not tried any longer yet - but suspect 6 is
about the current limit.

On my Nokia 5800, it seems that the Nokia ST app managed 2-3 hours OK
- not tried it any longer.

On Android, it's too early for me to say - but I know that the Google
MyTracks app can manage long sessions - 6 hours+ - although they do
have some sample-rate dropping code to do that - basically it depends
what your activity is:
- if you're walking, then you can probably get away with sampling only
every few minutes
- but if you ever want to do turn-by-turn directions in a car, then
you'll need to up the sampling rate to something much more frequent.

Friday, October 29, 2010

PDC 2010 Updates - First Look

The main updates from the PDC weren't that exciting... I haven't seen anything on Azure storage yet - hopefully soon...

The coolest thing I saw was Anders talking about c#5 - async and await - think linq for async tasks - see http://blogs.msdn.com/b/ericlippert/archive/2010/10/28/asynchrony-in-c-5-part-one.aspx and download CTP from http://msdn.microsoft.com/en-gb/vstudio/async.aspx - I liked :) Full video available on the pdcplayer... probably too much effort to find it!

The main things that might impact some of the projects that I'm working on were:
- a much better Azure management portal is on the way - at last!
- full IIS7 hosting - so you can set custom properties and so your web role can host multiple web projects :)
- Remote Desktop access to your web and worker role instances (not sure it's that useful to my projects but it made me feel happier)
- Velocity (Memcached) will be available soon
- Java will become a "first class citizen" ?!
- Extra small instances - I suspect that most of my worker roles could move to these

Azure overview is here:
SQL Azure updates are here:

Will keep an eye on some of the sessions tonight - especially Jai's deep dive into storage.

Stuart

Wednesday, October 27, 2010

How to do "TOP N" in nhibernate's query language

How to do "TOP N" in nhibernate's query language...

Seems like you can't - so instead you have to use:
- SetMaxResults(N)
on the IQuery object.

With help from:
http://stackoverflow.com/questions/555045/nhibernate-hqls-equivalent-to-t-sqls-top-keyword

Tuesday, October 26, 2010

The 5 second guide to adding WCF Client code

In case you ever have to blag some WCF client code ever...

1. Right click on your project
2. Choose "Add Service Reference"
3. In the dialog, enter the service URL wait for the "discovery" to happen, then change the namespace name and hit OK
4. In the client code just call the service - like
                var client = new MyNameSpace.MyServiceClient();
                int result = client.Method(param1, param2, param3);

Simples ;)

Tuesday, October 19, 2010

Converting datetimes to just the date (and to pretty text) in SQLServer

From http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype

DATEADD(dd, 0, DATEDIFF(dd, 0, [Datetime])) AS TheDate,

Also, this helps for text formatting

CONVERT(nvarchar, TheDate, NNN)
101 - 10/19/2010
102 - 2010.10.19
103 - 19/10/2010
104 - 19.10.2010
105 - 19-10-2010
106 - 19 Oct 2010
107 - Oct 19, 2010
108 - 00:00:00
109 - Oct 19 2010 12:00:00:000AM
110 - 10-19-2010
111 - 2010/10/19
112 - 20101019
113 - 19 Oct 2010 00:00:00:000

Monday, October 18, 2010

Parsing DateTime's into UTC

This article proved helpful - http://www.mindthe.net/devices/2008/05/23/tryparseexact-and-utc-datetime/

But actually I think the answer is to use BOTH AssumeUniversal AND AdjustToUniversal
            DateTime.TryParseExact(group.Value, this.customParseText, CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal, out dateTime);

Friday, October 15, 2010

Datetime comparison for Azure Table Storage REST API


string.Format("{0} le datetime'{1}'", PropertyName, XmlConvert.ToString(cutoffDate, XmlDateTimeSerializationMode.RoundtripKind))

although obviously this will then need to be UrlEncoded

Wednesday, October 13, 2010

Get a RelativePath string

        public string GetRelativePath(string rootPath, string fullPath)
        {
            Uri uri1 = new Uri(rootPath);
            Uri uri2 = new Uri(fullPath);

            Uri relativeUri = uri1.MakeRelativeUri(uri2);

            return relativeUri.ToString();
        }

Test if a path is a Directory?

        public bool IsDirectory(string path)
        {
            try
            {
                FileAttributes attr = System.IO.File.GetAttributes(path);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    return true;
                }
                return false;
            }
            catch (FileNotFoundException)
            {
                return false;
            }
            catch (DirectoryNotFoundException)
            {
                return false;
            }
        }

Monday, October 11, 2010

If you see Error 32 Internal Compiler Error: stage 'COMPILE' ....

If you see Error 32 Internal Compiler Error: stage 'COMPILE' ....

then what caused it for me...

was accessing a {get; private set;} variable

Removing that allowed the compile to proceed again

If you're looking for quick and effective free training on M$oft tools

This resource looks excellent:
http://channel9.msdn.com/Learn/Courses/

Then you can also play with code from:

There's so much resource out there!

Sunday, October 10, 2010

If you are using AutoFac and you see... "are you missing a using directive or an assembly reference" when using AutoFac

e.g if you see:

'Autofac.ContainerBuilder' does not contain a definition for 'RegisterAssemblyTypes' and no extension method 'RegisterAssemblyTypes' accepting a first argument of type 'Autofac.ContainerBuilder' could be found (are you missing a using directive or an assembly reference?)

or 
'Autofac.ContainerBuilder' does not contain a definition for 'RegisterInterface' and no extension method 'RegisterInterface' accepting a first argument of type 'Autofac.ContainerBuilder' could be found (are you missing a using directive or an assembly reference?)

or....

then check that you are using "using Autofac" at the top of the file

if you don't include this then you won't get the necessary extension methods inside your file's visible namespaces.

Friday, October 01, 2010

Back to basics - simple Azure table test results part 2

Another test - what happens if you try concurrent updates.... breaking the optimistic concurrency locking

        static TableServiceContext GetContext()
        {
            CloudTableClient client = new CloudTableClient(
                "https://***.table.core.windows.net",
                new StorageCredentialsAccountAndKey("***", "****"));

            //client.CreateTableIfNotExist("TestData");
            var context1 = client.GetDataServiceContext();

            return context1;
        }

        static Thing GetFredFromContext(TableServiceContext context)
        {
            var query = context.CreateQuery<Thing>("TestData");
            var subquery = from t in query
                           where t.PartitionKey == "Fred"
                           && t.RowKey == "Bloggs"
                           select t;

            var element = subquery.First();
            return element;
        }

        static void Main(string[] args)
        {
            var context1 = GetContext();
            var context2 = GetContext();

            var one = GetFredFromContext(context1);
            var two = GetFredFromContext(context2);

            one.TestField = "test2";
            two.TestField = "test3";

            context1.UpdateObject(one);
            context2.UpdateObject(two);

            context1.SaveChanges();

            try
            {
                context2.SaveChanges();
            }
            catch (Exception e)
            {
// exception is caught here - 
            }
        }


The exception is System.Data.Services.Client.DataServiceRequestException
The InnerException is [System.Data.Services.Client.DataServiceClientException] with StatusCode of 412 - from http://msdn.microsoft.com/en-us/library/dd179438.aspx

UpdateConditionNotSatisfied

Precondition Failed (412)

Back to basics - simple Azure table test results

What happens if you try to create an object twice:

            CloudTableClient client = new CloudTableClient(
                "https://thing.table.core.windows.net",
                new StorageCredentialsAccountAndKey("thing", "****blurb******"));

            client.CreateTableIfNotExist("TestData");
            var context1 = client.GetDataServiceContext();

            Thing t = new Thing();
            t.PartitionKey = "Fred";
            t.RowKey = "Bloggs";
            t.TestField = "test";

            context1.AddObject("TestData", t);
            var response = context1.SaveChanges();

            context1.Detach(t);

            context1.AddObject("TestData", t);
            response = context1.SaveChanges();

the answer... is that you get an exception thrown in the second "SaveChanges()" - the exception is System.Data.Services.Client.DataServiceRequestException - with an InnerException of type DataServiceClientException -with StatusCode 409 - EntityAlreadyExists 

Thursday, September 30, 2010

Azure Storage Performance

From a presentation by Brad Calder - Microsoft PDC 2009 


Per Object/Partition Performance at Commercial Availability

Throughput

Single Queue and Single Table Partition

Up to 500 transactions per second 


Single Blob

Small reads/writes up to 30 MB/s

Large reads/writes up to 60 MB/s


Latency

Typically around 100ms (for small trans)

But can increase to a few seconds during heavy spikes while load balancing kicks in

Tuesday, September 21, 2010

A really good explanation of SQL Server and indexes

It didn't answer my current question, but it was good to read this again:
http://www.sqlteam.com/article/sql-server-indexes-the-basics

For reference: my current question was how to optimise a query which does a > comparison on two columns.... I can see how to do it using a computed column with an index, but that's not available to me at present - as I'm using Fluent nhibernate...

This question helped a bit "What happens when a function is used in the WHERE clause? In that case, the index will not be used because the function will have to be applied to every row in the table."

Sunday, September 19, 2010

When your SQL log (ldf) file gets Huge...

If you're having problems with large SQL log files, then this was the most useful advice I found.

For my purposes I was a "no" - my data wasn't money sensitive... so I switched to "simple" and could then shrink my database using the Tasks right-click menu in SSMS


Do you make transaction backups?
Yes -> Do not shrink the log unless you have done some exceptional operation (such as a massive delete) as the "cost" of SQL Server re-growing the Log file is significant, and will lead to fragmentation and thus worse performance.
No and I don't want to -> Change the Recovery Model to "Simple" - Enterprise Manager : Right click database : Properties @ [Options]
Don't know -> Transaction log backups allow you to recover to a "point in time" - you restore the last Full Backup (and possibly a subsequently Differential backup) and then every log backup, in sequence, until the "point in time" that you want to roll-forward to.


Saturday, September 18, 2010

Timing tests on Azure

In order to test the performance of your app on Azure, you really need to test on Azure.

This is especially the case when your app needs to talk to local SQL Azure, Table, Blob, and Queue resources - you can't test the performance of these:
- when you are running the storage on the DevFabric
- when you are running on the real storage, but with your app on a dev machine outside of the data center

When you are running on Azure, then how do you get your results out.

Well, to start with I've just used some simple tests using System.Diagnostics.StopWatch:

At the start of the method to be tested
            List<KeyValuePair<string, long>> times = new List<KeyValuePair<string, long>>();
            times.Add(new KeyValuePair<string, long>("Original", 0L));
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();

Half way through:
            times.Add(new KeyValuePair<string,long>("namedPoint", timer.ElapsedMilliseconds));

And at the end:
            times.Add(new KeyValuePair<string, long>("timeToEnd", timer.ElapsedMilliseconds));
            timer.Stop();

            foreach (var t in times)
            {
                System.Diagnostics.Trace.TraceError(string.Format("{0}:{1}", t.Value, t.Key));
            }

This then uploads the results to Azure Diagnostics - currently Trace is routed to Table storage.

Obviously this is only a temporary solution - only suited for simple methods, and you have to remove this code for Production.

Friday, September 17, 2010

Azure Storage Tools

A useful list from http://blogs.msdn.com/b/windowsazurestorage/archive/2010/04/17/windows-azure-storage-explorers.aspx

Personally I quite like https://www.myazurestorage.com/ although I've also used http://www.cerebrata.com recently

Windows Azure Storage 
Explorer

Block Blob

Page Blob

Tables

Queues

Free

Azure Blob Client

X

Y

Azure Blob Compressor 
Enables compressing blobs for upload and download

X

Y

Azure Blob Explorer

X

Y

Azure Storage Explorer

X

X

X

Y

Azure Storage Simple Viewer

X

 

X

X

Y

Cerebrata Cloud Storage Studio

X

X

X

X

Y/N

Cloud Berry Explorer

X

X

Y

Clumsy Leaf Azure Explorer 
Visual studio plug-in

X

X

X

X

Y

Factonomy Azure Utility

X

Y

Gladinet Cloud Desktop

X

N

MyAzureStorage.com 
A portal to access blobs, tables and queues

X

X

X

X

Y

Space Block

X

Y

Windows Azure Management Tool

X

X

X

X

Y


Azure Links

Credit to Neil Mackenzie for this list - fromhttp://nmackenzie.spaces.live.com/blog/cns!B863FF075995D18A!706.entry

Azure Team

http://blogs.msdn.com/b/azuredevsupport/ – Azure Support Team

http://blogs.msdn.com/b/dallas/ – Microsoft Codename Dallas

http://blogs.msdn.com/b/sqlazure/ – SQL Azure Team

http://blogs.msdn.com/b/cloud/ - Windows Azure Developer Tools Team

http://blogs.msdn.com/b/windowsazurestorage/ – Windows Azure Storage Team

http://blogs.msdn.com/b/windowsazure/ – Windows Azure Team

Individual

http://blogs.msdn.com/b/partlycloudy/ – Adam Sampson

http://bstineman.spaces.live.com/blog/ – Brent Stineman (@BrentCodeMonkey)

http://blog.structuretoobig.com/ – Brian Hitney

http://channel9.msdn.com/shows/Cloud+Cover/ – Cloud Cover (@cloudcovershow)

http://www.davidaiken.com/ – David Aiken (@TheDavidAiken)

http://davidchappellopinari.blogspot.com/ – David Chappell

http://geekswithblogs.net/iupdateable/Default.aspx – Eric Nelson (@ericnel)

http://gshahine.com/blog/ – Guy Shahine

http://blogs.msdn.com/b/jmeier/ – J.D. Meier

http://blogs.msdn.com/b/jnak/ – Jim Nakashima (@jnakashima)

http://blog.maartenballiauw.be/ - Maarten Balliauw

http://nmackenzie.spaces.live.com/blog/ Neil Mackenzie (@mknz)

http://azuresecurity.codeplex.com/ - Patterns & Practices: Windows Azure Security Guidance

http://oakleafblog.blogspot.com/ – Roger Jennings (@rogerjenn)

http://dunnry.com/blog/ – Ryan Dunn (@dunnry)

http://scottdensmore.typepad.com/blog/ – Scott Densmore (@scottdensmore)

http://blog.smarx.com/ - Steve Marx (@smarx)

http://blogs.msdn.com/b/sumitm/ - Sumit Mehrotra

http://azure.snagy.name/blog/ – Steven Nagy (@snagy)

http://blog.toddysm.com/ - Toddy Mladenov (@toddysm)

Azure Status

http://www.microsoft.com/windowsazure/support/status/servicedashboard.aspx – Azure Status

Other Clouds

http://highscalability.com/ – High Scalability

http://perspectives.mvdirona.com/ – James Hamilton

http://www.allthingsdistributed.com/ – Werner Vogels

SQL Azure Management - Backup and Monitoring

SQL Azure Backup and Restore
SQL Azure does not support the normal SQL Server BACKUP commands.

It does provide inherent data redundancy and reliability. However, this will not help if:
  • There is an app bug which corrupts your data.
  • There's a hacker who destroys your data
  • The Microsoft's datacenter loses all of your data (unlikely but possible)
To cope with these scenarios, there are two mechanisms currently available to backup your data:
  • You can use the SQL Azure copy commands to copy your database contents to a second, still stored within SQL Azure - this will protect again only the first problem above (assuming the hacker has a way into your Azure store)
  • You can use the open source SQL Azure Migration Wizard to download data to a local copy - this will provide a recovery mechanism for all 3 items above
The use of this second tool is discussed further below:

SQL Azure Data Migration

Warning - using this for a backup process will involve a large amount of data transfer (which will cost money), but it's better than not having a backup at all.

Backup

To use this tool:
  1. download it from http://sqlazuremw.codeplex.com/
  2. choose "Analyze and migrate T-SQL database"
  3. choose the Azure database - yourserver.database.windows.net - username - username@yourserver - and password.
  4. Note that you can only connect to the SQL azure database from IP addresses whitelisted on the firewall settings on the SQL Azure web control panel
  5. choose "[databaseName]"
  6. choose "script all database objects"
  7. hit "next" and it will slowly happen
  8. choose your local SQL server to connect to
  9. create a new SQL server database
  10. hit "next" to insert the data into your local database
For restore, you need to go in the opposite direction

Restore

To do this:
  1. typically suspend the Azure web application
  2. use the Azure web user interface to drop the existing SQL Azure database
  3. run the steps above in reverse - from local to SQL Azure
  4. restart the Azure web application.
Notes:
    1. connect to SQL Azure using SQL Server Management Studio
    2. open a "New Query"
    3. type "CREATE DATABASE backupName AS COPY OF mainName"
    4. Hit Execute

      The state of the copy can then be monitored using "select name, state, state_desc from sys.databases where name = 'backupName"
Note that costs of running multiple databases on Azure suggest that you should not keep taking more and more backups and storing them all within SQL Azure.

SQL Azure Monitoring
There really isn't much that can currently be done in the way of monitoring the health of an Azure SQL Server.

This http://msdn.microsoft.com/en-us/library/ff394114.aspx document describes the ability to query:
  • Database size
  • Number of connections - and their activity
  • Some simple query performance
However, this doesn't really provide any clue as to monitoring the database "health" - e.g. uptime/status, loading, etc.

There is some access to overall status at http://www.microsoft.com/windowsazure/support/status/servicedashboard.aspx - but this is at a very coarse level.

The only current suggestions for checking a SQL server instance is alive are:
  • just rely on Microsoft uptime (under their SLA) - not ideal
  • use tools like Nagios to add "HTTP" monitoring to Azure applications connected to the SQL Server database - use this web monitoring to check the health of the server (at least to check it is alive).
  • try to build something (e.g. a web app) based around sys.dm_exec_connections (http://msdn.microsoft.com/en-us/library/ff394114.aspx) which would provide some analysis of loading.
  • try to extend the enzo SQL library - http://enzosqlbaseline.codeplex.com/ - it's benchmarking tools might give you some clue on current loading (but this monitoring might also impact your current performance).

Thursday, September 16, 2010

If you can't run the Visual Studio wizard for SharpArchitecture

If you see a series of messages like "A problem was encountered
creating the sub project 'sharp.Core'. A project with that name is
already opened in the solution."

Then it could be due to problems with AnkhSVN - see
http://www.softweb.net.au/blogs/development/sharp-architecture-new-project-wizard-is-incompatible-with-ankhsvn

So I had to uninstall source control to get it working....

Tuesday, September 14, 2010

Azure - stuck in Initialising-Busy-Stopping...repeat

This link seems a good reference!
 
http://blog.toddysm.com/2010/01/windows-azure-deployment-stuck-in-initializing-busy-stopping-why.html

Some points:
  • missing dependencies
  • problems with initialising WAD (Azure Diagnostics connection string)
  • problems with other connection strings
  • lack of permission (medium trust!)

If you hit a problem with ConfigMonitoringPoll - Polling for configuration changes - when using Azure Diagnostics

Reported as:
Polling for configuration changes:Microsoft.WindowsAzure.StorageClient.StorageClientException: The specified blob does not exist. ---> System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender) --- End of inner exception stack trace --- at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait() at Microsoft.WindowsAzure.StorageClient.CloudBlob.DownloadToStream(Stream target, BlobRequestOptions options) at Microsoft.WindowsAzure.Diagnostics.ControlChannel.<>c__DisplayClass10.<ConfigMonitoringPoll>b__f() at Microsoft.WindowsAzure.Diagnostics.ControlChannel.TryExpectError(HttpStatusCode status, Action act) at Microsoft.WindowsAzure.Diagnostics.ControlChannel.ConfigMonitoringPoll(Object sender, ElapsedEventArgs args); TraceSource 'WaWebHost.exe' event

Then the problem might be that you must initialise the Azure Diagnostics from the start of the WebRole - and not from the start of app in Global.asax - just add this new file to your webrole project:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using Microsoft.WindowsAzure.ServiceRuntime;

namespace MyProject.Web

{

public class WebRole : RoleEntryPoint

{

public override bool OnStart()

{

AzureDiagnostics.InitializeAzureDiagnostics();

return base.OnStart();

}

}

}

Adding Diagnostic monitoring to Azure

If you want to get some diagnostics from Windows Azure deployed applications then follow the instructions on: http://msdn.microsoft.com/en-us/library/ee843890

This gives you a solution like:

    public static class AzureDiagnostics

    {

        public static void InitializeAzureDiagnostics()

        {

            // do not run this code if we're not running in the cloud.

            if (!Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable)

                return;

 

            // Enabled the capture of partial crash dumps

            Microsoft.WindowsAzure.Diagnostics.CrashDumps.EnableCollection(false);

 

            // configure and start the diagnostics

            DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();

 

            AddPerformanceCounters(dmc);

            AddLogs(dmc);

            AddSystemEventLog(dmc);

            AddInfrastructureLogs(dmc);

 

            DiagnosticMonitor.Start("DiagnosticsConnectionString", dmc);

        }

 

        private static void AddInfrastructureLogs(DiagnosticMonitorConfiguration dmc)

        {

            dmc.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

            dmc.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(10.0);

        }

 

        private static void AddSystemEventLog(DiagnosticMonitorConfiguration dmc)

        {

            // Add event collection from the Windows Event Log

            dmc.WindowsEventLog.DataSources.Add("System!*");

            dmc.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

            dmc.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);

        }

 

        private static void AddLogs(DiagnosticMonitorConfiguration dmc)

        {

            dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);

            dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;           

        }

 

        private static void AddPerformanceCounters(DiagnosticMonitorConfiguration dmc)

        {

            List<string> counters = new List<string>();

            counters.Add(@"\Processor(_Total)\% Processor Time");

            counters.Add(@"\Memory\Available Mbytes");

            counters.Add(@"\TCPv4\Connections Established");

            counters.Add(@"\ASP.NET Applications(__Total__)\Requests/Sec");

            // These network interfaces removed - not that interesting for now

            //counters.Add(@"\Network Interface(*)\Bytes Received/sec");

            //counters.Add(@"\Network Interface(*)\Bytes Sent/sec");

            foreach (string counter in counters)

            {

                PerformanceCounterConfiguration counterConfig = new PerformanceCounterConfiguration();

                counterConfig.CounterSpecifier = counter;

                counterConfig.SampleRate = TimeSpan.FromSeconds(10);

                dmc.PerformanceCounters.DataSources.Add(counterConfig);

            }

            dmc.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(5.0);

        }

    }

 

 

Monday, September 13, 2010

Re: "The "COM0" port did not open." Bada device development

If you're trying to debug a Bada device and you see "The "COM0" port
did not open." under the entry for the Broker.exe in the Bada IDE
Console, then:

1. If it's the first time you've ever tried to connect then check that
you've installed the necessary USB drivers and have the device
attached.
2. If you've previously been using this fine, but this has suddenly
stopped working then try:
--- rebooting your phone
--- killing broker.exe in the PC task manager
--- setting your phone's USB connect to Samsung Kies or to Mass
Storage, and then using Run As rather than Debug As in the IDE
--- hit the task manager on the phone and choose "End All Applications"

I'm not entirely sure what worked for me... but I think it was a
combination of the last few in the end!

Saturday, August 21, 2010

Setting up a Samsung Wave (Bada) for debugging

Full instructions here - http://www.careace.net/2010/08/07/run_your_wave_app_on_actualdevice/

So far seems to work very well (although it does seem to help if you disconnect and reconnect the Wave between each debug session!)

Wednesday, August 18, 2010

View Stored Procedure Source Code

If you want to see the raw SQL behind your stored proc (like you can
in SQL Server Management Studio) then use:

EXEC sp_HelpText 'your procedure name'

Found in http://stackoverflow.com/questions/467482/how-do-i-programmatically-retrieve-sql-server-stored-procedure-source-that-is-ide

Sunday, July 11, 2010

A problem with "The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF"

Something changed on one of the web services I was using - suddenly one of my requests was failing with a WebException - 

The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF


To fix this I had to add this to my web.config/app.config:

<system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
</system.net>

Simples ;)

Friday, May 21, 2010

Low Pass Javascript

As part of the runsat work, I've had a continual battle to get elevation results "realistic"

This is particularly challenging because of "noise" in the sampled elevation data.

The latest attempt at this, has been to use a low pass filter - based on work at http://mshook.appspot.com/z/firkernel.htm - to smooth the elevation data.

You can see the effect: