Tuesday, April 14, 2009
Sunday, October 26, 2008
3.5 - Day 5
Ziua concluziilor. Si a tenisului de masa A fost o zi ploioasa, dar acest fapt nu a fost un impediment in calea ultimelor meciuri.
Concluzii:
1. frameworkul favorit - Entity Framework
2. frameworkul cel mai spectaculos - Silverlight
3. frameworkul cu arhitectura cea mai deosebita - MVC
4. mediul optim de lucru - in jurul unei mese rotunde imense, alaturi de ceilalti
5. modul optim de invatare - prin bagarea nasului in treaba celorlalti
6. modul optim de relaxare - ping pong
7. modul optim de petrecere a serilor - la un vin (de casa) impreuna cu ceilalti
Bineinteles ca am relationat totul cu programarea, bineinteles ca bancurile ad-hoc au fost comparatiile cu View State-ul si cu Stack Overflow-ul. La fel de bine inteles ca si faptul ca am plecat toti acasa mai castigati, mai destepti (in ale cunoasterii de 3.5) si mai … relaxati.
Abia astept urmatorul workshop.
Wednesday, October 22, 2008
3.5 - Day 2 & 3
Viata va developer ASP .NET… nu e usoara, asta ca sa nu spun ca e de-a dreptul %^$*&%$%#@ uneori. Cel putin era.
Dupa 3 zile de workshop am vazut ca, folosind noile tehnologii din .NET 3.5, pot face intr-o zi ceea ce alta data faceam intr-o saptamana. La asta ma ajuta Routing, MVC, Data Services, Entity Framework, AJAX, Dynamic Data si Silverlight.
Bineinteles ca aceste frameworkuri fac doar 80% din munca. Impropriu spus “doar”, nu ?
Preferatele mele de pana acum - Entity Framework in combinatie cu Dynamic Data.
Monday, October 20, 2008
3.5 - Day 1
- 12 people
- Lots of HOL
- No wireless in the hotel’s room :p
- pretty busy week
- group photo to be pyuslbished soon
- First instructional event about (ADO.NET EF, ADO.NET Data Services, AJAX, ASP MVC, SILVERLIGHT 2, ASP Routing, ASP.NET Dynamic Data)
Prezent
Day 1 - ADO NET Entity Framework
Been there done that, dar intotdeauna ramai cu intrebari si cu aspecte pe care stii ca le puteai rezolva mai bine. Asa ca sesiunea de astazi mi-a prins foarte bine.
Daca ar fi sa listez aici codul pe care in foloseam sa fac paginare pe 2005 (in procedura stocata SQL) mi-ar lua multe randuri. Varianta LINQ:
var products = (from p in this.context.Product
where p.ProductCategory.CategoryID == category.CategoryID
orderby p.Name
select p).Skip(10).Take(10);
(pagina 2 din n -10 produse)
Wednesday, August 13, 2008
Programatically removing an HttpModule from SharePoint Web.config (2)
Although web.config file sees no problem in duplicate add tags, the same thing does NOT happen with the remove tags. If two or more remove tags of the same module are present in the web.config file, an error is generated - so down the drain goes our solution if two or more install-uninstall sequences occur on the same web application.
What is the solution to this problem? I found it in one of Andrew Connell’s books - “Professional SharePoint 2007 Web Content Management Development” (find it in my Books sidebar). It is a fairly simple solution: at Http Module installation in a SharePoint site you add a property to the site to signal that the Http Module should be applied there. In the Http Module code behind you check if that property exists before letting the Http Module do what it is meant to do. At unistallation you remove the property, or make it null. And Voila! - although the tag in the web.config stands, the module will not act on sites unless they have the property it is looking for.
Tuesday, February 26, 2008
ADO NET Entity Framework Beta 3 Installation Troubleshooting
ADO .NET EF Beta 3 has 2 patches you need to install in order to be able to use it: Beta 3 patch and EF Tools patch. Or so they say… You also need to install a VS 2008 Patch. I found this tip
here. And installed the VS 2008 patch, then the Beta 3 release and then the Tools. No luck. The ADO NET Entity Data Model Item Template was not showing up in the Add New Item screen of VS 2008. But the VS 2008 command line recognised the edmgen command. Bugger…After a day and a thousand google searches I found the answer
here. You have to install the VS 2008 patch AFTER the Beta 3 and BEFORE the Tools.No comment.
Thursday, October 4, 2007
Http Handlers applied – Rss Feed
RSS Feeds are very popular these days.
Recently, I found myself in the need of using a rss feed for a “Joke of the day” web part. The tricky side of the business was that I had to provide only one like in the rss feed – the joke for the current day. Many options came into my mind, but the most elegant was by far the HttpHandler one.
An HttpHandler is an independent unit that manages the server response for a given situation: for example, a specific file extension. In my case, what I need was for the web application to create a rss file “on the fly” when a user requested a certain url. The url was http://mycompany.com/RssFeed/jokes.rss and the trick - the file didn’t even exist . When the url was requested, I had to tell the application that a rss file (stream) had to be generated and passed to the client.
How is this done? First of all, you need a class that generated the feed. This class needs to implement the IhttpHandler interface. What this class does is to read one joke from a data source (xml, database etc) and output it to the browser as a rss file. You can put this class in a ClassLibrary project, because you will need the dll. Here is the code:
namespace MDL.RSSLibDLL
{
public class RssHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context) // this is the function that needs to be implemented. It comes, by dfault, with the Context of the user in the application that it handles
{
// Get the file name from the requested url
string fileName = Path.GetFileName(context.Request.Path); // the rss file that the user wants
//generally, you want to cache your rss files
string cachedChan = context.Cache[fileName] as String;
if (cachedChan == null)
{
// The file is not in the cache
string profileFolder = ConfigurationSettings.AppSettings["rssProfileFolder"];
//get the rss profile – the phyisical structure
if (profileFolder == null)
{
context.Response.StatusCode = 404;
context.Response.End();
return;
}
// Verify that you actually have a profile for the requested feed(a source rss file to read the structure from )
string profilePath = profileFolder + “” + fileName;
if (!File.Exists(profilePath))
{
context.Response.StatusCode = 404;
context.Response.End();
return;
}
// create the rss response
RssChannel chan = new RssChannel(profilePath, DateTime.Now);
cachedChan = chan.GetResponse();
double cacheTimeout;
string appCacheTimeout = ConfigurationSettings.AppSettings["cacheTimeout"];
if (appCacheTimeout == null)
cacheTimeout = 30;
else
cacheTimeout = double.Parse(appCacheTimeout);
context.Cache.Insert(fileName, cachedChan, null, DateTime.Now.AddMinutes(cacheTimeout), TimeSpan.Zero);
}
context.Response.ContentType = “text/xml”;
context.Response.Write(cachedChan); // output the rss to the browser
}
public bool IsReusable
{
get
{
return true;
}
}
}
internal class RssChannel //my class that implements a Rss feed item
{
private string _title;
private string _link;
private string _description;
private string _language;
private string _date;
private string _profilePath; //resulting RSS structure
private ArrayList _items;
public RssChannel(string profilePath, DateTime date)
{
_profilePath = profilePath;
_date = date.Month.ToString() + “/” + date.Day.ToString();
Load();
}
public string Title
{
get { return (_title); }
set { _title = value; }
}
public string Link
{
get { return (_link); }
set { _link = value; }
}
public string Description
{
get { return (_description); }
set { _description = value; }
}
public string Language
{
get { return (_language); }
set { _language = value; }
}
public RssItem this[int index]
{
get
{
if (index < _items.Count)
return ((RssItem)_items[index]);
return (null);
}
}
public string GetResponse()
{
XmlElement workNode;
XmlElement itemNode;
RssItem currentItem;
XmlDocument rssDocument = new XmlDocument();
// Create the rss document node and set the its attributes
XmlElement docNode = rssDoc.CreateElement(“rss”);
XmlAttribute attr = rssDoc.CreateAttribute(“version”);
attr.Value = “2.0″;
docNode.Attributes.Append(attr);
rssDoc.AppendChild(docNode);
// Create the channel element and its children
XmlElement chanNode = rssDoc.CreateElement(“channel”);
docNode.AppendChild(chanNode);
workNode = rssDoc.CreateElement(“title”);
workNode.InnerText = _title;
chanNode.AppendChild(workNode);
workNode = rssDoc.CreateElement(“link”);
workNode.InnerText = _link;
chanNode.AppendChild(workNode);
workNode = rssDoc.CreateElement(“description”);
workNode.InnerText = _description;
chanNode.AppendChild(workNode);
workNode = rssDoc.CreateElement(“language”);
workNode.InnerText = _language;
chanNode.AppendChild(workNode);
// Add item nodes to the channel
for (int index = 0; index < _items.Count; index++)
{
currentItem = (RssItem)_items[index];
itemNode = rssDoc.CreateElement(“item”);
chanNode.AppendChild(itemNode);
workNode = rssDoc.CreateElement(“joke”);
workNode.InnerText = currentItem.Joke;
itemNode.AppendChild(workNode);
workNode = rssDoc.CreateElement(“date”);
workNode.InnerText = currentItem.Date;
itemNode.AppendChild(workNode);
}
return (rssDoc.OuterXml);
}
private void Load()
{
_items = new ArrayList();
// Set channel properties from the profile:
_title = profile.SelectSingleNode(“rss/channel/title”).InnerText;
_link = profile.SelectSingleNode(“rss/channel/link”).InnerText;
_description = profile.SelectSingleNode(“rss/channel/description”).InnerText;
_language = profile.SelectSingleNode(“rss/channel/language”).InnerText;
string _source = profile.SelectSingleNode(“rss/channel/source”).InnerText;
// Retrieve items from the joke source
// input your code depending on the datasource
…
RssItem currentItem = new RssItem( /*joke text field*/,/*joke date field*/);
_items.Add(currentItem);
…
}
// internal class that implements the Joke object
internal class RssItem
{
private string _joke;
private string _date;
internal RssItem(string joke, string date)
{
_joke = joke;
_date = date;
}
public string Joke
{
get { return (_joke); }
set { _joke = value; }
}
public string Date
{
get { return (_date); }
set { _date = value; }
}
}
}
This class uses 3 (or more) pieces of information that you need to provide from an external source:
- The rss profile file – the file with the rss structure
- The cache timeout value
- The data information – xml file path, database connection string, select query etc
My code used an xml file that had jokes for all the days of the year. What I did was to get the current date and then read from the xml file the corresponding joke.
You can pass this information in a very elegant way – the web.config file. The web config file of the web application that will serve the rss. This web application can have no pages at all – that is the beauty of it J. What you need to do for the web application is:
- Put this in the web.config:

