Ticus' Formules

Friday, August 27, 2021

Rename AppDomain.CurrentDomain.GetAssemblies() in runtime with Reflection.

If you need to rename the  'AppDomain.CurrentDomain.GetAssemblies()' for testing, here is something you can try:

 

 public static void RenameCurrentDomainAssemblies()

{

foreach (var a in AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("System")))

{

FieldInfo fullName = a.GetType().GetField("m_fullname", BindingFlags.Instance | BindingFlags.NonPublic);

fullName.SetValue(a, "Gotcha");

}


AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("SyS")).Dump();

}

Tuesday, August 10, 2021

Lo4Net - Insert Header (another approach)

 Temporary change the layout to display only the message.


ie:

ILayout configurationLayout = appender.Layout;

appender.Layout = new PatternLayout("%message");

myLogger.Info(MyHeader()); //MyHeader() returns any formated text you want to show.

appender.Layout = configurationLayout;

Log4Net - Insert Header programatically

Load log4net's XML configuration and insert an XML element in the appender's layout with the header information. 

ie:

XmlDocument doc = new XmlDocument();

doc.LoadXml("<layout type=\"log4net.Layout.PatternLayout\">" +

"<conversionPattern value=\"sample\" />" +

"</layout>");


XmlElement root = doc.DocumentElement;

XmlNode layout = doc.SelectSingleNode("//layout");

XmlElement elem = doc.CreateElement("header");

elem.SetAttribute("value", "My Header");

elem.SetAttribute("type", "log4net.Util.PatternString");

layout.AppendChild(elem);


Result:

<layout type="log4net.Layout.PatternLayout">

   <conversionPattern value="sample" />

   <header value="My Header" type="log4net.Util.PatternString" />

</layout>


Tuesday, January 21, 2014

OPEN A TEXT FILE USING C#


System.IO.StreamReader textIn=
new   System.IO.StreamReader(
new   System.IO.FileStream(dir, FileMode.OpenOrCreate, FileAccess.Read));
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Key", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("LastName", typeof(string));
table.Columns.Add("Salary", typeof(string));
while (textIn.Peek() != -1)
{
string row = textIn.ReadLine();
string[] columns = row.Split('|');
table.Rows.Add(columns[0], columns[1], columns[2], columns[3]);
}
textIn.Close();
return table;

Monday, March 4, 2013

IF YOU GOT THIS ERROR IN ECLIPSE + GRAILS 2.2.1

"Error opening zip file or JAR manifest missing : nullError occurred during initialization of VMagent library failed to init: instrument Grails"

1) Create a folder named: "/lib/com.springsource.springloaded" in your grails directory.
2) Copy the content of: "../lib/org.springsource.springloaded" to the folder that you created on step one.

Eg:
1) /usr/share/grails/lib$ sudo mkdir com.springsource.springloaded/
2) /usr/share/grails/lib$ sudo cp -r org.springsource.springloaded/springloaded-core/ com.springsource.springloaded/

Install Grails in Ubuntu Natty

1) Download the zip folder.
2) Unzip grailsx.x.zip
3) cp -r grails-x.x /usr/share/
4)Open ~/.profile and copy this:

JAVA_HOME=/usr/local/java/jdk1.7.0_09/
GRAILS_HOME=/usr/share/grails
PATH=$PATH:/usr/share/grails/bin
export JAVA_HOME PATH
export GRAILS_HOME PATH


Sources:
http://ullu.wordpress.com/2011/02/13/installing-groovy-grails-on-ubuntu/
http://mylearningongroovygrails.blogspot.com/2012/09/installing-grails-on-ubuntu-11.html

Wednesday, October 27, 2010

Install Java JDK on Ubuntu 10.04

sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk

Source: http://happy-coding.com/install-sun-java6-jdk-on-ubuntu-10-04-lucid/

Stats


View My Stats

Contributors