Friday, May 6, 2011

Using Visual Studio 2005 for buliding LynxOS applications

Hi, I am trying to build application for LynxOS (Hard Real time OS). The best method so far is to use an add on called VisualLynx which attach itself to VS 6.0 and replaces its make system with its on cross compiler linker etc. VS 6.0 is a real pain to use, so I wanted to use VS 2005 but it seems there is no add on for VS 2005. Is there a way to use what I already have (Visual Lynx for VS 6.0) on VS 2005....... Its a tough one I guess but if there is any way it would be a big help.

Thanks

From stackoverflow
  • I have typically cross compiled from linux for LynxOS builds. In that regard, I have used either xemacs or eclipse for my IDE on Redhat. Works like a champ.

    Jeremy Mayhew : I suppose that you could use eclipse on the Windows platform and that would allow you to use the same CDK that you are currently using.

WPF: Binding to ComboBox SelectedItem

Hi all

I have a UserControl with ComboBox that based on XML data:

<Root>
<Node Background="Yellow" Foreground="Cyan" Image="1.ico" Property="aaaa" Value="28" />
<Node Background="SlateBlue" Foreground="Black" Image="2.ico" Property="bbbb" Value="2.5" />
<Node Background="Teal" Foreground="Green" Image="3.ico" Property="cccc" Value="4.0" />
<Node Background="Yellow" Foreground="Red" Image="4.ico" Property="dddd" Value="0" /></Root>

Here is the UserControl XAML:

<UserControl x:Class="xxxxxxxx.MyComboBox"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         x:Name="myComboBoxControl">
<UserControl.Resources>
    <DataTemplate x:Key="dataTemplateNode">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="20"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto" MinWidth="20"/>
            </Grid.ColumnDefinitions>
            <Border Background="{Binding XPath=@Background}" Grid.Column="0">
                <Image Source="{Binding XPath=@Image}" 
                       Width="16" 
                       Height="16" 
                       Margin="3" />
            </Border>
            <Border Background="{Binding XPath=@Background}" Grid.Column="1">
                <TextBlock Foreground="{Binding XPath=@Foreground}" 
                           Margin="3"
                           Text="{Binding XPath=@Property}" />
            </Border>
            <Border Background="{Binding XPath=@Background}" Grid.Column="2">
                <TextBlock Foreground="{Binding XPath=@Foreground}" 
                           Margin="3" 
                           FontWeight="Bold"
                           Text="{Binding XPath=@Value}" />
            </Border>
        </Grid>
    </DataTemplate>

    <XmlDataProvider x:Key="xmlNodeList" 
                     Source="/data/Combo.xml" 
                     XPath="/Root/Node"/>
</UserControl.Resources>

<ComboBox Name="myComboBox" 
          ItemsSource="{Binding Source={StaticResource xmlNodeList}}" 
          ItemTemplate="{StaticResource dataTemplateNode}"
          HorizontalContentAlignment="Stretch" /></UserControl>

In the MainForm.xaml I have a TextBox that I want to bind to the my UserControl SelectedItem.

<StackPanel Orientation="Horizontal">
<local:MyComboBox1 x:Name="comboBoxST" />
<TextBox x:Name="textBoxST"/></StackPanel>

I will glad if you will guid me how to do that.

Thanks in advance!

From stackoverflow
  • The trick here is that when you have to bind to the SelectedItem on an ItemControl bound to XML, the selected item itself is an XmlElement, and you have to use XPath to get to the needed element/attribute.

    The easiest way to achieve this is to use DataContext:

    <TextBox x:Name=textBoxST 
        DataContext="{Binding ElementName=comboBoxST, Path=SelectedItem}" 
        Text="{Binding XPath=@Value}"/>
    
    : Hello saldoukhov! Thank you for the response, but, unfortunately, your solution doesn't works :-(. Maybe it because of the XML binding of original ComboBox incapsulated into UserControl?
  • The answer posted above was for the case of a list box placed directly on the form. In case of UserControl and templated ComboBox, I would avoid pure xml binding - too many factors can break it. Instead, use this code to create a dependency property:

      public MyComboBox()
        {
            InitializeComponent();
            myComboBox.SelectionChanged += MyComboBoxSelectionChanged;
        }
    
        void MyComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SetValue(SelValueProperty, ((XmlElement)e.AddedItems[0]).Attributes["Value"].Value);
        }
    
        public static readonly DependencyProperty SelValueProperty =
            DependencyProperty.Register("SelValue", typeof(string), typeof(MyComboBox),
                new FrameworkPropertyMetadata(""));
    

    And binding is simple then:

    <TextBox x:Name=textBoxST Text="{Binding ElementName=comboBoxST, Path=SelValue}"/>
    

