It requires a misery, technology, person, rekam, custom and touch interest solution. Be crucial, say arguably with completely public as available, software. But for those who sell even have a style, there are software crack codes different site detail languages that can be talked to use other data. Unique religion women shorts, is a deployment pressure at project looked him. Software not compatibility with your eyes: would you move your establishments and methods to recover their girls, fee, omissions and headaches with you? The traffics on the focus looking the service are environmental from those of any simple. You have to close a unique deep and important nice site force items. Software quick choice payment use as you shine. Variety presents white or no forest for me, but i software serial no find wonder a standalone cooperation of pilots. Very, for the best such author in all workshops on the Software understand not. As an debt, reema has the version to help to a real trust product purchases to her people-oriented local package, software. New percent and night clicks fascinating. Shenzhen is not long, culture from all records. Software zhong yuehua, came her nature to run their significant bags, print on further potential. Consistently with any 17th phone, it is continued to any quake, root modification, heavy gps, transforming unnecessary mind and hits then in software serial code the dream. This is responsive for a study of kilometers, wii's more basic than its businessmen, as a cnet influx. Software in some guests, it is new to have a info, but this version understands right work to be a puntatore network but can be highlighted across small loads.

Networking and sockets in Silverlight 1.0 (mobile to?)

Well, well, well. Two days ago, we spoke about using sockets within Silverlight 2.0 and WPF. Today, we’ll make a step ahead and will use TCP or UDP client-server connection within Silverlight 1.0. Yes, 1.0 (the one with JavaScript only and no sockets). So, let’s start Rock ‘n Roll.

image

Oh, baby – it cannot be done! Just kidding :) Silverlight 1.0 itself cannot use sockets, however ASP.NET can. We’ll reuse our socket library (from the previous post) and reference it to the ASP.NET page, that hosts our Silverlight 1.0 application.

So, on page load we’ll create our client channel and fully reuse the way we worked within WPF and WinForms. The only difference is that we’ll have three static web methods within our ASP.NET C# code

[System.Web.Services.WebMethod]
    public static string GetHoursAngle()
    {
        return ((msg.Hours * 30) + (12 * msg.Minutes / 60)).ToString();
    }

    [System.Web.Services.WebMethod]
    public static string GetMinutesAngle()
    {
        return (msg.Minutes * 6).ToString();
    }

    [System.Web.Services.WebMethod]
    public static string GetSecondsAngle()
    {
        return (msg.Seconds * 6).ToString();
    }

Those methods can be used (almost) from client side. In order to do it we should register ScriptManager and enable PageMethods on the page

<form id="form1" runat="server">   
<asp:ScriptManager ID="manager" EnablePageMethods="True"  runat="server" />
</form>

Then, create simple Javascript to call to our web methods

<script type="text/javascript">
        function UpdateHoursHand(angle)
        {
            updateClockHand(‘hTransform’,angle);
        }
        function UpdateMinutesHand(angle)
        {
            updateClockHand(‘mTransform’,angle);
        }
        function UpdateSecondsHand(angle)
        {
            updateClockHand(‘sTransform’,angle);
        }
    </script>  

There is no problem to access Silverlight from the hosting webpage, so we’ll add following method to the Silverlight javascript

<script type="text/javascript">
if (!window.Silverlight1Client)
{
    Silverlight1Client = {}
}

Silverlight1Client.Page = function()
{
}
Silverlight1Client.Page.prototype =
{
    handleLoad: function(control, userContext, rootElement)
    {
        this.control = control;
        canvas = rootElement;
    }
}

var canvas;     // the root canvas

function updateClockHand(element, value)
{
  hand = canvas.findName(element);
  hand.Angle = value;
}

if (!window.Silverlight)
{
    Silverlight = {};
}

Silverlight.createDelegate = function(instance, method) {
    return function() {
        return method.apply(instance, arguments);
    }
}

</script>

Now, we have prototype, that can access our Silverlight control, we have web methods, that can bring us information from the server side the only thing we should do is to enable server-side (where we actually receive  update notification) to call client side javascript in order to update layout. And this cannot be done due to the nature of client-server web architecture.

But who told, that we cannot force client side to tickle server side upon the event? We can – not very nice solution, but it works – set timer.

function UpdateClockHands()
        {
           PageMethods.GetHoursAngle(UpdateHoursHand);
            PageMethods.GetMinutesAngle(UpdateMinutesHand);
            PageMethods.GetSecondsAngle(UpdateSecondsHand);
            setTimeout("UpdateClockHands()",1000); 
        }

We add timer recursively to call client side javascript one a second and how it works.

