Steve Clements

.Net and then some....


News

Loading



MCP

Add to Technorati Favorites



Subscribe to this Blog by Email


this is Steve's profile
Locations of visitors to this page

My Stats

  • Posts - 133
  • Comments - 312
  • Trackbacks - 38

Twitter












Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


Image Galleries


Fav Blogs


Fav Places


Services!


Top Kudos



Hey, I need some advice/help, now I’ve been writing on this blog for a few years, I don’t blog a great deal in comparison to many of my peers and my blog doesn’t get a massive number of hits, BUT I seem to get a fair share of comment spammers!!

I have image verification on the comments and I have put an Akismet API key into the Geekswithblogs settings, but I still get a bunch of spam comments.

They could almost be real, until you see the link going off to some dating site or casino crap.

What does everyone do?? Delete them every time?? Moderate comments??

I would rather not moderate comments if possible, but is that the only way to stop the crap??

Thx

Technorati Tags: ,,


As Visual Studio 2010 IDE has been mostly written in WPF, extending the start page has become pretty darn easy and I for one find this quite interesting as I always open with the start page and the more customisation I can have the better!

There are a few things you will need to install first to get going

  • Visual Studio 2010 SDK
  • Start page project template, which you can either get from the New Project dialog, in the online gallery section in VS or download from here

 

I was going to write a blog post on how to create a custom start page, but decided that msdn have done such a good job I was pretty much wasting my time, so take a look here, it has in detail everything you need to know to get it done! :)



If for some reason you need to specify a specific connection string for a DataContext, you can of course pass the connection string when you initialise you DataContext object.  A common scenario could be a dev/test/stage/live connection string, but in my case its for either a live or archive database.

 

I however want the connection string to be handled by the DataContext, there are probably lots of different reasons someone would want to do this…but here are mine.

  • I want the same connection string for all instances of DataContext, but I don’t know what it is yet!
  • I prefer the clean code and ease of not using a constructor parameter.
  • The refactoring of using a constructor parameter could be a nightmare.

 

So my approach is to create a new partial class for the DataContext and handle empty constructor in there.

First from within the LINQ to SQL designer I changed the connection property to None.  This will remove the empty constructor code from the auto generated designer.cs file.

image

Right click on the .dbml file, click View Code and a file and class is created for you!

image

You’ll see the new class created in solutions explorer and the file will open.

We are going to be playing with constructors so you need to add the inheritance from System.Data.Linq.DataContext

  1. public partial class DataClasses1DataContext : System.Data.Linq.DataContext
  2.    {
  3.    }

 

Add the empty constructor and I have added a property that will get my connection string, you will have whatever logic you need to decide and get the connection string you require.  In my case I will be hitting a database, but I have omitted that code.

  1. public partial class DataClasses1DataContext : System.Data.Linq.DataContext
  2. {
  3.    // Connection String Keys - stored in web.config
  4.    static string LiveConnectionStringKey = "LiveConnectionString";
  5.    static string ArchiveConnectionStringKey = "ArchiveConnectionString";
  6.  
  7.    protected static string ConnectionString
  8.    {
  9.       get
  10.       {
  11.          if (DoIWantToUseTheLiveConnection) {
  12.             return global::System.Configuration.ConfigurationManager.ConnectionStrings[LiveConnectionStringKey].ConnectionString;
  13.          }
  14.          else {
  15.             return global::System.Configuration.ConfigurationManager.ConnectionStrings[ArchiveConnectionStringKey].ConnectionString;
  16.          }
  17.       }
  18.    }
  19.  
  20.    public DataClasses1DataContext() :
  21.       base(ConnectionString, mappingSource)
  22.    {
  23.       OnCreated();
  24.    }
  25. }

 

Now when I new up my DataContext, I can just leave the constructor empty and my partial class will decide which one i need to use.

Nice, clean code that can be easily refractored and tested.

 

Share this post :


