+ All Categories
Home > Documents > Practice Code

Practice Code

Date post: 19-Feb-2018
Category:
Upload: damir-galas
View: 251 times
Download: 0 times
Share this document with a friend

of 44

Transcript
  • 7/23/2019 Practice Code

    1/44

    JSON Example

    This page shows examples of messages formatted using JSON (JavaScript Object

    Notation)

    !

    "glossar#"$ !

    "title"$ "example glossar#"%

    "&loss'iv"$ !

    "title"$ "S"%

    "&lossist"$ !

    "&lossEntr#"$ !

    "'"$ "S&*"%

    "Sort+s"$ "S&*"%

    "&lossTerm"$ "Standard &enerali,ed *ar-up

    anguage"%

    "+cron#m"$ "S&*"%

    "+bbrev"$ "SO ../0$10.2"%

    "&loss'ef"$ !

    "para"$ "+ meta3mar-up language% used to create mar-up languages

    such as 'oc4oo-"%

    "&lossSee+lso"$ 5"&*"% "6*"7

    8%

    "&lossSee"$ "mar-up"

    8

    8

  • 7/23/2019 Practice Code

    2/44

    8

    8

    8

    The same text expressed as 6*$

    9:'O;T4; "3??O+SS??'T' 'oc4oo- @A1??EN"B

    9glossar#B9titleBexample glossar#9?titleB

    9&loss'ivB9titleBS9?titleB

    9&lossistB

    9&lossEntr# 'C"S&*" Sort+sC"S&*"B

    9&lossTermBStandard &enerali,ed *ar-up anguage9?&lossTermB

    9+cron#mBS&*9?+cron#mB

    9+bbrevBSO ../0$10.29?+bbrevB

    9&loss'efB

    9paraB+ meta3mar-up language% used to create mar-up

    languages such as 'oc4oo-9?paraB

    9&lossSee+lso OtherTermC"&*"B

    9&lossSee+lso OtherTermC"6*"B

    9?&loss'efB

    9&lossSee OtherTermC"mar-up"B

    9?&lossEntr#B

    9?&lossistB

    9?&loss'ivB

    9?glossar#B

    !"menu"$ !

    "id"$ "Dle"%

  • 7/23/2019 Practice Code

    3/44

    "value"$ "ile"%

    "popup"$ !

    "menuitem"$ 5

    !"value"$ "New"% "onclic-"$ ";reateNew'oc()"8%

    !"value"$ "Open"% "onclic-"$ "Open'oc()"8%

    !"value"$ ";lose"% "onclic-"$ ";lose'oc()"8

    7

    8

    88

    The same text expressed as 6*$

    9menu idC"Dle" valueC"ile"B

    9popupB

    9menuitem valueC"New" onclic-C";reateNew'oc()" ?B

    9menuitem valueC"Open" onclic-C"Open'oc()" ?B

    9menuitem valueC";lose" onclic-C";lose'oc()" ?B

    9?popupB

    9?menuB

    !"widget"$ !

    "debug"$ "on"%

    "window"$ !

    "title"$ "Sample Fonfabulator Gidget"%

    "name"$ "mainHwindow"%

    "width"$ I%

    "height"$ I

    8%

  • 7/23/2019 Practice Code

    4/44

    "image"$ !

    "src"$ "mages?Sunpng"%

    "name"$ "sun1"%

    "hOKset"$ LI%

    "vOKset"$ LI%

    "alignment"$ "center"

    8%

    "text"$ !

    "data"$ ";lic- Mere"%

    "si,e"$ A2%

    "st#le"$ "bold"%

    "name"$ "text1"%

    "hOKset"$ LI%

    "vOKset"$ 1%

    "alignment"$ "center"%

    "on*ouse>p"$ "sun1opacit# C (sun1opacit# ? 1) 0"

    8

    88

    The same text expressed as 6*$

    9widgetB

    9debugBon9?debugB

    9window titleC"Sample Fonfabulator Gidget"B

    9nameBmainHwindow9?nameB

    9widthBI9?widthB

    9heightBI9?heightB

  • 7/23/2019 Practice Code

    5/44

    9?windowB

    9image srcC"mages?Sunpng" nameC"sun1"B

    9hOKsetBLI9?hOKsetB

    9vOKsetBLI9?vOKsetB

    9alignmentBcenter9?alignmentB

    9?imageB

    9text dataC";lic- Mere" si,eC"A2" st#leC"bold"B

    9nameBtext19?nameB

    9hOKsetBLI9?hOKsetB

    9vOKsetB19?vOKsetB

    9alignmentBcenter9?alignmentB

    9on*ouse>pB

    sun1opacit# C (sun1opacit# ? 1) 0

    9?on*ouse>pB

    9?textB

    9?widgetB

    !"web3app"$ !

    "servlet"$ 5

    !

    "servlet3name"$ "cofax;'S"%

    "servlet3class"$ "orgcofaxcds;'SServlet"%

    "init3param"$ !

    "conDg&lossar#$installation+t"$ "=hiladelphia% =+"%

    "conDg&lossar#$adminEmail"$ "-smPpoboxcom"%

    "conDg&lossar#$powered4#"$ ";ofax"%

    "conDg&lossar#$powered4#con"$ "?images?cofaxgif"%

  • 7/23/2019 Practice Code

    6/44

    "conDg&lossar#$static=ath"$ "?content?static"%

    "template=rocessor;lass"$ "orgcofaxG#siw#gTemplate"%

    "templateoader;lass"$ "orgcofaxilesTemplateoader"%

    "template=ath"$ "templates"%

    "templateOverride=ath"$ ""%

    "defaultistTemplate"$ "listTemplatehtm"%

    "defaultileTemplate"$ "articleTemplatehtm"%

    "useJS="$ false%

    "jspistTemplate"$ "listTemplatejsp"%

    "jspileTemplate"$ "articleTemplatejsp"%

    "cache=ac-ageTagsTrac-"$ L%

    "cache=ac-ageTagsStore"$ L%

    "cache=ac-ageTagsQefresh"$ 2%

    "cacheTemplatesTrac-"$ 1%

    "cacheTemplatesStore"$ I%

    "cacheTemplatesQefresh"$ 1I%

    "cache=agesTrac-"$ L%

    "cache=agesStore"$ 1%

    "cache=agesQefresh"$ 1%

    "cache=ages'irt#Qead"$ 1%

    "searchEngineistTemplate"$ "forSearchEnginesisthtm"%

    "searchEngineileTemplate"$ "forSearchEngineshtm"%

    "searchEngineQobots'b"$ "GE43N?robotsdb"%

    "use'ataStore"$ true%

    "dataStore;lass"$ "orgcofaxSRl'ataStore"%

    "redirection;lass"$ "orgcofaxSRlQedirection"%

  • 7/23/2019 Practice Code

    7/44

    "dataStoreName"$ "cofax"%

    "dataStore'river"$ "commicrosoftjdbcsRlserverSServer'river"%

    "dataStore>rl"$

    "jdbc$microsoft$sRlserver$??O;+MOST$1AA'atabaseNameCgoon"%

    "dataStore>ser"$ "sa"%

    "dataStore=assword"$ "dataStoreTestuer#"%

    "dataStoreTestuer#"$ "SET NO;O>NT ONselect testCUtestU"%

    "dataStoreogile"$ "?usr?local?tomcat?logs?datastorelog"%

    "dataStorenit;onns"$ 1%

    "dataStore*ax;onns"$ 1%

    "dataStore;onn>sageimit"$ 1%

    "dataStoreogevel"$ "debug"%

    "max>rlength"$ I88%

    !

    "servlet3name"$ "cofaxEmail"%

    "servlet3class"$ "orgcofaxcdsEmailServlet"%

    "init3param"$ !

    "mailMost"$ "mail1"%

    "mailMostOverride"$ "mailL"88%

    !

    "servlet3name"$ "cofax+dmin"%

    "servlet3class"$ "orgcofaxcds+dminServlet"8%

    !

    "servlet3name"$ "DleServlet"%

    "servlet3class"$ "orgcofaxcdsileServlet"8%

    !

  • 7/23/2019 Practice Code

    8/44

    "servlet3name"$ "cofaxTools"%

    "servlet3class"$ "orgcofaxcms;ofaxToolsServlet"%

    "init3param"$ !

    "template=ath"$ "toolstemplates?"%

    "log"$ 1%

    "logocation"$ "?usr?local?tomcat?logs?;ofaxToolslog"%

    "log*axSi,e"$ ""%

    "dataog"$ 1%

    "dataogocation"$ "?usr?local?tomcat?logs?dataoglog"%

    "dataog*axSi,e"$ ""%

    "remove=age;ache"$ "?content?admin?removeVcacheCpagesWidC"%

    "removeTemplate;ache"$ "?content?admin?removeVcacheCtemplatesWidC"%

    "DleTransferolder"$ "?usr?local?tomcat?webapps?content?DleTransferolder"%

    "loo-n;ontext"$ 1%

    "admin&roup'"$ %

    "betaServer"$ true887%

    "servlet3mapping"$ !

    "cofax;'S"$ "?"%

    "cofaxEmail"$ "?cofaxutil?aemail?"%

    "cofax+dmin"$ "?admin?"%

    "DleServlet"$ "?static?"%

    "cofaxTools"$ "?tools?"8%

    "taglib"$ !

    "taglib3uri"$ "cofaxtld"%

    "taglib3location"$ "?GE43N?tlds?cofaxtld"888

  • 7/23/2019 Practice Code

    9/44

    The same Dle expressed as 6*$

    9Vxml versionC"1" encodingC"SO3..I031"VB

    9:'O;T4; "3??Sun *icros#stems% nc??'T' Geb +pplication LL??EN"

    "http$??javasuncom?jLee?dtds?web3appHLLdtd"B

    9web3appB

    9servletB

    9servlet3nameB

    cofax;'S

    9?servlet3nameB

    9servlet3classB

    orgcofaxcds;'SServlet

    9?servlet3classB

    9init3paramB

    9param3nameBconDg&lossar#$installation+t9?param3nameB

    9param3valueB=hiladelphia% =+9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBconDg&lossar#$adminEmail9?param3nameB

    9param3valueB-smPpoboxcom9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBconDg&lossar#$powered4#9?param3nameB

  • 7/23/2019 Practice Code

    10/44

    9param3valueB;ofax9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBconDg&lossar#$powered4#con9?param3nameB

    9param3valueB?images?cofaxgif9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBconDg&lossar#$static=ath9?param3nameB

    9param3valueB?content?static9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBtemplate=rocessor;lass9?param3nameB

    9param3valueBorgcofaxG#siw#gTemplate9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBtemplateoader;lass9?param3nameB

    9param3valueBorgcofaxilesTemplateoader9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBtemplate=ath9?param3nameB

    9param3valueBtemplates9?param3valueB

    9?init3paramB

  • 7/23/2019 Practice Code

    11/44

    9init3paramB

    9param3nameBtemplateOverride=ath9?param3nameB

    9param3valueB9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdefaultistTemplate9?param3nameB

    9param3valueBlistTemplatehtm9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdefaultileTemplate9?param3nameB

    9param3valueBarticleTemplatehtm9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBuseJS=9?param3nameB

    9param3valueBfalse9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBjspistTemplate9?param3nameB

    9param3valueBlistTemplatejsp9?param3valueB

    9?init3paramB

    9init3paramB

  • 7/23/2019 Practice Code

    12/44

    9param3nameBjspileTemplate9?param3nameB

    9param3valueBarticleTemplatejsp9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcache=ac-ageTagsTrac-9?param3nameB

    9param3valueBL9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcache=ac-ageTagsStore9?param3nameB

    9param3valueBL9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcache=ac-ageTagsQefresh9?param3nameB

    9param3valueB29?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcacheTemplatesTrac-9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcacheTemplatesStore9?param3nameB

  • 7/23/2019 Practice Code

    13/44

    9param3valueBI9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcacheTemplatesQefresh9?param3nameB

    9param3valueB1I9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcache=agesTrac-9?param3nameB

    9param3valueBL9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcache=agesStore9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcache=agesQefresh9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBcache=ages'irt#Qead9?param3nameB

    9param3valueB19?param3valueB

  • 7/23/2019 Practice Code

    14/44

    9?init3paramB

    9init3paramB

    9param3nameBsearchEngineistTemplate9?param3nameB

    9param3valueBforSearchEnginesisthtm9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBsearchEngineileTemplate9?param3nameB

    9param3valueBforSearchEngineshtm9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBsearchEngineQobots'b9?param3nameB

    9param3valueBGE43N?robotsdb9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBuse'ataStore9?param3nameB

    9param3valueBtrue9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStore;lass9?param3nameB

    9param3valueBorgcofaxSRl'ataStore9?param3valueB

    9?init3paramB

  • 7/23/2019 Practice Code

    15/44

    9init3paramB

    9param3nameBredirection;lass9?param3nameB

    9param3valueBorgcofaxSRlQedirection9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStoreName9?param3nameB

    9param3valueBcofax9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStore'river9?param3nameB

    9param3valueBcommicrosoftjdbcsRlserverSServer'river9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStore>rl9?param3nameB

    9param3

    valueBjdbc$microsoft$sRlserver$??O;+MOST$1AA'atabaseNameCgoon9?param3

    valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStore>ser9?param3nameB

    9param3valueBsa9?param3valueB

    9?init3paramB

  • 7/23/2019 Practice Code

    16/44

    9init3paramB

    9param3nameBdataStore=assword9?param3nameB

    9param3valueB9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStoreTestuer#9?param3nameB

    9param3valueBSET NO;O>NT ONselect testCUtestU9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStoreogile9?param3nameB

    9param3valueB?usr?local?tomcat?logs?datastorelog9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStorenit;onns9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStore*ax;onns9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

  • 7/23/2019 Practice Code

    17/44

    9param3nameBdataStore;onn>sageimit9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataStoreogevel9?param3nameB

    9param3valueBdebug9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBmax>rlength9?param3nameB

    9param3valueBI9?param3valueB

    9?init3paramB

    9?servletB

    9servletB

    9servlet3nameB

    cofaxEmail

    9?servlet3nameB

    9servlet3classB

    orgcofaxcdsEmailServlet

    9?servlet3classB

    9init3paramB

    9param3nameBmailMost9?param3nameB

    9param3valueBmail19?param3valueB

  • 7/23/2019 Practice Code

    18/44

    9?init3paramB

    9init3paramB

    9param3nameBmailMostOverride9?param3nameB

    9param3valueBmailL9?param3valueB

    9?init3paramB

    9?servletB

    9servletB

    9servlet3nameB

    cofax+dmin

    9?servlet3nameB

    9servlet3classB

    orgcofaxcds+dminServlet

    9?servlet3classB

    9?servletB

    9servletB

    9servlet3nameB

    DleServlet

    9?servlet3nameB

    9servlet3classB

    orgcofaxcdsileServlet

    9?servlet3classB

    9?servletB

  • 7/23/2019 Practice Code

    19/44

    9servletB

    9servlet3nameB

    cofaxTools

    9?servlet3nameB

    9servlet3classB

    orgcofaxcms;ofaxToolsServlet

    9?servlet3classB

    9init3paramB

    9param3nameBtemplate=ath9?param3nameB

    9param3valueBtoolstemplates?9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBlog9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBlogocation9?param3nameB

    9param3valueB?usr?local?tomcat?logs?;ofaxToolslog9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBlog*axSi,e9?param3nameB

    9param3valueB9?param3valueB

  • 7/23/2019 Practice Code

    20/44

    9?init3paramB

    9init3paramB

    9param3nameBdataog9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataogocation9?param3nameB

    9param3valueB?usr?local?tomcat?logs?dataoglog9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBdataog*axSi,e9?param3nameB

    9param3valueB9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBremove=age;ache9?param3nameB

    9param3valueB?content?admin?removeVcacheCpagesWidC9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBremoveTemplate;ache9?param3nameB

    9param3valueB?content?admin?removeVcacheCtemplatesWidC9?param3

    valueB

    9?init3paramB

  • 7/23/2019 Practice Code

    21/44

    9init3paramB

    9param3nameBDleTransferolder9?param3nameB

    9param3valueB?usr?local?tomcat?webapps?content?DleTransferolder9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBloo-n;ontext9?param3nameB

    9param3valueB19?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBadmin&roup'9?param3nameB

    9param3valueB9?param3valueB

    9?init3paramB

    9init3paramB

    9param3nameBbetaServer9?param3nameB

    9param3valueBtrue9?param3valueB

    9?init3paramB

    9?servletB

    9servlet3mappingB

    9servlet3nameB

    cofax;'S

  • 7/23/2019 Practice Code

    22/44

    9?servlet3nameB

    9url3patternB

    ?

    9?url3patternB

    9?servlet3mappingB

    9servlet3mappingB

    9servlet3nameB

    cofaxEmail

    9?servlet3nameB

    9url3patternB

    ?cofaxutil?aemail?

    9?url3patternB

    9?servlet3mappingB

    9servlet3mappingB

    9servlet3nameB

    cofax+dmin

    9?servlet3nameB

    9url3patternB

    ?admin?

    9?url3patternB

    9?servlet3mappingB

    9servlet3mappingB

    9servlet3nameB

  • 7/23/2019 Practice Code

    23/44

    DleServlet

    9?servlet3nameB

    9url3patternB

    ?static?

    9?url3patternB

    9?servlet3mappingB

    9servlet3mappingB

    9servlet3nameB

    cofaxTools

    9?servlet3nameB

    9url3patternB

    ?tools?

    9?url3patternB

    9?servlet3mappingB

    9taglibB

    9taglib3uriBcofaxtld9?taglib3uriB

    9taglib3locationB?GE43N?tlds?cofaxtld9?taglib3locationB

    9?taglibB

    9?web3appB

    The action and label values onl# need to be provided if the# are not the same as the

    id

    !"menu"$ !

    "header"$ "S@& @iewer"%

  • 7/23/2019 Practice Code

    24/44

    "items"$ 5

    !"id"$ "Open"8%

    !"id"$ "OpenNew"% "label"$ "Open New"8%

    null%

    !"id"$ "Xoomn"% "label"$ "Xoom n"8%

    !"id"$ "XoomOut"% "label"$ "Xoom Out"8%

    !"id"$ "Original@iew"% "label"$ "Original @iew"8%

    null%

    !"id"$ "ualit#"8%

    !"id"$ "=ause"8%

    !"id"$ "*ute"8%

    null%

    !"id"$ "ind"% "label"$ "ind"8%

    !"id"$ "ind+gain"% "label"$ "ind +gain"8%

    !"id"$ ";op#"8%

    !"id"$ ";op#+gain"% "label"$ ";op# +gain"8%

    !"id"$ ";op#S@&"% "label"$ ";op# S@&"8%

    !"id"$ "@iewS@&"% "label"$ "@iew S@&"8%

    !"id"$ "@iewSource"% "label"$ "@iew Source"8%

    !"id"$ "Save+s"% "label"$ "Save +s"8%

    null%

    !"id"$ "Melp"8%

    !"id"$ "+bout"% "label"$ "+bout +dobe ;@& @iewer"8

    7

    88

    The same message expressed as 6*$

  • 7/23/2019 Practice Code

    25/44

    9menuB

    9headerB+dobe S@& @iewer9?headerB

    9item actionC"Open" idC"Open"BOpen9?itemB

    9item actionC"OpenNew" idC"OpenNew"BOpen New9?itemB

    9separator?B

    9item actionC"Xoomn" idC"Xoomn"BXoom n9?itemB

    9item actionC"XoomOut" idC"XoomOut"BXoom Out9?itemB

    9item actionC"Original@iew" idC"Original@iew"BOriginal @iew9?itemB

    9separator?B

    9item actionC"ualit#" idC"ualit#"Bualit#9?itemB

    9item actionC"=ause" idC"=ause"B=ause9?itemB

    9item actionC"*ute" idC"*ute"B*ute9?itemB

    9separator?B

    9item actionC"ind" idC"ind"Bind9?itemB

    9item actionC"ind+gain" idC"ind+gain"Bind +gain9?itemB

    9item actionC";op#" idC";op#"B;op#9?itemB

    9item actionC";op#+gain" idC";op#+gain"B;op# +gain9?itemB

    9item actionC";op#S@&" idC";op#S@&"B;op# S@&9?itemB

    9item actionC"@iewS@&" idC"@iewS@&"B@iew S@&9?itemB

    9item actionC"@iewSource" idC"@iewSource"B@iew Source9?itemB

    9item actionC"Save+s" idC"Save+s"BSave +s9?itemB

    9separator?B

    9item actionC"Melp" idC"Melp"BMelp9?itemB

    9item actionC"+bout" idC"+bout"B+bout +dobe ;@& @iewer9?itemB

    9?menuB

  • 7/23/2019 Practice Code

    26/44

    using S#stem

    using S#stemO

    using S#stemSecurit#;r#ptograph#

    using S#stemNetSoc-ets

    public class main

    !

    public static void *ain(string57 args)

    !

    tr#

    !

    ??;reate a T;= connection to a listening T;= process

    ??>se "localhost" to specif# the current computer or

    ??replace "localhost" with the = address of the

    ??listening process

    Tcp;lient T;= C new Tcp;lient("localhost"%11)

    ??;reate a networ- stream from the T;= connection

    Networ-Stream NetStream C T;=&etStream()

    ??;reate a new instance of the Qijndael*anaged class

    ?? and encr#pt the stream

    Qijndael*anaged Q*;r#pto C new Qijndael*anaged()

    b#te57 Fe# C !x1% xL% xA% x% xI% x2% x/% x.% x0% x1%

    x11% x1L% x1A% x1% x1I% x128

  • 7/23/2019 Practice Code

    27/44

    b#te57 @ C !x1% xL% xA% x% xI% x2% x/% x.% x0% x1%

    x11% x1L% x1A% x1% x1I% x128

    ??;reate a ;r#ptoStream% pass it the Networ-Stream% and encr#pt

    ??it with the Qijndael class

    ;r#ptoStream ;r#ptStream C new ;r#ptoStream(NetStream%

    Q*;r#pto;reateEncr#ptor(Fe#% @)%

    ;r#ptoStream*odeGrite)

    ??;reate a StreamGriter for eas# writing to the

    ??networ- stream

    StreamGriter SGriter C new StreamGriter(;r#ptStream)

    ??Grite to the stream

    SGriterGriteine("Mello Gorld:")

    ??nform the user that the message was written

    ??to the stream

    ;onsoleGriteine("The message was sent")

    ??;lose all the connections

    SGriter;lose()

    ;r#ptStream;lose()

    NetStream;lose()

    T;=;lose()

    8

    catch

  • 7/23/2019 Practice Code

    28/44

    !

    ??nform the user that an exception was raised

    ;onsoleGriteine("The connection failed")

    8

    8

    8

    class ExceptionTest

    !

    static double Safe'ivision(double x% double #)

    !

    if (# CC )

    throw new S#stem'ivide4#XeroException()

    return x ? #

    8

    static void *ain()

    !

    ?? nput for test purposes ;hange the values to see

    ?? exception handling behavior

    double a C 0.% b C

    double result C

    tr#

    !

    result C Safe'ivision(a% b)

    ;onsoleGriteine("!8 divided b# !18 C !L8"% a% b% result)

  • 7/23/2019 Practice Code

    29/44

    8

    catch ('ivide4#XeroException e)

    !

    ;onsoleGriteine("+ttempted divide b# ,ero")

    8

    8

    8

    int caseSwitch C 1

    switch (caseSwitch)

    !

    case 1$

    ;onsoleGriteine(";ase 1")

    brea-

    case L$

    ;onsoleGriteine(";ase L")

    brea-

    default$

    ;onsoleGriteine("'efault case")

    brea-

    8

    public void Test()

    !

    for (int i C 1 i 9 11 iYY)

    !

  • 7/23/2019 Practice Code

    30/44

    if (i Z A CC WW i Z I CC )

    !

    ;onsoleGriteine("i,,4u,,")

    8

    else if (i Z A CC )

    !

    ;onsoleGriteine("i,,")

    8

    else if (i Z I CC )

    !

    ;onsoleGriteine("4u,,")

    8

    else

    !

    ;onsoleGriteine(i)

    8

    8

    8

    Ghat do #ou thin-V 'o we need to ma-e the code betterV

    Example L$

    Mide ;op# ;ode

    public void ;hec-()

    !

    for (int i C 1 i 9C 1 iYY)

  • 7/23/2019 Practice Code

    31/44

    !

    string output C ""

    if (i Z A CC ) ! output C "i,," 8

    if (i Z I CC ) ! output C output Y "4u,," 8

    if (output CC "") ! output C iToString() 8

    ;onsoleGriteine(output)

    8

    8

    Ghat do #ou thin- now V 'o we need to ma-e the code even betterV

    O-% let me help to ma-e it better Naming thing is one of the hardest job we have as

    a software developer 4ecause we spend a lot of time naming things% there are so

    man# things to name properties% methods% classes% Dles% projects etc Ge should

    spend some energies for naming things because names can be meanings +dding

    meaning to code is readabilit# all about

    Mide ;op# ;ode

    public void 'oi,,4u,,()

    !

    for (int number C 1 number 9C 1 numberYY)

    !

    var output C &eti,,4u,,Output(number)

    ;onsoleGriteine(output)

    8

    8

    private static string &eti,,4u,,Output(int number)

    !

  • 7/23/2019 Practice Code

    32/44

    string output C stringEmpt#

    if (numberZA CC )

    !

    output C "i,,"

    8

    if (numberZI CC )

    !

    output YC "4u,,"

    8

    if(stringsNullOrEmpt#(output))

    !

    output C numberToString()

    8

    return output

    8

    ublic class =roduct

    !

    public void &et+ctive=roducts()

    !

    ??

    8

    public void ;alculate=roduct+dditinal;ost()

    !

    ??

    8

    8

  • 7/23/2019 Practice Code

    33/44

    'o use camel;asing for method arguments and local variables

    Mide ;op# ;ode

    public class =roduct;ategor#

    !

    public void Save(=roduct;ategor# product;ategor#)

    !

    ??

    8

    8

    'o not use +bbreviations

    Mide ;op# ;ode

    ?? ;orrect

    =roduct;ategor# product;ategor#

    ?? +void

    =roduct;ategor# prod;at

    'o not use >nderscores in identiDers

    Mide ;op# ;ode

    ?? ;orrect

    =roduct;ategor# product;ategor#

    ?? +void

    =roduct;ategor# productH;ategor#

  • 7/23/2019 Practice Code

    34/44

    'o preDx interfaces with the letter

    Mide ;op# ;ode

    public interface +ddress

    !

    8

    'o declare all member variables at the top of a class% with static variables at the

    ver# top

    Mide ;op# ;ode

    public class =roduct

    !

    public static string 4randName

    public string Name!get set8

    public 'ateTime 'ate+vailable !get set8

    public =roduct()

    !

    ??

    8

    8

    'o use singular names for enums Exception$ bit Deld enums

    Mide ;op# ;ode

    public enum 'irection

  • 7/23/2019 Practice Code

    35/44

    !

    North%

    East%

    South%

    Gest

    8

    'o not su[x enum names with Enum

    Mide ;op# ;ode

    ??+void

    public enum 'irectionEnum

    !

    North%

    East%

    South%

    Gest

    8

    ??avoid

    public void ;hec-out(string shippingName% string shipping;it#%

    string shippingSate% string shippingXip% string billingName%

    string billing;it#% string billingSate% string billingXip)

    !

    8

    Mide ;op# ;ode

  • 7/23/2019 Practice Code

    36/44

    ??'O

    public void ;hec-out(Shipping+ddress shipping+ddress%4illing+ddress

    billing+ddress)

    !

    8

    Ge should introduce class instead of all parameters

    +void ;omplex Expressions

    Mide ;op# ;ode

    if(product=riceBI WW :products'eleted WW

    :productseatured WW productsExported)

    !

    ?? do something

    8

    Mide ;op# ;ode

    ??avoid

    if(product=riceB1I)

    !

    return false

    8

    else if(products'eleted)

    !

    return false

    8

    else if(:productseatured)

  • 7/23/2019 Practice Code

    37/44

    !

    return false

    8

    else if()

    !

    ??

    8

    return true

    Mide ;op# ;ode

    ??'O

    var is@alid C true

    if(product=riceB1I)

    !

    is@alidC false

    8

    else if(products'eleted)

    !

    is@alidC false

    8

    else if(:productseatured)

    !

    is@alidC false

    8

    return is@alid

  • 7/23/2019 Practice Code

    38/44

    got too man# responses% some agreeing but mostl# disagreeing that it was a good

    "standard" to enforce To Dnd out the potentialit# did some unit testing and found

    that for complex method that have multiple exit points usuall# have a set of tests

    for each of those paths

    Mide ;op# ;ode

    if( 4+'unction() CC true)

    !

    ?? expression

    if( anotherunction() CC true )

    !

    ?? expression

    return true

    8

    else

    !

    ??error

    8

    8

    else

    !

    ??error

    8

    return false

    Mide ;op# ;ode

    if( :&oodunction())

  • 7/23/2019 Practice Code

    39/44

    !

    ?? error

    return false

    8

    ?? expression

    if( :&oodunctionL())

    !

    ??error

    return false

    8

    ?? more expression

    return true

    namespace Geb+pplication1;ontrollers

    !

    public class ;ustomer

    !

    public string ;ustomerName ! get set 8

    public string +ddress ! get set 8

    8

    public class Test;ontroller $ ;ontroller

    !

    public ;ustomer &et;ustomer()

    !

    ;ustomer c C new ;ustomer()

    c;ustomerName C ";ustomer 1"

  • 7/23/2019 Practice Code

    40/44

    c+ddress C "+ddress1"

    return c

    8

    8

    8

    public override string ToString()

    !

    return this;ustomerNameY"\"Ythis+ddress

    8

    P!

    a#out C null

    8

    9:'O;T

  • 7/23/2019 Practice Code

    41/44

    return @iew("*#@iew")

    8

    else

    !

    return @iew("

  • 7/23/2019 Practice Code

    42/44

    public string ;ustomer;ode

    !

    set

    !

    H;ode C value

    8

    get

    !

    return H;ode

    8

    8

    public int d

    !

    get

    !

    return Hd

    8

    set

    !

    HdC value

    8

    8

    public double +mount

    !

  • 7/23/2019 Practice Code

    43/44

    set

    !

    H+mount C value

    8

    get

    !

    return H+mount

    8

    8

    8

    public class ;ustomer;ontroller $ ;ontroller

    !

    Whellip

    Whellip

    public @iewQesult 'ispla#;ustomer()

    !

    ;ustomer obj;ustomer C new ;ustomer()

    obj;ustomerd C 1L

    obj;ustomer;ustomer;ode C "11"

    obj;ustomer+mount C 0A

    return @iew("'ispla#;ustomer"%obj;ustomer)

    8

    8

    public class ;ustomer;ontroller $ ;ontroller

  • 7/23/2019 Practice Code

    44/44

    !

    Whellip

    Whellip

    public @iewQesult 'ispla#;ustomer()

    !

    ;ustomer obj;ustomer C new ;ustomer()

    obj;ustomerd C 1L

    obj;ustomer;ustomer;ode C "11"

    obj;ustomer+mount C 0A

    return @iew("'ispla#;ustomer"%obj;ustomer)

    8

    8

    9form actionC"'ispla#;ustomer" methodC"post"B

    Enter customer id $3 9input t#peC"text" nameC"d" ?B 9br ?B

    Enter customer code $3 9input t#peC"text" nameC";ustomer;ode" ?B9br ?B

    Enter customer +mount $39input t#peC"text" nameC"+mount" ?B9br ?B

    9input t#peC"submit" valueC"Submit customer data" ?B

    9?formB


Recommended