Saturday, September 22, 2007
As Keyword in C#
What is the different between explicitly cast ?
string str = (string) Request["nullSession"];
string str = Request["nullSession"] as string;
Both of them return the same (NULL)...
However probably, I will stick with my casting style because
1. It confused me when I need to convert from C# to VB
2. I can not using as keyword to replace
(int) 123.23 where I expect to get 123 as integer
----
123.21 as int
//throws The as operator must be used with a reference type ('int' is a value type)
123.21 as int16
//throws The as operator must be used with a reference type ('short' is a value type)
123.21 as double
//throws The as operator must be used with a reference type ('double' is a value type)
Saturday, September 8, 2007
JSON AJAX Localization
There is several way... to implement localization your web content in the client..
you either create a control and attached those assembly to your web site...
or just use... JSON object...
My preference is using JSON ( Javascipt Object Notation)....
* Create.. JSON Resource JS file for each.. languange...
Resource.js
MyReourceText={
"HeaderTitle":"Hello World",
"FooterText":"CopyRight By Kurniawan"
}
Resource.fr.js
MyReourceText={
"HeaderTitle":"Header Title in France",
"FooterText":"CopyRight By Kurniawan in france"
}
* Create.. UpdateResource js - this script will update your content use specific localize language.
Note:
-saperate this file from Resource.js...so you will not duplicate your code
UpdateResource.js
Sys.Application.add_load(SetupForm);
function SetupForm()
{
$get('HeaderTitle').innerText = MyReourceText.HeaderTitle;
$get('FooterText').innerText = MyReourceText.FooterText;
}
* In your aspx... add enable EnableScriptLocalization="true" in your ScriptManager
This will enable the
* Add those script reference into your script Manager
<asp:ScriptReference Path="Resource.js" ResourceUICulture="fr" />
<asp:ScriptReference Path="UpdateResource.js" />
**** THAT'S ALL ****
You may change your language from the browser or
from the your own control.... by using this...
System.Threading.Thread.CurrentThread.CurrentUICulture =
System.Globalization.CultureInfo.CreateSpecificCulture(cmbLang.SelectedValue);
and you can get the current language from your browser when not postback
cmbLang.Items.FindByValue(System.Threading.Thread.CurrentThread.
CurrentUICulture.TwoLetterISOLanguageName).Selected = true;
****
You may enable globalization.. to formating your date / currency into specific languange../ culture...
by activate EnableScriptGlobalization = "true" in Script Manager...
You can use
d.localeFormat("dddd, dd MMM yyyy");
****
Thursday, September 6, 2007
XAML ???
It extends for Extendsible Application Markup Language.
ZAMMEL is Xml based language to define object and their properties ...
It focused on UI for WPF/E (Windows Presentation Foundation/Everywhere)
You may check out Silverlight to begin with XAML.
Here is the Zammel Sample
<
<
Note:
* Xaml is different with WPF - Xaml is Xml based Markup
WPF is a graphics API
* XAML also supports things like 3D and controls, which SVG does not. It's different from SVG
* Saparate Design and Development
F# ???
Functional language ???
Why do we need to learn that language ???
So far I know... this language is meant to be more mathematical at heart, and thus creates more separation between the lower level machine details and the developer's code.
functional programming is supposed to be a "higher level" of programming than Java or C.
#light
(* Sample Windows Forms Program *)
(* We need to open the Windows Forms library *)
open System.Windows.Forms
(* Create a window and set a few properties *)
let form = new Form(Visible=true, TopMost=true, Text="Welcome to F#")
(* Create a label to show some text in the form *)
let label =
let temp = new Label()
let x = 3 + (4 * 5)
(* Set the value of the Text*)
temp.Text <- x
(* Remember to return a value! *)
temp
(* Add the label to the form *)
do form.Controls.Add(label)
(* Finally, run the form *)
do Application.Run(form)
Generic.Dictionary Serializable ?
One of the implication is when you put your dictionary in the session of Asp.net...
You will get problem... You will get an error when serializer run and
try to get your session ship out of your web service....
Here is the code... to
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
[XmlRoot("dictionary")]
public class DictionarySerializable
: Dictionary
{
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
if(reader.IsEmptyElement) return;
reader.Read();
while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
{
reader.ReadStartElement("item");
reader.ReadStartElement("key");
TKey key = (TKey)keySerializer.Deserialize(reader);
reader.ReadEndElement();
reader.ReadStartElement("value");
TValue value = (TValue)valueSerializer.Deserialize(reader);
reader.ReadEndElement();
this.Add(key, value);
reader.ReadEndElement();
reader.MoveToContent();
}
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
foreach (TKey key in this.Keys)
{
writer.WriteStartElement("item");
writer.WriteStartElement("key");
keySerializer.Serialize(writer, key);
writer.WriteEndElement();
writer.WriteStartElement("value");
TValue value = this[key];
valueSerializer.Serialize(writer, value);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
#endregion
}
Get bored with Web Service ???
Yeah... Probably... It has been too old for us....
Check it out Microsoft Astoria - Data Service....
http://astoria.mslivelabs.com
You may try to deploy your database into Web Data Service
It is also supported by ASP.NET Futures (May 2007)
Iron Phyton with ASP.Net Futures
* Restrict your column...
def GetColumns() :
return ["Column1","Column2",....]
* Add your custom column
def GetColumns() :
return ["Column1","Column2",....
["My Custom Column", lambda: "%s (%s)" % (Column3, Column4)]
]
* Rule level formating for your view
From System.Drawing import Color
def InitRow(row):
if "myKeyword" in Column1 :
row.BackColor = Color.Green
How easy it is ????