Server.Transfer and System.Threading.ThreadAbortException

See http://support.microsoft.com/kb/312629/EN-US/

I am using reponse.direct in my app as well and I am not getting the exception. The workaround that the knowledge base article suggests (Server.Execute) does not work for me. I am getting lots of javascript exceptions from the Ajax Toolkit on the target page if I use Server.Execute, and I did not dig into the cause.

My question - what arguments do you see against just swallowing the exception as a 'known limitation' and moving on?

My reason for using Server.Transfer in this one very specific case is that I want to mask the (real) target url of the page that is actually executing. It works pretty well, except for this exception (that the user never sees).

From stackoverflow
  • Make sure you are not calling Server.Transfer() within an exception handler (try..catch/finally).

    Edit:

    Server.Transfer always raises ThreadAbortException upon completion. If you wrap it in an exception handler you should trap for explicit exception types instead of just 'Exception'.

    See the help for Server.Transfer on MSDN. Here is info about ThreadAbortException

    cdonner : Why not? If I don't catch it in the originating page, the exception survives the call.
    Adam Markowitz : See updated answer.
  • Thanks a lot.

Scaling with a cluster- best strategy

I am thinking about the best strategy to scale with a cluster of servers. I know there is no hard and fast rules, but I am curious what people think about these scenarios:

  1. cluster of combination app/db servers that are round robin (with failover) balanced using dnsmadeeasy. the db's are synced using replication. Has the advantage that capacity can be augmented easily by adding another server to the cluster, and it is naturally failsafe.

  2. cluster of app servers, again round robin load balanced (with failover) using dnsmadeeasy, all reporting to a big DB server in the back. easy to add app servers, but the single db server creates a single failure point. Could possible add a hot standby with replication.

  3. cluster of app servers (as above) using two databases, one handling reads only, and one handling writes only.

Also, if you have additional ideas, please make suggestions. The data is mostly denormalized and non relational, and the DBs are 50/50 read-write.

From stackoverflow
  • Take 2 phisical machines and make them Xen servers

    • A. Xen Base alpha
    • B. Xen Base beta

    In each one do three virtual machines:

    1. "web" server for statics(css,jpg,js...) + load balanced proxy for dynamic request (apache+mod-proxy-balancer,nginx+fair)
    2. "app" server (mongrel,thin,passenger) for dynamic requests
    3. "db" server (mySQL, PostgreSQL...)

    Then your distribution of functions can be like this:

    • A1 owns your public ip and handle requests to A2 and B2
    • B1 pings A1 and takes over if ping fails
    • A2 and B2 take dynamic request querying A3 for data
    • A3 is your dedicated data server
    • B3 backups A3 second to second and offer readonly access to make copies, backups etc. B3 pings A3 and become master if A3 becomes unreachable

    Hope this can help you some way, or at least give you some ideas.

  • It really depends on your application.

    I've spent a bit of time with various techniques for my company and what we've settled on (for now) is to run a reverse proxy/loadbalancer in front of a cluster of web servers that all point to a single master DB. Ideally, we'd like a solution where the DB is setup in a master/slave config and we can promote the slave to master if there are any issues. So option 2, but with a slave DB. Also for high availability, two reverse proxies that are DNS round robin would be good. I recommend using a load balancer that has a "fair" algorithm instead of simple round robin; you will get better throughput. There are even solutions to load balance your DB but those can get somewhat complicated and I would avoid them until you need it.

    Rightscale has some good documentation about this sort of stuff available here: http://wiki.rightscale.com/ They provide these types of services for the cloud hosting solutions.

    Particularly useful I think are these two entries with the pictures to give you a nice visual representation.

    The "simple" setup:
    http://wiki.rightscale.com/1._Tutorials/02-AWS/02-Website_Edition/2._Deployment_Setup

    The "advanced" setup:
    http://wiki.rightscale.com/1._Tutorials/02-AWS/02-Website_Edition/How_do_I_set_up_Autoscaling%3f

  • I'm only going to comment on the database side:

    With a normal RDBMS a 50/50 read/write load for the DB will make replication "expensive" in terms of overhead. For almost all cases having a simple failover solution is less costly than implementing a replicating active/active DB setup. Both in terms of administration/maintenance and licensing cost (if applicable).

    Since your data is "mostly denormalized and non relational" you could take a look at HBase which is an OSS implementation of Google Bigtable, a column based key/value database system. HBase again is built on top of Hadoop which is an OSS implementation of Google GFS.

    Which solution to go with depends on your expected capacity growth where Hadoop is meant to scale to potentially 1000s of nodes, but should run on a lot less as well.

    I've managed active/active replicated DBs, single-write/many-read DBs and simple failover clusters. Going beyond a simple failover cluster opens up a new dimension of potential issues you'll never see in a failover setup.

    If you are going for a traditional SQL RDBMS I would suggest a relatively "big iron" server with lots of memory and make it a failover cluster. If your write ratio shrinks you could go with a failover write cluster and a farm of read-only servers.

    The answer lies in the details. Is your application CPU or I/O bound? Will you require terabytes of storage or only a few GB?

    Scott Miller : Thanks for these great ideas!

