DCSIMG
July 2007 - Posts - I Love C#
Sign in | Join | Help

I Love C#

Eyal Vardi

July 2007 - Posts

AJAX Controls and Samples Overview FREE

פורסם בתאריך Jul 28 2007, 02:55 AM על ידי Vardi

The Controls section contains examples of the individual Toolkit controls. The controls are demonstrated and their properties described. Relevant additional information and code snippets are also included.

Note: As detailed in the Architecture section, the Toolkit contains both WebForms and WinForms controls. While this Website demonstrates the WebForms controls, you need to install the Toolkit from CodePlex to access the WinForms controls.

http://www.mscui.net/ControlsAndSamples.aspx

XAML דינמי עם WPF

פורסם בתאריך Jul 27 2007, 08:42 AM על ידי Vardi

בהמשך לפוסט הקודם שלי אני רוצה לעביר את כל מה שעשיתי עם LINQ ל- Custom Control כך שנוכל
להשמש בפונקציות ב- XAML.  (ניתן להוריד את הדוגמאות וה- Controls  כאן.)

להלן מספר תמונות לדוגמא שנוצרו מ - Picture Language:

p1

p2

p3 p4

דגמאות עבודה עם ה- Controls:

1. אוסף קישור ל - E4DAPI.DLL.

2. דוגמא פשוטה של Beside.

<Page x:Class="E4DTest.Demos.Below"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Below"
    xmlns:E4D="clr-namespace:PictureLanguage;assembly=E4DAPI">

    <Grid>
       <E4D:Below Name="Below1">
<!-- Put your element (UIElement) --> <
Image Name="ImageE" Source="../Images/E4D.png" /> </E4D:Below> </Grid> </Page>

3. דוגמא של FlippedPairs

<Page Title="FlippedPairs"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:E4D="clr-namespace:PictureLanguage;assembly=E4DAPI" 
    x:Class="E4DTest.Demos.FlippedPairs" >

    <Grid>
      <E4D:FlippedPairs Name="fp">
<!-- Put your element (UIElement) --> <E4D:CornerSplit Name="cs" ReapetNumber="3">
<!-- Put your element (UIElement) --> <Image Source="..\Images\E4D.png" Stretch="Fill"/> </E4D:CornerSplit> </E4D:FlippedPairs> </Grid> </Page>

 4. אפשר לעבוד עם Controls גם ב-Belnd :

Belnd_Beside

Belnd_Spine_Beside

כרגע ה- API עובד על דוט-נט 3.5 בעתיד אני אשחרר גירסה ל- Silverlight ודוט-נט 3.0.

כאשר LINQ פוגש את WPF

פורסם בתאריך Jul 22 2007, 08:26 PM על ידי Vardi

במרכז הבין תחומי הכרתי לראשונה את SCHEME והתאהבתי. בפוסט זה אני מנסה להמחיש את התיכנות הפונקציונאלי ע"י תמונות. החומר מבוסס על העיונות מהספר Structure and Interpretation of Computer Programs.

המטרה ליצור תמונות בפונקציות רקורסויות, לדוגמא:

image image

פתרון:

1. נגדיר את הפונקציות הבסיס:

  • Below
    image 

    public static UIElement Below( this UIElement source )
    {
                UIElement cloned = source.Clone();
                return Below( source, cloned );
    }
    public static UIElement Below( this UIElement source, UIElement element )
    {
                Grid g = new Grid();
                RowDefinition r1 = new RowDefinition ();
                r1.Height = new GridLength ( 0.5 , GridUnitType.Star );
                RowDefinition r2 = new RowDefinition();
                r2.Height = new GridLength ( 0.5 , GridUnitType.Star );
                g.RowDefinitions.Add( r1 );
                g.RowDefinitions.Add( r2 );
                g.ShowGridLines = ShowGridLines;
                g.Children.Add( source );
                g.Children.Add( element );
                Grid.SetRow( source, 0 );
                Grid.SetRow( element, 1 );
    
                return g;
     }

  • Beside
    image
    public static UIElement Below( this UIElement source )
    {
                UIElement cloned = source.Clone();
                return Below( source, cloned );
    }
    public static UIElement Below( this UIElement source, UIElement element )
    {
                Grid g = new Grid();
                RowDefinition r1 = new RowDefinition ();
                r1.Height = new GridLength ( 0.5 , GridUnitType.Star );
                RowDefinition r2 = new RowDefinition();
                r2.Height = new GridLength ( 0.5 , GridUnitType.Star );
                g.RowDefinitions.Add( r1 );
                g.RowDefinitions.Add( r2 );
                g.ShowGridLines = ShowGridLines;
                g.Children.Add( source );
                g.Children.Add( element );
                Grid.SetRow( source, 0 );
                Grid.SetRow( element, 1 );
    
                return g;
    }

    מה קיבלנו?
    UIElementimage
         .Beside()
         .Below()
     שימו לב שיש ליצור CLONE כדי שנוכל לעבוד עם אותו UIElement במספר מקומות שונים בעץ.
    לשם כך יש לכתוב את הפונקציה CLONE הבאה:

  • private static UIElement Clone( this UIElement source )
     {
                string clon = XamlWriter.Save( source );
                UIElement cloned = (UIElement)XamlReader.Load(
                    XmlReader.Create( new StringReader( clon ) ) );
                return cloned;
    }

  • right-split n
     The image “http://mitpress.mit.edu/sicp/full-text/book/ch2-Z-G-36.gif” cannot be displayed, because it contains errors.


    public static UIElement RightSplit( this UIElement source, int n )
    {
                if( n == 0  || n < 0 )
                    return source.Clone();
    
                UIElement smaller = RightSplit( source, --n );
    
                return Beside( source.Clone() , smaller.Below() );
     }image
    // Use It
    UIElement
    .RightSplit(4);

 
  • corner-split n

      

public static UIElement CornerSplit( this UIElement source, int n )
 {
            if( n == 0 || n < 0 )
                return source.Clone();

            int s = n - 1;

            UIElement up          = UpSplit( source, s );
            UIElement right       = RightSplit( source, s );
            
            UIElement topLeft     = up.Beside();
            UIElement bottomRight = right.Below();
            
            UIElement corner      = CornerSplit( source, s );
            
            return
                Beside( Below( source.Clone(), topLeft ),
                        Below( bottomRight, corner ) );
}
image 
// Use It
UIElement
.CornerSplit( 4 );
 


 
  • Flipped Pairs
    למקצעונים בלבד !!!
// func that create func base on 4 funcs.
public
static Func< UIElement , UIElement > SquareOfFour( Func<UIElement,UIElement> tl, Func<UIElement,UIElement> tr, Func<UIElement,UIElement> bl, Func<UIElement,UIElement> br ) { return delegate( UIElement p ) { UIElement top = Beside( tl( p ), tr( p ) ); UIElement bottom = Beside( bl( p ), br( p ) ); return Below( top, bottom ); }; } public static UIElement FlippedPairs( this UIElement source ) { var func = SquareOfFour(
tr => tr.FlipV().FlipH() , tl => tl.FlipV(), FlipH, bl => bl.Clone() ); return func( source ); }
image 
// Use It
UIElement
   .CornerSplit( 4 )
   .FlippedPairs();
  • Spine
      
    public static UIElement Spine( this UIElement source, int n, int angle )
    {
       return source.Spine( new Grid(), n, angle, 0.5, 0.5 );
    }
    public static UIElement Spine( this UIElement source, 
    int n, int angle, double x, double y ) { return source.Spine( new Grid(), n, angle, x, y ); } public static UIElement Spine( this UIElement source, Panel panel,
    int n, int angle, double x, double y ) { if( n > 0 ) source.Spine( panel, --n, angle ,x , y ); if( n == 0 ) { panel.Children.Add( source.Clone() ); return panel; } panel.Children.Add( source.Rotate( angle * n , x , y) ); return panel; }
    public static UIElement Rotate( this UIElement source,
    int angle, double x , double y ) { UIElement e = source.Clone(); e.RenderTransformOrigin = new Point( x, y ); TransformGroup tg; if( e.RenderTransform is TransformGroup ) { tg = e.RenderTransform as TransformGroup; } else { tg = new TransformGroup(); } tg.Children.Add( new RotateTransform( angle ) ); e.RenderTransform = tg; return e; }


    image

    // Use It

    UIElement
    .Spine( 36 , 10 , 0.5 , 0.5 );