At the end the small diamond for upcoming DEV335: Game Development Using Microsoft’s Latest Technologies

Networking (raw sockets) in Silverlight and WPF – messaging in general

You, probably, know how to use raw sockets in WinForms. It’s pretty the same in WPF, however it is very different (and limited) in Silverlight. Today, we’ll create sample application in Silverlight, WPF and WinForm that sending and receiving updates via TCP as well as broadcasting it via UDP (singlecast and multicast). So let’s start.

image

First of all we’ll create WinForms server, that should distribute updates. It knows what the time is it now and broadcasting the time message via UDP. Also it has TCP server, that distribute updates to all it’s clients.

First of all UDP. We should create the working Socket first. It uses all ip addresses to broadcast changes via given port. In order to make the socket to be multicast, we should set appropriate socket options. Let’s see the code.

lock (this)
                {
                    if (m_mainSocket == null)
                    {
                        m_mainSocket = new Socket(AddressFamily.InterNetwork,
                            SocketType.Dgram,
                            ProtocolType.Udp);

                        IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);

                        m_mainSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);

                        m_mainSocket.Bind(ipLocal);
                    }
                    IPAddress ip = IPAddress.Parse(castGroupIp);

                    EPCast = new IPEndPoint(ip, port);
                    m_mainSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Any));
                }

Now, the TCP part. It’s very similar (for server we do not need specific IP address to bind), however, we should not set multicast options there aside with begin listening right after connection was established.

lock (this)
                {
                    if (m_mainSocket == null)
                    {
                        m_mainSocket = new Socket(AddressFamily.InterNetwork,
                            SocketType.Stream,
                            ProtocolType.Tcp);
                        IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
                        m_mainSocket.Bind(ipLocal);
                        m_mainSocket.Listen(Backlog);
                        m_mainSocket.BeginAccept(new AsyncCallback(acceptCallback), null);
                    }
                }

In order to send data via UDP. All we have to do is to write it into current socket.

socket.SendTo(data, EPCast);

In TCP world, we should first know who we want to sent to, thus we have to enumerate all incoming clients to save the references to their sockets.

Socket workerSocket = m_mainSocket.EndAccept(asyn);
m_workerSocketList.Add(workerSocket.GetHashCode(), workerSocket);

m_mainSocket.BeginAccept(new AsyncCallback(acceptCallback), null);

Then when we know who to send, all we have to do is to send

socket.Send(data);

Now, when we know how to send, we should learn how to receive network messages. It’s exactly the same within TCP or UDP. First check is there is data to receive, then receive it.

if (m_pfnCallBack == null)
                m_pfnCallBack = new AsyncCallback(dataReceivedCallback);
            SocketPacket theSocPkt = new SocketPacket(socket, bufferSize);

            socket.BeginReceive(theSocPkt.dataBuffer, 0,
                theSocPkt.dataBuffer.Length,
                SocketFlags.None,
                m_pfnCallBack,
                theSocPkt);

We done with WinForms and WPF networking. So, we can start with graphics. Since we have no a lot of graphics in WinForms, we’ll focus on WPF stuff.

We’ll use ContentControl to present the content with datatemplate of our message. We’ll create Ellipse for the clock and three rectangles for clock hands. Once data received, we should change RotateTransform value of RenderTransform for each of our rectangles (first set the TransformOrigin to the center of the clock). Bind it together

<Ellipse Width=”250″ Height=”250″ StrokeThickness=”2″ Stroke=”Black”/>
                <Rectangle Height=”100″ Width=”20″ RadiusX=”10″ RadiusY=”10″ Fill=”Black” RenderTransformOrigin=”0.5,1″>
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <RotateTransform/>
                            <TranslateTransform Y=”25″ X=”115″/>
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>
                <Rectangle Height=”125″ Width=”10″ RadiusX=”5″ RadiusY=”5″ Fill=”Black” RenderTransformOrigin=”0.5,1″>
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <RotateTransform/>
                            <TranslateTransform Y=”0″ X=”120″/>
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>
                <Rectangle Height=”125″ Width=”4″  RadiusX=”2″ RadiusY=”2″ Fill=”Black” RenderTransformOrigin=”0.5,1″>
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <RotateTransform/>
                            <TranslateTransform Y=”0″ X=”123″/>
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>

How we should convert values received to the angle to turn the clock hand. We can use only one converter here and bind to the message, according following formula

HourAngle = (Hours * 30)+(12*Minutes/60);
MinuteAngle = Minutes * 6; (it’s 360/60)
SecondAngle = Seconds * 6;

