Daily Archives

Articles indexed Monday June 18 2012

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

  • Enumerable.Range in and Expression and Entity Framework

    - by eka808
    I'm currently developping an expression method (used in linq to entity queries) who has to give me a daycount for a given period (start date and end date) decrementing this daycount if specials days are in the period. My idea was the following : Generate an enumerable with all the dates (and with Enumerable.Range) Make a .Where on this enumerable to remove the specials dates Like a MyEnumerable.Where(a = a != "20120101") After that, return a MyEnumerable.Count() I come with this code : return (p) => Enumerable .Range(1, 4) .Where(a => a != 20120101) .AsQueryable() .Count() I tried to cast as a list, as a queryable, both (like the example) and no way ! it doesn't work ! I always get this error : LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1[System.Int32] Range(Int32, Int32)' method, and this method cannot be translated into a store expression. Have you got an idea about that ? Using an enumerable is of course not mandatory, any working solutions is good ^^ Thank's by advance !

    Read the article

  • Why are symbols not frozen strings?

    - by Alex Chaffee
    I understand the theoretical difference between Strings and Symbols. I understand that Symbols are meant to represent a concept or a name or an identifier or a label or a key, and Strings are a bag of characters. I understand that Strings are mutable and transient, where Symbols are immutable and permanent. I even like how Symbols look different from Strings in my text editor. What bothers me is that practically speaking, Symbols are so similar to Strings that the fact that they're not implemented as Strings causes a lot of headaches. They don't even support duck-typing or implicit coercion, unlike the other famous "the same but different" couple, Float and Fixnum. The mere existence of HashWithIndifferentAccess, and its rampant use in Rails and other frameworks, demonstrates that there's a problem here, an itch that needs to be scratched. Can anyone tell me a practical reason why Symbols should not be frozen Strings? Other than "because that's how it's always been done" (historical) or "because symbols are not strings" (begging the question). Consider the following astonishing behavior: :apple == "apple" #=> false, should be true :apple.hash == "apple".hash #=> false, should be true {apples: 10}["apples"] #=> nil, should be 10 {"apples" => 10}[:apples] #=> nil, should be 10 :apple.object_id == "apple".object_id #=> false, but that's actually fine All it would take to make the next generation of Rubyists less confused is this: class Symbol < String def initialize *args super self.freeze end (and a lot of other library-level hacking, but still, not too complicated) See also: http://onestepback.org/index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.red http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol Why does my code break when using a hash symbol, instead of a hash string? Why use symbols as hash keys in Ruby? What are symbols and how do we use them? Ruby Symbols vs Strings in Hashes Can't get the hang of symbols in Ruby

    Read the article

  • Error after passing variable from jquery to code in c#

    - by Moraru Viorel
    I try to pass variable from jquery to code c# but something is wrong. I have in js this code: <script type="text/javascript"> var mySerial = '12345'; var fooUrl = '@Url.Action("Foo", "Home")'; window.location.href = fooUrl + '?mySerial' + encodeURIComponent(mySerial); </script> in controller : [HttpPost] public ActionResult Foo(string mySerial) { return View(); } After execution I keep this url: http://localhost:2214/@Url.Action("Foo",%20"Home")?mySerial12345 and I don't understand where's the problem, can someone help me?

    Read the article

  • Round-twice error in .NET's Double.ToString method

    - by Jeppe Stig Nielsen
    Mathematically, consider for this question the rational number 8725724278030350 / 2**48 where ** in the denominator denotes exponentiation, i.e. the denominator is 2 to the 48th power. (The fraction is not in lowest terms, reducible by 2.) This number is exactly representable as a System.Double. Its decimal expansion is 31.0000000000000'49'73799150320701301097869873046875 (exact) where the apostrophes do not represent missing digits but merely mark the boudaries where rounding to 15 resp. 17 digits is to be performed. Note the following: If this number is rounded to 15 digits, the result will be 31 (followed by thirteen 0s) because the next digits (49...) begin with a 4 (meaning round down). But if the number is first rounded to 17 digits and then rounded to 15 digits, the result could be 31.0000000000001. This is because the first rounding rounds up by increasing the 49... digits to 50 (terminates) (next digits were 73...), and the second rounding might then round up again (when the midpoint-rounding rule says "round away from zero"). (There are many more numbers with the above characteristics, of course.) Now, it turns out that .NET's standard string representation of this number is "31.0000000000001". The question: Isn't this a bug? By standard string representation we mean the String produced by the parameterles Double.ToString() instance method which is of course identical to what is produced by ToString("G"). An interesting thing to note is that if you cast the above number to System.Decimal then you get a decimal that is 31 exactly! See this Stack Overflow question for a discussion of the surprising fact that casting a Double to Decimal involves first rounding to 15 digits. This means that casting to Decimal makes a correct round to 15 digits, whereas calling ToSting() makes an incorrect one. To sum up, we have a floating-point number that, when output to the user, is 31.0000000000001, but when converted to Decimal (where 29 digits are available), becomes 31 exactly. This is unfortunate. Here's some C# code for you to verify the problem: static void Main() { const double evil = 31.0000000000000497; string exactString = DoubleConverter.ToExactString(evil); // Jon Skeet, http://csharpindepth.com/Articles/General/FloatingPoint.aspx Console.WriteLine("Exact value (Jon Skeet): {0}", exactString); // writes 31.00000000000004973799150320701301097869873046875 Console.WriteLine("General format (G): {0}", evil); // writes 31.0000000000001 Console.WriteLine("Round-trip format (R): {0:R}", evil); // writes 31.00000000000005 Console.WriteLine(); Console.WriteLine("Binary repr.: {0}", String.Join(", ", BitConverter.GetBytes(evil).Select(b => "0x" + b.ToString("X2")))); Console.WriteLine(); decimal converted = (decimal)evil; Console.WriteLine("Decimal version: {0}", converted); // writes 31 decimal preciseDecimal = decimal.Parse(exactString, CultureInfo.InvariantCulture); Console.WriteLine("Better decimal: {0}", preciseDecimal); // writes 31.000000000000049737991503207 } The above code uses Skeet's ToExactString method. If you don't want to use his stuff (can be found through the URL), just delete the code lines above dependent on exactString. You can still see how the Double in question (evil) is rounded and cast.

    Read the article

  • HOWTO: implement a jQuery version of ASP.Net MVC "Strongly Typed Partial Views"

    - by Sam Carleton
    I am working on a multi-page assessment form where the questions/responses are database driven. Currently I the basic system working with Html.BeginForm via standard ASP.Net MVC. At this point in time, the key to the whole system is the 'Strongly Typed Partial Views'. When the question/response is read from the database, the response type determines which derived model is created and added to the collection. The main view it iterates through the collection and uses the 'Strongly Typed Partial Views' system of ASP.Net MVC to determine which view to render the correct type of response (radio button, drop down, or text box). I would like to change this process from a Html.BeginForm to Ajax.BeginForm. The problem is I don't have a clue as to how to implement the dynamic creation of the question/response in the JavaScript/jQuery world. Any thoughts and/or suggestions? Here is the current code to generate the dynamic form: @using (Html.BeginForm(new { mdsId = @Model.MdsId, sectionId = @Model.SectionId })) { <div class="SectionTitle"> <span>Section @Model.SectionName - @Model.SectionDescription</span> <span style="float: right">@Html.CheckBoxFor(x => x.ShowUnansweredQuestions) Show only unaswered questions</span> </div> @Html.HiddenFor(x => x.PrevSectionId) @Html.HiddenFor(x => x.NextSectionId) for (var i = 0; i < Model.answers.Count(); i++) { @Html.EditorFor(m => m.answers[i]); } }

    Read the article

  • Rails & Twilio: Receiving nil when storing texts received from Twilio

    - by Jon Smooth
    I have set up the request URL in my Twilio account to have it POST to: myurl.com/receivetext. It appears to be successfully posting because when I check the database using the Heroku console I see the following: Post id: 5, body: nil, from: nil, created_at: "2012-06-14 17:28:01", updated_at: "2012-06-14 17:28:01" Why is it receiving nil for the body and from attributes? I can't figure out what I'm doing wrong! The created and updated at are storing successfully but the two attributes that I care about continue to be stored as nil. Here's the Receive Text controller which is receiving the Post request from Twilio: class ReceiveTextController < ApplicationController def index @post=Post.create!(body: params[:Body], from: params[:From]) end end EDIT: When I dump the params I receive the following: "{\"controller\"=\"receive_text\", \"action\"=\"index\"}" I attained this by inserting the following into my ReceiveText controller. @params = Post.create!(body: params.inspect, from: "Dumping Params") and then opening up the Heroku console to find the database entry with from = "Dumping Params". I simulated a Twilio request with a curl with the following command curl -X POST myurl.com/receivetext route -d 'AccountSid=AC123&From=%2B19252411234' I checked the production database again and noticed that the curl request did work when obtaining the FROM atribute. It stored the following: params.inspect returned "{\"AccountSid\"=\"AC123\", \"From\"=\"+19252411234\", \"co..." I received a comment stating: "As long as twilio is hitting the same URL with the same method (GET/POST) it should be filling the params array as well" I have no idea how to make this comment actionable. Any help would be greatly appreciated! I'm very new to rails. Here's my database migration (I have both attributes set to string. I have tried setting it to text and that didn't work either) : class CreatePosts < ActiveRecord::Migration def change create_table :posts do |t| t.string :body t.string :from t.timestamps end end end Here is my Post model: class Post < ActiveRecord::Base attr_accessible :body, :from end Routes (everything appears to be routing just fine) : MovieApp::Application.routes.draw do get "receive_text/index" get "pages/home" get "send_text/send_text_message" root to: 'pages#home' match '/receivetext', to: 'receive_text#index' match '/pages/home', to: 'pages#home' match '/sendtext', to: 'send_text#send_text_message' end Here's my gemfile (incase it helps) source 'https://rubygems.org' gem 'rails', '3.2.3' gem 'badfruit' gem 'twilio-ruby' gem 'logger' gem 'jquery-rails' group :production do gem 'pg' end group :development, :test do gem 'sqlite3' end group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'uglifier', '>= 1.0.3' end

    Read the article

  • Save object using variable with object name

    - by FBE
    I'm wondering what an easy way is to save an object in R, using a variable objectName with the name of the object to be saved. I want this to easy save objects, with their name in the file name. I tried to use get, but I didn't manage to save the object with it's original object name. Example: If I have the object called "temp", which I want to save in the directory "dataDir". I put the name of the object in the variable "objectName". Attempt 1: objectName<-"temp" save(get(objectName), file=paste(dataDir, objectName, ".RData", sep="")) load(paste(dataDir, objectName, ".RData", sep="")) This didn't work, because R tries to save an object called get(objectName), instead of the result of this call. So I tried the following: Attempt 2: objectName<-"temp" object<-get(objectName) save(object, file=paste(dataDir, objectName, ".RData", sep="")) load(paste(dataDir, objectName, ".RData", sep="")) This obviously didn't work, because R saves the object with name "object", and not with name "temp". After loading I have a copy of "object", instead of "temp". (Yes, with the same contents...but that is not what I want :) ). So I thought it should be something with pointers. So tried the following: Attempt 3: objectName<-"temp" object<<-get(objectName) save(object, file=paste(dataDir, objectName, ".RData", sep="")) load(paste(dataDir, objectName, ".RData", sep="")) Same result as attempt 2. But I'm not sure I'm doing what I think I'm doing. What is the solution for this?

    Read the article

  • Rails: How to have dynamic association

    - by Aaron Dufall
    I'll use an example to explain what behaviour I would like to achieve. If you had a project management app and you added a task, but not all the contributors are users of the app. So when you adding contributors to the task you can enter a user name or email address. Here is the part that I'm finding a little tricky. The task model has many contributors which are linked through the user model, but from this point on I want to achieve 2 things. Store the non members email(this would obviously be quite simple) If that email address was to create an account it would then link that user to the task and remove the temporally saved email. This way, when that user creates an account all the related tasks will already be associated with their email. Is this something that i could achieve with a polymorphic association? or is there something else I should be looking at?

    Read the article

  • OnChange on textbox Event calling twice

    - by Abhi
    I am adding onchange event dynamically using Jqery.. When I am changing the textbox the event is firing twice and two times alert boxes are coming sometimes 3 times. if(Country.toUpperCase().indexOf("MALAYSIA")!=-1) { debugger; if(productDesc.toUpperCase().indexOf("SV")!=-1) { $("#<%=txtlAxis.ClientID%>").change(function() { if(productDesc.toUpperCase().indexOf("SV")!=-1) { alert('2'); } }); } }

    Read the article

  • Facebook - Publish Checkins using Graph API

    - by Zany
    I'm trying to publish Checkin using Facebook Graph API. I've gone through Facebook API documentation (checkins) and also have the publish_checkins permission. However, my checkin is not getting published. May I know is there anything wrong or am I missing anything else? Thank you for your time :) fbmain.php $user = $facebook->getUser(); $access_token = $facebook->getAccessToken(); // Session based API call if ($user) { try { $me = $facebook->api('/me'); if($me) { $_SESSION['fbID'] = $me['id']; $uid = $me['id']; } } catch (FacebookApiException $e) { error_log($e); } } else { echo "<script type='text/javascript'>top.location.href='$loginUrl';</script>"; exit; } $loginUrl = $facebook->getLoginUrl( array( 'redirect_uri' => $redirect_url, 'scope' => status_update, publish_stream, publish_checkins, user_checkins, user_location, user_status' ) ); main.php (Updated: 18/6/2012 11.12pm) <?php include_once "fbmain.php"; if (!isset($_POST['latitude']) && !isset($_POST['longitude'])) { ?> <html> <head> //ajax POST of latitude and longitude </head> <body> <script type="text/javascript"> window.fbAsyncInit = function() { FB.init({ appId: '<?php echo $facebook->getAppID() ?>', cookie: true, xfbml: true, oauth: true, frictionlessRequests: true }); FB.Canvas.setAutoGrow(); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script> ... <input type="button" value="Check In!" onclick="checkin(<?=$facebook?>);"/></span> </body> </html> <?php } else { print_r($_POST['latitude']); print_r($_POST['longitude']); ?> <script type="text/javascript"> // not using latitude and longitude to test function checkin($fb) { try { $tryCatch = $facebook->api('/'.$_SESSION['fbID'].'/checkins', 'POST', array( 'access_token' => $fb->getAccessToken(), //corrected 'place' => '165122993538708', 'message' =>'I went to placename today', 'coordinates' => json_encode(array( 'latitude' => '1.3019399200902', 'longitude' => '103.84067653695' )) )); } catch(FacebookApiException $e) { $tryCatch=$e->getMessage(); } return $tryCatch; } </script> <?php } ?>

    Read the article

  • AdMob ad is showing in iOS simulator, but not on iDevice

    - by Ben Toscano
    As the heading states, I can get my AdMob Ad to show in the iOS 5.1 and 6.0 simulator just fine, however, when running my application on my iOS 5.1.1 or 6.0 devices, there is just a blank space where the ad should be served. The code in my .m file is as follows: bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, 411.0 - GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)]; bannerView_.adUnitID = @"**myID**"; bannerView_.rootViewController = self; [self.view addSubview:bannerView_]; [bannerView_ loadRequest:[GADRequest request]]; //GADRequest *r = [[GADRequest alloc] init]; //r.testing = YES; //[bannerView_ loadRequest:r]; Furthermore, if I initiate testing of ads (see commented-out section), the test ad shows on both the simulator AND my iDevices, which is baffling me! What am I missing? Thanks for your help.

    Read the article

  • Context path routing in Tomcat ( service swapping )

    - by jojovilco
    Here is what I would like to achieve: I have a web service A which I want to be able to deploy side by side with other web services of type A - different version(s). For now I assume 2 instances side by side. I need it because the service has a warm up stage, which takes some time to build up stuff from DB and only after it is ready it can start serving requests ... I was thinking to deploy to Tomcat context paths like: "/ServiceA-1.0", "/ServiceA-2.0" and then have a "virtual" context like "/ServiceA" which will point to the desired physical service e.g. "/ServiceA-1.0". So external world will know about ServiceA, but internally, my ServiceA related stack would know about versioned ServiceA url ( there are more components involved but only ServiceA is serving outer world ). When new service is ready, I would just reconfigure the "virtual" context to point to a new service. So far, I was not able to find out how to do this with Tomcat and starting to tkink it is not possible. I found suggestions to place Apache Server in front of Tomcat and do the routing there, but I do not want to enroll another piece of software unless necessary. My questions are: - is this kind of a "virtual" context and routing possible to do with Tomcat? - any other options, wisdom and lessons learned how to achieve this kind of service swapping scenario? Best, Jozef

    Read the article

  • How to hadle a tags inside another tags in NSXMLParser

    - by SimpleMan
    I have a file: <xml> <component>something <system>somethingDeeper <value>somethingDeepest</value> </system> </component> <component>somethinfDifferent <value>somethingDifferentDeeper</value> </component> <value>somethingNew</value> </xml> So i want to distinguish what is inside another tag (ex. <system>) what is not. How to do this with NSXMLParser ? I currently use BOOL ivar's but this is a lot of tags and this is not as elegant as i want it to be. I know that NSXMLParser is a SAX parser and i understand that. In above example I will be enter to didEndElement method three times with: elementName equal value Is there a more elegant way to distinguish what entry was from <component> tag above what not?

    Read the article

  • How do I move the location of an xcodeproj file without breaking external build target?

    - by petFoo
    I have an Xcode project with a directory structure like this: MasterProjectDir/projectname.xcodeproj MasterProjectDir/ProjectSubDir/whatever.c MasterProjectDir/ProjectSubDir/etc.c MasterProjectDir/ProjectSubDir/Makefile My xcodeproj uses an external build target to point to the Makefile using these settings: Build Tool: /usr/bin/make Arguments: $(ACTION) Directory: ./ProjectSubDir For various reasons, I need to change the project directory structure to look like this: MasterProjectDir/projectname.xcodeproj MasterProjectDir/whatever.c MasterProjectDir/etc.c MasterProjectDir/Makefile I copied the .xcodeproj file into the ProjectSubDir and the project somehow still knows where to look for the files (?!?! - this is odd because their location is set as "relative to group" and I've just moved the xcodeproj file). It won't build. I get the following error: make: * No targets specified and no makefile found. Stop. Command /usr/bin/make failed with exit code 2 I could use a little help on this. There must be a setting I need to change somewhere.

    Read the article

  • WPF closing child- closes parent-window

    - by Thomas Spranger
    i have the pretty same sample as mentioned here. Fast concluded: MainWindow closes when the last childwindow is closed. My Problem: I couldn't solve my problems with the described solutions. I can't produce a program where it als takes place. Only in one of my bigger progs. Maybe someone has an idea or knows any further steps. Thanks for reading - Thomas As requested here's a bit of code: This is the part in the MainWindow: bool editAfterSearch = false; Movie selectedMovie = (Movie)this.listView.SelectedItem; Movie backup = (Movie)selectedMovie.Clone(); if (new OnlineSearchWindow().EditMovieViaOnlineSearch(ref selectedMovie, out editAfterSearch)) { this.coverFlow.Update(selectedMovie); } And that's the part of the ChildWindow: public bool EditMovieViaOnlineSearch(ref Movie preset, out bool editAfter) { this.exitWithOk = false; this.editMovieAfterSearch = false; this.tbx_SearchTerm.Text = preset.Title; this.linkedMovie = preset; this.ShowDialog(); editAfter = editMovieAfterSearch; if (this.exitWithOk) { this.linkedMovie.CloneOnlineInformation(ref preset); preset.Bitmap = this.linkedMovie.Bitmap; return true; } else { return false; } }

    Read the article

  • Can't read AppletViewer properties file - Applet

    - by White rose
    I have create a java applet program and compiled, it generates a class file. while running the applet viewer in command prompt it shows a following warning message. D:\Applets\Appletsappletviewer FirstApplet.java Warning: Can't read AppletViewer properties file: C:eswaran_s.VMSPL.hotjava\properties Using defaults. After I have run this command once again, it does not shows a warning messsage but the applet viewer is not running. How can I solve this issue?

    Read the article

  • Ruby on Rails Increment Counter in Model

    - by febs
    I'm attempting to increment a counter in my User table from another model. class Count < ActiveRecord::Base belongs_to :user after_create :update_count def update_count user = User.find(self.user_id) user.increment(:count) end end So when count is created the goal would be to increment a counter column for that user. Currently it refuses to get the user after creation and I get a nil error. I'm using devise for my Users Is this the right (best practice) place to do it? I had it working in the controllers, but wanted to clean it up. I'm very inexperienced with Model callbacks.

    Read the article

  • Windows Azure Evolution &ndash; Caching (Preview)

    - by Shaun
    Caching is a popular topic when we are building a high performance and high scalable system not only on top of the cloud platform but the on-premise environment as well. On March 2011 the Windows Azure AppFabric Caching had been production launched. It provides an in-memory, distributed caching service over the cloud. And now, in this June 2012 update, the cache team announce a grand new caching solution on Windows Azure, which is called Windows Azure Caching (Preview). And the original Windows Azure AppFabric Caching was renamed to Windows Azure Shared Caching.   What’s Caching (Preview) If you had been using the Shared Caching you should know that it is constructed by a bunch of cache servers. And when you want to use you should firstly create a cache account from the developer portal and specify the size you want to use, which means how much memory you can use to store your data that wanted to be cached. Then you can add, get and remove them through your code through the cache URL. The Shared Caching is a multi-tenancy system which host all cached items across all users. So you don’t know which server your data was located. This caching mode works well and can take most of the cases. But it has some problems. The first one is the performance. Since the Shared Caching is a multi-tenancy system, which means all cache operations should go through the Shared Caching gateway and then routed to the server which have the data your are looking for. Even though there are some caches in the Shared Caching system it also takes time from your cloud services to the cache service. Secondary, the Shared Caching service works as a block box to the developer. The only thing we know is my cache endpoint, and that’s all. Someone may satisfied since they don’t want to care about anything underlying. But if you need to know more and want more control that’s impossible in the Shared Caching. The last problem would be the price and cost-efficiency. You pay the bill based on how much cache you requested per month. But when we host a web role or worker role, it seldom consumes all of the memory and CPU in the virtual machine (service instance). If using Shared Caching we have to pay for the cache service while waste of some of our memory and CPU locally. Since the issues above Microsoft offered a new caching mode over to us, which is the Caching (Preview). Instead of having a separated cache service, the Caching (Preview) leverage the memory and CPU in our cloud services (web role and worker role) as the cache clusters. Hence the Caching (Preview) runs on the virtual machines which hosted or near our cloud applications. Without any gateway and routing, since it located in the same data center and same racks, it provides really high performance than the Shared Caching. The Caching (Preview) works side-by-side to our application, initialized and worked as a Windows Service running in the virtual machines invoked by the startup tasks from our roles, we could get more information and control to them. And since the Caching (Preview) utilizes the memory and CPU from our existing cloud services, so it’s free. What we need to pay is the original computing price. And the resource on each machines could be used more efficiently.   Enable Caching (Preview) It’s very simple to enable the Caching (Preview) in a cloud service. Let’s create a new windows azure cloud project from Visual Studio and added an ASP.NET Web Role. Then open the role setting and select the Caching page. This is where we enable and configure the Caching (Preview) on a role. To enable the Caching (Preview) just open the “Enable Caching (Preview Release)” check box. And then we need to specify which mode of the caching clusters we want to use. There are two kinds of caching mode, co-located and dedicate. The co-located mode means we use the memory in the instances we run our cloud services (web role or worker role). By using this mode we must specify how many percentage of the memory will be used as the cache. The default value is 30%. So make sure it will not affect the role business execution. The dedicate mode will use all memory in the virtual machine as the cache. In fact it will reserve some for operation system, azure hosting etc.. But it will try to use as much as the available memory to be the cache. As you can see, the Caching (Preview) was defined based on roles, which means all instances of this role will apply the same setting and play as a whole cache pool, and you can consume it by specifying the name of the role, which I will demonstrate later. And in a windows azure project we can have more than one role have the Caching (Preview) enabled. Then we will have more caches. For example, let’s say I have a web role and worker role. The web role I specified 30% co-located caching and the worker role I specified dedicated caching. If I have 3 instances of my web role and 2 instances of my worker role, then I will have two caches. As the figure above, cache 1 was contributed by three web role instances while cache 2 was contributed by 2 worker role instances. Then we can add items into cache 1 and retrieve it from web role code and worker role code. But the items stored in cache 1 cannot be retrieved from cache 2 since they are isolated. Back to our Visual Studio we specify 30% of co-located cache and use the local storage emulator to store the cache cluster runtime status. Then at the bottom we can specify the named caches. Now we just use the default one. Now we had enabled the Caching (Preview) in our web role settings. Next, let’s have a look on how to consume our cache.   Consume Caching (Preview) The Caching (Preview) can only be consumed by the roles in the same cloud services. As I mentioned earlier, a cache contributed by web role can be connected from a worker role if they are in the same cloud service. But you cannot consume a Caching (Preview) from other cloud services. This is different from the Shared Caching. The Shared Caching is opened to all services if it has the connection URL and authentication token. To consume the Caching (Preview) we need to add some references into our project as well as some configuration in the Web.config. NuGet makes our life easy. Right click on our web role project and select “Manage NuGet packages”, and then search the package named “WindowsAzure.Caching”. In the package list install the “Windows Azure Caching Preview”. It will download all necessary references from the NuGet repository and update our Web.config as well. Open the Web.config of our web role and find the “dataCacheClients” node. Under this node we can specify the cache clients we are going to use. For each cache client it will use the role name to identity and find the cache. Since we only have this web role with the Caching (Preview) enabled so I pasted the current role name in the configuration. Then, in the default page I will add some code to show how to use the cache. I will have a textbox on the page where user can input his or her name, then press a button to generate the email address for him/her. And in backend code I will check if this name had been added in cache. If yes I will return the email back immediately. Otherwise, I will sleep the tread for 2 seconds to simulate the latency, then add it into cache and return back to the page. 1: protected void btnGenerate_Click(object sender, EventArgs e) 2: { 3: // check if name is specified 4: var name = txtName.Text; 5: if (string.IsNullOrWhiteSpace(name)) 6: { 7: lblResult.Text = "Error. Please specify name."; 8: return; 9: } 10:  11: bool cached; 12: var sw = new Stopwatch(); 13: sw.Start(); 14:  15: // create the cache factory and cache 16: var factory = new DataCacheFactory(); 17: var cache = factory.GetDefaultCache(); 18:  19: // check if the name specified is in cache 20: var email = cache.Get(name) as string; 21: if (email != null) 22: { 23: cached = true; 24: sw.Stop(); 25: } 26: else 27: { 28: cached = false; 29: // simulate the letancy 30: Thread.Sleep(2000); 31: email = string.Format("{0}@igt.com", name); 32: // add to cache 33: cache.Add(name, email); 34: } 35:  36: sw.Stop(); 37: lblResult.Text = string.Format( 38: "Cached = {0}. Duration: {1}s. {2} => {3}", 39: cached, sw.Elapsed.TotalSeconds.ToString("0.00"), name, email); 40: } The Caching (Preview) can be used on the local emulator so we just F5. The first time I entered my name it will take about 2 seconds to get the email back to me since it was not in the cache. But if we re-enter my name it will be back at once from the cache. Since the Caching (Preview) is distributed across all instances of the role, so we can scaling-out it by scaling-out our web role. Just use 2 instances and tweak some code to show the current instance ID in the page, and have another try. Then we can see the cache can be retrieved even though it was added by another instance.   Consume Caching (Preview) Across Roles As I mentioned, the Caching (Preview) can be consumed by all other roles within the same cloud service. For example, let’s add another web role in our cloud solution and add the same code in its default page. In the Web.config we add the cache client to one enabled in the last role, by specifying its role name here. Then we start the solution locally and go to web role 1, specify the name and let it generate the email to us. Since there’s no cache for this name so it will take about 2 seconds but will save the email into cache. And then we go to web role 2 and specify the same name. Then you can see it retrieve the email saved by the web role 1 and returned back very quickly. Finally then we can upload our application to Windows Azure and test again. Make sure you had changed the cache cluster status storage account to the real azure account.   More Awesome Features As a in-memory distributed caching solution, the Caching (Preview) has some fancy features I would like to highlight here. The first one is the high availability support. This is the first time I have heard that a distributed cache support high availability. In the distributed cache world if a cache cluster was failed, the data it stored will be lost. This behavior was introduced by Memcached and is followed by almost all distributed cache productions. But Caching (Preview) provides high availability, which means you can specify if the named cache will be backup automatically. If yes then the data belongs to this named cache will be replicated on another role instance of this role. Then if one of the instance was failed the data can be retrieved from its backup instance. To enable the backup just open the Caching page in Visual Studio. In the named cache you want to enable backup, change the Backup Copies value from 0 to 1. The value of Backup Copies only for 0 and 1. “0” means no backup and no high availability while “1” means enabled high availability with backup the data into another instance. But by using the high availability feature there are something we need to make sure. Firstly the high availability does NOT means the data in cache will never be lost for any kind of failure. For example, if we have a role with cache enabled that has 10 instances, and 9 of them was failed, then most of the cached data will be lost since the primary and backup instance may failed together. But normally is will not be happened since MS guarantees that it will use the instance in the different fault domain for backup cache. Another one is that, enabling the backup means you store two copies of your data. For example if you think 100MB memory is OK for cache, but you need at least 200MB if you enabled backup. Besides the high availability, the Caching (Preview) support more features introduced in Windows Server AppFabric Caching than the Windows Azure Shared Caching. It supports local cache with notification. It also support absolute and slide window expiration types as well. And the Caching (Preview) also support the Memcached protocol as well. This means if you have an application based on Memcached, you can use Caching (Preview) without any code changes. What you need to do is to change the configuration of how you connect to the cache. Similar as the Windows Azure Shared Caching, MS also offers the out-of-box ASP.NET session provider and output cache provide on top of the Caching (Preview).   Summary Caching is very important component when we building a cloud-based application. In the June 2012 update MS provides a new cache solution named Caching (Preview). Different from the existing Windows Azure Shared Caching, Caching (Preview) runs the cache cluster within the role instances we have deployed to the cloud. It gives more control, more performance and more cost-effect. So now we have two caching solutions in Windows Azure, the Shared Caching and Caching (Preview). If you need a central cache service which can be used by many cloud services and web sites, then you have to use the Shared Caching. But if you only need a fast, near distributed cache, then you’d better use Caching (Preview).   Hope this helps, Shaun All documents and related graphics, codes are provided "AS IS" without warranty of any kind. Copyright © Shaun Ziyan Xu. This work is licensed under the Creative Commons License.

    Read the article

  • Determining the State of a User using their Hostname

    - by PhpMyCoder
    Not sure if this is the right SE site. I figured this question doesn't belong on SO, but if you think it doesn't belong here either, I apologize. I've been looking into determining the location, specifically the state, of a user accessing my website. One of the options I've known about for a while is the GeoIP City Database, however this isn't the most cost effective solution and I'm cheap so I was looking for a less expensive way. Something that occurred to me was that my state was in the public hostname assigned to me by Comcast: (Dash Separated IP).hsd1.ma.comcast.net Could it be possible that other ISPs follow this same pattern of inserting the state abbreviation into their users' hostnames? I've been looking around for a list of hostnames for other ISPs, but I haven't found anything. Can anyone verify that this holds true for other major ISPs?

    Read the article

  • How to manage large number of desktop VMs?

    - by symcbean
    I'm looking at the feasibility of providing remote access to multiple virtual machines. The VMs themselves will provide user desktops. To make best use of the available resources, I'd like the VMs to hibernate when the user disconnects. Which implies being able to start them up when a user connects. Ideally each user would 'own' a VM image - but if not then I'd require that the session was terminated. Obviously this would require the remote access protocol to be tied into the VM management. Is there anything out there to provide such functionality? (extra credit for open protocols! ;)

    Read the article

  • No video signal and server shuts down

    - by Ilya
    I have a brand new server. The motherboard is Intel S2600CP4, two 8-core Intel E5-2600 processors. RAM is 8 DIMM slots of 8 GB each (KVR1600D3D4R11SK4/32GI, I installed them into the blue slots), Power supply is 1050W Corsair. Most of the time the server won't start up - the fans are spinning, but I don't have video signal. And it keeps restarting on its own every 3 mins. But maybe after 30 mins it will eventually load and show something on the screen. I even was able to install ESXi 5.0 (vSphere) on it. It recognizes both CPUs and all of the 64GB of RAM. But even then it worked only for around 5 hours and then restarted on its own. What's the problem? That's a very expensive peace of hardware and I can't afford purchasing a new motherboard/CPU. By the way, on the front panel the "System Status" LED is constantly amber (not blinking), even when the server started successfully. And also in the BIOS I can see lots of "processor 01 unable to apply microcode update 8160" fatal errors. Please help me with issue, I will really appreciate this!

    Read the article

  • Reinstall ruby (or just yaml lib)

    - by Christian Sciberras
    I've installed ruby 1.9 from source, and tried installing gem 'bundler': < gem install bundler > /usr/local/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>': > It seems your ruby installation is missing psych (for YAML output). > To eliminate this warning, please install libyaml and reinstall your ruby. > .... I've not been able to cleanly uninstall ruby (wtf?!), and installing libyaml at this point didn't help either. So it seems I've ended up with a fk-ed up server since I can't rollback nor fix the issue. Of course, I do have backups, but this situation is ridiculous nonetheless. Surely there must be a real fix?

    Read the article

  • Configuring port forwarding on Fortigate 50B

    - by GomoX
    I can't for the life of me get port forwarding to work on my Fortigate 50B. I followed the setup tips described on this other SF thread with no success. The only specific difference I can find is we are using load balancing through 2 different internet uplinks. Is there any caveat specific to this scenario that I might be missing? If you need any specific additional information please ask because I think I have checked everything: Virtual IP mapping on external interface wan1 ACCEPT all from any on wan1 to the corresponding server on internal No seeming offending firewall rules (any specific pitfalls that I might want to check for?)

    Read the article

  • IPv6 connections routed to IPv4 device

    - by Yvan JANSSENS
    I have an IBM 9406-250 with V5R1 and IPv4 only connectivity, and want it to be reachable over IPv6. I cannnot install an IPv6 stack on it, but I want it to be accessible by IPv6 so I can drop the requirement to VPN to my home network. I have an OpenWRT device running, which takes care of the IPv6 routing on my network and the tunnel to SIXXS, and I was wondering if it is possible to assign another IPv6 address to that device, and route it to the IPv4 IBM computer. Which software do I need for this, and how is this technique called?

    Read the article

  • DAS vs SAN storage for serving 2 to 4 nodes

    - by Luke404
    We currently have 4 Linux nodes with local storage, arranged in two active/passive pairs with storage mirrored using DRBD, running virtual machines (actually using Xen Hypervisor) for typical hosting workloads (mail, web, a couple VPS, etc.). We're approaching the (presumed) maximum IOPS of those servers, and we're planning to migrate to an external storage solution with two active nodes, with capacity for up to four active nodes. Since we're an all-Dell shop I've done some research and found the MD3200 / MD3200i products should be the ones we're looking for. We are pretty sure we won't be attaching more than 4 hosts on a single storage and I'm wondering if there is any clear advantage for one or the other. In theory I should be able to attach 4 SAS hosts to a single MD3200 (single links on a single controller MD3200, or dual redundant SAS links from each host to a dual-controller MD3200), or 4 iSCSI hosts to a single MD3200i (directly on its 4 GigE ports without any switch, again with dual links for the dual controller option). Both setups should let us implement live VM migration since all hosts can access all the LUNs at the same time, and also some shared filesystem like GFS2 or OCFS2. Also, both setups should allow full redundancy of the whole system (assuming dual controllers in the storage). One difference I can see is that the DAS solution is actually limited to 4 hosts while the iSCSI one should be able to grow to more hosts (adding two GigE switches to the mix). One point for the iSCSI solution is that it would allow us to start out with our current nodes and upgrade them at a later time (we can't add other SAS controllers, but they already have 4 GigE ports each). With the right (iSCSI|SAS) controllers I should be able to connect diskless nodes and boot them off the external storage which I think is a good thing (get rid of any local storage). On the other hand, I would have thought the SAS one to be cheaper but it seems like an MD3200 actually costs a little less than an MD3200i (?) (please note: I've used Dell gear in my examples since that's what we're looking for but I assume the same goes with other vendors) I would like to know if my assumptions above are correct, and if I'm missing any important difference between the two setups.

    Read the article

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