String.Join concatenates an array of strings together without checking for empty entries. This means the separator character is added twice, between non-empty items sometimes. String[] input = {foo, null, bar};
var result = String.Join(",", input);
// result == "foo,,bar"
My alternative uses the IEnumerable.Aggregate extension method, it checks for there empty entries and when it finds one doesn't add a redundant separator.
string[] input = { "foo", null, "bar" };
string result = input.Aggregate((x, y) => String.IsNullOrEmpty(y) ? x : string.Concat(x, ",", y));
// result == "foo,bar"
After a week of geeking out, PDC 2008 is over. It was an intense week with a bunch of interesting announcements and promising technologies. The highlights: “Dublin”: an application server build upon IIS 7 (Win2k8) hosting WCF and WF 4.0. But it’s more! Besides hosting WCF and WF, it also includes tooling (in the IIS management interface and Power Shell commandlets), templates in Visual Studio for deploying and a database filled with management information. (See also: BB18). “Geneva”: an STS (Security Token Server) which allows you to extract the authentication from your applications (making it the problem of the IT professionals ). Using the Geneva Server and the Geneva Framework federation, extracting metadata about your users from diverse sources (age, shoe size etc.) becomes a matter of configuration instead of a matter of fragile hardcoded queries. (See also: BB42). C# Futures: dynamic types, a little love from the dynamic languages for their static cousins. (See also: TL16 and TL10). Boku: the best presentation from MSFT research, a ‘game’ which allows you to program using an Xbox controller. “Oslo”: a language “M”, a visual modeler “Quadrant” and a repository. Everything is data, the quadrant visual modeler is stored as data in the repository. “M” (and MGrammer and MSchema) allows you to define your own DSL for your problem (e.g. music library with songs), build a grammar for it and create an object graph in memory. Quadrant is a visual modeler for your Visual DSL, which gives your end users a very rich editing experience. I did a hands on lab with “Oslo” and Dublin, modeling a WCF and WF solution and deploying it all from Quadrant, very slick! (See also: TL23 and TL31). Windows Azure: making hosting easy and cheap. Combined with all the announced services (.NET Services, SQL Services, Access Services, Workflow Services etc.) this is a very compelling story for hosting your websites and –applications without the headaches of scaling and maintenance. (See also: ES16 and BB01). CodeContract class: the new CodeContract class in .NET 4.0 allows you to defined pre- and post-conditions for the parameters of your methods (should never be null) and uses static analysis to verify those conditions. (This and more changes to the CLR in 4.0 see: PC49). Expect more detailed posts about these and other subjects after my vacation. See you at PDC 2009 (17 November 2009 – 20 November 2009).
Scott Hanselman has some great tips for cleaning up disk space under Windows Vista. The best tip is using vsp1cln.exe to remove the sp1 install files. vsp1cln.exe - After you install Vista SP1, it leaves around the original files so you can uninstall the Service Pack if you want. After a few months with the Service Pack, I've decided for myself that it's a good thing and decided I don't need the option. Open up an administrative command prompt. That means, click the Start Menu, type cmd.exe, then right-click on it and click "Run as Administrator." Alternatively, you can press Ctrl-Shift-Enter to run something as Administrator. Next, type "vsp1cln" at the command prompt. If you select yes, you'll get back around 2 to 3 gigs. The only thing, again is that you can't uninstall SP1.
Last week the timeline for PDC08 was posted on the PDC site. All the sessions you previously selected, to help make a better schedule, are already added to your personal schedule. This is my schedule, based on the sessions I selected. As you can see, I have a small challenge, with 2-4 sessions at the same time, so I’m going to have some difficult choices to make. | Monday, October 27 | | | 8:30 AM - 11:00 AM | Keynote | | 11:00 AM - 12:15 PM | Identity Roadmap for Software + Services Deep Dive: The New Rendering Engine in Microsoft Internet Explorer 8 Under the Hood: Advances in the .NET Type System | | 12:45 PM - 1:30 PM | Datacenters and Resilient Services "Dublin" and .NET Services: Extending On-Premises Applications to the Cloud | | 1:45 PM - 3:00 PM | Identity: "Geneva" Server and Framework Overview The Future of C# | | 3:30 PM - 4:45 PM | Microsoft Silverlight, WPF and the Microsoft .NET Framework: Sharing Skills and Code Deep Dive: Dynamic Languages in Microsoft .NET Parallel Programming for C++ Developers in the Next Version of Microsoft Visual Studio | | 5:15 PM - 6:30 PM | Developing and Deploying Your First Cloud Service Microsoft Visual C++: 10 Is the New 6 WF 4.0: A First Look IronRuby: The Right Language for the Right Job Microsoft Visual Studio Team System Database Edition: Overview | | Tuesday, October 28 | | | 8:30 AM - 12:00 PM | Keynote | | 12:45 PM - 1:30 PM | WCF: Zen of Performance and Scale | | 1:45 PM - 3:00 PM | SQL Server 2008: Developing Large Scale Web Applications and Services SQL Server 2008: Beyond Relational Essential Cloud Storage Services Developing Applications Using Data Services A Lap around "Oslo" | | 3:30 PM - 4:45 PM | Architecture of the Building Block Services Identity: "Geneva" Deep Dive "Oslo": The Language | | 5:15 PM - 6:30 PM | Live Services: Building Applications with the Live Framework Identity: Live Identity Services Drilldown Architecting Services for the Cloud ASP.NET and JQuery Entity Framework Futures | | Wednesday, October 29 | | | 8:30 AM - 11:00 AM | Keynote | | 10:30 AM - 11:45 AM | SQL Server Data Services: Futures Live Services: Live Framework Programming Model Architecture and Insights Service Bus Services: Connectivity, Messaging, Events, and Discovery Microsoft Internet Information Services 7.0 and Beyond WCF 4.0: Building WCF Services with WF in Microsoft .NET 4.0 Parallel Programming for Managed Developers with the Next Version of Microsoft Visual Studio Panel: The Future of Programming Languages 403AB | | 12:00 PM - 12:45 PM | SQL Server 2008: Developing Secure Applications Microsoft XNA Game Studio: An Overview | | 1:15 PM - 2:30 PM | SQL Server 2008: New and Future T-SQL Programmability Logging, Diagnosing, and Troubleshooting Applications Running Live in the Cloud Modeling Data for Efficient Access at Scale Concurrency Runtime Deep Dive: How to Harvest Multicore Computing Resources | | 3:00 PM - 4:15 PM | Live Services: Mesh Services Architecture and Concepts "Dublin": Hosting and Managing Workflows and Services in Windows Application Server SQL Server 2008: Deep Dive into Spatial Data Offline-Enabled Data Services and Desktop Applications "Oslo": Repository and Models | | 4:45 PM - 6:00 PM | .NET Services: Access Control Service Drilldown Deploying Web Applications with Microsoft Internet Information Services 7.0 and the Web Deployment Tool Business Considerations for Cloud Computing WF 4.0: Extending with Custom Activities | | Thursday, October 30 | | | 8:30 AM - 9:45 AM | SQL Server Data Services : Under the Hood Dynamics Online: Building Business Applications with Commerce and Payment APIs Developing RESTful Services Microsoft .NET Framework: Declarative Programming Using XAML Research: Contract Checking and Automated Test Generation with Pex | | 10:15 AM - 11:30 AM | Messaging Services: Protocols, Protection, and How We Scale ASP.NET: Cache Extensibility Microsoft .NET Framework: CLR Futures | | 1:45 PM - 3:00 PM | Workflow Services: Orchestrating Services and Business Processes Using Cloud-Based Workflow Identity: Windows CardSpace "Geneva" Under the Hood An Introduction to Microsoft F# |
Last week the final (25) sessions were added to the PDC Session list, making it a total of 178 sessions. I’m not sure which sessions are new or updated, so this list will not be unfamiliar to regular readers of this blog (all 5 of you). The sessions I will try to attend, if they can schedule around my wishes, are: sessions about “Oslo”, “Zermatt”, CLR Futures, some language sessions (C#, F#, Dynamic Languages, XAML), “Dublin” and the Parallel Symposium.
Update: I had another look at the session list today and 10 more sessions were added, making it a total of 188.
In 1936 Alan Turing wrote a paper "On Computable Numbers, with an Application to the Entscheidungsproblem [0]". The most interesting result of this paper is not the conclusion, that there cannot be a general solution to the Entscheidungsproblem, but how Alan Turing reached that conclusion. In his paper he introduces a computing machine (a Turing machine) with a limited number of operations, by showing that such a machine can not determine the ultimate fate of all other machines, he proves there is not general solution. In 2008 Charles Petzold wrote "The Annotated Turing", in this book he dissects the original paper from Alan Turing. This book not only presents the original paper (and the appendix and corrections) with numerous annotations and samples, but also is a biography of Alan Turing's life and an introduction to the mathematical background, required for understanding the paper. The book concludes with an overview how the Turing machines can be used to help understand the human mind and the universe. This is a highly recommended book, which is very accessible for anyone with a general interest in computes and mathematics. And a must read for all developers, who want to understand why there can't be a general program which verifies all programs are error free. [0] The Entscheidungsproblem asks for a general decision procedure with a finite number of steps to determine the provability of any given well-formed formula.
The ‘normal’ use case for using templated databound controls like the listview control is to specify the control and the templates in declarative markup and bind the control in the code-behind. <asp:ListView runat="server" ID="listview">
<LayoutTemplate>
<ol><li runat="server" id="itemPlaceholder" />< span>ol>
< span>LayoutTemplate>
<ItemTemplate>
<li><%#Eval("item") %>< span>li>
< span>ItemTemplate>
< span>asp:ListView>
and in the code-behind:
listview.DataSource = ....
listView.DataBind();
But when you’re building a webpart or a composite control, this is generally not really an option. The way to define templates in the code-behind is to define two classes which implement the ITemplate interface and assign an instance of these classes to the LayoutTemplate and the ItemTemplate properties. (There are a lot more templates you can use, but these are used to show how the concept works.)
The Layout template is the simplest to define:
private class LayoutTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
var ol = new HtmlGenericControl("ol");
var li = new HtmlGenericControl("li") { ID = "itemPlaceholder" };
ol.Controls.Add(li);
container.Controls.Add(ol);
}
}
The only requirement is that it control with the ID itemPlaceHolder, the listview uses this ID to find the control to replace with the item template when databinding.
The InstantiateIn method in the item template is similar to that method in the layout template: a control is created (the same type as previously) and this is added to the container control, effectively replacing the child-control (with the itemPlaceHolder ID) from the layout template. The only difference is that we register for the databinding event of the childcontrol. In the databinding method a reference to the childcontrol is obtained (the sender parameter) and a reference to the current item from the bound collection.
private class ItemTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
var li = new HtmlGenericControl("li");
li.DataBinding += DataBinding;
container.Controls.Add(li);
}
public void DataBinding(object sender, EventArgs e)
{
var container = (HtmlGenericControl)sender;
var dataItem = ((ListViewDataItem)container.NamingContainer).DataItem;
container.Controls.Add( new Literal(){Text = dataItem.ToString() });
}
}
Complete source: FibonacciControl.txt (1.88 KB)
As Dare Obasanjo writes, there are a number of things you have to give thought when implementing OpenID on your website. The real question you’ll have to answer is: how easy do I make it for users to participate on my website and how hard do I make it for spammers to flood my website. But by delegating authentication to an OpenID provider, your implicitly trusting that provider to do the right thing when authenticating a user. Since, as Tim Bray speculated, there is nothing stopping a provider from “succesfully authenticating” any user URL, you can’t blindly trust any OpenID provider. So depending on the requirements you have for the authentication of your users, you can white-list providers you trust (like HealthVault), or if you’re only worried about bots, you can ask them to solve a Captcha. So the consequence is: since you can’t really trust all OpenID providers, so you force your user to register for a specific one (making their OpenID no longer their single online id) or make them to jump through hoops (by proving they are human). Does OpenID really make it easier for a user to use your site? Or does it make it easier for you (the developer), since you can drop in a control and think you don’t have worry about authentication. See also: OpenID is too hard & The problem(s) with OpenID
|