Wednesday, August 27, 2008

XML Schemas
(XML သဒၵါ (၀ါ) XML အဓိပၸါယ္ သတ္မွတ္မွဳ) - အပိုင္း ( ၅ )

အပိုင္း ( ၁ ) ၊
( ၂ ) ၊ (၄) ႏွင့္ ( ၅) ကို အရင္ဖတ္ၾကည့္ေစခ်င္ပါသည္။



Content model ေတြဖန္တီးဖို ့အတြက္ <simpleType> element ကိုအသံုးၿပဳပါတယ္။ ဒါေပမယ့္ အဲဒီ content model ေတြဟာ simple content ၿဖစ္ေနဆဲပါပဲ။ simple content ဆိုတာ data ပဲပါၿပီး child elements ဒါမွမဟုတ္ mixed contents ေတြ မပါတဲ့ ဟာပါ။ simple content ၿဖစ္ေနဆဲေပမယ့္ <simpleType> က ၿပဳလြယ္ၿပင္လြယ္၊ ေၿပာင္းလဲလြယ္တဲ့ အဆင့္တစ္ခုကို ၿဖစ္ေစပါတယ္။ (a level of flexibility) လက္ရိွ ရိွေနတဲ့ ေဒတာ အမ်ိဳးအစား ေတြမွာ ကန္ ့သတ္ခ်က္ေတြ ၿပဳလုပ္ႏိုင္တာမ်ိဳးေပါ့။

ဘာေၾကာင့္ အဲဒီ ကန္ ့သတ္ခ်က္ေတြက အသံုး၀င္ရတာလဲလို ့ ေမးခဲ့ရင္ ဒါေလးကို ေတြးၾကည့္ၾကမယ္။ ကၽြန္ေတာ္တို ့ပစၥည္း တစ္ခုအတြက္ ကုန္စရင္း (inventory) ကို element တစ္ခုေၾကညာၾကမယ္။ ဒီေတာ့ <inventory> ဆိုတဲ့ element ေလးကို ကၽြန္ေတာ္တုိ ့ ဖန္တီးမယ္ေပါ့။ ဒါေပမယ့္ ကၽြန္ေတာ္တို ့ ၾကိဳသိေနတယ္။ ဒီ ပစၥည္း ဟာ အခု ၂၀၀ ထက္ပိုၿပီး သိုေလွာင္ရံုထဲမွာမရိွႏိုင္ဘူးဆိုပါစို ့။ လံုး၀မရိွတာက်ေတာ့ ၿဖစ္ႏိုင္တယ္။ ဒီလို ကန္ ့သတ္ခ်က္ေလးေတြ ပါလာၿပီဆိုရင္၊ ေနာက္ၿပီး ဒီလုိ ဟာေလးေတြက မၾကာခဏ သံုးရေတာ့မယ္၊ ထပ္ခါထပ္ခါသံုးရေတာ့မယ္ဆိုရင္ ကၽြန္ေတာ္တို ့ဟာ <simpleType> ကို သံုးၿပီး XML သဒၵါ (Schema) ကုိေၾကညာသင့္ၿပီေပါ့။ ေအာက္မွာၾကည့္မယ္။

<xs:element name="inventory">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="200"/>
</xs:restriction>
</xs:simpleType>
</xs:element>


အဲဒီ ေၾကညာခ်က္ေလးက <inventory> လို ့ေခၚတဲ့ element တစ္ခုကို ၿဖစ္ေစတယ္။ သူမွာ တန္ဖိုး (value) က 0 ကေန ၂၀၀ အထိအၿမင့္ဆံုးပါႏိုင္ပါတယ္။
(တခု သတိၿပဳပါ။ ကၽြန္ေတာ္တို ့သံုးတဲ့ ေဒတာအမ်ိဳးအစားဟာ XML မွာ ရိွၿပီးသား ေဒတာအမ်ိုးအစား ဆိုတာပါပဲ။ interger အမ်ိဳးအစားေပါ့။ ဒါကို ကၽြန္ေတာ္တို ့က restriction ဆိုတာနဲ ့ကန္ ့သတ္ရံုပဲ ကန္ ့ သတ္လိုက္တာပါ။)

