Blog Home  Home Feed your aggregator (RSS 2.0)  
kevin Mocha - Thursday, November 08, 2007
Bookmarks collected from web.
 
 Thursday, November 08, 2007

Following are some of my observations got from the book:

Chapter 1&2

  • XAML is just a way to use .NET APIs. WPF and XAML can be used independently from each other.
  • XAML specification defines rules that map .NET namespaces, types, properties, and events into XML namespaces, elements, and attributes.
  • Markup extensions are just classes with default constructors.
  • An object element can have three types of children: a value for a content property, collection items, or a value that can be type-converted to its parent.

Chapter 3 Important new Concepts in WPF

Logic Tree

The logical tree concept is straightforward, but why should you care about it? Because just about every aspect of WPF (properties, events, resources, and soon) has behavior tied to the logical tree. For example, property values are sometimes propagated down the tree to child elements automatically, and raised events can travel up or down the tree. Both of these behaviors are discussed later in this chapter.

Visual Tree
A similar concept to the logical tree is the visual tree. A visual tree is basically an expansion of a logical tree, in which nodes are broken down into their core visual components. Rather than leaving each element as a “black box,” a visual tree exposes the visual implementation details. For example, although a ListBox is logically a single control, its default visual representation is composed of more primitive WPF elements: a Border, two ScrollBars, and more.

Dependency Properties

A dependency property depends on multiple providers for determining its value at any
point in time. These providers could be an animation continuously changing its value, a
parent element whose property value trickles down to its children, and so on. Arguably
the biggest feature of a dependency property is its built-in ability to provide change notification.

Change Notification (Property Trigger)   

Property Value Inheritance

Multiple Providers

Attached Properties

Routed Events (routing Strategies:tunneling, bubbling, Direct)

Attached Events

Commands: a more abstract and loosely-coupled version of events.

 

image

Thursday, November 08, 2007 7:22:43 PM UTC  #    Comments [0]    |  Trackback

From: http://www.mikeduncan.com/3-hot-uses-for-httpcontextcurrentitems-they-wont-tell-you-about/

Generally, HttpContext.Current.Items doesn’t get all that much hot blog press, but let me tell you, I’m here to change all that. For those out of the know, System.Web.HttpContext.Current.Items is a sweet key-value pair collection you can use to pass objects around up and through all components that participate in a single HTTP request. What does this mean? This means that in a way similar to sticking something in the Session or cache, you can jam some values into the HttpContext.Current.Items for your request, say in a HttpModule way down low before you’ve even begun to fetch a page, and have those values readable/writable later from your page and all its usercontrols. The Items only persist through this one-night-stand of a single request and then supposedly “lose your number” but that’s ok, because we don’t really need all their drama after that anyway.

1) Preparing objects down low, on the down-low.

As alluded to earlier, one sweet use of HCI (as we call in on the street) is in HttpModules. Let’s say you are doing some url-rewriting for user-friendliness or SEO reasons. While you’re at it, why not do a little preparation for your page? If you have a query param of state abbreviation that comes in commonly, populate an additional full state name display field ahead of time. Clean up your strings with proper casing, do whatever utils you think you can get away with while you have the request in your hand. I have a little object of getters and setters that I populate in the the HttpModule, and stick it in the Current.Items for its way up the stack. Now my pages and usercontrols can pull out my cleaned up custom object from the Context.Items and act accordingly, pass it down the line to methods, whatever. The vibe is maybe a hint at a smidgen of a wee bit Model View Controller-ish, but not really.

2) Making params and pages more unit-testable.

With something like #1 in place, you can pull objects of params and prepared goodness out of the request and process them in your code behind, presenter, usercontrol, whatever strikes your pattern fancy. If this bundle of params is a in a nice little object that implements an interface, this makes unit testing logic that under normal circumstances relies upon getting info from the System.Web namespace (querystring params mostly) nice and easily decoupled. Pros of this are that your view calling your presenter can stay super lean and mean without having to populate a bunch info from query strings which will end up going through standard transformations you could have handled earlier on. A con is that the population of these params might be a bit mysterious to other devs who don’t see the HttpModule in action, sort of a like a table that gets populated from somewhere or other, but you don’t know what trigger where. I hate that.

3) Populating usercontrols without the hassle.

