Lunarmedia Blog

Personal blog by Anders Vindberg filled with dissimilar things ranging from molecular cooking sessions to innovation theories and web development combined with interesting daily thoughts all served with a dried academic tongue. Some of it may be indecipherable as my original tongue is Danish (no excuse) but do try and keep me entertained by commenting my tangled words.

CSControl:Pager Template Styling

Styling the pager control in Community Server always escapes me so here is an example:

<CSControl:Pager id="pager" runat="Server" Tag="div" style='text-align: center;'>
<FirstLinkTemplate>
  <CSControl:CSLinkData LinkTo="Link" LinkCssClass="TextButton" runat="server"><ContentTemplate><span><span>Newest</span></span></ContentTemplate></CSControl:CSLinkData>
</FirstLinkTemplate>
<PreviousLinkTemplate>
  <CSControl:CSLinkData LinkTo="Link" LinkCssClass="TextButton" runat="server"><ContentTemplate><span><span>Newer</span></span></ContentTemplate></CSControl:CSLinkData>
</PreviousLinkTemplate>
<PageLinkTemplate>
  <CSControl:CSLinkData LinkTo="Link" Property="Text" Text="<span><span>{0}</span></span>" LinkCssClass="TextButton" runat="server" />
</PageLinkTemplate>
<CurrentPageLinkTemplate>
  <CSControl:CSLinkData Tag="Span" CssClass="TextButtonDisabled" Property="Text" Text="<span><span>{0}</span></span>" runat="server" />
</CurrentPageLinkTemplate>
<SeparatorTemplate></SeparatorTemplate>
<NextLinkTemplate>
  <CSControl:CSLinkData LinkTo="Link" LinkCssClass="TextButton" runat="server"><ContentTemplate><span><span>Older</span></span></ContentTemplate></CSControl:CSLinkData>
</NextLinkTemplate>
<LastLinkTemplate>
  <CSControl:CSLinkData LinkTo="Link" LinkCssClass="TextButton" runat="server"><ContentTemplate><span><span>Oldest</span></span></ContentTemplate></CSControl:CSLinkData>
</LastLinkTemplate>
</CSControl:Pager>

Source: http://getben.com/archive/2007/01/30/introduction-to-chameleon-questions-and-answers.aspx

Visual Studio (VS) 2010 Build Configuration dropdown

If you happen to be missing the Build configuration dropdown menu from your toolbar in Visual Studio 2010 and can't find it in the Build toolbar here is how you add it back in:

Tools -> Customize -> Commands (tab). Select "Toolbar:" and then select "Build" from the dropdown.

Click on "Add Command", select "Build" in Categories and find "Solution Configurations" (at the bottom). Click "Ok" and it is back in the "Build" toolbar!

No comments, yet!

Entity Framework 4.0 RC: Cannot insert the value NULL into column '*_Id', table 'Paragraphs'; column does not allow nulls. INSERT fails. The statement has been terminated.

Entity Framework 4.0 RC bug. Usually after an "update model from database" I encounter this error message: Cannot insert the value NULL into column '*_Id', table 'column does not allow nulls. INSERT fails. The statement has been terminated.

To fix the association between the many-to-one relationship (in my case Paragraphs to Translation), you need to edit the .edmx model file and remove StoreGeneratedPattern="Identity" from the Paragraphs node.

See more here: http://stackoverflow.com/questions/2243618/how-do-you-insert-or-update-many-to-many-tables-in-net-entity-framework/2339834#2339834

No comments, yet!

LINQ to Entities - Common queries (.Net 4.0)

T-Sql "WHERE IN":

Sql:

SELECT * FROM People
WHERE Firstname IN ('Peter', 'Steve', 'John', 'Bruno')


LINQ:

var names = new string[] { "Peter", "Steve", "John", "Bruno" };

var matches = from person in people
        where names.Contains(person.Firstname)
        select person;

No comments, yet!

Encrypting connectionstrings.config in IIS 6.0

Simply call these two commands in cmd prompt:

  1. C:\WINDOWS\microsoft.net\Framework64\v2.0.50727\aspnet_regiis.exe -pef "connectionStrings" C:\MyWebsiteFolder
  2. C:\WINDOWS\microsoft.net\Framework64\v2.0.50727\aspnet_regiis -pa "NetFrameworkConfigurationKey" "Network Service"

If you still get a: "Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened." Then call the second command again but replace "Network Service" with "ASPNET".

Source: MS Patterns & Practices: http://msdn.microsoft.com/en-us/library/ms998283.aspx

T-SQL Dynamic Sorting and Order By

