Author Archive

Play-off: HTML5, Flash and Silverlight. Who is the last to die?

Eugene Akinshin

“Prediction is difficult—especially of the future”
/Mark Twain/

I noticed that people ask me with increasing frequency: «What to use to write our new on-line application: HTML5, Flash or Silverlight? » on what I invariably respond: «It is necessary to carry out the careful analysis of business requirements to your software in order to answer to this question» that certainly sounds better, than «who the hell knows», but has the same value.

Old kind days, when having written the application for Windows, you could be sure that 99 % of the solvent demand will be met, are irrevocably passing. Now, as in times when dinosaurs were vigorously running on the earth, before absolute domination of Microsoft on desktop, it is necessary to port applications to a set of incompatible platforms: Windows, MacOS, iOS, Android, Windows Phone, you name it. The thing that doesn’t represent a great problem if you create another primitive client for a social network, turns to huge amount of work when developing unpretentious casual game and becomes the real nightmare when it comes to the creation of corporate software. There are very few people who enjoy controlling identity of constantly changing business logic simultaneously implemented in different programming languages, never mind expenses for support of this zoo that strongly exceed cost of the monoplatform solution. In such situation, it is not surprising that uniform cross-platform development environment became some kind of the «sacred Graal» for the developers which searches cause, perhaps, more holy wars, than searches of original Graal by crusaders have caused.

(more…)

July 5th, 2011

How to turn Silverlight DataGrid to TreeGrid in 15 minutes.

Eugene Akinshin

by Eugene Akinshin, Ph.D., Founder of Perpetuum Software LLC

I am one of those guys who constantly try to convince people around them that Silverlight is a wonderful thing and how it is easy to design user-friendly user interface with it. And as expected my enthusiasm rarely understood by colleagues especially by experienced developers whose favorite argument is “All this can be perfectly done in Windows Forms (MFC, VCL, OWL, HTML, Ajax, you name it), so we don’t need this disgusting Silverlight”. And it is hard to argue against it as nothing absolutely new can be created – as musicians blamed for plagiarism say “There are only seven notes”. Power of Silverlight UI Framework is not in the ability to design incredible pile of effects and animation, but in the simplicity and lightning speed of implementation of sophisticated scenarios.

And today I have a vivid sample. In practice, there often appears a necessity to use a hybrid control joining functionality of the TreeView and DataGrid components, i.e. of the tree representing information by each item in several columns with all abilities characteristic to table view: changing columns by a single mouse movement, sorting upon a click on the column title, editing cell content etc. For example, such control is an essential part of the interface of any mailer: Outlook Express, Windows Mail, Mozilla Thunderbird.

And I needed such a control when decided to create an on-line message board to represent message chains in the thread.

If you are a Windows Forms developer and face the requirement to use this control – this is a bad luck. Most likely you will have to buy special third party library – standard toolbox doesn’t include such control, and independent development will take several hundreds of men hours.

But if you use Silverlight your life will be much easier. Combination of mechanisms of templates and data binding makes it possible to turn an ordinary DataGrid to such control in minutes.

To do it, we need to create a data source making hierarchical structure be flat list.

Such data source creates a wrapper around each element and its Level and IsExpanded properties serve to display correct shift and state of each element in the original hierarchy.