Mobile devices for developers

I need to develop some programs for mobile devices but haven't decided the platform to build upon. I'm looking for Palm or Pocket PC devices that have Touch screen and Wi-Fi connection and are cheep because I'll need to buy several of them.

I don't really need camera, mp3 players, video players, pdf readers or anything else since the apps are going to be simple data collection to feed via wireless to a server database.

I'm proficient with C and C#. I could learn Java if I had to.

What devices do you recommend? Linux devices maybe?

PS: Changed the title because I don't want a flamewar between platforms. Please, don't answer with Windows Mobile sucks/rules. I'm looking for devices instead.

Thanks

From stackoverflow
  • You should probably target the Windows Mobile platform. The Palm platform is rather archaic and no longer widely used. The development environment is also rather spartan, while Microsoft has full IDEs available for Windows Mobile development. You might also consider the iPhone/iPod touch platform - I have a feeling the number of devices will multiply at an exponential rate and I've heard that developing applications is much easier due to the completeness of the system stack.

  • You should probably at least evaluate the Apple iPod Touch. It certainly meets your basic "touch screen + WiFi" spec, and your users presumably won't object to all the the other nice features that will come along for the ride.

    I don't know what your cutoff for "cheap" is, but $299 for the base model seems pretty reasonable for a high-quality touch screen and WiFi in a pocketable device.

    Andy Dent : you can buy refurbished models from Apple which have new battery and earbuds, cheaper than most eBay offerings
  • Windows Mobile
    It supports C#, and Visual Studio comes with the mobile SDK. So if you know C# you probably already have the tools you need. And in spite of the iPhone/iPodTouch buzz, the Windows Mobile deployment is still 10X greater.

  • Windows Mobile and CE used to suck, really, really badly. These days however it's definitely passable and worth checking out, especially if you code C#. Just remember that it is the baby brother of the full framework and has nowhere near enough toys and throws a lot of NotImplementedExceptions. :)

  • Blackberry publishes its SDK on its web site. Its apps run J2ME, so with some Java experience it shouldn't be too difficult to get started. They also give you an emulator. Disclaimer: I have no experience in writing Blackberry apps, but I looked into it once.

    I would not recommend a PalmOS based handset. I have written code for PalmOS and it's about as painful as writing raw Win32 code in C. Since Palm has switched its high end handsets to Windows Mobile, PalmOS will just remain stagnant and only run on the slower, less capable hardware.

    If I were to write a mobile app, I'd agree that Windows Mobile is worth checking out.

  • In order of preference

  • It all depends on the users who you are targeting at, If you are looking for a wide market then you should be fine with J2ME/Blackberry . However most of them lack the touchscreen and wifi features ( The HTC range of phones [WIFI/TouchScreen/Windows Mobile] have a JVM built with it),so it would work on most of the Windows devices also.

    If you are making a more niche product, moving with the current buzz 'iphone' will be good . Windows Mobile is also worth checking out

  • If you are comfortable with Visual Studio then programming for windows mobile is extremely easy. The SDK for mobile comes with emulators for all the latest and popular versions of windows mobile- and you can even debug on teh device itself using a USB cable.

    On windows mobile you have a choice: Develop a .Net application or develop native (likely MFC based). Either one gives you a great development environment.

    As far as iPhone development goes- you would need an apple computer to install and use iPhone SDK- and you can't run an iPhone app on your phone. You would have to go through the process of getting it registered with iTunes for you to install your own apps on your own phone!

    When I first started playing with mobile development I had a few questions:

    • Can I develop using my favorite IDE- Visual Studio. Will it be as easy as developing a desktop app: yes.
    • Will I be able to access the internet from my application without 'unlocking' or in some other way enabling the phone that was not intended by the service provider? yes.
    • Will I be able to access device specific functionality such as GPS easily? Is there good support for doing so within the API? Yes.
  • The best option here would be the Neo Freerunner, with that device you can build a dedicated unit were every aspect is made especially for you're needs. The Freerunner is WiFi enabled, and has a touch interface. If you use the Qt SDK, a lot of the work is already done for you. It comes complete with emulator, as a Live linux cd. You can run in a WM, such as wmplayer. Everything is included.

    I'm not gonna lie, it will take tweaking. But the final product would be really nice and intuitive.

  • Looking at Windows Mobile devices, your requirement of touchscreen pretty much sets your pricing at the higher end of the spectrum. You'll get those things you say you don't need just because of that.

    Here's expansys's selection of touchscreens.

    Mobdeal is a handy one too as that effectively filters all phones by features.

    I've developed against the HTC TYTN 2, HTC Touch Diamond and randomly a PSION Teklogix Ikon

    There's generally very little difference between these models, some manufacturers have SDKs that can help sometimes.

    I think your cheapest option will probably be something like getting HTC TYTN 2s on ebay. They're pretty old now (hence cheap) but have Wifi, camera, touchscreen, qwerty keypad all the things you seem to be after.

  • you can target iPhone "touch" platform with Apple's iPhone SDK. the development environment requires a Mac, but you can get the entire IDE + tool chain + excellent debugging and profiling tools for free. And the free documentation is top notch.

    As a registered iPhone developer, it is free (no cost) to target the simulator, which is sufficient for most learning and development you'll likely need to up front.

    To target the actual hardware device (and up to and including release/selling your app on the Apple's AppStore) is only $99/yr. If you got an iPod Touch for your hardware target, most of the SDK applies and you are not tied into a service contract for an iPhone.

    iPhone app development environment is in Objective-C, but it is a really productive, object-oriented environment so do not concerned that that may be a language you are unfamiliar with.

    If you decide that your mobile app(s) would be better suited as webapps, the iPhone/iPod touch platform again is an industry leader in this space, and you have the additional benefit or being able to target other mobile platforms (and not necessarily be tied to one mobile SDK).

What does floating point error -1.#J mean?

Recently, sometimes (rarely) when we export data from our application, the export log contains float values that look like "-1.#J". I haven't been able to reproduce it so I don't know what the float looks like in binary, or how Visual Studio displays it.

I tried looking at the source code for printf, but didn't find anything (not 100% sure I looked at the right version though...).

I've tried googling but google throws away any #, it seems. And I can't find any lists of float errors.

From stackoverflow
  • It can be either negative infinity or NaN (not a number). Due to the formatting on the field printf does not differentiate between them.

    I tried the following code in Visual Studio 2008:

    double a = 0.0;
    printf("%.3g\n", 1.0 / a);  // +inf
    printf("%.3g\n", -1.0 / a); // -inf
    printf("%.3g\n", a / a);    //  NaN
    

    which results in the following output:

    1.#J
    -1.#J
    -1.#J
    

    removing the .3 formatting specifier gives:

    1.#INF
    -1.#INF
    -1.#IND
    

    so it's clear 0/0 gives NaN and -1/0 gives negative infinity (NaN, -inf and +inf are the only "erroneous" floating point numbers, if I recall correctly)

    Michael Burr : Interesting... I wonder why it ends up with a 'J' when truncating the infinity/NaN indicators?
    RBerteig : The J is the result of rounding the "digits" IN to one less place.
    RBerteig : The translation of NaN and INF to a code with a leading digit and a dot is a IMHO a gross mistake. It is way too easy to end up with a numeric field in a text file that can be re-read (with an imperfect but plausible parser, admittedly) as the value +1 or -1 which is rather unlike the value that was printed. It would be much better to write it as +#INF, -#INF, and so forth.
    Michael Burr : @RBerteig: thanks for pointing out the rounding going on... As for the formatting, C90 seems to be silent on how Infinity and NaN should be formatted. C99 specifies that strings like "inf", "-inf", "nan" (or minor variations of those) must be used. Unfortunately, C99 is the bastard step-child of C/C++ language specs.

grid selected row

Hi iam using infragistics ultrawebgrid in this how to get the selected row index in the button click event

From stackoverflow
  • Is the "button click event" the ClickCellButton event or some other Infragistic event that is passing in a CellEventArgs? If so you can grab it directly from that.

    private void grid_ClickCellButton(object sender, CellEventArgs e)
    {
        int rowIndex = e.Cell.Row.Index;
    }
    

    As you can see, once you have the cell object you can move along to the row and even the others cells (via e.Cell.Row.Cells) you want to.

    If you are using an event that is passing in RowEventArgs you can do that same thing.

    private void grid_AfterRowUpdate(object sender, RowEventArgs e)
    {
        int rowIndex = e.Row.Index;
    }