Using the CASE expression its possible to do efficient sorting and ordering by different parameters in one query. Here is an example from Greg Beech's Tech Blog which also includes paging:

 

DECLARE @SortType TINYINT, @SortAscending BIT, @FirstRow INT, @MaxRows INT;
SELECT @SortType = 2, @SortAscending = 0, @FirstRow = 10, @MaxRows = 10;

WITH FoundCustomers AS
(
    SELECT
        ROW_NUMBER() OVER
        (
            ORDER BY
                CASE WHEN @SortType = 0 AND @SortAscending = 1 THEN c.ContactName END ASC
                ,CASE WHEN @SortType = 0 AND @SortAscending = 0 THEN c.ContactName END DESC
                ,CASE WHEN @SortType = 1 AND @SortAscending = 1 THEN c.CompanyName END ASC
                ,CASE WHEN @SortType = 1 AND @SortAscending = 0 THEN c.CompanyName END DESC
                ,CASE WHEN @SortType = 2 AND @SortAscending = 1 THEN c.Country END ASC
                ,CASE WHEN @SortType = 2 AND @SortAscending = 0 THEN c.Country END DESC
        ) AS RowNumber
        ,c.*
    FROM
        dbo.Customers c
)
SELECT
    fc.*
FROM
    FoundCustomers fc
WHERE
    fc.RowNumber BETWEEN @FirstRow AND @FirstRow + @MaxRows - 1
ORDER BY
    fc.RowNumber;

CSControl:ConditionalContent - a thing to remember!

When using the ConditionalContent control from CommunityServer, always remember to use the <ContentConditions> tag when detailing the condition. Hmm that sounds obvious. No, its not. The control also has the DisplayCondition tag which is what we commonly use for other controls! Here is an example of correct usage:

<CSControl:ConditionalContent runat="server">
  
<ContentConditions><CSControl:QueryStringPropertyValueComparison
QueryStringProperty="condition" Operator="EqualTo"
ComparisonValue="true" runat="server" /></ContentConditions>
   <TrueContentTemplate>It's true!</TrueContentTemplate>
   <FalseContentTemplate>It's false!</FalseContentTemplate>
</CSControl:ConditionalContent>

Ahh that was good.

301 Redirect

I always forget this particular code and spend time finding it again and again: This is for redirecting call to the root domain in Community Server to the /forums/ folder. I usually create a blank aspx page that does the redirect - otherwise the page will load (which may be several 20-30 kb before directing). In SiteUrls_override.config you can set the "home" location name to the redirect file.

<%@ Page %>
<%@ Import Namespace="System.Web" %>

<script language="C#" runat="server">

    protected override void OnInit(EventArgs e)
    {
        System.Web.HttpContext context = System.Web.HttpContext.Current;

        context.Response.Status = "301 Moved Permanently";
        context.Response.AddHeader("Location", "/forums/");

    }
</script>
No comments, yet!

OpenSocial API for CSharp