ဒီလိုေၾကညာခဲ့တဲ့ အတြက္ တကယ္လို ့ XML Document ဖိုင္ထဲမွာ ဒီလို တက္(tag) ကေလးေတြပါလာရင္ အိုေကၿပီး
<inventory>190</inventory>
<inventory>0</inventory>
<inventory>49</inventory>


ဒီလိုေလးေတြေတာ့ ပါလို ့မရဘူးေပါ့။
<inventory>201</inventory>
<inventory>250</inventory>


<simpleType> element ကို ေၾကညာတဲ့ အခါေတြမွာ restriction ရယ္၊ list ရယ္၊ union ရယ္ပဲ ပါလို ့ ရပါတယ္။

ထပ္သိထားရမွာက <simpleType> element မွာ id နဲ ့ name ဆိုတဲ့ စြမ္းရည္ၿပစကားလံုး (attributes) ေလးေတြပါလို ့ရတယ္။ ဒီလို simple type တစ္ခုကို name သတ္မွတ္ေပးလို ့ရတဲ့ အတြက္ အက်ိဳးေက်းဇူးကေတာ့ ကၽြန္ေတာ္တို ့ဟာ အၿခား element ေတြေၾကညာတဲ့ အခါမွာ အဲဒီ type ကို အဲဒီ name ကိုအသံုးၿပဳ ၿပီး ၿပန္ေခၚသံုးလို ့ ရၿခင္းပါပဲ။ ထပ္ခါထပ္ခါ အသံုးၿပဳႏိုင္ၿခင္း ( reusable) ၿဖစ္တာေပါ့။

<xs:simpleType name="currency">
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>

<xs:element name="price" type="currency"/>


အေပၚက နမူနာမွာ ကၽြန္ေတာ္တို ့ဟာ price လို ့ေခၚတဲ့ element တခုရိွတယ္။ အဲဒီ price ဟာ decimal အမ်ိဳးအစားၿဖစ္ၿပီး ေတာ့ ဒသမဂဏန္း ၂ လံုးပဲ ပါလို ့ရမယ္။

ဒီေတာ့ ကၽြန္ေတာ္တို ့ဟာ decimal ကို base ေဒတာအမ်ိဳးအစားအေနနဲ ့ယူလိုက္ၿပီး သူ ရဲ ့ဒသမဂဏန္းကို xs:fractionDigits တက္(tag)က တန္းဖိုး 2 ဆိုၿပီး ေၿပာင္းလိုက္တယ္။ တကယ္ decimal ေဒတာအမ်ိဳးအစားဟာ ဒသမ ၂ လံုးပဲ ပါတာမဟုတ္ဘူး။ ဒါေၾကာင့္ ကၽြန္ေတာ္တုိ ့က ဒီလို ေၿပာင္းၿပီးေတာ့ မွ ကၽြန္ေတာ္တို ့ေၿပာင္းထားတဲ့ အမ်ိုးအစား (type) ကို currency လို ့ simpleType ရဲ ့ name မွာ ေၾကညာလိုက္တယ္။ ဒသမဂဏန္း ၂ လံုးနဲ ့ဟာကို currency လို ့ နာမည္ေပးလိုက္တယ္ေပါ့ဗ်ာ။

ၿပီးေတာ့ XML Document ထဲမွာ အဲဒီ နာမည္ကို ယူၿပီး ဒီလို သံုးလိုက္လို ့ရပါၿပီ။

<xs:element name="price" type="currency"/>


