Keywords
Tuesday, January 10, 2012
Connecting VS2008 to TFS2010
One of the things I spent a fuck load of time on was getting VS2008 connecting to TFS2010. Finally, got it to work. This is how:
1. I installed VS2008
2. Then downloaded and installed Microsoft Visual Studio 2008 Service Pack 1 (Installer), get it here
3. Then, downloaded and installed Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010 (Installer), get it here
4. Checked in VS2008 if it installed correctly
Finally, I drilled down into the registry, to "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers" (you should be able to find it, if not make sure you installed the earlier mentioned stuff in the correct order).
In here, I added a string value where the value name can be anything and the value data field should contain the full address of your server.
From here, you should be able to go to the Team Explorer window in VS and add the team project. That's it.
Friday, January 6, 2012
Note2Self: Configuring web service for web application usage
Steps:
1 Add 'endpoint' element to 'client':
<client> <endpoint address="http://localhost/YourService/ServicesYou.asmx" binding="basicHttpBinding" bindingConfiguration="###MyCustomBindingName1###" contract="###DefinedConfigurationName###" name="###stringEndPointConfigurationName###" /> </client>###MyCustomBindingName1### -- is a reference to what will be added to the system.serviceModel/bindings/basicHttpBinding/ element. Preferably, prefix it with the binding type (i.e. in this case: "basicHttpBinding_MyCustomBindingName1")
###DefinedConfigurationName### -- should be the value that you defined in the Reference.CS file. To be more specific in the attribute before the interface definition:
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://WebServices/", ConfigurationName = "###DefinedConfigurationName###")]2 Create binding element
<binding name="###MyCustomBindingName1###" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
I changed the maxReceivedMessageSize and maxBufferSize to the max. allowed size since I had trouble retrieving large DataTables.
Monday, December 12, 2011
Binding an ASP.NET dropdown list to a SharePoint list
using (SPWeb web = SPContext.Current.Site.OpenWeb()) { SPList list = web.Lists["TestConnectionList"]; ddlConnections.DataSource = list.Items; ddlConnections.DataValueField = "Title"; ddlConnections.DataTextField = "Title"; ddlConnections.DataBind(); }In this case, the name of the resource SharePoint list is called 'TestConnectionList' and the name of the dropdown list 'ddlConnections'. Make sure that you also specify the exact same column names in the list in the DataValueField and DataTextField or otherwise you'll get an exception thrown at you. As you can see, I am also using a scope so that the SPWeb object gets destroyed after usage. This is because I am explicitly calling the site.OpenWeb();
Friday, November 18, 2011
Serialization & deserialization in C#
[Serializable]
public class MetalBand
{
private string _bandName;
private int _intMembers;
private string _genre;
public MetalBand()
{
}
public string BandName
{
get { return _bandName; }
set { _bandName = value; }
}
public int NumberOfMembers
{
get { return _intMembers; }
set { _intMembers = value; }
}
public string Genre
{
get { return _genre; }
set { _genre = value; }
}
}
Suppose you’ve got an instance of this object like so:
MetalBand myBandObject = new MetalBand();
myBandObject.BandName = "Skeletonwitch";
myBandObject.Genre = "Blackened Thrash";
myBandObject.NumberOfMembers = 5;
And you would need to pass this data on to a web service, you would need to serialize it first. This means that you convert an object state into a format which can be transported and/or stored. Here is how to:
XmlSerializer serializer = new XmlSerializer(typeof(MetalBand));
XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.OmitXmlDeclaration = true;
StringWriter stringWriter = new StringWriter();
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, writerSettings))
{
serializer.Serialize(xmlWriter, myBandObject);
}
XmlDocument doc = new XmlDocument();
// here is your serialized object
doc.LoadXml(stringWriter.ToString());
The XmlSerializer class will do the actual magic of conversion, the MetalBand object type is passed on to the constructor of the class
The instance of the XLMWriterSettings holds a supporting set of features on the XmlWriter object, which is created by the XmlWriter.Create. With the OmitXmlDeclaration property set to true, we state that we do not want to write an XML declaration in our document.
We are then serializing the object instance into the XmlWriter stream with the chosen Xml declaration settings. Then we simply create a new instance of an XmlDocument and blast the xml stream right into it.
As for deserialization, you can instantiate another object of XmlSerializer or use the same one created earlier. Then use the XmlNodeReader, which is also a stream reader, to stream that puppy into the Deserialize method.
XmlSerializer xSerializer = new XmlSerializer(typeof(MetalBand));
XmlNodeReader reader = new XmlNodeReader(doc);
MetalBand mySecondBandObject = (MetalBand)xSerializer.Deserialize(reader);
That is all there is to it
Tuesday, September 20, 2011
Setting up Business Connectivity Services in SharePoint 2010
Other SP peers seemed to have the same problem and many could solve it by installing a WCF hotfix (KB976462), however this did not work for me. I will show you three checks I did in order to have stuff working. 1. Check if the Business Data Connectivity Service is running. You can find it by going to "Central Administration" -> "Manage services on server". If it has stopped, start it again.
2. Make sure you've got a Business Data Connectivity Service Application set up in "Application Management" ->"Service Applications"->"Manage service applications"
3. The next one is what I overlooked and made me waste hours of my life. Go to "Application Management"->"Service Applications"->"Configure service applications associations". In here you need to check whether your BCS Application Proxy is checked, otherwise it won't work.
Monday, September 19, 2011
Appliance of Strategy Design Pattern
using System; using System.Collections.Generic; using System.Linq; using System.Text; // Appliance of the Strategy Pattern namespace ConsoleApplication5 { class Program { static void Main(string[] args) { Dude Earl = new Dude("Albert"); Dude Gary = new Dude("Gary"); Earl.SetMorningRitual(new CigaretteSmoker()); Gary.SetMorningRitual(new CoffeeDrinker()); Earl.WakeUp(); Gary.WakeUp(); // During the day Earl decides to give up smoking and start drinking coffee in the morning instead. Earl.SetMorningRitual(new CoffeeDrinker()); Earl.WakeUp(); Console.ReadKey(); } } class Dude { IMorningRitual _behaviour; String _name; public Dude(String MyName) { _name = MyName; } public void SetMorningRitual(IMorningRitual Behaviour) { _behaviour = Behaviour; } public void WakeUp() { Console.WriteLine(this._name + " just woke up"); _behaviour.DoMorningRitual(); } } public interface IMorningRitual { void DoMorningRitual(); } public class CigaretteSmoker : IMorningRitual { public void DoMorningRitual() { Console.WriteLine("Still sleepy but gonna smoke one anyway.. *lights cigarette\n"); } } public class CoffeeDrinker : IMorningRitual { public void DoMorningRitual() { Console.WriteLine("A morning without coffee is like something without something. Aahhh delicious!\n"); } } }
Thursday, June 16, 2011
Multiple recs merged into one with multiple columns
and the desired end result should be like::
then use this script i created:
1: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2: * User : Gary
3: * Date : 20110616
4: * Description : Pivoting multiple rows into one row with multiple columns
5: *
6: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7:
8: --// Create example table with the usual All-American names
9:
10: CREATE TABLE #PivotRows (
11: FirstName VARCHAR(10)
12: , LastName VARCHAR(15)
13: , ModelOfInterest VARCHAR(15)
14: )
15:
16:
17: INSERT INTO
18: #PivotRows
19: SELECT 'John','Cunningham','CORSA' UNION ALL
20: SELECT 'John','Cunningham','ASTRA' UNION ALL
21: SELECT 'John','Cunningham','ANTARA' UNION ALL
22: SELECT 'Mick','Clarkson' ,'SIGNUM' UNION ALL
23: SELECT 'Mick','Clarkson' ,'AGILA' UNION ALL
24: SELECT 'Robert','Flanigan','INSIGNIA'
25:
26:
27:
28: SELECT * FROM #PivotRows
29:
30:
31: --// Shake and serve
32:
33: SELECT
34: FirstName
35: , LastName
36: , MAX(CASE WHEN rowid=1 THEN [ModelOfInterest] ELSE NULL END) AS ModelOfInterest1
37: , MAX(CASE WHEN rowid=2 THEN [ModelOfInterest] ELSE NULL END) AS ModelOfInterest2
38: , MAX(CASE WHEN rowid=3 THEN [ModelOfInterest] ELSE NULL END) AS ModelOfInterest3
39: , MAX(CASE WHEN rowid=4 THEN [ModelOfInterest] ELSE NULL END) AS ModelOfInterest4
40: FROM
41: (
42: SELECT
43: ROW_NUMBER() OVER ( PARTITION BY [FirstName],[LastName] ORDER BY [FirstName],[LastName] ) AS rowid
44: , *
45: FROM #PivotRows
46: ) t1
47: GROUP BY
48: FirstName
49: , LastName



