Friday, January 23, 2015
Sunday, January 18, 2015
Working in designtime with Data in MVVM
If we develop applications ( XAML based) we have a problem with see the data in design view. Every application become successful when its interface is attractive. If our application is based on internet or any other computational task there is difficulty on make Interfaces without running the application real time. Here is solution for it
Use design time data binding which already with the xaml based application
Today we going to develop the windows 8.1 store application. ( This is same with any XAML based Application )
1. Create Windows 8.1 store application form the Visual studio. (I named it as DesignTimedata )
2. Create ViewModel to bind the run time data , In following here is My MainViewModel.cs
With this example we are not going to the use internet or other tasks .therefore just hard corded the values in constructor
2. Then bind the ViewModel to the View with relevant tags.
You can use Singleton or Page Resource binding . In here Im using Bind the ViewModel to the Page in XAML . It gives me intellisense in XAML .
Here is my MainPage.xaml
Here is my design time ViewModel. It will contains all test data which displayed in design view in visual studio
4. Then lets bind the design time data into the design (xaml) . In here there is always tag like this
With this d we can define all the properties which page have and change them. but none of them are effecting the real application .
Lets bind the ViewModel to the page and use it with design time . Here is my full page
Now we can see the vaues that we put to test the Application UI and make any changes to it.
Here is runtime result of the app
Enjoy
Full Code
http://bit.ly/1xiJ3yZ
Use design time data binding which already with the xaml based application
Today we going to develop the windows 8.1 store application. ( This is same with any XAML based Application )
1. Create Windows 8.1 store application form the Visual studio. (I named it as DesignTimedata )
2. Create ViewModel to bind the run time data , In following here is My MainViewModel.cs
With this example we are not going to the use internet or other tasks .therefore just hard corded the values in constructor
namespace DesignTimeData.Runtime { public class MainViewModel:INotifyPropertyChanged { private string _Title { get; set; } public string Title { get { return _Title; } set { _Title = value; OnPropertyChanged("Title"); } } private string _Description { get; set; } public string Description { get { return _Description; } set { _Description = value; OnPropertyChanged("Description"); } } public MainViewModel() {
// Hard coded runtime data
this._Title = "Title in Run time"; this._Description = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna."; } // Create the OnPropertyChanged method to raise the event // Use in MVVM public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); } } } }
2. Then bind the ViewModel to the View with relevant tags.
You can use Singleton or Page Resource binding . In here Im using Bind the ViewModel to the Page in XAML . It gives me intellisense in XAML .
Here is my MainPage.xaml
<Page x:Class="DesignTimeData.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:DesignTimeData" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:runtime="using:DesignTimeData.Runtime" mc:Ignorable="d"> <Page.DataContext> <runtime:MainViewModel/> </Page.DataContext>
3 .Then Create New Class which have exact name of your view model. Better to use different namespace / folder . In this case It is MainViewModel Here is my design time ViewModel. It will contains all test data which displayed in design view in visual studio
namespace DesignTimeData.DesignTimedata { public class MainViewModel { public string Title { get { return "DesignTime Title"; } } public string Description { get { return "Design time description"; } } } }
4. Then lets bind the design time data into the design (xaml) . In here there is always tag like this
mc:Ignorable="d"with every page. something defines under this tag will not be displayed in the runtime. then this is the one that we need to use.
With this d we can define all the properties which page have and change them. but none of them are effecting the real application .
Lets bind the ViewModel to the page and use it with design time . Here is my full page
<Page x:Class="DesignTimeData.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:DesignTimeData" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:desgn="using:DesignTimeData.DesignTimedata" xmlns:runtime="using:DesignTimeData.Runtime" mc:Ignorable="d"> <Page.DataContext> <runtime:MainViewModel/> </Page.DataContext> <d:Page.DataContext> <desgn:MainViewModel /> </d:Page.DataContext> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Margin="100,150,0,0"> <TextBlock Style="{StaticResource HeaderTextBlockStyle}" Text="{Binding Title}"/> <TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{Binding Description}"/> </StackPanel> </Grid> </Page>
Now we can see the vaues that we put to test the Application UI and make any changes to it.
Here is runtime result of the app
Enjoy
Full Code
http://bit.ly/1xiJ3yZ
Tuesday, January 13, 2015
Time Zone clonflictions with Cloud Services .. How to avoid .
7:36 AM
8.1, ASP, ASP .NET, Azure, Cloud Computing, Microsoft, Visual Studio, WCF, Web Services
No comments
There is problems when you are developing applications which based on cloud services. That is , time of your service (servers ) are different than the time that your application. If you are using time stamp based data pulling from the cloud service you are in big trouble.
Here if two basic solutions that you can use in those scenarios
1. Use UTC (absolute) Time (highly recommended)
2. Change time zone of the server according to the requirement
Use absolute time you can just do with simple DateTime object.
in C# simply like this
Change Time zone of the Server ( Instances of cloud service )
This is the Task that you cannot find lot of documentation
If you follow following steps You can easily change server time zone ( In azure (cloud) it will randomly create and no one can predict that which instance of the server will run entire service life cycle *Its never happens with cloud) in every running instance once it starting
1. Create batch (*.bat) file with flowing command
Here is time zone reference
2. Add it in to the cloud service ( Not to the cloud service project )
*Add it to project which identifies as role (web, worker) by cloud project . In following example You need to add batch file into WebRole1 project
3. Then R-Click on the batch file and select properties from visual studio . In properties under the Advanced change Copy To Output Directory property in to copy always.
4. Then go to the Cloud project and open the ServiceDefinition.csdf file
5. Under WebRole Tag add Start up task as follow .
Now it is done ... You free to go with your cloud service
Enjoy
Here if two basic solutions that you can use in those scenarios
1. Use UTC (absolute) Time (highly recommended)
2. Change time zone of the server according to the requirement
Use absolute time you can just do with simple DateTime object.
in C# simply like this
DateTime.UtcNow
Change Time zone of the Server ( Instances of cloud service )
This is the Task that you cannot find lot of documentation
If you follow following steps You can easily change server time zone ( In azure (cloud) it will randomly create and no one can predict that which instance of the server will run entire service life cycle *Its never happens with cloud) in every running instance once it starting
1. Create batch (*.bat) file with flowing command
tzutil /s "Sri Lanka Standard Time"
Here is time zone reference
Index | Name of Time Zone | Time |
000 | Dateline Standard Time | (GMT-12:00) International Date Line West |
001 | Samoa Standard Time | (GMT-11:00) Midway Island, Samoa |
002 | Hawaiian Standard Time | (GMT-10:00) Hawaii |
003 | Alaskan Standard Time | (GMT-09:00) Alaska |
004 | Pacific Standard Time | (GMT-08:00) Pacific Time (US and Canada); Tijuana |
010 | Mountain Standard Time | (GMT-07:00) Mountain Time (US and Canada) |
013 | Mexico Standard Time 2 | (GMT-07:00) Chihuahua, La Paz, Mazatlan |
015 | U.S. Mountain Standard Time | (GMT-07:00) Arizona |
020 | Central Standard Time | (GMT-06:00) Central Time (US and Canada |
025 | Canada Central Standard Time | (GMT-06:00) Saskatchewan |
030 | Mexico Standard Time | (GMT-06:00) Guadalajara, Mexico City, Monterrey |
033 | Central America Standard Time | (GMT-06:00) Central America |
035 | Eastern Standard Time | (GMT-05:00) Eastern Time (US and Canada) |
040 | U.S. Eastern Standard Time | (GMT-05:00) Indiana (East) |
045 | S.A. Pacific Standard Time | (GMT-05:00) Bogota, Lima, Quito |
050 | Atlantic Standard Time | (GMT-04:00) Atlantic Time (Canada) |
055 | S.A. Western Standard Time | (GMT-04:00) Caracas, La Paz |
056 | Pacific S.A. Standard Time | (GMT-04:00) Santiago |
060 | Newfoundland and Labrador Standard Time | (GMT-03:30) Newfoundland and Labrador |
065 | E. South America Standard Time | (GMT-03:00) Brasilia |
070 | S.A. Eastern Standard Time | (GMT-03:00) Buenos Aires, Georgetown |
073 | Greenland Standard Time | (GMT-03:00) Greenland |
075 | Mid-Atlantic Standard Time | (GMT-02:00) Mid-Atlantic |
080 | Azores Standard Time | (GMT-01:00) Azores |
083 | Cape Verde Standard Time | (GMT-01:00) Cape Verde Islands |
085 | GMT Standard Time | (GMT) Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London |
090 | Greenwich Standard Time | (GMT) Casablanca, Monrovia |
095 | Central Europe Standard Time | (GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague |
100 | Central European Standard Time | (GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb |
105 | Romance Standard Time | (GMT+01:00) Brussels, Copenhagen, Madrid, Paris |
110 | W. Europe Standard Time | (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna |
113 | W. Central Africa Standard Time | (GMT+01:00) West Central Africa |
115 | E. Europe Standard Time | (GMT+02:00) Bucharest |
120 | Egypt Standard Time | (GMT+02:00) Cairo |
125 | FLE Standard Time | (GMT+02:00) Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius |
130 | GTB Standard Time | (GMT+02:00) Athens, Istanbul, Minsk |
135 | Israel Standard Time | (GMT+02:00) Jerusalem |
140 | South Africa Standard Time | (GMT+02:00) Harare, Pretoria |
145 | Russian Standard Time | (GMT+03:00) Moscow, St. Petersburg, Volgograd |
150 | Arab Standard Time | (GMT+03:00) Kuwait, Riyadh |
155 | E. Africa Standard Time | (GMT+03:00) Nairobi |
158 | Arabic Standard Time | (GMT+03:00) Baghdad |
160 | Iran Standard Time | (GMT+03:30) Tehran |
165 | Arabian Standard Time | (GMT+04:00) Abu Dhabi, Muscat |
170 | Caucasus Standard Time | (GMT+04:00) Baku, Tbilisi, Yerevan |
175 | Transitional Islamic State of Afghanistan Standard Time | (GMT+04:30) Kabul |
180 | Ekaterinburg Standard Time | (GMT+05:00) Ekaterinburg |
185 | West Asia Standard Time | (GMT+05:00) Islamabad, Karachi, Tashkent |
190 | India Standard Time | (GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi |
193 | Nepal Standard Time | (GMT+05:45) Kathmandu |
195 | Central Asia Standard Time | (GMT+06:00) Astana, Dhaka |
200 | Sri Lanka Standard Time | (GMT+06:00) Sri Jayawardenepura |
201 | N. Central Asia Standard Time | (GMT+06:00) Almaty, Novosibirsk |
203 | Myanmar Standard Time | (GMT+06:30) Yangon Rangoon |
205 | S.E. Asia Standard Time | (GMT+07:00) Bangkok, Hanoi, Jakarta |
207 | North Asia Standard Time | (GMT+07:00) Krasnoyarsk |
210 | China Standard Time | (GMT+08:00) Beijing, Chongqing, Hong Kong SAR, Urumqi |
215 | Singapore Standard Time | (GMT+08:00) Kuala Lumpur, Singapore |
220 | Taipei Standard Time | (GMT+08:00) Taipei |
225 | W. Australia Standard Time | (GMT+08:00) Perth |
227 | North Asia East Standard Time | (GMT+08:00) Irkutsk, Ulaanbaatar |
230 | Korea Standard Time | (GMT+09:00) Seoul |
235 | Tokyo Standard Time | (GMT+09:00) Osaka, Sapporo, Tokyo |
240 | Yakutsk Standard Time | (GMT+09:00) Yakutsk |
245 | A.U.S. Central Standard Time | (GMT+09:30) Darwin |
250 | Cen. Australia Standard Time | (GMT+09:30) Adelaide |
255 | A.U.S. Eastern Standard Time | (GMT+10:00) Canberra, Melbourne, Sydney |
260 | E. Australia Standard Time | (GMT+10:00) Brisbane |
265 | Tasmania Standard Time | (GMT+10:00) Hobart |
270 | Vladivostok Standard Time | (GMT+10:00) Vladivostok |
275 | West Pacific Standard Time | (GMT+10:00) Guam, Port Moresby |
280 | Central Pacific Standard Time | (GMT+11:00) Magadan, Solomon Islands, New Caledonia |
285 | Fiji Islands Standard Time | (GMT+12:00) Fiji Islands, Kamchatka, Marshall Islands |
290 | New Zealand Standard Time | (GMT+12:00) Auckland, Wellington |
300 | Tonga Standard Time | (GMT+13:00) Nuku'alofa |
2. Add it in to the cloud service ( Not to the cloud service project )
*Add it to project which identifies as role (web, worker) by cloud project . In following example You need to add batch file into WebRole1 project
3. Then R-Click on the batch file and select properties from visual studio . In properties under the Advanced change Copy To Output Directory property in to copy always.
4. Then go to the Cloud project and open the ServiceDefinition.csdf file
5. Under WebRole Tag add Start up task as follow .
<WebRole name="*****" vmsize="Small"> <Startup> <Task commandLine="NameOfBatchFile.bat" executionContext="elevated" taskType="simple"/> </Startup>
<Sites> <Site name="Web"> <Bindings> <Binding name="Endpoint1" endpointName="Endpoint1" /> </Bindings> </Site> </Sites> <Endpoints> <InputEndpoint name="Endpoint1" protocol="http" port="80" /> </Endpoints> </WebRole>
Now it is done ... You free to go with your cloud service
Enjoy
Subscribe to:
Posts (Atom)