တကယ္လို ့ အၿခား element တခု ၊ ဥပမာ- totalAmount ဆိုတဲ့ element ကလည္း price လိုပဲ ဒသမဂဏန္း ၂ လံုးဆိုရင္-

<xs:element name=”totalAmount” type="currency"/>


paymentAmount ကလည္း ဒသမ ၂ လံုးပဲ ဆိုပါစို ့။

<xs:element name=”paymentAmount” type="currency"/>


ဆိုၿပီး သံုးလိုရပါတယ္။ ေတြ ့လား။ currency ဆိုတဲ့ ေဒတာအမ်ိဳးအစားကို ပဲ ေခၚသံုးထားတယ္။ တခါတည္း simpletype အေနနဲ ့ ေၾကညာၿပီး ထပ္ေၾကညာစရာမလို ေတာ့ဘူး။ မဟုတ္ရင္ element အသစ္တစ္ခု ဖန္တီးတိုင္း ဒသမ ၂ လံုးဆိုတာကို ေၾကညာေနရမွာ။ အခု မလိုေတာ့ဘူး။ currency ဆိုတဲ့ name ကို ေခၚသံုးရံုပဲ။ ဒါကို ထပ္ခါထပ္ခါ အသံုးၿပဳႏိုင္ၿခင္း ( reusable) ၿဖစ္တယ္လို ့ေခၚတယ္။ ဘယ္ element ကမဆို သူတို ့ရဲ ့ ေဒတာအမ်ိုးအစား (data type ) အတြက္ သင့္ေလွ်ာ္တယ္ဆိုရင္ တၿခား XML ရဲ ့ ရိွၿပီးသားေဒတာ (build in datatype – eg: Int, Decimal , etc..) ေတြလိုပဲ ေခၚသံုးႏိုင္တယ္။

(သတိၿပဳရန္- type=”currency” ဆိုတာ XML Build-in DataType( XML မွာ အလိုအေလွ်ာက္ပါၿပီးသား ေဒတာအမ်ိုးအစား) မဟုတ္ဘူး။ ကၽြန္ေတာ္တို ့ အေပၚမွာ <simpleType> ဆိုၿပီးေက်ညာခဲ့လို ့သံုးလို ရတာ။ သူဟာ ေဒတာ အမ်ိဳးအစားတစ္ခုလို ့ၿဖစ္သြားပါတယ္။ အဲဒါကို အဓိကေၿပာခ်င္တာပါပဲ။)

ဒါဟာ XML သဒၵါ (schema) ရဲ ့ အလြန္ေကာင္းတဲ့ အားသာခ်က္တစ္ခုပါပဲ။

<simpletype> မွာ ကၽြန္ေတာ္တို ့ <list> <restriction> < union> ေတြကိုသံုးလို ့ ရတယ္လို ့ ေၿပာခဲ့ပါတယ္။
အေပၚမွာ <restriction> ကို သံုးၿပသြားခဲ့ပါတယ္။ အခု <list> ကိုသံုးၿပီး ဘယ္လို ့ အားသားခ်က္ေတြရိွလဲ၊ ဘယ္လိုကိစၥေတြကို လုပ္လို ့ရလဲ ဆိုတာၾကည့္ရေအာင္။

List

List က တန္ဖိုးတစ္ခုတည္းထက္ တန္ဖိုးအမ်ားၾကီးကိုလက္ခံႏိုင္တဲ့ ကိုယ္ပိုင္ ေဒတာ အမ်ိဳးအစားတစ္ခုကို ဖန္တီးတာကို ေၾကညာခ်င္တဲ့အခါမွာ သံုးလို ့ရပါတယ္။ ဥပမာ - ကၽြန္ေတာ္တို ့က color ဆိုတဲ့ element ေလးတစ္ခုကို တည္ေဆာက္မယ္ဆိုပါစို ့။ အဲဒီ ေလးဟာ မွာ အနီ (red) ၊ အ၀ါ (yellow) ၊ အၿပာ (blue) ၊ အစိမ္း (green) စသည္ၿဖင့္ ပါမယ္ေပါ့။ အဲဒီအခါ ကၽြန္ေတာ္တို ့က XML သဒၵါ (XML schema) မွာ ဒီလုိေၾကညာေပးလို ့ရတာေပါ့။