public sealed class GridTreeDataSource
{
public GridTreeDataSource(IList originalSource, Func<object, IList> getChildren)
{
OriginalSource = originalSource;
GetChildren = getChildren;
Source = new ObservableCollection<GridTreeDataItem>();
FillWithGridTreeItems(Source, OriginalSource, 0);
}
public IList OriginalSource { get; private set; }
private Func<object, IList> GetChildren { get; set; }
public ObservableCollection<GridTreeDataItem> Source { get; private set; }
private void FillWithGridTreeItems(IList<GridTreeDataItem> destinationCollection, IList sourceCollection, int level)
{
foreach (object item in sourceCollection)
{
GridTreeDataItem treeItem = new GridTreeDataItem(item, this, level);
treeItem.IsVisible = (level == 0);
destinationCollection.Add(treeItem);
IList list = GetChildren(item);
if (list != null)
FillWithGridTreeItems(treeItem.Children, list, level + 1);
}
}
internal void NotifyIsExpandedChanged(GridTreeDataItem item)
{
if (item.IsVisible)
{
if (!item.IsExpanded)
{
RemoveChildren(item);
}
else
{
int index = Source.IndexOf(item);
AddChildren(item, ref index);
}
}
}
private void AddChildren(GridTreeDataItem element, ref int index)
{
foreach (var item in element.Children)
{
Source.Insert(++index, item);
item.IsVisible = true;
if (item.IsExpanded)
{
AddChildren(item, ref index);
}
}
}
private void RemoveChildren(GridTreeDataItem element)
{
foreach (var item in element.Children)
{
Source.Remove(item);
item.IsVisible = false;
RemoveChildren(item);
}
}
}
public class GridTreeDataItem : INotifyPropertyChanged
{
internal GridTreeDataItem(object item, GridTreeDataSource owner, int level)
{
Item = item;
Owner = owner;
Level = level;
}
public GridTreeDataSource Owner { get; private set; }
public object Item { get; private set; }
public int Level { get; private set; }
public bool IsVisible { get; internal set; }
private bool isExpanded = false;
public bool IsExpanded
{
get
{
return isExpanded;
}
set
{
if (value != isExpanded)
{
isExpanded = value;
RaisePropertyChanged(“IsExpanded”);
Owner.NotifyIsExpandedChanged(this);
}
}
}
private List<GridTreeDataItem> children = new List<GridTreeDataItem>();
public List<GridTreeDataItem> Children
{
get
{
return children;
}
}
public bool HasChildren
{
get
{
return Children.Count > 0;
}
}
#region INotifyPropertyChanged Members
protected void RaisePropertyChanged(string name)
{
OnPropertyChanged(new PropertyChangedEventArgs(name));
}
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventHandler temp = PropertyChanged;
if (temp != null)
{
temp(this, args);
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}

As you see, here are only 150 lines of trivial code. (And there could be even less if I wasn’t a follower of the formatting style when each curly bracket takes a separate line :) ).

Then substitute template for the first table column using the designed structure as a data source:

<data:DataGrid x:Name=”dataGrid” AutoGenerateColumns=”False” IsReadOnly=”True” CanUserSortColumns=”False”>
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Header=”Ex”>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation=”Horizontal” Margin=”{Binding Level, Converter={StaticResource mc}}>
<ToggleButton x:Name=”ExpanderButton” IsChecked=”{Binding IsExpanded, Mode=TwoWay}
Visibility=”{Binding HasChildren, Converter={StaticResource vc}}
VerticalAlignment=”Center” IsTabStop=”False” TabNavigation=”Once” Margin=”2″ Template=”{StaticResource btnTemplate}/>
<TextBlock Text=”{Binding Item.Name}VerticalAlignment=”Center”/>
</StackPanel>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTextColumn Binding=”{Binding Item.Num}Header=”Num”/>
</data:DataGrid.Columns>
</data:DataGrid>

And this is it! TreeGrid can be used! The result looks like that.

To make it understandable and more obvious, I simplified this implementation a little; the sample is not ideal as it comes to performance and it doesn’t include functions for manipulations over the tree, such as ExpandAll etc. But the main point is that this code is taken from the real application. Prototype of this project is being tested at the moment and you can make sure that it really works.

You can download source code of this sample and use it for examination and in your applications.

If you have any questions or comments, please feel free to contact me directly at eugene@perpetuumsoft.com

kick it on DotNetKicks.com

March 12th, 2010

Print Reporting Services reports from Silverlight Applications!

Eugene Akinshin