If you know you have values in your hand at page on_load or earlier, it’s pretty damn convenient to stick them in the HttpContext.Current.Items and then just read them out from whatever usercontrols may or may not be dynamically included on the page. No finding child controls from the page, no finding parent info from the controls. No casting, scoping or otherwise thinking about precisely what order what will fire. If you have the data at page_load, your controls can get it. Don’t call me, and I won’t call you either. Ta-dow (does anyone say that anymore?).

So there you have it, HttpContext.Current.Items, arcane enough to give you guru-cred to the mid-range noobs, simple enough that it can be leveraged for good and / or evil. Awesome.

Thursday, November 08, 2007 7:19:38 PM UTC  #    Comments [0]    |  Trackback
 Tuesday, November 06, 2007
Show date in english:
ToString("MM/dd", new System.Globalization.CultureInfo("en-us"))

//
// Any source code blocks look like this
//

DateTime dt = DateTime.Now;
String strDate="";
strDate = dt.ToString("MM/dd/yyyy"); // 07/21/2007
strDate = dt.ToString("dddd, dd MMMM yyyy"); //Saturday, 21 July 2007
strDate = dt.ToString("dddd, dd MMMM yyyy HH:mm"); // Saturday, 21 July 2007 14:58
strDate = dt.ToString("dddd, dd MMMM yyyy hh:mm tt"); // Saturday, 21 July 2007 03:00 PM
strDate = dt.ToString("dddd, dd MMMM yyyy H:mm"); // Saturday, 21 July 2007 5:01
strDate = dt.ToString("dddd, dd MMMM yyyy h:mm tt"); // Saturday, 21 July 2007 3:03 PM
strDate = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss"); // Saturday, 21 July 2007 15:04:10
strDate = dt.ToString("MM/dd/yyyy HH:mm"); // 07/21/2007 15:05
strDate = dt.ToString("MM/dd/yyyy hh:mm tt"); // 07/21/2007 03:06 PM
strDate = dt.ToString("MM/dd/yyyy H:mm"); // 07/21/2007 15:07
strDate = dt.ToString("MM/dd/yyyy h:mm tt"); // 07/21/2007 3:07 PM
strDate = dt.ToString("MM/dd/yyyy HH:mm:ss"); // 07/21/2007 15:09:29
strDate = dt.ToString("MMMM dd"); // July 21
strDate = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK"); // 2007-07-21T15:11:19.1250000+05:30
strDate = dt.ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"); // Sat, 21 Jul 2007 15:12:16 GMT
strDate = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss"); // 2007-07-21T15:12:57
strDate = dt.ToString("HH:mm"); // 15:14
strDate = dt.ToString("hh:mm tt"); // 03:14 PM
strDate = dt.ToString("H:mm"); // 5:15
strDate = dt.ToString("h:mm tt"); // 3:16 PM
strDate = dt.ToString("HH:mm:ss"); // 15:16:29
strDate = dt.ToString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'"); // 2007-07-21 15:17:20Z
strDate = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss"); // Saturday, 21 July 2007 15:17:58
strDate = dt.ToString("yyyy MMMM"); // 2007 July
Tuesday, November 06, 2007 10:10:34 PM UTC  #    Comments [0]    |  Trackback

<asp:GridView ID="GridViewYardSales" runat="server" CssClass="yui-datatable-theme"
                            AutoGenerateColumns="false" DataSourceID="YardSaleDataSource" AllowSorting="true"
                            OnRowCommand="GridViewYardSales_RowCommand" OnRowCreated="GridViewYardSales_RowCreated"
                            DataKeyNames="ItemId">
                            <RowStyle CssClass="data-row" />
                            <AlternatingRowStyle CssClass="alt-data-row" />
                            <Columns>
                                <asp:BoundField DataField="ItemId" HeaderText="ItemId" ReadOnly="True" SortExpression="ItemId"
                                    Visible="false"></asp:BoundField>
                                <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20px">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButtonViewOnMap" runat="server" OnClientClick=<%# String.Format("javascript:ViewOnMapById('{0}');", Eval("ItemId")) %>>
                                Map</asp:LinkButton><br />
                                        <asp:LinkButton ID="LinkButtonItinerary" runat="server" CommandName="Command_Itinerary"
                                            CommandArgument='<%# Eval("ItemId") %>'>Itinerary </asp:LinkButton><br />
                                        <asp:LinkButton ID="LinkButtonViewDetail" runat="server" CommandName="Command_ViewItemDetail"
                                            CommandArgument='<%# Eval("ItemId") %>'>Detail
                                        </asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Title">
                                    <ItemTemplate>
                                        <%# Eval("Title") %><br />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Date">
                                    <ItemTemplate>
                                        <%# Eval("Time") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

 