<xs:element name=”color” type=”xs:string”></xs:element>


ဒါေပမယ့္ ဒီလိုေၾကညာရင္ ကၽြန္ေတာ္တို ့ရဲ ့ <color> မွာ တန္ဖိုး (value) တစ္ခုပဲပါလို ့ရမယ္။ ဒီလိုမ်ိဳး -
<color>red</color>  (ဒါက အနီ)
<color>green</color> (ဒါက အ၀ါ အဲလို တစ္ခုမွာ တန္ဖိုး တခုပဲပါလို ့ရမယ္)


တကယ္လို ့ ကၽြန္ေတာ္တို ့က <color> မွာ တန္ဖိုးေတြ တစ္ခုထက္မက ပါေစခ်င္တယ္ဆိုပါစို ့။<list> ကို သံုးၿပီးလုပ္လို ့ ရၿပီေပါ့။

<xs:element name=”color”>
<xs:simpleType>
<xs:list itemType=”xs:string”>
<xs:restriction>
<xs:minLength value=”1”/>
<xs:maxLength value=”5”/>
</xs:restriction>
</xs:list>
</xs:simpleType>
</xs:element>


ဒီ XML Schema မွာ <simpleType> ထဲမွာ <list> ကိုထည့္ၿပီး ေၾကညာထားပါတယ္။ အဲဒီ <list> မွာ itemType ဆိုတဲ့ စြမ္းရည္ၿပ စကားလံုး (attribute) တစ္ခုလည္းသံုးထားတယ္။ သူက ဘာကိုေၿပာတာလည္းဆိုေတာ့ ဒီ list ထဲမွာ ပါမဲ့ ေဒတာအမ်ိဳးအစားကို ေၿပာၿပတယ္။ ဒီမွာဆို xs:string ၊ (စာအစဥ္အတန္း) ေဒတာအမ်ိဳးအစားေပါ့။ ဟုတ္တယ္ေလ။ ပါမဲ့ တန္ဖိုးက Red, Blue, Green စသည္ဆိုေတာ့ string အမ်ိဳးအစား ေဒတာေပါ့။ ၿပီးေတာ့ ကၽြန္ေတာ္တုိ ့ အေပၚက သံုးဖူးတဲ့ <restriction> ကို ၿပန္သံုးတယ္။ ဒီေနရာမွာေတာ့ ကၽြန္ေတာ္တို ့က <minLength> နဲ ့ <maxLength> တက္(ဂ္) ေလးကို သံုးထားတယ္။ အဲဒီ တက္(ဂ္)ေလး ၂ ခုက ဘာကိုေၿပာလည္းဆိုေတာ့ <color> element ထဲမွာ ပါမဲ့ တန္းဖိုး အေရအတြက္။ အခု <list> ကိုသံုးလိုက္ေတာ့ <color> ထဲမွာ တန္ဖိုးက တစ္ခုတည္းမဟုတ္ေတာ့ဘူးေလ။ တခုထက္မက ပိုၿပီးပါလာနိုင္ၿပီ မဟုတ္လား။ ဒီေတာ့ ကၽြန္ေတာ္တို ့က min နဲ ့ max ကိုသံုးၿပီး အႏွိမ့္ဆံုး ဘယ္ႏွစ္ခု၊ အၿမင့္ဆံုး ဘယ္ႏွခု ပါခြင့္ရိွႏိုင္သလဲဆိုတာကို သတ္မွတ္ေပးလိုက္တယ္။ ဒီမွာဆို အႏွိမ့္ဆံုး ၁ ခု၊ အၿမင့္ဆံုး ၅ ခုပါခြင့္ ရိွတယ္ေပါ့။