Im currently looking for an OpenSocial API for the dotnet (.net) platform preferably written in csharp (C#). There are already APIs for PHP, Ruby, and other open source frameworks - where is the .net version?

It seems that the OpenSocial movement is less active in the proprietary world which for our sake (im part of it) is unfortunate. I believe the advent of OpenSocial will heavily be reflected in the future of the web.

No comments, yet!

Enable/Disable "Question & Answers"

In CS 2008.5 its possible to post a forum topic that is a "Question" or a "Discussion". In order to enable this you need to check two places in the Controlpanel.

  1. In Forum Administration - Configuration - Global Forum Settings
    1. Set "Enable Thread Status Tracking" to Yes
  2. In Forums and Groups - Forums
    1. Select to "Edit" the particular forum - in "Allowed Thread Types" check "Questions and Answers".

And you are done!

CustomCondition in Community Server

Often I find situations where I need to do a customized condition comparision. To enable this, Telligent have added the following chameleon control:

<CSControl:CustomCondition runat="server" CustomResult='<%# ((CommunityServer.Discussions.Components.Forum) ForumControlUtility.Instance().GetCurrentForum(Container)).SectionID == ForumControlUtility.Instance().GetCurrentThread(this.Page).SectionID %>'
            />

In this example I check the sectionId of the current forum (eg. in a dropdown list populated with all the forums) and the forum in which the thread im viewing is in.

No comments, yet!

Website Performance Optimization

Today I implemented some of the best practice guidelines for speeding up websites. It has resulted in significant improved load times on the subtitle website Subscene. Although all "rules" as specified by Yahoo has not been implemented yet it has already decreased load times to the half. For future developments all guidelines will be followed, first implemented in the new translator markedplace Lingbay.

Scott Hanselman has a post about enabling proxy caching in IIS.

No comments, yet!

Lingbay - A Marketplace for Linguistic Jobs

The new marketplace for linguistic jobs (Lingbay) is nearing completion. Expected launch is around April this year. If you want to be notified when we go live sign-up today!

About Lingbay:

Lingbay is an auction-house for linguistic related jobs, including translations, proofreadings, and transcriptions. As a freelance translator you bid on linguistic jobs and are paid the agreed amount after completion. As an outsourcer or employer you receive competitive quotes on jobs directly from the translator.

For a successful launch the procedure is as follows:

  1. Collect a email-list of interested parties (active)
  2. Gather a registered list of translators, linguistic professionals, and students
  3. Launch a working beta version with active linguistic jobs

In addition to the listed procedure, a large ad-campaign will run as Lingbay is launched. A website like Lingbay requires a critical mass the be meet in order for the marketplace to function. First, a group of freelance translators needs to be ready to complete linguistic jobs within a certain period. Secondly, a continous flow of new jobs are needed to keep the marketplace active. The strategy employed is designed to fulfill that purpose.

How to Add Extended Properties

In Community Server its easy to add extended properties to the user profile without having to write any code:

To your CommunityServer.config file, add

<ExtendedUserData>
  <add name="EXTENDED ATTRIBUTE NAME" />
</ExtendedUserData>

Then on your theme pages:

  • User Register (/themes/YOURTHEME/user/createuser.aspx)
  • Edit Profile (/themes/YOURTHEME/user/edituser.aspx)
  • Edit User page in Membership Administration in Control Panel (/ControlPanel/Membership/UserEdit.aspx)

add the following input field:

<asp:TextBox id="EXTENDED ATTRIBUTE NAME" runat="server" />

That's it!

Retrieve Extendedproperties Via SQL

In Community Server, dynamic user fields are saved in extended properties. In order to retrieve them in Sql add the following function:

/*------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
------------------------------------------------------------------------------*/

CREATE function [dbo].[FetchExtendendAttributeValue] (
@Key nvarchar(4000),
@Keys nvarchar(4000),
@Values nvarchar(4000)
)

/*
CS uses ExtendedAttributes to allow metadata about a post, user, or section to be stored
in a special ':' delimited format. This enables storing metadata without adding new columns
to any tables, changing sprocs, etc.

However, any data stored in this format is not easily queryable (so use it wisely :)

Occassionaly, you may want to query against this data. This function should make that task simple!

Keys are stored in this format: string:S:Int:Int = Key + :S : Starting Location : Length :

An example: 'Theme:S:0:7:dummyTotalPosts:S:7:1:BannedUntil:S:8:21:UserBanReason:S:29:5:'

Values are stored in a single string with no spaces between them.
An example: 'default04/20/2005 12:16:41 AMOther'

Theme starts a 0 and continues for 7 characters (default)
dummyTotalPosts starts at 7 and coninutes for 1 character (0)
BannedUntil starts at 8 and continues for 21 characters (4/20/2005 12:16:41 AM)
*/

RETURNS nvarchar(4000)
AS
BEGIN
DECLARE @Value nvarchar(4000)
Declare @CharIndex int
Declare @StartIndex int
Declare @Len int

--Find the index of the key
Set @CharIndex = CHARINDEX(@Key + ':s',@Keys)

--If the key does not exist, return NULL
if(@CharIndex = 0)
RETURN NULL

--If the key is not the first, remove any leading keys
if(@CharIndex > 1)
Begin
Set @Keys = Stuff(@Keys,1,@CharIndex-1,'')
End

--Remove the Key from the keys list. This will
Set @Keys = Stuff(@Keys,1,Len(@Key+':S:'),'')

--Find the location of the : after the starting location
Set @CharIndex = CHARINDEX(':',@Keys)

--Grab the starting location
Set @StartIndex = SUBSTRING(@Keys,1,@CharIndex-1)

--Remove the starting location from the Keys
Set @Keys = Stuff(@Keys,1,@CharIndex,'')

--Find the lenght value's index
Set @CharIndex = CHARINDEX(':',@Keys)

--Find the lenghth value
Set @Len = SUBSTRING(@Keys,1,@CharIndex-1)

--Get the value from the values string
Set @Value = SUBSTRING(@Values,@StartIndex+1,@Len)


RETURN @Value
END

Source: http://code.communityserver.org...

More Posts Next page »