OK, so its Sport Relief time and I going to run…it’s no marathon, but if you know me, you would know that’s out of the question…so I’m doing this!!!

Sponsor me…just a few quid is all i ask!!!

http://www.mysportrelief.com/stevecl



I am both a Google docs and Windows SkyDrive user, one thing however that I am always thought would help, especially with SkyDrive, as its essentially a backup tool for me is being able to access through Windows explorer (or FTP would suffice!).

Well I have found a little app that does just that!!

It’s from Gladinet and the catch line is “Delivering cloud services to your desktop and operating system”, it does connect to other things like Azure blob store and Amazon.

You can download a free version and the only restriction seems to be a limit of 1000 files per job.

I would recommend you give it a go, its not the quickest thing in the world to navigate around, but for me the main purpose is for backup.  It does have a built in backup tool, which I am yet to explore, as I’m a SyncBack user I’m going to setup a SyncBack job and see how it gets on!

You can just use explorer and drag and drop files in, it uploads in the background in groups of 5 files.  That’s ok for the odd file I guess, but automation is the way forward for me!

image

Another job sorted!

Technorati Tags: ,,,,,,A,,,

Share this post :


I am talking in the context of services such as Google Docs. I don’t have a huge amount of documents, but I simply don’t have the perfect solution for having these docs available anywhere and everywhere I am. I like many users I expect work on/want access to docs in different locations and on different machines.
Google docs seems like a perfect solution, but when you don’t have an Internet connection, like when you are on a plane for example, its not a good solution at all.

Then there are services like Live Mesh, DropBox that both sync files on your local machine, into the cloud and sync to any other machine where you have the software installed. Well sometimes you are working on a machine that isn’t yours, or you don’t/cant install anything.
Going back to Google Docs, despite the fact that it’s an excellent service, but lets face it , Google Docs doesn’t have the same features or usability as MS Word/Excel etc.
Then there’s Office Live, which again is kind of a mix, but still not perfect. You need to install the software, do connect to your online DMS (Office Live), open the file from Word/Excel, edit and save directly back to the cloud.

So what do I want? Well I want it all, I want to be able to store docs in the my own secure DMS, be able to upload scanned docs (which I do with google docs at the moment, it works well!), read/edit those docs on my iPhone (which is possible, but its not great!). But I think the mostly I would like to have the option to work on them locally or in the cloud.

With the new Office web apps on the horizon, it looks like this may be a reality, although Word for the web isn’t released yet, Excel is and looks great. One problem, the docs have to be in my SkyDrive, which as far as I am aware cannot be linked directly to my local copy of MS Word? Perhaps this will come!!
I still don’t think I will be able to edit or even have great viewing experience on my iPhone for these docs as lets face it…the iPhone is apple and Word is Microsoft! But one can dream!!

[Posted from Blogo on the Mac!] [[ Prefer Live Writer!!]]

[So much that I had to open in Live writer to sort the formatting out!]




I came up against a problem, it seems like a pretty specific problem, but none the less the solution took me a while to figure out, so worth sharing!

My problem: I have a user control that contains some text among other things, but the text is of various length, the containing textblock therefore, like the user control has a dynamic height (set the Height property to System.Double.NaN).

There are n instances of the user control within a StackPanel, as a control is added to the StackPanel I want a StoryBoard which animates the Height and the Opacity.  The Height of course I do not know.

So I need to the set the Value of the Double Animation at runtime.

The XAML for the StoryBoard.

Code Snippet
  1. <Storyboard x:Name="sbExpandControl">
  2.     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(FrameworkElement.Height)">
  3.         <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
  4.         <EasingDoubleKeyFrame KeyTime="00:00:02" Value="100" x:Name="expandToHeight"/>
  5.     </DoubleAnimationUsingKeyFrames>
  6.     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.Opacity)">
  7.         <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
  8.         <EasingDoubleKeyFrame KeyTime="00:00:02" Value="1"/>
  9.     </DoubleAnimationUsingKeyFrames>
  10. </Storyboard>

 