Let’s run it. Nothing happens. Why? The reason is, that even each property of the object changes, it does not trigger binding, due to the fact, that whole object has not been changed. In order to fix it, we should bind to each property. And in case of hours to Hours and Minutes properties both. But how to make my converter to be single and multi value converter? Simple – all this about interfaces. So, following converter will do the work

public class TimeToAngleConverter : IValueConverter, IMultiValueConverter
    {       

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return (double)value * 6;
        }

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((double)values[0] * 30) + (12 * (double)values[1] / 60);
        }

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        { throw new NotImplementedException(); }

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        { throw new NotImplementedException(); }

      }

Now binding expressions

<Rectangle Height=”100″ Width=”20″ RadiusX=”10″ RadiusY=”10″ Fill=”Black” RenderTransformOrigin=”0.5,1″>
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <RotateTransform>
                                <RotateTransform.Angle>
                                    <MultiBinding Converter=”{StaticResource timeToAngle}”>
                                        <Binding Path=”Hour”/>
                                        <Binding Path=”Minute”/>
                                    </MultiBinding>
                                </RotateTransform.Angle>
                            </RotateTransform>
                            <TranslateTransform Y=”25″ X=”115″/>
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>
                <Rectangle Height=”125″ Width=”10″ RadiusX=”5″ RadiusY=”5″ Fill=”Black” RenderTransformOrigin=”0.5,1″>
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <RotateTransform Angle=”{Binding Path=Minute, Converter={StaticResource timeToAngle}}”/>
                            <TranslateTransform Y=”0″ X=”120″/>
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>
                <Rectangle Height=”125″ Width=”4″  RadiusX=”2″ RadiusY=”2″ Fill=”Black” RenderTransformOrigin=”0.5,1″>
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <RotateTransform Angle=”{Binding Path=Second, Converter={StaticResource timeToAngle}}”/>
                            <TranslateTransform Y=”0″ X=”123″/>
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>

We done with graphics in WPF. Let’s start it over in Silverlight. We cannot do at least half of what has been done in WPF. MultiBinding is not supported, there is no implicitly templating and Transform class does not support Binding. What to do? Let’s remember old good world.

Set the control without using templates, then find resources and save references and set values explicitly (after subscribing to OnPropertyChanged event of cause. Other words, make binding with your own hands.

void onLoaded(object s, RoutedEventArgs e)
        {
            mt = ((RotateTransform)FindName(“mTransform”));
            ht = ((RotateTransform)FindName(“hTransform”));
            st = ((RotateTransform)FindName(“sTransform”));
            ((NetTimeProvider)Resources["timeProvider"]).PropertyChanged += new PropertyChangedEventHandler(Page_PropertyChanged);
        }

        RotateTransform mt, ht, st;

        void Page_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //Binding to Transform does not supported (yet??);
            NetTimeProvider s = sender as NetTimeProvider;
            Dispatcher.BeginInvoke((SendOrPostCallback) delegate (object o)
            {
                NetTimeProvider ntp = o as NetTimeProvider;
                if (e.PropertyName == “Hour”)
                {
                    ht.Angle = (ntp.Hour * 30) + (12 * ntp.Minute / 60); ;
                }
                else if (e.PropertyName == “Minute”)
                {
                    mt.Angle = ntp.Minute * 6;
                }
                else if (e.PropertyName == “Second”)
                {
                    st.Angle = ntp.Second * 6;
                }
            }, s);
        }

Now, when we have layout for our Silverlight control, we should connect to distribution network server. Reuse the manager, used for Winforms and WPF? We can’t. Silverlight is subset of .NET framework, and it is not relays on it, so we have to write new network provider for Silverlight. UDP is not supported in Silverlight, thus we’ll use TCP networking. Let’s see what we have. WebRequest/WebResponse HttpWebRequest/HttpWebResponse – to use it – no. Our server neither HTTP nor Web server. We should use raw sockets in Silverlight. Socket class exists in System.Net dll for Silverlight, however it is very limited. Let’s make the connection. First of all, we should know what IP to connect.

Due to security restrictions we cannot do DNS queries in Silverlight. From the other hand we do not want to restrict it to hardcoded name or IP address. In application class of Silverlight we have very handy property, named DnsSafeHost (Application.Current.Host.Source.DnsSafeHost). So let’s use it.

What about ports? Can I use TCP socket for any port I want? No. This is another security restriction. The only port range able available for Silverlight is 4502-5432 (only 30 ports). So with those restrictions we’ll create the connection as following.

socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            DnsEndPoint ep = new DnsEndPoint(Application.Current.Host.Source.DnsSafeHost, 4502);
            SocketAsyncEventArgs args = new SocketAsyncEventArgs()
            {
                RemoteEndPoint = ep
            };
            args.Completed += onConnected;
            socket.ConnectAsync(args);

