Daily Archives

Articles indexed Wednesday February 23 2011

Page 8/13 | < Previous Page | 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • The application has stopped unexpectedly: How to Debug?

    - by Android Eve
    Please note, unlike many other questions having the subject title "application has stopped unexpectedly", I am not asking for troubleshooting a particular problem. Rather, I am asking for an outline of the best strategy for an Android/Eclipse/Java rookie to tackle this formidable task of digesting huge amounts of information in order to develop (and debug!) a simple Android application. In my case, I took the sample skeleton app from the SDK, modified it slightly and what did I get the moment I try to run it? The application (process.com.example.android.skeletonapp) has stopped unexpectedly. Please try again. OK, so I know that I have to look LogCat. It's full of timestamped lines staring at me... What do I do now? What do I need to look for? Is there a way to single-step the program, to find the statement that makes the app crash? (I thought Java programs never crash, but apparently I was mistaken) How do I place a breakpoint? Can you recommend an Android debug tutorial online, other than this one?

    Read the article

  • How to set an image based on iphone platform in objective-c

    - by Toran Billups
    I'm moving my application from 3.x to 4.x as I prepare for the app store and found that I need to have 2 copies of all my custom pngs - my question is how can I determine what img to show and when. Example - how do I know to show the Find.png vs the [email protected] Is it "safe" or "correct" to look for 4.x specific apis or does the iphone have a way to determine what platform you are on at runtime? Thank you in advance

    Read the article

  • Is there a way to efficiently yield every file in a directory containing millions of files?

    - by Josh Smeaton
    I'm aware of os.listdir, but as far as I can gather, that gets all the filenames in a directory into memory, and then returns the list. What I want, is a way to yield a filename, work on it, and then yield the next one, without reading them all into memory. Is there any way to do this? I worry about the case where filenames change, new files are added, and files are deleted using such a method. Some iterators prevent you from modifying the collection during iteration, essentially by taking a snapshot of the state of the collection at the beginning, and comparing that state on each move operation. If there is an iterator capable of yielding filenames from a path, does it raise an error if there are filesystem changes (add, remove, rename files within the iterated directory) which modify the collection? There could potentially be a few cases that could cause the iterator to fail, and it all depends on how the iterator maintains state. Using S.Lotts example: filea.txt fileb.txt filec.txt Iterator yields filea.txt. During processing, filea.txt is renamed to filey.txt and fileb.txt is renamed to filez.txt. When the iterator attempts to get the next file, if it were to use the filename filea.txt to find it's current position in order to find the next file and filea.txt is not there, what would happen? It may not be able to recover it's position in the collection. Similarly, if the iterator were to fetch fileb.txt when yielding filea.txt, it could look up the position of fileb.txt, fail, and produce an error. If the iterator instead was able to somehow maintain an index dir.get_file(0), then maintaining positional state would not be affected, but some files could be missed, as their indexes could be moved to an index 'behind' the iterator. This is all theoretical of course, since there appears to be no built-in (python) way of iterating over the files in a directory. There are some great answers below, however, that solve the problem by using queues and notifications. Edit: The OS of concern is Redhat. My use case is this: Process A is continuously writing files to a storage location. Process B (the one I'm writing), will be iterating over these files, doing some processing based on the filename, and moving the files to another location. Edit: Definition of valid: Adjective 1. Well grounded or justifiable, pertinent. (Sorry S.Lott, I couldn't resist). I've edited the paragraph in question above.

    Read the article

  • Day dreaming about automatic RGB color function in PHP

    - by Sam
    Hello fellow earthlings. A quesion about RGB color and its usefulness in a simple tiny php code: Imagine I have variable $colorA containning a valid six char color. say B1B100, a greenish natural color. Now If I would like to make a new color from that, which is, say, ten steps lighter thatn that original color, roughly. $colorA = B1B100 // original color php code with little color engine lightening stuff up goes here $colorB = ?????? // original color lightened up Is there a php ready function that KNOWS rgb colors something like php function RGB ( input color, what to do, output color) Where what to do could be +/- 255 values of brightness etc etc. Is something like this already possible or am I day dreaming? rgb($colorA, +10, $colorB) If this does not exist, what would be the shortest code for doing this? Link suffices. Suggestions and ideas are answers to me. Thanks.

    Read the article

  • How do I Print a dynamically created Flex component/chart that is not being displayed on the screen?

    - by Adam Jones
    I have a several chart components that I have created in Flex. Basically I have set up a special UI that allows the user to select which of these charts they want to print. When they press the print button each of the selected charts is created dynamically then added to a container. Then I send this container off to FlexPrintJob. i.e. private function prePrint():void { var printSelection:Box = new Box(); printSelection.percentHeight = 100; printSelection.percentWidth = 100; printSelection.visible = true; if (this.chkMyChart1.selected) { var rptMyChart1:Chart1Panel = new Chart1Panel(); rptMyChart1.percentHeight = 100; rptMyChart1.percentWidth = 100; rptMyChart1.visible = true; printSelection.addChild(rptMyChart1); } print(printSelection); } private function print(container:Box):void { var job:FlexPrintJob; job = new FlexPrintJob(); if (job.start()) { job.addObject(container, FlexPrintJobScaleType.MATCH_WIDTH); job.send(); } } This code works fine if the chart is actually displayed somewhere on the page but adding it dynamically as shown above does not. The print dialog will appear but nothing happens when I press OK. So I really have two questions: Is it possible to print flex components/charts when they are not visible on the screen? If so, how do I do it / what am I doing wrong? UPDATE: Well, at least one thing wrong is my use of the percentages in the width and height. Using percentages doesn't really make sense when the Box is not contained in another object. Changing the height and width to fixed values actually allows the printing to progress and solves my initial problem. printSelection.height = 100; printSelection.width = 100; But a new problem arises in that instead of seeing my chart, I see a black box instead. I have previously resolved this issue by setting the background colour of the chart to #FFFFFF but this doesn't seem to be working this time. UPDATE 2: I have seen some examples on the adobe site that add the container to the application but don't include it in the layout. This looks like the way to go. i.e. printSelection.includeInLayout = false; addChild(printSelection);

    Read the article

  • Javascript closures with google geocoder

    - by DaNieL
    Hi all, i still have some problems with javascript closures, and input/output variables. Im playing with google maps api for a no profit project: users will place the marker into a gmap, and I have to save the locality (with coordinates) in my db. The problem comes when i need to do a second geocode in order to get a unique pairs of lat and lng for a location: lets say two users place the marker in the same town but in different places, I dont want to have the same locality twice in the database with differents coords. I know i can do the second geocode after the user select the locality, but i want to understand what am i mistaking here: // First geocoding, take the marker coords to get locality. geocoder.geocode( { 'latLng': new google.maps.LatLng($("#lat").val(), $("#lng").val()), 'language': 'it' }, function(results_1, status_1){ // initialize the html var inside this closure var html = ''; if(status_1 == google.maps.GeocoderStatus.OK) { // do stuff here for(i = 0, geolen = results_1[0].address_components.length; i != geolen) { // Second type of geocoding: for each location from the first geocoding, // i want to have a unique [lat,lan] geocoder.geocode( { 'address': results_1[0].address_components[i].long_name }, function(results_2, status_2){ // Here come the problem. I need to have the long_name here, and // 'html' var should increment. coords = results_2[0].geometry.location.toUrlValue(); html += 'some html to let the user choose the locality'; } ); } // Finally, insert the 'html' variable value into my dom... //but it never gets updated! } else { alert("Error from google geocoder:" + status_1) } } ); I tryed with: // Second type of geocoding: for each location from the first geocoding, i want // to have a unique [lat,lan] geocoder.geocode( { 'address': results_1[0].address_components[i].long_name }, (function(results_2, status_2, long_name){ // But in this way i'll never get results_2 or status_2, well, results_2 // get long_name value, status_2 and long_name is undefined. // However, html var is correctly updated. coords = results_2[0].geometry.location.toUrlValue(); html += 'some html to let the user choose the locality'; })(results_1[0].address_components[i].long_name) ); And with: // Second type of geocoding: for each location from the first geocoding, i want to have // a unique [lat,lan] geocoder.geocode( { 'address': results_1[0].address_components[i].long_name }, (function(results_2, status_2, long_name){ // But i get an obvious "results_2 is not defined" error (same for status_2). coords = results_2[0].geometry.location.toUrlValue(); html += 'some html to let the user choose the locality, that can be more than one'; })(results_2, status_2, results_1[0].address_components[i].long_name) ); Any suggestion? EDIT: My problem is how to pass an additional arguments to the geocoder inner function: function(results_2, status_2, long_name){ //[...] } becose if i do that with a clousure, I mess with the original parameters (results_2 and status_2)

    Read the article

  • Help using left outer joins in SQL...

    - by Waffles
    I'm trying to create a list of people, their friends, and their friends of friends. My table of people is this: People: NAME Jow Smith Sandy Phil Friends LIKER LIKEE jow smith smith jow sandy phil Now, what I want is a table like this: User Friend FriendofFriend Jow smith jow Smith jow smith sandy phil phil I'm trying to create a table using the following: SELECT P.NAME, F.LIKEE, F2.LIKEE FROM PEOPLE P LEFT OUTER JOIN FRIENDS F ON P.NAME = F.LIKER LEFT OUTER JOIN FRIENDS F2 ON F.LIKEE = F2.LIKER But the above isn't working. How can I get a table of people and their friends, regardless of whether or not they actually HAVE any friends?

    Read the article

  • C# (With .NET & Visual Studio) WebForms - How can I get the title of a page ..?

    - by Ashley Davies
    Prety long question; How can I do the following in C#: Open a webpage (Prefferably not visible) Check whether the page redirects to a different page (Site is down, 404, etc.) Check if the title is not equal to a said string Then seperately, (They need to click a confirm button) open their browser, and go to the adress of the first (It'll be the only one) hyperlink on the site. I literally have been looking on google for ages and haven't found anything similar to what I need. Whether you give me a link to a site with a tutorial on this area of programming or actual source code doesn't make a difference to me.

    Read the article

  • How do I populate an NSMutableArray in one class with another object?

    - by AngeloS
    Hello, I know this is a simple answer, but I can't seem to find the solution. I created an object in its own class and I am trying to populate it with data from another class. For simple data types like NSString, I have no problem, but when trying make an NSMutableArray equal to another NSMutableArray or when I try to populate a NSMutableArray with another objects (like strings), I keep getting exception errors... Here is the object I am trying to populate: #import <Foundation/Foundation.h> @interface RSSFeedList : NSObject { NSString *subject; NSMutableArray *rssfeedDetail; } @property (nonatomic, retain) NSString *subject; @property (nonatomic, retain) NSMutableArray *rssfeedDetail; @end This is how I was able to populate the NSString 'subject' in another class: rssFeedList.subject = @"test"; However, if I follow similar convention within that same class with respect to an Array, it throws an exception: rssFeedList.rssfeedDetail = rssItemDetailArray; Where rssItemDetailArray is a NSMutableArray that I have built in the same class. I have also tried to add items (i tried strings for testing) to the NSMutableArray directly like so to no avail: [rssFeedList.rssfeedDetail addObject:@"test"]; Any ideas?? Thanks in advance!!

    Read the article

  • Web Safe Area (optimal resolution) for web app design

    - by M.A.X
    I'm in the process of designing a new web app and I'm wondering for what 'web safe area' should I optimize the app layout and design. I did some investigation and thinking on my own but wanted to share this to see what the general opinion is. Here is what I found: Optimal Display Resolution: w3schools web stats seems to be the most referenced source (however they state that these are results from their site and is biased towards tech savvy users) http://www.w3counter.com/globalstats.php (aggregate data from something like 15,000 different sites that use their tracking services) StatCounter Global Stats Display Resolution (Stats are based on aggregate data collected by StatCounter on a sample exceeding 15 billion pageviews per month collected from across the StatCounter network of more than 3 million websites) NetMarketShare Screen Resolutions (marketshare.hitslink.com) (a web analytics consulting firm, they get data from browsers of site visitors to their on-demand network of live stats customers. The data is compiled from approximately 160 million visitors per month) Display Resolution Summary: There is a bit of variation between the above sources but in general as of Jan 2011 looks like 1024x768 is about 20%, while ~85% have a higher resolution of at least 1280x768 (1280x800 is the most common of these with 15-20% of total web, depending on the source; 1280x1024 and 1366x768 follow behind with 9-14% of the share). My guess would be that the higher resolution values will be even more common if we filter on North America, and even higher if we filter on N.American corporate users (unfortunately I couldn't find any free geographically filtered statistics). Another point to note is that the 1024x768 desktop user population is likely lower than the aforementioned 20%, seeing as the iPad (1024x768 native display) is likely propping up those number. My recommendation would be to optimize around the 1280x768 constraint (*note: 1280x768 is actually a relatively rare resolution, but I think it's a valid constraint range considering that 1366x768 is relatively common and 1280 is the most common horizontal resolution). Browser + OS Constraints: To further add to the constraints we have to subtract the space taken up by the browser (assuming IE, which is the most space consuming) and the OS (assuming WinXP-Win7): Win7 has the biggest taskbar footprint at a height of 40px (XP's and Vista's is 30px) The default IE8 view uses up 25px at the bottom of the screen with the status bar and a further 120px at the top of the screen with the windows title bar and the browser UI (assuming the default 'favorites' toolbar is present, it would instead be 91px without the favorites toolbar). Assuming no scrollbar, we also loose a total of 4px horizontally for the window outline. This means that we are left with 583px of vertical space and 1276px of horizontal. In other words, a Web Safe Area of 1276 x 583 Is this a correct line of thinking? I tried to Google some design best practices but most still talk about designing around 1024x768 which seems to be quickly disappearing. Any help on this would be greatly appreciated! Thanks.

    Read the article

  • Post wall message on facebook account

    - by Zeroshade
    Hello, I am trying to implement some functionality in a blackberry app, that I saw in other application. Basically it's a window that has a message, and a Facebook icon. When you click on the icon it launches a new window, this window asks the user for permissions(user and password), and then the message is posted in the user's wall. So my question is how can I replicate that?. I have been looking at the graph api, but I just can't figure out how to do all of this in one step. I mean just typing the url in the browser, and some post data. Thanks a lot.

    Read the article

  • NSManagedObject - NSSet gets removed ??

    - by aryaxt
    I have an nsmanagedObject this NSManagedObject contains an NSSet. the data for NSSet get's lost when i call release on an NSManagedObject with retain count of 2. Wouldn't retaining an NSManagedObject also retain all it's properties?? - (id)initViewWithManagedObject :(NSManagedObject)obj { if (self = [super init]) { self.managedObject = obj; } } - (void)dealloc { [self.managedObject release]; //Here is when the nsset data gets removed [super dealloc]; } Below describes how the property was created @interface MyManagedObject :NSManagedObject @property (nonatomic, retain) NSSet *mySet; @end @implementation MyManagedObject @dynamic mySet; @end

    Read the article

  • Increasing width of UISearchDisplayController PopOver Results

    - by George
    I have an iPad app that has a UISearchBar in its navigation bar. When I enter text in the search bar the results are automatically displayed in a UIPopOverController. That's great except the popover's default size is not wide enough for my needs. Is there a way to set its width? Apple has done this themselves with Safari's search bar. The popover that displays search results is a good bit wider than the default and they have removed the "Results" title from the popover.

    Read the article

  • Object leak using "retain"

    - by Abhinav
    I have a property defined with retain attribute which I am synthesizing: @property (nonatomic, retain) UISwitch *mySwitch; And inside my loadView I am doing this: self.mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 40, 20)]; And finally inside my dealloc I am doing this: self.mySwitch = nil; Am I leaking this object (mySwitch) as I have used one alloc? Should I autorelease it while assigning it frame? Please suggest.

    Read the article

  • Comparing two ISO8601 dates strings in PHP

    - by oompahloompah
    I need to compare (actually rank/sort) dates in a PHP script. The dates are ISO-8601 Date format i.e. YYYY-MM-DD I wrote a comparison function which splits the dates and compares by year/month/day. However, it seems this may be overkill and I could just as easily done a simple string comparison like: if ($date1 < $date2) // do something elseif( $date1 > $date2) //do something else else //do yet another thing Is my assumption about (ISO-8601) Date string comparison correct - i.e. can I get rid of my function (to save a few clock cycles on the server), or is it safer to explicity do the comparison in a custom function?

    Read the article

  • How to create a static delegate from main-viewcontroller?

    - by geforce
    Hi, hope someone can help me on learning some new stuff about delegates in iOS-programming. I have a "MainViewController" which is the first VC when the app starts. I´ve a kind of modelselection with different UIImageViews and after choosing one of them, i´m pushing a new VC. I want to handle the modelChoice with a delegate, so all other viewControllers can listen to that and act based on the users choice. But does that mean that i have to alloc a new instance of that "MainViewController" in every VC? Whats the solution on that? How do i create (i think its called) static delegate? Would be great to learn that.. Thanks for sharing..

    Read the article

  • Delete element from array

    - by Julio Diaz
    Is there a way I can get rid of some elements in an array. for instance, if i have this array int testArray[] = {0,2,0,3,0,4,5,6} Is there a "fast" way to get rid of the elements that equal 0 int resultArray[] = {2,3,4,5,6} I tried this function but I got lost using Lists public int[] getRidOfZero(int []s){ List<> result=new ArrayList<>(); for(int i=0; i<s.length; i++){ if(s[i]<0){ int temp = s[i]; result.add(temp); } } return result.toArray(new int[]); }

    Read the article

  • reading 2 lines from IniFile

    - by Lakkerw
    Trying again. On advice, adding the piece of code that I do understand. I am fine with the fact that I have to save 4 bits of information in two lines like so: IniFile.WriteString('TestSection','Name','Country'); IniFile.WriteString('TestSection','City','Street'); My question is more about loading this information back into the form. If in my IniFile I have saved for example the following code [TestSection] John=Uk London=barlystreet Mike=Spain Madrid=eduardostrata Emma=USA New York=1st Avenue Made up information in the IniFile. Added through the code above. Now my question is: How could I load for example, when I type in an edit box Mike, the rest of the belonging information.(Spain, Madrid,eduardostrata).

    Read the article

  • Safely deploying changes to production servers

    - by oazabir
    When you deploy incremental changes on a production server, which is running and live all the time, you some times see error messages like “Compiler Error Message: The Type ‘XXX’ exists in both…”. Sometimes you find Application_Start event not firing although you shipped a new class, dll or web.config. Sometimes you find static variables not getting initialized and so on. There are so many weird things happen on webservers when you incrementally deploy changes to the server and the server has been up and running for several weeks. So, I came up with a full proof house keeping steps that we always do whenever we deploy some incremental change to our websites. These steps ensure that the web sites are properly recycled , cached are cleared, all the data stored at Application level is initialized. First of all you should have multiple web servers behind load balancer. This way you can take one server our of the production traffic, do your deployment and house keeping tasks like restarting IIS, and then put it back. Then you can do it for the second server and so on. This ensures there’s no outage for customer. If you can do it reasonable fast, hopefully customers won’t notice discrepancy between the servers some having new code and some having old code. You should only do this when your changes aren’t drastic. For ex, you aren’t delivering a complete revamped UI. In that case, some users hitting server1 with latest UI will suddenly get a completely different experience and then on next page refresh, they might hit server2 with old code and get a totally different experience. This works for incremental non-dramatic changes only.   During deployment you should follow these steps: Take server X out of load balancer so that it does not get any traffic. Stop all windows services on the server. Stop IIS. Delete the Temporary ASP.NET folders of all .NET versions incase you have multiple .NET versions running. You can follow this link. Deploy the changes. Flush any distributed cache you have, for ex, Velocity or Memcached. Start IIS. Start the windows services on the server. Warm up all websites by hitting major URLs on the websites. You should have some automated script to do this. You can use tinyget to hit some major URLs, especially pages that take a lot of time to compile. Read my post on keeping websites warm with zero coding. Put server X back to load balancer so that it starts receiving traffic. That’s it. It should give you a clean deployment and prevent unexpected errors. You should print these steps and hang on the desk of your deployment guys so that they never forget during deployment pressure.

    Read the article

  • 36 Hour Free Offer: jQuery Fundamentals Training

    - by ScottGu
    Pluralsight (a great .NET training company) is offering the opportunity to watch their jQuery Fundamentals course for free for the next 36 hours. The course is presented by the most excellent Dan Wahlin and contains 5 hours of great end to end content.  Pluralsight will be offering this jQuery Fundamentals course for free until Thursday evening (9pm PST). Pluralsight has about 100 other great training courses available similar to this one.  They recently launched a new subscription plan that allows you to watch all of their courses online starting from $29 a month.  They also offer a 10 day free trial option that you can use to try it out.  You can learn more about it here. Free jQuery 1.5 Visual Cheat Sheet While on the topic of jQuery, I wanted to link to one other useful resource to download if you are using jQuery – which is a free jQuery PDF “cheat sheet” for the jQuery 1.5 APIs. You can download it for free here. Hope this helps, Scott P.S. I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

    Read the article

  • Introducing Data Annotations Extensions

    - by srkirkland
    Validation of user input is integral to building a modern web application, and ASP.NET MVC offers us a way to enforce business rules on both the client and server using Model Validation.  The recent release of ASP.NET MVC 3 has improved these offerings on the client side by introducing an unobtrusive validation library built on top of jquery.validation.  Out of the box MVC comes with support for Data Annotations (that is, System.ComponentModel.DataAnnotations) and can be extended to support other frameworks.  Data Annotations Validation is becoming more popular and is being baked in to many other Microsoft offerings, including Entity Framework, though with MVC it only contains four validators: Range, Required, StringLength and Regular Expression.  The Data Annotations Extensions project attempts to augment these validators with additional attributes while maintaining the clean integration Data Annotations provides. A Quick Word About Data Annotations Extensions The Data Annotations Extensions project can be found at http://dataannotationsextensions.org/, and currently provides 11 additional validation attributes (ex: Email, EqualTo, Min/Max) on top of Data Annotations’ original 4.  You can find a current list of the validation attributes on the afore mentioned website. The core library provides server-side validation attributes that can be used in any .NET 4.0 project (no MVC dependency). There is also an easily pluggable client-side validation library which can be used in ASP.NET MVC 3 projects using unobtrusive jquery validation (only MVC3 included javascript files are required). On to the Preview Let’s say you had the following “Customer” domain model (or view model, depending on your project structure) in an MVC 3 project: public class Customer { public string Email { get; set; } public int Age { get; set; } public string ProfilePictureLocation { get; set; } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } When it comes time to create/edit this Customer, you will probably have a CustomerController and a simple form that just uses one of the Html.EditorFor() methods that the ASP.NET MVC tooling generates for you (or you can write yourself).  It should look something like this: With no validation, the customer can enter nonsense for an email address, and then can even report their age as a negative number!  With the built-in Data Annotations validation, I could do a bit better by adding a Range to the age, adding a RegularExpression for email (yuck!), and adding some required attributes.  However, I’d still be able to report my age as 10.75 years old, and my profile picture could still be any string.  Let’s use Data Annotations along with this project, Data Annotations Extensions, and see what we can get: public class Customer { [Email] [Required] public string Email { get; set; }   [Integer] [Min(1, ErrorMessage="Unless you are benjamin button you are lying.")] [Required] public int Age { get; set; }   [FileExtensions("png|jpg|jpeg|gif")] public string ProfilePictureLocation { get; set; } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Now let’s try to put in some invalid values and see what happens: That is very nice validation, all done on the client side (will also be validated on the server).  Also, the Customer class validation attributes are very easy to read and understand. Another bonus: Since Data Annotations Extensions can integrate with MVC 3’s unobtrusive validation, no additional scripts are required! Now that we’ve seen our target, let’s take a look at how to get there within a new MVC 3 project. Adding Data Annotations Extensions To Your Project First we will File->New Project and create an ASP.NET MVC 3 project.  I am going to use Razor for these examples, but any view engine can be used in practice.  Now go into the NuGet Extension Manager (right click on references and select add Library Package Reference) and search for “DataAnnotationsExtensions.”  You should see the following two packages: The first package is for server-side validation scenarios, but since we are using MVC 3 and would like comprehensive sever and client validation support, click on the DataAnnotationsExtensions.MVC3 project and then click Install.  This will install the Data Annotations Extensions server and client validation DLLs along with David Ebbo’s web activator (which enables the validation attributes to be registered with MVC 3). Now that Data Annotations Extensions is installed you have all you need to start doing advanced model validation.  If you are already using Data Annotations in your project, just making use of the additional validation attributes will provide client and server validation automatically.  However, assuming you are starting with a blank project I’ll walk you through setting up a controller and model to test with. Creating Your Model In the Models folder, create a new User.cs file with a User class that you can use as a model.  To start with, I’ll use the following class: public class User { public string Email { get; set; } public string Password { get; set; } public string PasswordConfirm { get; set; } public string HomePage { get; set; } public int Age { get; set; } } Next, create a simple controller with at least a Create method, and then a matching Create view (note, you can do all of this via the MVC built-in tooling).  Your files will look something like this: UserController.cs: public class UserController : Controller { public ActionResult Create() { return View(new User()); }   [HttpPost] public ActionResult Create(User user) { if (!ModelState.IsValid) { return View(user); }   return Content("User valid!"); } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Create.cshtml: @model NuGetValidationTester.Models.User   @{ ViewBag.Title = "Create"; }   <h2>Create</h2>   <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>   @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>User</legend> @Html.EditorForModel() <p> <input type="submit" value="Create" /> </p> </fieldset> } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } In the Create.cshtml view, note that we are referencing jquery validation and jquery unobtrusive (jquery is referenced in the layout page).  These MVC 3 included scripts are the only ones you need to enjoy both the basic Data Annotations validation as well as the validation additions available in Data Annotations Extensions.  These references are added by default when you use the MVC 3 “Add View” dialog on a modification template type. Now when we go to /User/Create we should see a form for editing a User Since we haven’t yet added any validation attributes, this form is valid as shown (including no password, email and an age of 0).  With the built-in Data Annotations attributes we can make some of the fields required, and we could use a range validator of maybe 1 to 110 on Age (of course we don’t want to leave out supercentenarians) but let’s go further and validate our input comprehensively using Data Annotations Extensions.  The new and improved User.cs model class. { [Required] [Email] public string Email { get; set; }   [Required] public string Password { get; set; }   [Required] [EqualTo("Password")] public string PasswordConfirm { get; set; }   [Url] public string HomePage { get; set; }   [Integer] [Min(1)] public int Age { get; set; } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Now let’s re-run our form and try to use some invalid values: All of the validation errors you see above occurred on the client, without ever even hitting submit.  The validation is also checked on the server, which is a good practice since client validation is easily bypassed. That’s all you need to do to start a new project and include Data Annotations Extensions, and of course you can integrate it into an existing project just as easily. Nitpickers Corner ASP.NET MVC 3 futures defines four new data annotations attributes which this project has as well: CreditCard, Email, Url and EqualTo.  Unfortunately referencing MVC 3 futures necessitates taking an dependency on MVC 3 in your model layer, which may be unadvisable in a multi-tiered project.  Data Annotations Extensions keeps the server and client side libraries separate so using the project’s validation attributes don’t require you to take any additional dependencies in your model layer which still allowing for the rich client validation experience if you are using MVC 3. Custom Error Message and Globalization: Since the Data Annotations Extensions are build on top of Data Annotations, you have the ability to define your own static error messages and even to use resource files for very customizable error messages. Available Validators: Please see the project site at http://dataannotationsextensions.org/ for an up-to-date list of the new validators included in this project.  As of this post, the following validators are available: CreditCard Date Digits Email EqualTo FileExtensions Integer Max Min Numeric Url Conclusion Hopefully I’ve illustrated how easy it is to add server and client validation to your MVC 3 projects, and how to easily you can extend the available validation options to meet real world needs. The Data Annotations Extensions project is fully open source under the BSD license.  Any feedback would be greatly appreciated.  More information than you require, along with links to the source code, is available at http://dataannotationsextensions.org/. Enjoy!

    Read the article

  • PEX - are you licenced for it?

    - by TATWORTH
    There is an interesting artcile about PEX at http://blogs.msdn.com/b/ukmsdn/archive/2011/02/22/featured-article-pex-and-visual-studio.aspx PEX can be downloaded from http://research.microsoft.com/en-us/projects/pex/downloads.aspx The licence conditions are: "Pex and Moles are Power Tools available for commercial use for MSDN subscribers. Moles is also available separately for commercial use without requiring an MSDN subscription. Pex and Moles are also available for academic and non-commercial use." I note with interest that it is now available to MSDN subscribers. If I recall correctly it used to be only available to VS Team versions.

    Read the article

  • Is now the right time to move to .NET 4?

    - by bconlon
    The reason I pose this question is that I'm looking at WPF development and so using the latest version seems sensible. However, this means rolling out the .NET 4 runtime to PCs on old versions of the framework. Windows XP is still the number one O/S (estimated 40%+ market share). To run .NET 4 on XP requires Service Pack 3, and although it is good practice to move to the latest service packs, often large companies are slow to keep up due to the extensive testing involved. In fact, .NET 4 is not installed as standard with any Windows O/S as yet - Windows 7 and 2008 Server R2 have 3.5 installed. This is not quite as big an issue as it was for .NET 3.5 as .NET 4 is significantly smaller as it doesn't include the older runtimes - .NET 3.5 SP1 included .NET 3 and .NET 2 and was 250MB, although this was reduced by doing a web install. The size is also reduced a bit if you target the .NET 4 Client Profile, which should be OK for many WPF applications, and I think this may be rolled out as part of Windows service packs soon. But still, if your application is only 4-5 MB and you need 40-50 MB of Framework it is worth consideration before jumping in and using the new shiny features. #

    Read the article

  • Apress Deal of the day - 23/Feb/2011 - Ultra-Fast ASP.NET: Building Ultra-Fast and Ultra-Scalable Websites Using ASP.NET and SQL Server

    - by TATWORTH
    Today's $10 deal of the day at http://www.apress.com/info/dailydeal  is Ultra-Fast ASP.NET: Building Ultra-Fast and Ultra-Scalable Websites Using ASP.NET and SQL Server by Richard Kessig - ISBN 978-1-4302-2383-2 I won a copy of this book at 101 Books. Richard Kessig is an all-star member of forums.asp.net - see http://forums.asp.net/members/RickNZ.aspx - this book has been on before as deal of the day. If you did not get a copy then, I suggest getting it today. " Ultra-Fast ASP.NET provides a practical guide to building extremely fast and scalable web sites using ASP.NET and SQL Server. It strikes a balance between imparting usable advice and backing that advice up with supporting background information. $49.99 | Published Nov 2009 | Rick Kiessig"

    Read the article

  • Digital HD Transition

    - by Bill Evjen
    The HD Experience Roughly 53% of the viewing public has HD capable devices in their home 24% think they are watching HD while they have no subscription to any HD content Today’s HD Considerations Choices abound: format resolution – 720p, 1080i/p frame rates compression and wrapping audio compression and delivery metadata packaging, delivery, and usage content delivery protocols Metadata is going to be a part of the overall experience With emerging technologies: Super Hi-Vision (SHV, UHDTV 4320p), 3D HEVC/H.265, WEBM/VP8 HDBaseT, P2PTV Dolby Pulse/HE-AAC Industry standardization Metadata registration, packaging, and delivery standards Improved picture and sound quality is a logical next step but we need to also think about the end to end viewing experience including; 3D video and audio content Mixed-mode viewing to bring interactive and immersive experiences Content Transportability both on-to and off-of the aircraft High Definition Standardization Analog switch off around the world DTV transition completed: 17 countries DTV transition in progress: 45 countries The EU has mandated the end of 2012 as the final date for Analog Switch Off D-Cinema was standardized by SMPTE in 2006 Airlines are installing HD displays today Passengers are bringing their own devices now HD TV on airlines are getting bigger and bigger – bigger than SD was – now up to 23” Gray scale data input for color – 6 to 8 bit Contrast – 400 to 700 Backlit – LED Encryption – can it be the same for HD? PPV in the cabin?

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13  | Next Page >