protected void GridViewYardSales_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Retrieve LinkButton control
                int m_RowIndex = e.Row.RowIndex;
                string id = GridViewYardSales.DataKeys[m_RowIndex].Value.ToString();
                LinkButton lb = (LinkButton)e.Row.FindControl("LinkButtonItinerary");

                if (IsItemAlreadyInItinerary(id))
                {
                    lb.Text = "Remove";
                }
                else
                {
                    lb.Text = "Add";
                }
            }
        }

        protected void GridViewYardSales_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Command_Itinerary")
            {
                string id = e.CommandArgument.ToString();

                GridViewRow selectedRow = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
                LinkButton lb = (LinkButton)selectedRow.FindControl("LinkButtonItinerary");

                if (!IsItemAlreadyInItinerary(id))
                {
                    AddItemToItinerary(id);
                    lb.Text = "Remove";
                }
                else
                {
                    RemoveItemFromItinerary(id);
                    lb.Text = "Add";
                }
            }
            else if (e.CommandName == "Command_ViewItemDetail")
            {
                string id = e.CommandArgument.ToString();
                Response.Redirect("ViewSale.aspx?id=" + id);
            }
        }

Tuesday, November 06, 2007 9:42:39 PM UTC  #    Comments [0]    |   |  Trackback

<asp:GridView ID="GridViewYardSales" runat="server" CssClass="yui-datatable-theme"
                            AutoGenerateColumns="false" DataSourceID="YardSaleDataSource" AllowSorting="true"
                            OnRowCommand="GridViewYardSales_RowCommand" OnRowCreated="GridViewYardSales_RowCreated"
                            DataKeyNames="ItemId">
                            <RowStyle CssClass="data-row" />
                            <AlternatingRowStyle CssClass="alt-data-row" />
                            <Columns>
                                <asp:BoundField DataField="ItemId" HeaderText="ItemId" ReadOnly="True" SortExpression="ItemId"
                                    Visible="false"></asp:BoundField>
                                <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20px">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButtonViewOnMap" runat="server" OnClientClick=<%# String.Format("javascript:ViewOnMapById('{0}');", Eval("ItemId")) %>>
                                Map</asp:LinkButton><br />
                                        <asp:LinkButton ID="LinkButtonItinerary" runat="server" CommandName="Command_Itinerary"
                                            CommandArgument='<%# Eval("ItemId") %>'>Itinerary </asp:LinkButton><br />
                                        <asp:LinkButton ID="LinkButtonViewDetail" runat="server" CommandName="Command_ViewItemDetail"
                                            CommandArgument='<%# Eval("ItemId") %>'>Detail
                                        </asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Title">
                                    <ItemTemplate>
                                        <%# Eval("Title") %><br />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Date">
                                    <ItemTemplate>
                                        <%# Eval("Time") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

Tuesday, November 06, 2007 9:37:14 PM UTC  #    Comments [0]    |   |  Trackback
Tuesday, November 06, 2007 4:38:17 AM UTC  #    Comments [0]    |   |  Trackback
 Monday, November 05, 2007
Monday, November 05, 2007 9:48:15 PM UTC  #    Comments [0]    |   |  Trackback
 Sunday, November 04, 2007

<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20px">
 <ItemTemplate>
          <%# Convert.ToInt32(DataBinder.Eval(Container, "DataItemIndex")) + 1 %>.
   </ItemTemplate>
 </asp:TemplateField>

Sunday, November 04, 2007 9:19:02 PM UTC  #    Comments [0]    |   |  Trackback
 Saturday, November 03, 2007

nextdooryardsale(s) yardsalenextdoor yardsalecitymap(s) yardsaleminer yardsaledailymap

yardsalemapplet

Saturday, November 03, 2007 4:19:46 PM UTC  #    Comments [0]    |  Trackback

http://gsalr.com/ 

Very good layout and nice trip planner

 

http://thriftmapper.com

Can find the neighbor sales within specified miles.

 

http://www.yardsalebloodbath.com/

Yard sale blog

Saturday, November 03, 2007 3:03:27 PM UTC  #    Comments [0]    |  Trackback
  1. Add map check button on addnew page
  2. Add error page
  3. Add search page
  4. Add date check service (Remove or archive old items)
  5. Add admin management notification.
  6. Add gui for operator
  7. Add configuration to allow user to add ad in Craigslist way 
  8. Update grid code
  9. Update layout and style
  10. Add Logo
  11. Decide domain name
  12. Add small icon for sale types