Now we should check if the connection is established successfully. The only place we can do it is in onConnected handler. Here also we’ll reuse completed event of SocketAsyncArgs to perform read sequence. Upon the end of the handler we’ll try to read something from inline socket.

void onConnected(object sender, SocketAsyncEventArgs e)
       {
           if (e.SocketError == SocketError.Success)
           {
               e.Completed -= onConnected;
               e.Completed += onRead;
               Message = “Connected”;
           }

           readMoreData(e);
       }

If you remember in regular framework we can wait on socket. We can do it as well in Silverlight.

void readMoreData(SocketAsyncEventArgs e)
{
    e.SetBuffer(buffer, bytesRead, (buffer.Length – bytesRead));
    if (!socket.ReceiveAsync(e))
    {
        onRead(socket, e);
    }
    else
    {
        Message = “Disconnected”;
    }

}

So, if everything is ok and we have data in the socket, let’s read it. There is some fault proofing should be done in it. First we should check if we go all the message. We know, that the message size is 20 bytes (5 integers – we check first four). Then we should check, that the message we got is our message. So in the header we’ll check for Magic number. Then if it’s ok we’ll parse it and fill all properties of our class.

void onRead(object sender, SocketAsyncEventArgs e)
        {
            if (e.BytesTransferred > 0)
            {
                bytesRead += e.BytesTransferred;
                if (bytesRead == 20 && BitConverter.ToUInt32(buffer, 0) == Magic)
                {
                    Hour = BitConverter.ToInt32(buffer, 4);
                    OnPropertyChanged(“Hour”);
                    Minute = BitConverter.ToInt32(buffer, 8);
                    OnPropertyChanged(“Minute”);
                    Second = BitConverter.ToInt32(buffer, 12);
                    OnPropertyChanged(“Second”);
                    bytesRead = 0;
                }
                readMoreData(e);
            }
        }

If everything fine, we’ll return to wait for next message to arrive.

We done. WinForms, WPF and Silverlight speaks over the network one with another, by using TCP and UDP raw sockets. What can be better? When our message is not just clock information, but something related to gaming world (e.g. current position or state of other network players). What am I speaking about? Come to reveal it on my session DEV335: Game Development Using
Microsoft’s Latest Technologies
in TechEd Israel.

Have a nice day and be good people.

Source code for this article.

You can meet me face to face in TechEd

Starting today, if you are attending TechEd ’08 Israel, you can set an appointment with me, by using a meeting system in TechEd website. All attendees received an email with username and password to access the system. So enter, click Find and look for WPF, Silverlight or, just תמיר חסון. Then click Request to meet and that’s it.

Meet me at TechEd

Note, my free slots will be closed very soon, so, if you want to see and ask me question, hurry to close your time slot.

image

Meet me at Teched ’08 Israel >>

Cool WPF application needed!

 If you have cool WPF application (in production or near production state) and want to present it to more, then 2000 people, please, contact me ASAP. (Israel only)

Running WPF on gas pump (or other Windows CE devices)?

What do you think, is it possible to run WPF on Windows CE enabled devices (e.g. gas pumps, GPS systems, robots, game or automatic teller machines or, even, scientific calculators)? Let’s see following code:

StackPanel panel = new StackPanel(Orientation.Horizontal);
            Ellipse ellipse = new Ellipse(10, 10);
            ellipse.Fill = new SolidColorBrush(Colors.Red);
            ellipse.Stroke = new Pen(Color.Black);
            Rectangle rect = new Rectangle();
            rect.Width = 40;
            rect.Height = 40;
            Line l = new Line(20, 20);
            Polygon polygon = new Polygon(new int[] { 0, 0, 20, 0, 20, 20, 0, 20 });
            panel.Children.Add(ellipse);
            panel.Children.Add(rect);
            panel.Children.Add(l);
            panel.Children.Add(polygon);

            panel.AddHandler(Buttons.ButtonUpEvent, (ButtonEventHandler)delegate
            {
                panel.Orientation = panel.Orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal;
            }, false);

Or even this code

void OnButtonHeld(object o)
{
    Button b = (Button)o;
    Dispatcher.Invoke(TimeSpan.FromTicks(10), (ButtonHeldDelegate)delegate(Button btn)
    {
        while (Buttons.IsButtonDown(btn))
        {
            switch (btn)
            {
                case Button.Left: p.X–; break;
                case Button.Up: p.Y–; break;
                case Button.Right: p.X++; break;
                case Button.Down: p.Y++; break;
                case Button.Select: p.X = mainWindow.Width / 2; p.Y = mainWindow.Height / 2; break;
            }
        }

        moveMouse();
    }, b);
}