אפשר להוסיף פונקציות כיד הדמיון...Flip, Scale  ועוד.
השלב הבא לבנות לפונקציות ביטוי ב- XAML לדוגמא:

<PictureAPI:CornerSplit Count="4">
     <PictureAPI:FlippedPairs>
        <!-- UIElement -->
        <Image/> 
    </PictureAPI:FlippedPairs>
</PictureAPI:CornerSplit>
imageimage  
 

 אותו קוד רק תמונה אחרת.
בנית קוד XAML תפורסם בפוסט המשך.

להיפתר מבעית ה-KnownType כאשר עובדים בין מערכות דוט-נט ב-WCF

פורסם בתאריך Jul 19 2007, 09:04 PM על ידי Vardi

יש מחלקה, NetDataContractSerializer שיודעת לעביר את הטיפוס בהודעה. הבעיה שצריך לעטוף את המחלקה כדי שיהיה אפשר להשתמש בה כ-Attribute.

מאמר בנושא: http://www.thoughtshapes.com/WCF/UsingInterfacesAsParametersTwo.htm

מה שחסר בפתרון  זה היכולת לשים את Attribute על ה-Class ולא על Method. 

כדי ש-Attribute יכול להיות על ה-Class צריך לממש את הממשק IContractBehavior

להלן התוספת שלי:

    public class NetDataContractAttribute : Attribute, IContractBehavior, IOperationBehavior
    {
        #region IOperationBehavior
        public void AddBindingParameters(OperationDescription description, 
BindingParameterCollection parameters) { } public void ApplyClientBehavior(OperationDescription description,
ClientOperation proxy) { ReplaceDataContractSerializerOperationBehavior(description); } public void ApplyDispatchBehavior(OperationDescription description,
DispatchOperation dispatch) { ReplaceDataContractSerializerOperationBehavior(description); } public void Validate(OperationDescription description) { } #endregion private static void ReplaceDataContractSerializerOperationBehavior(
OperationDescription description) { DataContractSerializerOperationBehavior dcsOperationBehavior =
description.Behaviors.Find<DataContractSerializerOperationBehavior>(); if (dcsOperationBehavior != null) { description.Behaviors.Remove(dcsOperationBehavior); description.Behaviors.Add(
new NetDataContractSerializerOperationBehavior(description)); } } #region IContractBehavior Members public void AddBindingParameters(ContractDescription contractDescription,
ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ContractDescription contractDescription,
ServiceEndpoint endpoint, ClientRuntime clientRuntime) { foreach (OperationDescription od in contractDescription.Operations) { ReplaceDataContractSerializerOperationBehavior(od); } } public void ApplyDispatchBehavior(ContractDescription contractDescription,
ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime) { } public void Validate(ContractDescription contractDescription,
ServiceEndpoint endpoint) { }
#endregion }
 

מחשבות בנושא LINQ & VAR

פורסם בתאריך Jul 19 2007, 08:42 PM על ידי Vardi

נתקלתי בשאלה שעדין אין לי בשבילה פתרון אלגנטי.
 השאלה: כאשר משתמשים למשל בביטוי,

var q1 = 
                customers
                .Where ( c => c.Orders.Count >= 15 )
                .Select( c => c.Country );
print( q1 );
והעכשיו רוצים לעביר את q1 למתודה כל שהיא למשל print, המתודה חייבת לכבל את הארגומנת מסוג אובייקט, אם רוצים את היכולת לשלוח לה כל סוג של שאליתה.

פתרון שני שחשבתי עליו להפוך את print ל-Extension Methods ואז מקבלים:

var q1 = 
                customers
                .Where ( c => c.Orders.Count >= 15 )
                .Select( c => c.Country )
.print( q1 );

 אבל זה מחייב אותי ש-print יהיה static.

מחשבות בנושא Silverlight המשך

פורסם בתאריך Jul 19 2007, 08:14 PM על ידי Vardi

יש לי בעיה אם זה שאני צריך ללמוד שני סוגים של API, סילברלייט ו-WPF. החזון שלי שאנשים יוכלו לכתוב קוד ב-WPF ושהם מקמפלים אותו לבחור באיזה CLR הם רוצים שהוא ירוץ, כלומר בסביבת דוט-נט 3.0 או SL. האם זה בכלל אפשרי? ע"פ דעתי כן. אפשר לפרק את IL שנוצר מהקוד של WPF ל-IL של SL, המעבר אולי לא פשוט אך הוא אפשרי. נכן ש-IL של SL יותר פרמיטיבי אך הוא מספיק טוב.
למעשה מה שאני מנסה לומר במקום לרוץ ולבנות עוד פקדים ב-SL שיש אותם ב-WPF להשקיע את הזמן
בכתיבת תוכנה שתיקח קוד של WPF ותעביר אותו לקוד ש-SL יוכל להריץ אותו.
אם זכרוני לא מטעה אותי בורלנד היה להם חבילת פקדים שיודעת לרוץ על דוט-נט או על WIN32.
העקרון דומה.

מחשבות בנושא Silverlight

פורסם בתאריך Jul 16 2007, 03:18 AM על ידי Vardi

1. SL זה לא Smart Client Application אי אפשר לעבוד עם החצים, קדימה אחורה והשוק לא קיבל את הגישה הזו בפלש ולא באפלט גאווה.

2. SL נותן לנו דפים יותר עשירים, נכון. בשביל שארגון יעבוד עם הטכנולוגיה הוא צריך יכולות של שרת (ASP.NET ) שיוכל ליצר דפי XAML דינמיים וקוד דינמי בצד הדפדפן. בדיוק את אותו מודל פיתוח של AJAX Toolkit. מה שאני רוצה לראות זה שאני שם GRID בדף ה-ASP שלי והוא מרנדר ושולח לדפדפן את ה-XAML והקוד הרלוונטי. למעשה אם אנחנו רוצים אנחנו יכולים לכתוב Control Adapter לפקדים שלנו ולהפוך אותם ל-SL, הרבה מאוד עבוד...

3. ב-ASP הפקדים כמו Repeter, DataLIst ו- FormView שכיחים מאוד בעבודה היום יומית, אני צריך את אותו הסיגנון בכתיבת דפי XAML דינמים.

4. כתיבת UserControl ב-SL צריכה לתמוך ב- Design Time מה שלא מצאתי תיעוד על זה.

5. כתיבת רכיב SL צריכה להיות עטופה כ- Wes Server Control ולהיות מותקנת ב- Toolbox, כמו הפקדים XAML ו- Media שמיקרוסופט מספקת לנו ב-ASP.NET Futures.

כל הדוגמאות והמצגות באתר Are You Ready for 2008?

פורסם בתאריך Jul 15 2007, 03:16 PM על ידי Vardi

R U Ready for 2008? ממשיך !!!

פורסם בתאריך Jul 09 2007, 04:57 PM על ידי Vardi

תודה לכל המשתתפים, למעלה מ - 400 איש עד עכשיו. הקוד והמצגות יהיו זמנים עד סוף השבוע.

בעקבות ההצלחה אנחנו פותחים מחזור שני לרוב הקורסים. להלן פירוט הקורסים עם התאריכים.

08 / 07 / 2007

11 / 07 / 2007

15 / 07 / 2007

16 / 07 / 2007

18 / 07 / 2007

22 / 07 / 2007

23 / 07 / 2007

25 / 07 / 2007

26 / 07 / 2007

ושוב תודה לכולם, למדריכם ולמשתתפים שעזרו באירוע.