How do I find the country code of the phone?
Or perhaps other information about the country that the phone is at?
You can use the CultureInfo.CurrentCulture.Name property:
String currentCultureName = System.Globalization.CultureInfo.CurrentCulture.Name;
will return the culture name that the phone is set to in the format "languagecode-country/regioncode", for example "en-US"
If you're looking for the country of the devices present location you can pull this from the location service and reverse geocoding. An sample implementation here by Nick Harris.
How to Reverse Geocode a Location to an Address on Windows Phone 7
That is what exactly the globalization part in .net is all about. It stores the culture information in a cultureinfo class. currentculture gives the current culture settings.
The most important class in the System.Globalization namespace is the class CultureInfo. CultureInfo represents a culture and defines calendars, formatting of numbers and dates, and sorting strings that are used with the culture. The class RegionInfo represents regional settings(such as the currency) and shows if the region is using the metric system. In the same region, you can use multiple languages. One example is the region of Spain with its Basque(eu-ES), Catalan(ca-ES), Spanish(es-ES), Galician(gl-ES)cultures
eg: CultureInfo ci = new CultureInfo(“fr-FR”);
Refer More in the PPT
Related
I want to read PidTag properties from a specific e-mail message via Graph API REST call.
For singleValueExtendedProperties that is no problem as each of them has a specific GUID and in the filter query parameter can easily search for id with the corresponding property.
However I can't do the same with PidTags (i.e. the PidTag PidTagAccess or as OutlookSpy would show it: PR_ACCESS) because all of those PidTags have only the following attributes:
Tag num: HEX
Tag sym: String
Type: PropertyType
Value: Int
Does anyone have an idea how I could get those PidTags from an Outlook message?
I tried to put different types of attributenames into the filter query that weren't listed in the api and didn't really expect it to work. But it's better to try something out rather than to assume it won't work.
Use the proptag format to access properties predefined by MAPI, or by a client or server, and that have not already been exposed in Microsoft Graph. These properties have property identifiers in the 0x0001-0x7fff range. You can find more information about that in the Outlook extended properties overview.
Each predefined property in MAPI has well-defined description in MSDN with a property type, description and its identifier. For example, take a look at the PidTagAccess property description where you can get the required information. In OutlookSpy you may find the same information I believe.
Identifier for PidTagAccess is 0x0FF4 and type is integer, so valid id format for singleValueExtendedProperties is '{type} {proptag}'
Query to read the property:
https://graph.microsoft.com/v1.0/me/messages/{message_id}?$expand=singleValueExtendedProperties($filter=id eq 'Integer 0x0FF4')
Since you are already using OutlookSpy (I am its author), you can build your Graph queries with any MAPI properties in OutlookSpy: click Message button in the Graph group on the OutlookSpy ribbon, click "Query Parameters", check "$expand" checkbox and click the button to the right of the edit box.
In your particular case (PR_ACCESS MAPI property), the query will be singleValueExtendedProperties($filter=id eq 'Integer 0x0FF4')
I need some help getting the value and unit of a result from the FHIR Observation DSTU2 resource. I want to map these values to strings but it looks like Observation.value[x] can have different type of data. Any thoughts on how to do this in C#? I tried a few ways but no luck so far because the sandbox I'm using contains results as strings, Quantity and CodeableConcept.
http://hl7.org/fhir/observation-definitions.html#Observation.value_x_
For the Observation.value field you indeed have a choice of type, so the data in the FHIR resource can hold any of the choices listed for that field.
If you use the Hl7.Fhir.Dstu2 library - the official C# reference implementation available through NuGet, you can use it to easily retrieve the resources from your sandbox and get them into a POCO. Here's an example:
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
var client = new FhirClient("<your sandbox url>");
var obs = client.Read<Observation>("Observation/<technical id>");
// now you can access obs.Value regardless of the type in it
if you need to serialize the data to xml or json, you use the serializer:
using Hl7.Fhir.Serialization;
var serializer = new FhirJsonSerializer();
Console.WriteLine(serializer.SerializeToString(obs));
I am working on .NET 4.0 MVC3 web application. The application is all in English and allows users to fill information regarding different regions. For simplicity let's say we have two regions: United States and Western Europe.
Now in the view I present a string let's say Project opening, but if the user works on region United States I would like it to read Project initiation.
When I think about this functionality I immediately think about resource files for different regions, but independent from the UI culture.
Does anyone have a recipe how to achieve what I want?
Would be also nice, if in the future I could make it read e.g. ExtendedDisplayAttribute(string displayName, int regionId) placed over properties of my ViewModels.
EDIT
I am already at the stage where I can access region information in a helper that should return the string for this region. Now I have a problem with the resource files. I want to create multiple resource files with failover mechanism. I expected there would be something working out of the box, but the ResourceManager cannot be used to read resx files.
Is there any technique that will allow me to read the values from specific resource files without some non-sense resgen.exe?
I also do not want to use System.Resources.ResXResourceReader, because it belongs to System.Windows.Forms.dll and this is a Web app.
Just in case someone wants to do the same in the future. This article turned out to be really helpful: http://www.jelovic.com/articles/resources_in_visual_studio.htm
The piece of code that I use (VB) is:
<Extension()>
Public Function Resource(Of TModel)(ByVal htmlHelper As HtmlHelper(Of TModel), resourceKey As String) As MvcHtmlString
Dim regionLocator As IRegionLocator = DependencyResolver.Current.GetService(GetType(IRegionLocator))
Dim resources = New List(Of String)
If Not String.IsNullOrEmpty(regionLocator.RegionName) Then
resources.Add(String.Format("Website.Resources.{0}", regionLocator.RegionName))
End If
resources.Add("Website.Resources")
Dim value = String.Empty
For Each r In resources
Dim rManager = New System.Resources.ResourceManager(r, System.Reflection.Assembly.GetExecutingAssembly())
rManager.IgnoreCase = True
Try
value = rManager.GetString(resourceKey)
If Not String.IsNullOrEmpty(value) Then
Exit For
End If
Catch
End Try
Next
Return New MvcHtmlString(value)
End Function
I'm trying to determine whether or not the user would prefer metric or imperial units in my app.
Is there anyway to do this? I've been trying with CultureInfo to no avail.
Cheers,
Cameron.
You want RegionInfo.IsMetric
My app use phone number as user ID, It will be good to detect the home PLMN of the SIM card and convert it to the country code(like +1, +33, etc.), then you don't have input the digits.
I guess it could be done with RIL in windows mobile, but in a windows phone 7 it seems there is no such kind of APIs.
Another choice is to get the CultureInfo, but some times the CultureInfo may not match with the SIM you are using, for example you take your phone abroad, usually you keep the phone region settings as your home land but you may use a local SIM card.
There does not appear to be any API action that allows you to look at the specific cultures embedded into a SIM for WP7. However, if you the general culture option is still appropriate you could do something like this:
string countryCode = CultureInfo.CurrentCulture.Name;
try {
RegionInfo reg = new RegionInfo(countryCode);
string name = reg.Name;
string displayname = reg.DisplayName;
string ISORegion = reg.TwoLetterISORegionName;
string currency = reg.CurrencySymbol;
string eng = reg.EnglishName;
string native = reg.NativeName;
}
catch (ArgumentException argEx) {
// The country code was not valid
}
If your application needs to be based on the current location please consider using the GPS task. Details for getting GPS data can be reviewed here.
Also converting the GPS data to a specifc country can be completed by geocode reversing as shown here.