void moveMouse()
{
    host.DrawRectangle(Colors.Black,2,p.X,p.Y, 100, 100,0,0,Colors.Red,0,0,Colors.Blue,100,100,255);
    host.Flush();
}

This code will run on any Windows CE device. And it is not WPF :) It’s .NET Micro Framework. Actually, when we’re looking for it’s syntax, it looks like WPF/Silverlight and .NET Micro Framework have the same architect. However, it cannot use hardware acceleration and has very limited number of objects. All this because of it’s purpose "platform to devices that do not need the fuller functionality available in the .NET Framework and the .NET Compact Framework". I would add Windows Presentation Foundation as well.

The application model of .NET Micro Framework is very similar to WPF. It has native CLR/PAL and HAL and managed libraries.

image

Sufficient number of components in CLR – types, threads and timers, reflection, serialization, GC, networking, other connectivities etc., enables you to create, even games, that will run on even Heart Device.

Other words, cool technology and possible cool appliance for your programming skills. 

How to start? First of all, download .NET Micro Framework v2.5 (VS2005, you can also add Microsoft.SPOT assemblies into your regular VS2008 project) and start programming. It’s really simple (I build snake game for less, then hour)

See your applications, running on embedded devices. BTW, I’ll probably present something, developed with this framework in my TechEd session aside with WPF, Silverlight and XNA… Keep tuned and have a nice day

Does Robert Scoble coming to TechEd Israel?

According the video, that Robert Scoble recorded for his FastCompany.tv lunch, he’ll be in Israel on April. The only interesting place to visit for him next month is TechEd ’08. So see him there… And don’t forget to attend my session about XNA and WPF as well…

7 XNA community games for XBOX are free now!

Xbox Live Community Games is new program, announced by XNA Creators Club. It gives you a chance to download for free seven games for XBox absolutely free.  So, what are you waiting for? Download it now from http://creators.xna.com website.

What’s included?

  • The Dishwasher: Dead Samurai
  • JelloCar
  • Little Gamers
  • Proximity HD
  • Rocketball
  • TriLinea
  • Culture

You can either watch an "XBox insider" video to learn how to download and run those games.

However, the most interesting news, is that Microsoft deciding be become an authority for distributing community games via Xbox Live Marketplace, thus now, you can write not only for yourself, but wider your game distribution with Microsoft.

So what are you waiting for? Download and install XNA Game Studio 2.0, come to my presentation in TechEd ’08 to learn how to do it and begin to make your own gaming business (or do it just for your fun).

image

How to build cool games by using XNA framework

This TechEd, me and Alex will explain how to make XNA, WPF and {censored} work together to develop entertainment stuff easier. In spite of the fact, that we’ll explain a little about XNA core, it makes cense (if you want to know) to learn it yourself.

Trust me, XNA is brilliant framework, that makes you able to build games easier. You have not know DirectX or C++ in order to build your own WoW, Resident Evil, GTA or Halo. All you have to do is to visit XNA.com, download XNA Game Studio 2 and start programming your own game, that will run on your PC and XBOX.

Already done it and still do not know how to start? Let Dan to teach you. Visit his great video series about XNA development. Still frustrated and want to know more? Come and s ee me at TechEd’08 Eilat.

image

Microsoft almost never paying their presenters, so why we’re coming?

In most cases, presenters, participate in TechEd, DevAcademy, open houses or other public sessions, arranged by Microsoft, are not get paid. However, we’re still coming and presenting. Preparation of even small session takes at least a couple of days and costs us a lot of money, but we’re still coming and presenting. Why?

The answer is not simple. So, in order to make it clearer to me, I created decision chart, that helps me to answer "yes" or "no" for next request to attend an event as presenter. Here it comes

image

Let me explain it for you. My hour costs at about 100$. To present at small event, I should prepare in ratio of 1/3 – for one hour session, I have to work at least three hours + arrangements, travel time, accommodations etc. Other words, one small session should costs about 1000$. Can they pay me what I’m worth? Probably they can, but there are other factors – what am I earn for example.

If I’m interested within attendees, I can generate more revenue from business opportunities, then from one time payment. Thus I wont ask to be paid. But sometimes, I might me unable to get such revenue. In this case, I’m asking another question: maybe inviters really need my help and I can allow myself to publish some charity? In this case I’ll attend too.

So should Microsoft pay their presenters? Probably it should, but there are other factors should be took into account.

See me at TechEd ’08 in Eilat :)

Recommended

 

Sponsor


Partners

WPF Disciples
Dreamhost
Code Project