Nicko think on software, web, ideas

October 17, 2007

Get XML from Embedded Resources

Filed under: Code and Code — Nicko Satria Utama @ 9:43 am

For some situation, I need to save data or configuration as a default to the DLL and EXE files. First I make XML file in Visual Studio and fill the contents. After that set XML file’s Build Action to Embedded Resource. After compiling and produce DLL or EXE you can access the resources using the methods below.

/// <summary>
/// Get XML from Embedded Resources
/// </summary>
/// <returns></returns>
public XmlReader GetXmlConfig()
{

XmlReader xmlReader = null;
Assembly asm = Assembly.LoadFrom(“myLibrary.dll”);
if (asm != null)
{

string[] strArr = asm.GetManifestResourceNames();
if (strArr != null && strArr.Length > 0)

{

foreach (string str in strArr)
{

if (str.EndsWith(“MyXML.xml”))
{

Stream stream = asm.GetManifestResourceStream(str);
xmlReader = XmlReader.Create(stream);

}

}

}

} return xmlReader;

}

October 2, 2007

Short Meeting at THR

Filed under: Code and Code, Peoples — Nicko Satria Utama @ 10:12 pm

Saturday I went to I met Salamun, Cipto and Eriawan there. It was nice since we talked freely without any interruption and problem.

We talk everything on programming approach, how to handle the data, how to write the code etc. We have some conclusion on how bad and good programming.

  • Always thinks keep codes long enough in one methods if only called once.
    For example if have methods RunForDataX that run sql statement to get data and manipulate it.
    public void RunForDataX()
    {
    // — 200 lines –
    }
    It is hard to maintain the long codes so I like to split up into methods with shorter codes.
  • Loading unnecessary data and code to memory and manipulating on the fly. It is expensive for desktop and web application even you deploy on server farm.
  • Bad class or library design. Some classes have no design at all or not use defacto pattern/guide. Some hasĀ  implement it wrong. It will increase maintenance cost.
  • Don’t know when it will freeze. Any new improvement and feature added but don’t know when it has to be freeze and deliver the products.
  • Build in the wrong way, wrong library and wrong tools.
  • Misuse and overuse the code or even the technology.
  • Make unnecessary object dependency and sometimes calling some methods in the sequentially. Most of the codes is too tight coupling.

Blog at WordPress.com.