Showing posts with label dotnet. Show all posts
Showing posts with label dotnet. Show all posts

2007-10-15

The naked object

Consider a forest with birds singing in the trees and flowers covering its floor. We caneasily walk
along its paths or you can be adventurous an make your own paths. We can
select any aspect of its complex
ecosystem and study it for your doctoral thesis. There is
unlimited complexity, yet any human can
master it to suit his or her purposes. There is no
reason why a computer system should be more
complex than a forest. I believe that the
current complexity is man-made, and that we can
resolve it by changing our approach to
software development. We merely need to get our priorities right and create
the appropriate
tools. If we decide to build systems for people, then we will get systems tha can be mastered by people.
Trygve Reenskaug In the foreword to Naked objects R. Pawson Phd Thesis


An approach offered by creators of Naked objects framework looks very interesting, at least for the quick prototyping. Refuse, auto generation of UI, return to the OO basis - full-fledged objects with considerable behavior.

A big advantage is that the interaction with user happens by the most usual noun-verb script. IMHO, only Raskin zoom interface is required to be absolutelly happy. And for the convenient navigation on great number of open objects something like Leap is needed.

In web implementation from the outside it's very similar to like Django admin interface interface, in full-fledged GUI clients interface is much more interesting.

Update 18.10.2007: Naked objects discussing at ltu
Update 29.10.2007: Martin Fowler's article with the critique of objects without behavior and a critical response to it in some blog.

2007-10-05

I believe

With simple, consistent code, change analysis is a breeze. A simple trace through the layers of code with a text-search tool will generally reveal exactly what needs to be changed, and where. A solid test plan will identify what changes broke the system and how, and allow developers to respond appropriately.

No, it’s not fun and not challenging. It’s just good software


http://de.worsethanfailure.com/Articles/The-Mythical-Business-Layer.aspx

2007-08-29

What the fun??

I do not understand.

Why in NUnit and in new Junt instead of simplest agreements of tests naming attributes and annotations are used. All the same, it's very difficult to give more suitable names to SetUp, TearDown and TestSomething methods.

It's hard to agree with an opinion that it's more clear in such a way
[SetUp]
public void SetUp() {}


Class attribute instead of the inheritance from TestCase is great. Now the free place of ancestor a class being tested can get. This is for a case of protected stuff is desired to be tested.

Yes, if in a base class suddenly there are methods which names start with Test and which are not tests themselves then indeed needed things can be selected only with explicit attributes. But this is such a rare case...

P.S. Many other things related to testing I consider are better to implement with attributed.

2007-08-24

Not a day without a bug - ContextMenuStrip appears after second click

A hot flood happens on rsdn - Property in С# - is it bad or good.

Here is a bug to piggy bank of opponents of syntactic sugar:

If in ContextMenuStrip initially there are no elements and during handling event Opening add an element but do not set e.Cancel = false then on the first click menu will not appear.

And this is in spite of e.Cancel is set to false by default. Exactly this stupid row in the sample from Microsoft is tend to be ignored by many people.

P.S. Yesterday there was a bug also, but it was in Spring.Net 1.1 M2. The version number and open source allows to close one's eyes to it...

Update 29.08.2007 By hook or by crook: A small sample how to by means of a couple of strings of code and a small helper class to test properties behavior.

2007-08-21

Not a day without a bug

One more evident blunder. In DataGridView there is Russian text, I select everything, copy and paste to в Excel - instead of the text I see hieroglyphs.

The problem again is quite famous. It's amazing that a correct solution "out of the box" has not been googled at once, just common advices - "look here, look there".

Though indeed just coding of a text, putting into the clipboard should be indicated right.

private void dataGridView_FixCopyEncoding_OnKeyUp(object sender, KeyEventArgs e)
{

DataGridView dataGrid = sender as DataGridView;
if (dataGrid != null && (e.KeyCode == Keys.Insert
|| (e.Control && e.KeyCode == Keys.C)))
{
if (dataGrid.GetCellCount(DataGridViewElementStates.Selected) > 0)
{
string content = dataGrid.GetClipboardContent().GetText();
Clipboard.SetText(content, TextDataFormat.UnicodeText);
}
}
}

If somebody wishes to make a little bit more correct of course it is better to inherit and redefine DataGridView.GetClipboardContent().


I was very surprised when saw that on RightCtrl-Insert press two messages come instead of one. The first is e.Control == false && e.KeyCode = LButton | ShiftKey and the second is e.Control == false && e.KeyCode = Insert.

2007-08-20

Right click on treeview

I've triggered a backflash and surprised. Either I do not understand something or it is indeed a banal blunder in Treeview from WinForms.

On right mouse click context menu appears but tree node has not become selected. I've found one more similar complaint

It seems to be generally accepted behavior - right click and the selection moved to a node under the mouse and the menu appeared. The most interesting thing is that in Visual Studio it works exactly so.

Well, dumb fix:
private void treeView_MouseClick(object sender, MouseEventArgs e)
{

if (e.Button == MouseButtons.Right)
{

TreeNode node = treeView.GetNodeAt(e.X, e.Y);

if (node != null)
{
treeView.SelectedNode = node;

}
}
}


Update: 24.08.2007 And it is much better to tie the bug fix to NodeMouseClick

2007-08-10

C#: Generic type conversion

I've come across a strange restriction of generic in C#. The only good thing is the most problems appear  during programming the popular language are solved by a second query to google.

Because of the error "Cannot convert type 'string' to 'T'" instead of the evident:

do so
public static T GetSetting<T>(string key)
{
   return (T)ConfigurationManager.AppSettings[key];
}

write like this:

public static T GetSetting<T>(string key) where T : IConvertible
{
   return (T)Convert.ChangeType(ConfigurationManager.AppSettings[key], typeof(T));
}





Update 13.08.2007: And in addition, in spite of autoboxing the problem with simple type arrays is remained. If we have variable of type Object which stores array of strings that one can easy get n value with explicit cast, everything has become more interesting with array of integers:

[Test]
public void testCastArray()
{
Object object_arr = new String[] { "a", "b", "c" };
Object[] object_arr_cust = (Object[])object_arr;
Assert.AreEqual(object_arr_cust[1], "b");

Object value_arr = new Int32[] { 1, 2, 3 };
Array value_arr_cust = (Array)value_arr;
Assert.AreEqual(value_arr_cust.GetValue(1), 2);
}

[Test]
[ExpectedException(typeof(InvalidCastException))]
public void testInvalidArrayCast()
{
Object value_arr = new Int32[] { 1, 2, 3 };
Object[] value_arr_cust = (Object[])value_arr;
Assert.AreEqual(value_arr_cust[1], 2);
}

2007-08-07

DateTimePicker and nullable value

Is it really that the simplest solution of bringing closer together DataBinding and nullable types is to change a behavior of a control itself?


class NullableDateTimePicker : DateTimePicker
{
[Bindable(true)]
public object DBValue
{
get
{
if (this.Checked)
return base.Value;
else
return System.DBNull.Value;
}
set
{
if (System.Convert.IsDBNull(value))
this.Checked=false;
else
this.Value = Convert.ToDateTime(value);
}
}
}

Though in the ideal case it should be solved at the databinding level instead of the custom control.

2007-07-13

Unsecure by design

Avoiding Connection String Injection Attacks
A connection string injection attack can occur when dynamic string concatenation is used to build connection strings based on user input. If the string is not validated and malicious text or characters not escaped, an attacker can potentially access sensitive data or other resources on the server. For example, an attacker could mount an attack by supplying a semicolon and appending an additional value. The connection string is parsed using a "last one wins" algorithm, so the hostile input would be substituted for a legitimate value.
msdn


And why rational escaping mechanism is not provided for every eventually? It's all the same impossible to specify any symbol in the password.

using Oracle.DataAccess.Client;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
System.Data.OracleClient.OracleConnectionStringBuilder builder =
new System.Data.OracleClient.OracleConnectionStringBuilder();
builder.DataSource = "dev";
builder.Pooling = false;
builder.UserID = "user";
builder.Password = "a\"';1234";
OracleConnection connection = new OracleConnection();
connection.ConnectionString = builder.ConnectionString;
connection.Open();
}
}
}

2007-07-11

Links: Powershell in action

I like to study script languages possibilities not from books with artificial samples but during digging real files. More associations remain in memory.

The main thing in the automation is just to remember such a possibility in a right moment.