သတိ။ <minLength> နဲ ့ <maxLenght>တို ့က string (စာအစဥ္အတန္း) တစ္ခုလံုးရဲ ့ အရွည္ကို ေၿပာတာမဟုတ္ပါ။ <list> ရဲ ့ အရွည္ (list ထဲမွာ ဘယ္ႏွခုပါလည္းဆိုတာ) ကိုေၿပာတာပါ။

ဒီေတာ့ ၾကည့္ၾကမယ္။

<color>Red Blue Green</color> ဒါဆို အားလံုးအိုေကေပါ့။ Red, Blue, Green ဆိုမွ List က ၃ ခုပဲရိွေသးတာပဲ။ ဟုတ္။

<color>Red Blue Green Black Orange Purple Brown</color> ဒီလိုေတာ့ မရဘူးေပါ့။ ဘာလို ့ လည္းဆိုေတာ့ အၿမင့္ ဆံုး ရိွရမယ့္ အရွည္ ထက္ ပိုမ်ားေနတယ္ေလ။ အၿမင့္ဆံုးအရွည္က ၅ ၊ အခုက ၇ ခု၇ိွေနတယ္။

<color></color> ဒီလိုလည္းမရဘူး။ အနည္းဆံုး တန္းဖိုး ၁ ခုပါရမယ္လို ့သတ္မွတ္ထားခဲ့တယ္။ မွတ္မိတယ္ထင္ပါတယ္။

<list> က ကၽြန္ေတာ္တို ့ element ထဲမွာ တန္ဖိုးတစ္ခုထက္ပိုၿပီး ထည့္ေပးခ်င္တဲ့ အခါ၊ အဲလို element ကို schema (သဒၵါ) မွာ ေၾကညာရတဲ့ အခါမ်ိဳး အသံုးက်ပါတယ္။

ဆက္ရန္။

ထပ္ေရးေနပါတယ္ဗ်ာ..။ :D

အာေကလာ (akela)

Aug 27, 2008 12.02 pm

Monday, December 10, 2007

XML Schemas
(XML သဒၵါ (၀ါ) XML အဓိပၸါယ္ သတ္မွတ္မွဳ) - အပိုင္း ( ၄ )

အပိုင္း ( ၁ ) ၊
( ၂ ) ႏွင့္ ( ၃) ကို အရင္ဖတ္ၾကည့္ေစခ်င္ပါသည္။

Content Models

တခါတေလမွာ Empty element ေတြဟာ အေရးပါအရာေရာက္ေပမယ့္ မ်ားေသာအားၿဖင့္ တန္ဖိုး (value) ရိွတဲ့ element ေတြပဲမ်ားပါတယ္။ element တစ္ခုဟာ ရိုးစင္းတဲ့ content အမ်ိဳးအစားေတြရိွတယ္။ number တို ့ string တို ့လိုမ်ိဳးေပါ့။ ဒါမွမဟုတ္ စာေတြတၿခား element ေတြ ေရွာေထြးေနတာမိ်ဳးလည္း ၿဖစ္တက္တယ္။

element တစ္ခုဟာ သူ ့ေအာက္မွာ အၿခား element မရိွဘဲ တန္ဖိုး (value) ပဲရိွတယ္ဆိုရင္ သူကို ရိုးရွင္းတဲ့ content (simple content) လို ့ေခၚတယ္။တကယ္လို ့ element တစ္ခုဟာ သူကိုယ္တိုင္က parent element ၿဖစ္ၿပီး သူ ့ေအာက္မွာ child element ေတြရိွတယ္ဆိုရင္ သူ ့ကို element content လို ့ေခၚတယ္။ ေနာက္ဆံုး တစ္ခုအေနနဲ ့ စာေတြေရာ ၊ child element ေတြေရာ ေရာေထြးၿပီးရိွေနတယ္ဆိုရင္ သူကို mixed content လို ့ေခၚတယ္။ ဒါက ဘယ္အေၿခအေနမွာ ဘယ္လို သံုးႏွန္းတာလည္းဆိုတာကို ေၿပာတာပါ။