The HttpHandlers section tells the application that the handler for the rss files is the RssHandler class.
- Add the Classlibrary application dll in the bin directory
- Tell IIS that you want to handle the rss file requests differently.
![]()
You can copy the executable path from another extension mapping.
Now all the requests for a rss file will be handled by the RssHandler class. The beauty of it is that you can particularize the class for different rss files.
Here is a sample structure for the rss file:
![]()
If you build this solution and install it on your localhost, if you then go to http://localhost/my_app_name/jokes.rss you should be shown a feed with one item for the corresponding date.
Monday, September 24, 2007
.NET for every-day-useful tasks :)
What do you know, it pays off to be a .NET developer You, of course, knew that you can develop applications for your pocket PC, but let’s face it, did you ever really need to do that for your own personal pocket pc phone? Nop. There are so many freeware tools out there, that it would really be a waste of time to sit down and write them yourself. But this time… maybe it’s worth it. This link describes a user scenario that we all find ourselved in all the time - the loud volume of your phone ring tone. As we walk on the street with out MP3 player in our years or in the car with the radio loud enough to cover the noisy city, we have the ring volume at the maximum level, isn’t it? All good, untill we find ourselves in a meeting with the boss (and usually the rest of the colleagues) in a big or small room (size doesn’t matter really). And there it goes - the phone rings.
Wouldn’t it be great for our super cool phone to be as smart as us ? And to adjust the volume of the ring tone according to the surrounding noises (or lack of) ? The MSDN article describes the solution.
“When .NET rocks, developers”… adjust their ring tones
Monday, September 17, 2007
List.FindAll
Generic lists are very powerfull 2.0 tools. If you use them, try to take advantage of every property they have. For exemple, instead of using a foreach statement to find one or more items in a list, use the Find() and FindAll() functions.
The Find All() function is used when we want to retrieve all the ietms in a list that have a certain property. Let’s suppose that we the next class:
public class QuarterlyReport{
#region Private Properties
private string _complaintType;
private string _productClass;
private string _incidentGrade;
#endregion
#region Public Properties
public string ComplaintType
{ get{ return _complaintType;}}
public string ProductClass
{get { return _productClass; }}
public string IncidentGrade
{get { return _incidentGrade; }}
#endregion
…
public static List<QuarterlyReport> GetAll(…)
{ … }
}
The GetAll() method returns all the Report objects from the database.
Sometimes you need to avoid querying the database several times. For example, the getAll() method might return objects that have diferent ComplaintType attribute values. How do you use the FindAll() method to get, from the returned list, the reports that have ComplaintType = “X” ?
First, you build a class that will serve as an implemetation of generic Predicate:
public class ReportMatcher
{
string type;
public ReportMatcher(string _type)
{
this.type = _type;
}
public bool Test(QuarterlyReport rep)
{
if (rep.ComplaintType.Equals(type) )
return true;
else
return false;
}
}
Then, all you need to do in code is to use this class as your filter:
List<QuarterlyReport> allReports = QuarterlyReport.GetAll(…);
ReportMatcher rm = new ReportMatcher(“X”);
List<QuarterlyReport> rep = reportErrors.FindAll(rm.Test);
If you need, you can add more preoerties to the ReportMatch class and, this way, more filters to the search.
This method also helps if you are using DataSet.Select and want to bind the result of the Select() to a data object. You can read the dataset into a generic list and then search it with FindAll().
Wednesday, September 5, 2007
Maintaining page vertical position at postback
If you search this in Google, you will get tons of answers that give a javascript solution - more or less complicated. If you are working on an ASP NET application, the solution can be simple and straight-forward:
Page.MaintainScrollPositionOnPostBack = true;
You can also use the SmartNavigation property, but this one is marked as deprecated.