Firstly I need to new up the user control, set all the properties, add the control to the StackPanel, set the height of the DoubleAnimation and fire the StoryBoard.

Just simply going UserControl.ActualHeight will return 0 because the layout engine has not calculated the ActualHeight property. Which is the problem!!!

So we need to use the Dispatcher class (you can find out more on MSDN).

Code Snippet
  1. UserComment uc = new UserComment()
  2. {
  3.     Comments = v.Comments,
  4. };
  5.  
  6. stkComments.Children.Insert(0, uc);
  7. stkComments.Dispatcher.BeginInvoke(() =>
  8.     {
  9.         uc.ExpandControl();
  10.     });

In the User Control (UserComment)

Code Snippet
  1. public void ExpandControl()
  2. {
  3.     expandToHeight.Value = this.ActualHeight;
  4.     sbExpandControl.Begin();
  5. }

 

Hope this helps!



By Default scrolling with the mouse wheel is not enabled in the Silverlight DataGrid, actually I don’t think any control has it enabled.

Personally I think its pretty standard functionality for things to scroll with the mouse wheel.

So, I have got this little chunk of code that takes does the trick, nothing fancy going on here, but it works a treat.

Code Snippet
  1. private void dgResults_MouseWheel(object sender, MouseWheelEventArgs e)
  2. {
  3.     if (!e.Handled)
  4.     {
  5.         int rowsToMove = 0;
  6.         if (e.Delta < 0)
  7.         {
  8.             rowsToMove = e.Delta / 120 * -1;
  9.         }
  10.         else
  11.         {
  12.             rowsToMove = e.Delta / 120 * -1;
  13.         }
  14.  
  15.         if (dgResults.SelectedIndex == 0
  16.                 || dgResults.SelectedIndex == (dgResults.ItemsSource.Cast<ItemSourceType>().ToList().Count - 1))
  17.         { return; }
  18.  
  19.         dgResults.SelectedIndex = dgResults.SelectedIndex + rowsToMove;
  20.         dgResults.ScrollIntoView(dgResults.SelectedItem, dgResults.Columns[0]);
  21.     }
  22. }

 

 

To explain a little…I found that my delta would change in multiples of 120, depending on how fast I scrolled, –120 if I scrolled down, +120 is I scrolled up.  I needed to change this as if I scrolled down I needed the SelectedIndex to increase, so that’s what the first bit does.

Then I check that I’m not at either 0 or the last item in the datagrid, set the selected index and use the ScrollToView() method.

You may need to change slightly if you have horizontal scrolling, to stay with the correct column, for me having the first column is more than ideal, perfect in fact.

Note: This code has been tested nowhere except on  my dev machine. So, here goes!!



The issue is with Sharepoint blog category view. The page should only show the posts which have been tagged with the category you click on, but I have found this not to be the case.

I posted a thread on the Sharepoint blog forums and thankfully Laura Rogers came up with a solution.

 

Here we go…

Navigate to the category.aspx page of the Sharepoint blog.

Add a Query string (URL) Filter web part.

clip_image002

 

 

 

 

Modify the query string web part settings. Query string parameter name must be Name.

clip_image004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Remove the filter from the posts web part.

Go into the Posts web parts settings, click edit the current view.

clip_image006

 

 

 

 

 

 

 

 

 

In the Filter section, change the option selected.

clip_image008

 

 

 

 

 

 

Now connect the query string web part to the posts web part.

clip_image010

 

 

 

 

 

 

 

 

 

You will get this little popup (you may need to allow popups). Select Category from the list.

clip_image012

 

 

 

 

 

 

 

 

 

 

That’s it.

Your category filtering should now work.



I had a little mishap last night at the driving range...

Needless to say I am now in the market for a new driver...I never liked the sound of that one anyway!!

 

 

Technorati Tags: ,