element တစ္ခုကို တည္ေဆာက္တဲ့ အခါ အရိုးရွင္းဆံုးနည္းကေတာ့ built in data type (XML မွာ အလိုအ ေလွ်ာက္ပါၿပီးသား data အမ်ိဳးအစား) ကို သံုးတာၿဖစ္ပါတယ္။အဲဒီထဲမွာ string, decimal, date, Boolean, နဲ ့ time တို ့ပါ၀င္ၾကပါတယ္။ data အမ်ိဳးအစားက လည္း built in၊ content ကလည္း ရိုးရွင္းတဲ့ ေဒတာ (simple data) ဆိုရင္ stand alone element declaration ကို သံုးလို ့ရပါတယ္။ ဥပမာ -

<xs:element name="quantity" type="xs:interger"/>

ဒီ ေၾကညာခ်က္ေလးက <quantity> ဆိုတဲ့ element တစ္ခုကို အသံုးၿပဳႏိုင္ေအာင္လုပ္ေပးပါလိမ္မယ္။ ေဒတာ အမ်ိဳးအစားကေတာ့ interger ေပါ့။

<quantity>5</quantity>

ေဒတာအမ်ိဳးအစာ decimal ၊ temperature element အတြက္ဆိုရင္

<xs:element name="temperature" type="xs:decimal"/>

XML ဖိုင္ထဲမွာေတာ့ ဒီလိုသံုးလို ့ရေရာေပါ့။

<temperature>9.89</temperature>

ေဒတာအမ်ိဳးအစာ date၊ holiday element အတြက္ဆိုရင္

<xs:element name="holiday" type="xs:date"/>

XML ဖိုင္ထဲမွာေတာ့ ဒီလိုသံုးလို ့ရေရာေပါ့။

<holiday>2007-12-13</holiday>

date ေဒတာအမ်ိဳးအစားက YYYY-MM-DD(ႏွစ္၊ လ၊ ရက္) ကို သတ္မွတ္ေပးပါတယ္။

ေဒတာအမ်ိဳးအစာ boolean ၊ attendenct element အတြက္ဆိုရင္

<xs:element name="attendenct" type="xs:boolean"/>

XML ဖိုင္ထဲမွာေတာ့ ဒီလိုသံုးလို ့ရေရာေပါ့။

<attendenct>true</attendenct>

ေဒတာအမ်ိဳးအစာ string ၊ title element အတြက္ဆိုရင္

<xs:element name="title" type="xs:string"/>

XML ဖိုင္ထဲမွာေတာ့ ဒီလိုသံုးလို ့ရေရာေပါ့။

<title>XML Schema Introduction</title>

အဲဒီလို ေပါ့။ ဟုတ္လား။
ပံုစံ ထုတ္ၾကည့္ရင္ ဒီလို ေၿပာလို ့ရမယ္။

<xs:element name="element" type="xs:data_type"/>

element ေတြကို ဒီလို ေၾကညာတာဟာ simple content (အထဲမွာ data ပဲပါၿပီး ဘာမွမပါတာ) ေတြအတြက္ဆို အလုပ္လုပ္ပါ တယ္။ ဒါေပမယ့္ တကယ္လက္ေတြ မွာေတာ့ အဲဒီလို ့ string, date , decimal , boolean ေဒတာေလးေတြ ပဲ ပါတာ မဟုတ္ဗ်။ ပိုၿပီးေတာ့ ရွုပ္ေထြးတယ္။ ဒါေၾကာင့္ content model ဆိုၿပီးၿဖစ္လာရတယ္။ ေအာက္ကေတာ့ အဲဒီအေၾကာင္းပါပဲ။