An interesting article in MSDN Magazine - Light testing with Windows PowerShell

2007-04-20

There is only one right include strategy

There is only one right way of the implementation of searching of included files. In case if include contains a relative path it should be relative to the folder where the inclusive file is placed. Actually, it is so in C/C++.

Either I do not understand something, or Nant has surprised me
Let's take the following folders structure:

./
a/
a.build
all.build
common.build

I'd like to build project «a» if I'm located at folder «a» and if I'm in the root I'd like to build all projects.
The situation has become complicated because of the common file common.build which contains required useful settings.

At a first sight nant includes files relative to a current working directory (basedir project attribute)

The contents of a.build file

<project name="all" basedir="..">
<include buildfile="common.build"/>
<echo message="building a type - ${type}"/>
<echo message="base-dir ${project::get-base-directory()}"/>
</project>


The contents of all.build file

<project name="all" basedir=".">
<include buildfile="common.build"/>
<include buildfile="a/a.build"/>
<echo message="building all type - ${type}"/>
</project>


Run a.build being in folder a - everything is cool.

Being in the folder with the file all.build - run:

NAnt 0.85 (Build 0.85.2478.0; release; 14.10.2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///D:/Temp/2007-04-19/all.build
Target framework: Microsoft .NET Framework 2.0


BUILD FAILED

D:\Temp\2007-04-19\a\a.build(3,7):
Build file 'D:\Temp\2007-04-19\a\common.build' does not exist.

Total time: 0 seconds.


I have the impression that files included in the main file are searched relative to the working directory, but the files included into included files are searches relative to the inclusive file.

2007-04-06

Generic Visitor Combinators

It's simple and practical - Visitor Combination and Traversal Control.

The main idea is to separate specific code that executes concrete actions from the code that effects visits check.








IdentyDo nothing
Sequence(v1,v2)Sequentially perform visitor v2 after v1.
FailRaise exception.
Choice(v1,v2)Try visitor v1. If v1 fails, try v2 (left-biased choice).
All(v)Apply visitor v sequentially to every immediate subtree.
One(v)Apply visitor v sequentially to the immediate subtrees until it succeeds.


So, it's rather flexible to implement different actions by combine it and inherit from it.


TopDown(v) = def Sequence(v,All(TopDown(v)))
BottomUp(v) = def Sequence(All(BottomUp(v)),v)
IfZeroAddOne = def TopDown(Try(Sequence(IsZero,AddOne)))

2007-03-12

PowerShell - The first one object(!) shell


...Microsoft Exchange Server 2007 where everything is done via command line interfaces and the administrative GUI is layered on top of those commands.
Wikipedia


Came across it by accident.
get-process | where { $_.WS -gt 1000MB } | stop-process

It's beautiful... now through pipes goes not only just text but full-fledged .NET objects, anytime and everywhere one can easily get access to a required object field. Farewell, sed and awk.

Killer feature - the possibility of creation and trying COM-object just in interpreter.
$a = New-Object -comobject Excel.Application
$a.Visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "A value in cell A1."
$b.SaveAs("C:\Scripts\Test.xls")
$a.Quit()

It makes me glad that methods autocompletion works.

According to one's choise any .net build can be loaded.
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$d = [Windows.Forms.MessageBox]::Show("msg")

Аnd one can send e-mail
$Attach     = new-object System.Net.Mail.Attachment("C:\Test.txt")  
$SMTPClient = new-object System.Net.Mail.SMTPClient
$Msg = new-object System.Net.Mail.MailMessage

$Msg.Attachments.add($Attach)
$Msg.To.Add("BillGates@Microsoft.Com")
$Msg.from="Vasya.Pupkin@Mail.Ru"
$Msg.Subject="Subject"
$Msg.Body="This is body of E-Mail"

$SMTPClient.Host="SMTP.Mail.Ru"

$SMTPClient.Send($Msg)

There is a simple auto-completion of paths. There is even Far plug-in

In short, it's a practical thing for those on Windows.

I'm curious, if there were some tries of objects extension of shells under *nix?

2006-10-11

Asta la Vista, baby

We visited Microsoft event «Developer days 06» organized in Novosibirsk. The registration, six presentations, two coffee breaks, one dinner. In short, had a good time.

In the beginning I swore and wanted to describe in details all bugs of Vista and the new framework but all my records a lost because of an error occurred in Windows Mobile 2003.
Therefore short and calm.

The 1st presentation — Asta la Vista, baby
Microsoft Windows Vista и Microsoft Office 2007

For no purpose they presented Vista on week laptop (1 Gb RAM, embedded video intell). Constantly winked cursor spoiled the impression. Presentation of automatic killing a program using too much system resources failed, system rebooted.

The support of file versioning is embedded. There is still no answer for the following question. A file of version 1 was changed and saved, got the version 2, then rolled back. How to get back to the version 2?

Will I whether bind it on Linux? Trace by gamin changes in Document folder and automatically call svn commit. Plus bookmark module to Nautilus — to show versions and roll back.

In spite of extended possibilities of documents searching speakers did not use it, preferring searching in folders in the old ways.

IMHO Explorer has become overdriven with features, they managed to demonstrate the magic possibility of documents preview only after a little hitch and searching in menus. But these all are little fault findings.

Standard games are roolez. Very beautiful.

There is an embedded possibility of limitation of computer using for concrete user. One can switch on spying on visited sites and messager logs. Everything is for parents to control their child activities. Asta la vista, baby.

There was no time for the new Office demonstration, they casually mentioned that now Office supports formulas in TeX format, but it was not lead to a response from the audience. Those who knows TeX raised hands, it was 3 or 4 persons.

The 2nd presentation - continuous integration
Microsoft Visual Studio Team System for Database Professionals

Microsoft has discovered America one more time. There is a chance that now a lot of developers will join to the rational style of databases development, continuous integration, version control, automate testing. So far a tool there is for MSSQL only and has bugs as it is properly for beta, but I think that somebody will soon take advantage of the opportunity for Oracle. That's another story that the approach is quite famous and IMHO it needs a special tool only for decreasing enter threshold.

The 3-d presentation — integrators, do not sleep!
Windows Communication Foundation

I've always been interested why the functionality embedded to BPEL is not implemented as a library. Well, Microsoft just did it, very elegant from the first look — xml + attributes. As opposed to BPEL there is a possibility not to tie to web services and to chose an interaction protocol and even partially manage pieces of message header/body. I see so that one can use sessions support implemented in the protocol itself that's again very pleasant in opposed to BPEL.

In case of .Net<->.Net interaction it makes sense to choose one from binary protocols from the default set. For example, for a local interaction take named pipes and easy implement analogue of GStreamer.

Let me guess, just now somebody is implementing connectors to these new 4th protocols for Java.


The 4th presentation — creating monsters
Windows Presentation Foundation

Yes, XAML can totally change an application appearance simple tag turns into amusing puzzle, if to use image of rotated cube instead of the usual picture. Monsters scaring users by their look and behavior now can be implemented even more faster. Though in web peoples have got accustomed to it and very notable solutions are met. It is good that layouts by hook or by cook have appeared in .NET.

The 5th presentation - drm?
Windows CardSpace

A new unified standard of shared authentification and authorization. The speaker read me to sleep. To whom in first place is profitable this unification? To DRM? Safety of online payments will increase? Hm... There is still no answer how and where in the system is storying all information about user and how difficult to stole it.


The 6th presentation — own workflow again.
Windows Workflow Foundation

I wonder that did not sound buzzwords bpel, bpmn, bpm. Paint yet another xml format, compile and host. There is still no answer how to change workflow dynamically. What will happen with the current state of business processes? Is it possible to organize work of several versions of one workflow simultaneously? For example, to let old processes to finish in the old way.

The demonstration of dynamic garbage collector paradigm from Microsoft as an example of coffee break and waiters.
garbage collector

2006-07-25

MFC vs WinForms vs SWT

All that you need to know to embed an Office application into:

MFC
http://www.rsdn.ru/article/com/xoffice.xml and http://www.rsdn.ru/article/com/autoatl.xml
two articles in about 10-12 pages - beat in a drum to adjust a project


WinForms
http://blogs.gotdotnet.ru/personal/k_savelev/PermaLink.aspx?guid=6d39ad7d-d1ae-4daf-8ce2-9b881ca7091a
A heap of links, ready external component and therefore a little headache when installing application to client


SWT
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/WordOLE.htm
a couple strings of code and everithing works from the box