- add a public propery on App class to retain the data during current lifecycle;
- add a public propery on the target page, and then in the prev page's OnNavigatedFrom event set the value of the property for the next page;
- use the property State from the application's current PhoneApplicationService instance, which is a type of generic dictionary. But the object been stored has to be serializable (the reason is when app goes to deactivated it will serialize the objects to isolated storage);
- isolate storage. BUT obviously it is not wise to frequently access isolate storage during application running. Here is a great article of compairing the performance of using isolate storage http://blogs.claritycon.com/kevinmarshall/2010/11/03/wp7-serialization-comparison/
Tuesday, 7 June 2011
Ways of passing data between WP7 pages
Friday, 18 February 2011
How Secure Are Query Strings Over HTTPS?
- URLs are stored in web server logs,
- URLs are stored in the browser history,
- URLs are passed in Referrer headers
Monday, 19 July 2010
Developing on SharePoint 2010 (Day 2)
a) SharePoint Server Architecture
b) SharePoint Object Hierarchy
So as you can see the SharePoint Object model is relatively straightforward. Here we have a very simple slip of code which start from reaching all services of the Farm and navigate through to the item and file level objects.
1: foreach (SPService svc in SPFarm.Local.Services)
2: {
3: if (svc is SPWebService)
4: {
5: foreach (SPWebApplication webApp in ((SPWebService)svc).WebApplications)
6: {
7: foreach (SPSite site in webApp.Sites)
8: {
9: foreach (SPWeb web in site.AllWebs)
10: {
11: foreach (SPList list in web.Lists)
12: {
13: foreach (SPListItem i in list.Items)
14: {
15: // do something
16: }
17: }
18:
19: foreach (SPFile f in web.Files)
20: {
21: // do something
22: }
23: }
24: }
25: }
26: }
27: }
Friday, 9 July 2010
Oracle Procedures (version 11.1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Temporary Tables vs. Table Variables
| Temp Table | Table Variable | |
| record transaction logs? | Yes | No |
| inside transaction scope? | Yes | No |
| cross execution batch? | Global temp table | No way |
| support index? | Yes | No |
| where to store? | Tempdb | Memory |
Thursday, 8 July 2010
Developing on SharePoint 2010 (Day 1)
This article is talking about developing web parts for SharePoint 2010 using Visual Studio 2010. If you are looking for articles for older version of SharePoint or Visual Studio I recommend this URL: http://www.aspfree.com/c/a/Windows-Scripting/Beginning-SharePoint-Web-Part-Development/
First of all, there are two types of web parts VS 2010 supports: Standard Web Part (which in VS 2010 Item Template list named Web Part) and Visual Web Part.
A standard web part is just a class inherited from abstract class WebPart. Below is the Inheritance Hierarchy of WebPart class.
1: WebControl
2: |---Panel
3: |---Part
4: |---WebPart
To add contents into standard web part we need override the CreateChildControls method and inside put code logic to create sub controls manually and add them into the Controls collection. See the code below:
1: protected override void CreateChildControls()
2: {
3: LiteralControl msg = new LiteralControl("test");
4: this.Controls.Add(msg);
5: }
The visual web part, in the other hand, give you a visual design UI to drag existed web control in. But if you check the source code, a visual web part is just a standard web part plus a Web.UI.UserControl. And in the overrided CreateChildControls method used a trick like this:
this.Controls.Add(Page.LoadControl(_controlPath));
One more thing for visual web part: the value _controlPath is the physical URL of the user control and the value of it is maintained by VS 2010.
Monday, 10 May 2010
How to convert UTF-8 to urlencoded string
As you know, System.Web.HttpUtility.UrlEncode can easily convert UTF-8 string into the format of %xx%xx so it can be used in a URL string. Now imagine you are not working on a ASP.NET project and you don’t want to add reference of System.Web.dll in your project, then how can you do the same thing? Below is one solution I found:
1: private static string GetEncodedString(string username)
2: {
3: StringBuilder sb = new StringBuilder();
4: byte[] btyes = System.Text.Encoding.Default.GetBytes(username);
5: for (int i = 0; i < btyes.Length; i++)
6: {
7: sb.Append(@"%" + Convert.ToString(btyes[i], 16));
8: }
9:
10: return sb.ToString();
11: }
Now if you pass in chinese string 你好 it will turn out %c4%e3%ba%c3, which is exactly what I want. The reason I create this method is because I am trying to use HttpWebRequest component to directly post data to a web page and I need a way to submit UTF-8 string.
BTW, the only difference between my method and UrlEncode is my method will convert all characters in the passed in string to %xx format even it is ASCII but UrlEncode won’t do that.
Monday, 12 April 2010
Star Schema, Snowflake Schema and others
Star schema resembles a star, one or more fact tables are surrounded by single level dimension tables (one completely de-normalized table per relationship). Dimension tables aren't normalized - that means even if you have repeating fields such as name or category no extra table is added to remove the redundancy.
Snowflake schema resembles a snowflake because comparing with Star Schema the dimension tables are further normalized or have parent tables.
Either way the fact tables are usually designed in third normal form because all data depends on either one dimension or all of them, not on combinations of a few dimensions.
Star Schema vs. Snowflake Schema
The reason for using a star schema is its simplicity from the users' point of view: queries are never complex because the only joins and conditions involve a fact table and a single level of dimension tables, without the indirect dependencies to other tables that are possible in a better normalized snowflake schema.
Snowflake schema generates more joins than a star schema during, which translates into longer queries. Therefore it is normally recommended to choose the star schema design over the snowflake schema for optimal performance.
Snowflake schema does have an advantage of providing more flexibility.
Disadvantage of Star Schema
A well designed database has to be in 3NF whereas the star schema's dimensions are de-normalized. Normally a huge number of redundant data existed in dimension tables.
For improving query performance many pre-processes (sum, grouping, resort etc) have been done on the dimension’s purpose and saved in the dimension table. When business logic changed to modify the related pre-processes are always hard.
When create new dimension table and build relationship with fact table, it can cause geometrically fact table size increasing.
How to Index Star/Snowflake Schema Data
Declare a primary key in each dimension table.
For star dimensions, declare foreign key (FK) relationships between each dimension table and the corresponding fact table. Additionally, for snowflake dimensions, declare FK relationships between each secondary dimension table and the primary dimension table that it augments.
Make sure that there is a primary key associated with the fact table(s), even if you have to use an IDENTITY field.
Declare indexes on each of the primary keys in the dimension tables and in the fact table(s).
Declare indexes on each of the foreign keys in the fact table(s).
Sunday, 14 March 2010
WTF: UAC and rsAccessDenied error in Windows 2008 R2 (x64)
Here is today’s WTF, imaging you spend whole day installed SSRS and finally start creating your first report service, but when you are trying to deploy it you keep receiving error message regarding denied accessing, it is really confused me.
This is not the worst part yet, if you google the error type [rsAccessDenied] you can find the solution is accessing http://localhost/reports/ and assign proper user roles to the report service login user. But when login http://localhost/reports/ in Windows 2008 R2, you can see only a blank home page without any settings you can work with. This is because UAC blocked the dynamic content in this page. Even I added the URL to trusted site list, you can still only see a blank page, which really piss me off.
To overcome this issue, you have to turn off UAC and restart the computer, and then access http://localhost/reports/ you can see all the functionality you need.
Followed are some tips installing SSRS 2008 x64 on Windows 2008 R2 x64
First thing first I strongly suggest installing VS2008, SQL SERVER 2008 in the default path, otherwise you will suffer installation failure soon or later, especially for the Business Intelligence Development Studio.
Another thing you need know is Report Service is no longer relying on IIS. Even you stopped IIS service you can still access Report Service from URL http://localhost/Reports and http://localhost/ReportService.
Assuming you have already installed SSRS 2008 with SQLSERVER 2008, next step is configure database connection. To do this go to Microsoft SQL Server 2008/Configuration Tools/Reporting Service Configuration Manager, then click database page and connect the database server you want. The reporting service manager will create two databases ReportServer and ReportServerTempDB for itself.
Another thing you may need to know is the SSRS report web service asmx URLs are:
http://localhost/ReportServer/ReportService2005.asmx (to manage the service)
http://localhost/ReportServer/ReportExecution2005.asmx (to create reports)
Even you installed MSSQL2008 the services are still named 2005, isn't it kind of WTF. :)
Monday, 8 March 2010
SILVER - An easy way to remember asp.net lifecycle
I – Initialize
L – Load
V – Validate
E – Event Handling
R – Render
Haha,really easy to remember.
Wednesday, 24 February 2010
TransactionScopeOption.Suppress
But there is one thing you may not know, which is, if there is another TransactionScope further down the stack it will react as if there was no ambient transaction (and create one if necessary).
So if you have 3 scopes as follows: .Required -> .Suppress -> .Required: Then 2 transactions will be created. The innermost TransactionScope with .Required will see that there is no ambient transaction and will creates one for itself.
One thing to remember, to keep the code consistence, always call scope.Complete() at the end of your suppress TransactionScope even you know logically there will be no transaction created. There will be no any overhead caused by doing that.
Friday, 19 February 2010
101 LINQ Samples
http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx
Diagrams of determining the dimensions of elements
Sunday, 31 January 2010
ViewData vs. TempData
ViewData is only available in current request but TempData, which stored in user session, whose life will be around current and the right next requests. In the other word, if you are trying to share data between two continued request or during a redirection then TempData will be your choice.
BTW, to ensure you get the data by either ViewData or TempData you can use the code
<%=ViewData["name"] ?? TempData["name"]%>
Tuesday, 26 January 2010
List<T> working with DataGridView
Case 1: when you edited the data in a bound List<T>, simply call DataGridView.Refresh() to allow you changes be shown. Or you can set the DataSource of the DataGridView to null and reset the DataSource to the List<T>.
Case 2: when you added or removed records from the List<T> then you cannot refresh the DataGridView to see your changes, in this case you have to re-bind the DataSource (by re-bind I mean set the DataSource to null and then set it back to the List<T> otherwise the re-bind will not happen since the DataGridView will think the datasource didn't change)
Case 3: When you directly bind a List<T> to a DataGridView you will find it doesn't allow you adding or deleting record from the UI even you set the AllowUserToAddRows and AllowUserToDeleteRows. To allow you do these things in DataGridView UI we are going to use another Type BindingSource which implemented related interface to allow DataGridView add/edit/delete data from its data source. The sample code:
List<T> data = new List<T>();
BindingSource binding = new BindingSource();
inding.DataSource = data;
DataGridView.DataSource = binding;
Go back to Case 1 and 2, when you are using BindingSource instead of directly use List<T> now you have another way to refresh your DataGridView, BindingSource.ResetBindings(bool) which forces the DataGridView to reread all the items from the List<T> and refresh their displayed values.
Wednesday, 20 January 2010
How to add a Form into Tab control
The properties are:
FormBorderStyle = None; //remove the form border and title area, make it like a flat piece
TopLevel = false; //TopLevel control cannot be embeded
WindowState = Normal; //If you are going to set the Dock value, WindowState cannot be Maximized
The last thing is do not forget call form.Show(), otherwise the form is not going to render itself.
Tuesday, 12 January 2010
How to set K2 login model for Joomla 1.5
Step1, download K2 full package and install it
Step2, enable K2 login model
Step3, assign existed user to K2 user group
Step4, to let the user publish new items, you have to change the related K2 user group to allow item editing, add items, editing level (All or Own), and publish items
You can ignore all the other settings and log in as the user, and then you can see a link Add New Item below your login user name now.
In case you want to know more about implement K2: A quick step-by-step guide on installing and setting up K2.
Monday, 25 May 2009
SQL Server Date Time Functions
GETDATE()
Returns the current system date and time in the SQL Server standard internal format for datetime values.
DATEPART(datepart, date)
Returns an integer that represents the specified datepart of the specified date.
DATENAME(datepart, date)
Returns a character string representing the specified datepart of the specified date.
DATEADD(datepart, diffNum, date)
Returns a new datetime value based on adding an interval to the specified date.
DATEDIFF(datepart, date1, date2)
Returns the number of date and time boundaries crossed between two specified dates.
Year(date), Month(date), Day(date) are working exactly same with DATENAME(year/month/day, date)
The param datepart is the parameter that specifies on which part of the date to calculate the difference.
Saturday, 16 May 2009
ASP.NET page event ordering
- Master page child controls initialization: All server controls contained within the master page are first initialized.
- Content page child controls initialization: All server controls contained in the content page are initialized.
- Master page initialization: The master page itself is initialized.
- Content page initialization: The content page is initialized.
- Content page load: The content page is loaded (this is the Page_Load event followed by the Page_LoadComplete event).
- Master page load: The master page is loaded (this is also the Page_Load event followed by the Page_LoadComplete event).
- Master page child controls load: The server controls on the master page are loaded onto the page.
- Content page child controls load: The server controls on the content page are loaded onto the page.


.jpg)
.jpg)
.jpg)