<simpleType>

ဆက္ရန္။(ေနာက္ေန ့မွ ဒီပိုစ္မွာပဲ ဆက္ေရးပါမယ္)။

အာေကလာ(akela)
Dec 10, 2007 09:53 pm





Wednesday, December 5, 2007

temp Explaination




namespace testingWebLinks

{
class Program
{
static void Main(string[] args)
{
string line;

Dictionary<string,string> dictionaryOutLinks = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ out links ဘယ္ႏွခုရိွလည္း ကို သိမ္းမွာ။
Dictionary<string,string> dictionaryInLinks = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ in links ဘယ္ႏွခုရိွလည္း ကို သိမ္းမွာ။
Dictionary<string,string> dictionaryOutPages = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ ဘယ္ out page ေတြဆီိကို ထြက္သြားတာလည္းကို သိမ္းမွာ။
Dictionary<string,string> dictionaryInPages = new Dictionary<string,string>();
သူက page တစ္ခုစီမွာ ဘယ္ in page ေတြက ၀င္လာတာလည္းကို သိမ္းမွာ။

dictionaryInLinks.Clear();
dictionaryOutLinks.Clear();
dictionaryInPages.Clear();
dictionaryOutPages.Clear();
ဒါကေတာ့ စစခ်င္း clear လုပ္တာပါ။ အေရးမၾကီးပါ။

// Read the file and display it line by line.
String visitedString = "Visited:";
သူက ငါတို ့ဖတ္မဲ့ link က visited link ဟုတ္လား မဟုတ္လားကို စစ္ဖို ့။
String curVisitStr = String.Empty;
သူကေတာ့ လက္ရိွ visited link ကို သိမ္းထားဖို ့ (program အရ လိုေနလို ့ပါ။ေလာဂ်စ္အရ အေရးမၾကီး)။

Int32 inCounter = 0; in links စုစု ေပါင္း
Int32 outCounter = 0; out link စုစုးေပါင္း
Boolean isInVisited = false; သူက မလို ပါဘူး။

System.IO.StreamReader file = new System.IO.StreamReader("C:\\Documents and Settings\\nhyan\\Desktop\\weblinks.txt");
ငါတို ့.. web log file ကို ဖတ္လိုက္တာ။
try
{
while ((line = file.ReadLine()) != null) တစ္ေၾကာင္းခ်င္းloop ပတ္တယ္။
{
if (line.StartsWith(visitedString))ဖတ္လိုက္တဲ့ link က visited နဲ ့ စတာလားကို စစ္
{
if (outCounter != 0) ပထမဆံုး visited link လား ေနာက္မွ ေတြ ့တဲ့ visited link လားစစ္
{
dictionaryOutLinks[curVisitStr.Trim()] = outCounter.ToString();
outCounter = 0; isInVisited = false;
}
dictionaryOutLinks.Add(line.Trim(), outCounter.ToString());
dictionaryOutPages.Add(line.Trim(), String.Empty);
ပထမဆံုး visited link ကို သိမ္းတယ္။သူရဲ ့ counter က ေလာေလာဆယ္ 0 ေပါ့။
curVisitStr = line.Trim();
curVisitStr ထဲကို လက္ရိွ link ကို ထည့္တယ္။
isInVisited = true; ဒါကမလို
}
else ဖတ္လိုက္တဲ့ link က visited နဲ ့ စတာမဟုတ္ဘူးဆိုရင္
{
if (isInVisited == true)ဒါလည္း မလို
{
if (!dictionaryInLinks.ContainsKey(line.Trim()))
In links dictionary ထည္းမွာ လက္ရိွ link ဟာ ရိွပီးလား ကို စစ္( မ၇ိွေသးဘူးဆိုရင္)
{
inCounter++; in coutner ကို ၁ တိုး
dictionaryInLinks.Add(line.Trim(), inCounter.ToString());
In links dictionary ကို လက္ရိွ Link က key၊ in counter က value အၿဖစ္ သိမ္း
outCounter++;
out counter ကိုလည္း ၁ တိုး.. ဒါက တစ္ေၾကာင္းဖတ္တိုင္း တိုးရမွာေလ ။ အခုက out link ကို ဖတ္ေနတာ
dictionaryInPages.Add(line.Trim(), curVisitStr);
in page dictionary ကို လည္း လက္၇ွိဖတ္ေနတဲ့ link ရယ္၊ အေပၚက visited link ၇ယ္ကို key value အၿဖစ္သိမ္း
}
else
In links dictionary ထည္းမွာ လက္ရိွ link ဟာ ရိွပီးလား ကို စစ္( ရိွတယ္ဆိုရင္) ရိွပီးသားကို update လုပ္ရမယ္ေလ အသစ္ထည့္လို ့မရေတာ့ဘူး
{
String tempValue = String.Empty;
String tempString = String.Empty;

// in link dictionar ကို key လက္၇ိွ link ေပးပီ ေတာ့ value ကို ထုတ္ယူ
dictionaryInLinks.TryGetValue(line.Trim(), out tempValue);
inCounter = Convert.ToInt32(tempValue);
inCounter++;
အဲဒီ value ကို ၁ တိုး
dictionaryInLinks[line.Trim()] = inCounter.ToString();
ၿပန္ပီးေတာ့ ထည့္

//dictionaryInLinks.Remove(line);
//dictionaryInLinks.Add(line, inCounter);

//တဆက္တည္း in page ပါ update လုပ္သြား
dictionaryInPages.TryGetValue(line.Trim(), out tempValue);
လက္ရိွ link ကို key အၿဖစ္ ေပးပီးေတာ့ထုတ္ယူ
tempString = tempValue.Trim() + "::" + curVisitStr.Trim();
value ကို update လုပ္
dictionaryInPages[line.Trim()] = tempString;
ၿပန္ထည့္

outCounter++;
ဒါကေတာ့ out counter ကို ၁ တိုးရမယ္ေလ။
}
String tempOutValue = String.Empty;
dictionaryOutPages.TryGetValue(curVisitStr.Trim(), out tempOutValue);
tempOutValue = tempOutValue + "::" + line.Trim();
dictionaryInLinks[curVisitStr.Trim()] = tempOutValue;
}
}
}

ဒီေအာက္ပိုင္းက.. dictionary ထည္းမွာ သိမ္းထားတာေတြကို txtဖိုင္မွာ ၿပန္၇ိုက္ထုတ္တာ။
Int32 i = 0;
TextWriter twOutLink = new StreamWriter("C:\\Documents and Settings\\nhyan\\Desktop\\outLinks.txt");
foreach (KeyValuePair kvp in dictionaryOutLinks)
{
if (i == 0)
{
// write a line of text to the file
twOutLink.Write("OUT LINKS");
twOutLink.WriteLine("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t PAGES");

i = 1;
}

twOutLink.WriteLine("{0} \t\t\t\t {1}",
kvp.Key, kvp.Value);
}
// close the stream
twOutLink.Close();

Int32 j = 0;

TextWriter twInLink = new StreamWriter("C:\\Documents and Settings\\nhyan\\Desktop\\inLinks.txt");
foreach (KeyValuePair kvp in dictionaryInLinks)
{
if (j == 0)
{
// write a line of text to the file
twInLink.Write("OUT LINKS");
twInLink.WriteLine("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t PAGES");

j = 1;
}

twInLink.WriteLine("{0} \t\t\t\t {1}",
kvp.Key, kvp.Value);
}
// close the stream
twInLink.Close();
}
catch (KeyNotFoundException exp)
{
Console.Write(exp.ToString());
}

// Suspend the screen.
Console.ReadLine();
}
}
}