Are you a developer? I’m sure you are. So don’t turn and go away! You knocked at the right door! In this article I’m going to talk about your problems and your concerns. And, by the way, where you address yourself if you have ones? I have no doubts that the only place where you can share your worries and difficulties is developer forum. There you can ask all the necessary questions connected with the most important problems giving braking effect to your software development process. And neither any software company nor Perpetuum Software LLC in particularly can stop paying attention to frequent queries regularly appearing in the posts of forum members. So how Perpetuum Software LLC can help inquisitive developers? Let’s start our Q&A session.
 
Q: Is there a tool intended to work with Reporting Services reports in Silverlight on the software development market?
A: Actually, this question can be seen on the forums devoted to Silverlight technology. Perpetuum Software offers you a unique Silverlight Viewer for Reporting Services. This is the first product on the market which allows developers to display Reporting Services reports directly in Silverlight applications. It’s a true Silverlight control easily integrated into any Silverlight application and an up-to-date solution on the base of two powerful technologies: MS SQL Reporting Services и Silverlight 3.0.
 
Q: What advantages does MS SQL Reporting Services 2005 give to developers and end-users?
A: Once I saw the funniest but at the same time the only possible answer: Great). Probably, the member of the forum who wrote this was quite right. Today SSRS is one of the most widely used components for report creation. This can be explained by the large list of advantages among which are higher developer’s productivity and more opportunities for end-users control. Silverlight Viewer for Reporting Services developed by Perpetuum Software LLC is created on the base of SSRS. It allows developers to use all the advantages of this technology.
 
Q: Is it possible to print reports from Silverlight?
A: At first sight the absence of printing ability in Silverlight 3.0 makes it an impossible thing. That’s why experienced developers may simply ignore this question. But a new version of Silverlight Viewer for Reporting Services 1.1 solves this problem of paramount importance. Printing Reporting Services reports from Silverlight viewer became possible. Now you can print any report you need without applying unnecessary efforts and exporting to other formats. Everything you need is to press printing button.
 
Q: Can I view reports in Silverlight without referring to MS SQL 2005 Reporting Service server?
A: Of course, you can! With a new version of Silverlight Viewer for Reporting Services 1.1 you get an ability to work with reports created in MS SQL RS without setting MS SQL RS server. Now end-users can just open Silverlight viewer and start enjoying their work with reports.
 
As you see a new version of Silverlight Viewer for Reporting Services 1.1 is able to help developers to solve many disturbing problems. Now the whole set of abilities used in desktop applications, out-of-browser mode, extended report abilities: PDF, Excel, Cvs, Xml, Mhtml, TIFF and advanced Html export are at their disposal.
It’s an open secret that Silverlight Viewer for Reporting Services 1.1 is a confident step on the software development market of corporate reporting systems. So why not avoid vain efforts and use the best?! Who knows, may be in this case you won’t post on forums…
 
On-line demo is available…

October 22nd, 2009

Poor Internet Application, Rich Internet Application

Eugene Akinshin

What’s the buzz (word)? Tell me what’s happening?

«The computer industry is the only industry that is more fashion-driven than women’s fashion» – Larry Ellison, CEO of Oracle likes to say. And you can’t but agree when year from year you see that some promising technologies don’t fulfill promises and consign to history; they are forced out from the pages of IT journals and blogs by other even more promising ones. In this season Software as a Service, Cloud computing, Rich Internet Applications (RIA), and Web 2.0 (I need to mention that the last term is going out of date) are of current interest. The meaning of all these mysteries words generally comes to the fact that main part of the application is executed on the server side and the end user gets access to all necessary functionality via the internet browser.
 
What the hell, excuse my French, do we need all those RIAs, SaaS and other WebTwo’s for? Are we doing badly without them? Aren’t normal desktop apps more convenient and efficient; don’t they fulfill the same functions much better without being dependant on internet connection? And in general, isn’t it a regress to the mainframes epoch with powerful servers and weak terminals? Absolutely, but I should accept that up-to-date applications have some disadvantages that became extremely evident since the broadband access to Internet is available virtually everywhere. And here are some of them.
(more…)

October 7th, 2009