Saturday, November 03, 2007 4:00:09 AM UTC  #    Comments [0]    |  Trackback
 Thursday, October 25, 2007
Thursday, October 25, 2007 3:49:48 PM UTC  #    Comments [0]    |  Trackback
 Monday, October 22, 2007

今天看了一篇关于网站运作、服务器负载的文章,讲得很独到,也很有意义,很现实,建议大家都看看,这些问题我相关很多创业项目忽略或处理得不够深。
这个文章中提到的问题很多看起来是很细的一件事情,但恰恰这就直接导致运作的成败
大家讨论,一定要仔细看完!
原文:

我做过多个2.0公司的技术顾问,简单的谈谈2.0公司遇到的问题(涉及隐私,我用A B C D代替),这里就不再赘述大家众所周知的页面静态化,缓存和代码安全等问题了,有点技术的2.0公司的CTO都知道这些东西,我们谈点发展之后的问题
A公司
A公司做的是SNS网站,程序是两个毛头小伙子做的,目标直指51,程序开发是一帆风顺,功能也比51牛多了,推广也是一帆风顺(A公司有自己独到的推广方式。但是当ALEXA到2W的时候问题出来了,每天下午4点左右,网站速度慢的惊人,基本上打不开,公司三台服务器CPU100%,让人郁闷的是公司的网络配置方式,居然是双WEB的集群,而单独一台DB数据库。整个瓶颈在数据库,于是我建议做DB的集群,分析了一下数据结构,MD,典型的WEB程序员的作品,没有一点数据库设计规范,功能实现是可以,如果要扩展,不可能,集群基本上是不可能的,怎么办?不能办,于是,一个月的时间修改程序,数据结构基本上换了一遍 前期砸进去的几十万打了水飘,用户走光了。
结论:WEB2.0前期设计的时候不应该只考虑功能,应该认真考虑一下底层和数据结构了。
B公司
B公司也是做的SNS网站,程序是3个人开发的,CEO是某名牌大学的经济学硕士,有点知己网的味道,又有一些特色出来,说实话,公司的潜力不错,CEO 有很强的运作能力,感觉前景不错。系统架构还行,但是---但是系统崩溃了,why?系统没有考虑到用户有个海量的说法,文件也有个海量的说法,用户的相册,图片全部存贮在WEB服务器的一个分区上,每个用户一个目录,而打开性能监视器,磁盘的IO高的惊人,基本上无暇响应。众所周知,文件系统也是一个数据库,单独大文件无所谓,关键是整个是300多个G的零碎文件,大量的读写操作,系统崩溃,数据丢失,文件系统的一个链断了,用户数据全部丢失!!!这是一个非常沉重的问题,系统整整停了一个月来做数据恢复(单独文件很容易,但是海量文件目前还没有一个软件能组织起来软件架构)。解决方案:修改程序架构,做分布式文件存贮(程序修改用了8天,但是文件转移却又用去了将近一个月),20万用户损失殆尽
结论:WEB2.0前期的设计应该有应付海量存贮的考虑,整个涉及了程序架构的修改,前期规划不好的话基本上思路一条。
C公司
C公司是一个值得尊敬的公司,CEO技术出身,和比尔盖茨一样,大学未毕业出来做网络,01到03年做短信狠赚了一笔,后来做的小项目也小有所成,说实话,我很佩服。公司做的是校友方面,但是更偏重myspace风格,注重个人主页,推广方面也下了大手笔。系统崩溃的原因其实很简单,由于采用的是微软的 SqlServer,而微软直接就告诉了我们,SQLSERVER不支持集群,他们的数据库超负载,100%就没有下去过,只能横向增加配置,采用了4路 4核CPU系统,但是系统还是崩溃了... 高互动注定了高负载。解决方案:现从基本入手,解决掉几个程序耗能大户,对数据库采用横向切割,将用户每10万进行分组,同时对数据库系统进行散列,将多个表垂直分割,同时进行文件分组,解决问题. 因为修改了数据结构,程序也基本上大动了一下。 好在系统没有出大错,损失不算很大,不过对用户体验造成了很坏的影响。
结论:WEB2.0前期设计应该有良好的散列考虑,程序应该能有配合的扩充性,符合数据库的扩充
D公司
D公司是一个各个方面做的比较好的公司,做了CDN加速,图片也独立分出了N个服务器,数据库不错的一个,(CTO是个数据库专家),系统崩溃的原因在于 WEB,按道理说WEB很容易做集群的,但是发现集群并解决不掉问题,他们的集群只允许做4台的WEB集群,但是4台都当掉了。仔细分析,找到原因,我估计整个也是大部分CTO最容易犯的一个错误,或者说他们根本就想不到的问题,就是WEB上传的问题,上传的时候由于时间的原因,线程是保持链接的,300 个线程就可以把一个WEB Server当掉了。解决方案:这个最简单,把上传和其他耗能大户分离出独立出来。程序改动不是很大,但是之前半个月速度满对用户体验的损失也不可小视。
结论:没有什么结论了,毕竟有海量访问经验的CTO不多,也就是那几个大站的。
总结:不是泼冷水,模仿其实是很容易的,随便找几个WEB程序员就能做到,并且很简单,速度可能还很高效,因为WEB2.0无非就是跟数据库打交道,会操作数据库就会做。但是真正做大并不容易,因为能应付海量访问的程序并不简单,现在的程序员都太自命不凡,其实真正有经验的并不多,不要相信一个月薪5K- -10K的程序员能给你多大的惊喜,能应付海量访问的程序员不是那个价格。如果您想做2.0,想做大,有几个个建议:
一.找DBMS的专家设计好数据库,大部分程序员都不知道分区视图,数据散列,数据组的概念
二.设计好程序架构(这个其实不难,有个高人指导就行了),保持良好的扩展性,成本考虑可以找兼职的系统架构设计师做好系统架构,确定将来的发展瓶颈。
三.考虑好文件存贮的问题。文件存贮的技术含量看起来很低,其实是很高的,可以考虑反向代理的方案。文件存贮出问题了,站点基本上就完蛋了,不仅仅是RAID的问题和存贮服务器的问题,不过道理倒是一点就破的
四.中国国情考虑,这个最致命,需要考虑电信和网通的问题,CDN并不能解决所有问题。互动性的东西并CDN并不是很有效。最关键的是,现有的双线机房遇到DDOS攻击基本上都会当掉,原因很简单,双线机房都是私人机房,本身就不会有太高的带宽,随便攻击一下就可以D掉(顺带提一个笑话,我知道一个双线机房的老总总共1G的带宽却买了4G的金盾墙,很简单800M的攻击就可以搞定)。
五.网络延迟的问题,这是分布式系统必须要考虑的,程序要能容忍0到100秒的数据延迟的功能,也就是同步的问题。不要小看这几十秒,问题很大的,如果你的站点有交互式功能,比如即时聊天,你可以想象一下是个什么结果。对于即时聊天的东西,可以用反向代理来解决(成本较高)。但是对于留言和评论的影响不大,但是如果系统为了健壮做了缓存和静态化的时候,这个东西可能就是灾难性的了。
六.分散你的程序,如果你没有太多的资金构筑动辄百万的服务器,建议把功能分散开来,比如相册一台服务器,留言一台服务器
七.看好你的程序员,如果没有很好的激励措施的话你的程序员很容易写出敷衍性的代码,而这个可能就是将来的大患,程序架构定下来后要修改可能就要费牛劲了。最好你的CTO能对你100%的衷心,100%的负责。
八.文件同步的问题,这个问题可能你觉得没有必要,如果你看一下网通和电信的TTL就明白了,同步要支持续传,并且不能是持续的,否则你的成本会高出N倍,不要期望能通过你的软件实现,交给你的程序员吧,把上面的话告诉他他就知道怎么做了。
九.最狠的一个问题了,也是吃亏最大的问题,不管您跟网警的关系多好,看好你的用户,审核好你的东西,一被停机可能就致命,本人就吃过N次亏。
十.最后,祝各位站长一番风顺,大展宏图。

朋友发的,不知道哪里看到的

Monday, October 22, 2007 1:13:16 PM UTC  #    Comments [0]    |  Trackback
 Friday, October 19, 2007

http://www.4guysfromrolla.com/webtech/061103-1.shtml

 

<input type="button" id="btnPrint" onclick="window.print()" value="Print">

Friday, October 19, 2007 9:17:28 PM UTC  #    Comments [0]    |   |  Trackback
Copyright © 2008 Kevin Mocha. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: