A classical musician turned programmer... or something

You have a site, a blog, a something. And you're using WordPress. Ok, that's cool. It's free and nifty, but you HAVE to keep it up-to-date. Nutty hackers and their b0ts are all over the net, HOPING people like YOU don't upgrade your site(s).

So after that warning, you want to upgrade to the latest version of WordPress. You upload your junk and go to your site and BOOM! Blank screen.

  • Make sure your wp-config.php file has no white space(s) after the closing ?> mark.

Ok fixed that...

Next you try to login... and WHAMMMMMM! You're bounced back to the login screen. No errors, no messages in the UI... nuttin.

  • Make sure that the wp-content/plugins folder has been renamed to something else, like wp-content/plugins_butt

Once you have logged in, rename that folder back to 'plugins' (you can also turn off the active plugins in the db, but it requires that you save its contents)

Those things helped me, I hope it helps you too!

Tags:

Here's a method I've been working on for a recent project. It will make a csv file from a generic list of type <T>.

There are methods out there for doing similar with DataTables... I like working with generic lists myself.

It does what it needs to do, but I'm not terribly happy with it yet, especially with a class with multiple constructors (all properties are used in csv).

(sorry about the formatting... gotta find a c# code format plugin...)
UPDATE: http://drupal.org/project/geshifilter

/// <summary>
/// Creates the CSV from a generic list.
/// </summary>;
/// <typeparam name="T"></typeparam>;
/// <param name="list">The list.</param>;
/// <param name="csvNameWithExt">Name of CSV (w/ path) w/ file ext.</param>;
        public static void CreateCSVFromGenericList<T>(List<T> list, string csvNameWithExt)
        {
            if (list == null || list.Count == 0) return;
 
                //get type from 0th member
                Type t = list[0].GetType();
                string newLine = Environment.NewLine;
 
                using (var sw = new StreamWriter(csvNameWithExt))
                {
                    //make a new instance of the class name we figured out to get its props
                    object o = Activator.CreateInstance(t);
                    //gets all properties
                    PropertyInfo[] props = o.GetType().GetProperties();
 
                    //foreach of the properties in class above, write out properties
                    //this is the header row
                    foreach (PropertyInfo pi in props)
                    {
                        sw.Write(pi.Name.ToUpper() + ",");
                    }
                    sw.Write(newLine);
 
                    //this acts as datarow
                    foreach (T item in list)
                    {
                        //this acts as datacolumn
                        foreach (PropertyInfo pi in props)
                        {
		  //this is the row+col intersection (the value)
                            string whatToWrite =
                                Convert.ToString(item.GetType()
                                                     .GetProperty(pi.Name)
                                                     .GetValue(item, null))
                                    .Replace(',', ' ') + ',';
 
                            sw.Write(whatToWrite);
 
                        }
                        sw.Write(newLine);
                    }
                }  
        }

So there you have it... C# generic list to csv file!

Couple things to change/ideas...

  • take in a delimiter (string) (comma is standard now, but it could be anything, use that as .Replace() of value as well)
  • remove last comma in header row.
  • fix this line 'Type t = list[0].GetType();' (I don't like it!)

Any suggestions are welcome!

kick it on DotNetKicks.com

Tags:

So, are YOU going to DevConnections 2008 at Mandalay Bay? (See pathetic poll to the right).

This is my second time to vegas in <6 months and this time, I'm hoping to check out Alex, Picasso, and Ed Roman Guitars.

I'm going with a bunch of guys from w0rk. Should be fun, though I've read some not-so-good reviews of our hotel... (Can't be the Venetian every time...)

kick it on DotNetKicks.com

When rockin' out the NAnt build process, I thought it was necessary to have a folder that accurately states the build version/number of the enclosed assembly. I'm sure I could have done this w/code, but eff that... I wanted to have a bit of fun, trying the <code> tags from within the build file itself.

Given a path to an assembly, ${build.dir} will echo something like:

build-38372-383748--2010-10-10

I've found it handy for:

  • Doing something at build time wo/another console app.
  • Keeping track of builds (duh)
  • Impressing the ladies.

(Sorry about the whacked formatting!)

<property name="build.dir" value="build" />
<property name="pathToAssembly" value="C:\your\moms\house\nice.dll" />
<target name="getbuildnum">
<script language="C#" prefix="method" >
<imports>
<import namespace="System.Reflection" />
</imports>
<code>
<![CDATA[
[Function("get-version-from-assembly")]
public string GetVersionFromAssembly(string assPath) {
Assembly ass = Assembly.LoadFrom(assPath);
return "build-"+ass.GetName().Version.ToString()
.Replace(".","-")+"--"+DateTime.Now.ToString("yyyy-MM-dd");
}
]]>
</code>
</script>
<property name='build.dir' value='${method::get-version-from-assembly(pathToAssembly)}' />
<echo message='${build.dir}' />
</target>

kick it on DotNetKicks.com

So... who's going to OWASP NYC AppSec 2008 Conference?? It's coming up very soon...aka NEXT WEEK!

I'm looking forward to the following talks...

· Get Rich or Die Trying - Making Money on The Web, The Black Hat Way (HOT!)
· Next Generation Cross Site Scripting Worms
· Bypassing web application/service security controls using Encoding, Transcoding, Filter Evasion, and other Canonicalization Attacks

kick it on DotNetKicks.com

So just a quickie post. NAnt doesn't play very nicely with the MSBuild task especially with .NET 3.5, so I thought I'd post a snippet from a build file that I think I finally like (and works!).

* project has been renamed [to csharptocsharp] to protect the innocent lame!

<property name="msbuild" value="C:/WINDOWS/Microsoft.NET/Framework/v3.5/MSBuild.exe" />
<target name="compile" description="Compiles using the AutomatedDebug Configuration">
<!-- NAnt doesn't like this part! :( -->
<!--<msbuild project="src\csharptocsharp.com.sln">
<property name="Configuration" value="AutomatedDebug" />
</msbuild>-->
<!-- So we just use an exec task instead!-->
<exec program="${msbuild}">
<arg value="src\csharptocsharp.com.sln" />
<arg value="/v:n" />
<arg value="/p:Configuration=AutomatedDebug" />
<arg value="/p:WarningLevel=0" />
</exec>
</target>

kick it on DotNetKicks.com

So here's a short follow up to a comment from anonymous2 in the Visual Studio automate testing post. Anon2 was right! I totally needed coverage and fxcop to be built into the build process... so here we go with another attempt at using Visual Studio's post-build events to automate testing [and make it even hotter!].

With the suggestion from this comment. All of these items are now fully contained in the project. All tools live in the project's /lib folder and all results live in /reports.

Ahem...

set NCOVER=C:\SVN\TNCMSDemo\trunk\lib\ncover\NCover.Console.exe
set NUNIT=C:\SVN\TNCMSDemo\trunk\lib\nunit\nunit-console.exe
set NUNITXML=C:\SVN\TNCMSDemo\trunk\reports\nunit.xml
set FXCOP=C:\SVN\TNCMSDemo\trunk\lib\fxcop\fxcopcmd.exe

copy /Y "$(ProjectDir)Web.config" "C:\SVN\TNCMSDemo\trunk\TNCMSTest\App.config"

%NCOVER% %NUNIT% /xml %NUNITXML% "C:\SVN\TNCMSDemo\trunk\TNCMSTest\bin\Debug\TNCMSTest.dll" //x "C:\SVN\TNCMSDemo\trunk\reports\Coverage.xml" //l "C:\SVN\TNCMSDemo\trunk\reports\Coverage.log"

%FXCOP% /project:C:\SVN\TNCMSDemo\trunk\tncms.fxcop /out:C:\SVN\TNCMSDemo\trunk\reports\FxCopReport.xml

"C:\SVN\TNCMSDemo\trunk\lib\nunit\nunitresults\nunitresults.exe" %NUNITXML% C:\SVN\TNCMSDemo\trunk\reports\

Now some explanation:
We set some vars because programmers are lazy like efficiency.
set NCOVER=C:\SVN\TNCMSDemo\trunk\lib\ncover\NCover.Console.exe
set NUNIT=C:\SVN\TNCMSDemo\trunk\lib\nunit\nunit-console.exe
set NUNITXML=C:\SVN\TNCMSDemo\trunk\reports\nunit.xml
set FXCOP=C:\SVN\TNCMSDemo\trunk\lib\fxcop\fxcopcmd.exe

We copy a Web.config to an App.config of our test project to do 'expectation' assurance / testing.
copy /Y "$(ProjectDir)Web.config" "C:\SVN\TNCMSDemo\trunk\TNCMSTest\App.config"

Here's where the sauce begins to flow. I call NCover (shorthand as %NCOVER%) which calls NUnit console (%NUNIT%).

%NCOVER% %NUNIT%

I designate a custom-named xml output file for the nunit process with the /xml switch.
/xml %NUNITXML%

Next is the path to the dll to test
"C:\SVN\TNCMSDemo\trunk\TNCMSTest\bin\Debug\TNCMSTest.dll"

The //x switch is for a custom-named coverage xml file (in this case, I want to control the location)
//x "C:\SVN\TNCMSDemo\trunk\reports\Coverage.xml"

The //l switch is for a custom-named coverage log (again, I want to control the final location) [we're almost done!]
//l "C:\SVN\TNCMSDemo\trunk\reports\Coverage.log"

Now I call FxCop's command line utility app.
%FXCOP%

Here is the reference to the .fxcop project file I made with the actual FxCop desktop app
/project:C:\SVN\TNCMSDemo\trunk\tncms.fxcop

And here is where I want its output to go.
/out:C:\SVN\TNCMSDemo\trunk\reports\FxCopReport.xml

Finally, I use NUnitResults to generate a nice html report.
"C:\SVN\TNCMSDemo\trunk\lib\nunit\nunitresults\nunitresults.exe"

%NUNITXML% is the path to the nunit xml file (see above)
%NUNITXML%

And here is the directory that I want it to live.
C:\SVN\TNCMSDemo\trunk\reports\

Now that you have that sorted out, you can spend your time crafting hot c0de.

Stuff you will need to accomplish the above:
NUnit console
NUnitResults
FxCop
NCover console

If you thought that was the opposite of teh suX0r, or something to add/fix/nuke... leave a comment [or kick it]! (or leave one anyway)

kick it on DotNetKicks.com

This isn't really new, I know, I know I've heard it all before about ReSharper. "ReSharper is ok but...," or "It's expensive..." or "Blah blah ReSharper...," or some other comment from some jerky developer deeming it useless. Even if you think the rewards aren't that great in terms of orgiastic programming results;
think about your hands (and fingers), and all the wasted keystrokes. Damnit.

<slightDigression>
Scott Hanselman discusses the programmer's hands and how important they are to your career (BC: and of course, your life). Although ReSharper may not indeed save you from some terrible hand condition... Everything helps.

I spent hours a day for years in my past life as a classical musician honing finger movements for ultimate efficiency. Why? Because you want to be able to pick your nose when your 80.

Yes I have a crazy ergo keyboard and trackball rat.
</slightDigression>

In any case. My comment to the unbelievers is:

Have fun wasting your time. [loser]

I am in no way affiliated with ReSharper, JetBrains, or any other Visual Studio plugin like CodeRush. I'm just a coder d00d. But, like me, if you're in a situation where the company you work for supports time-saving tools for their developers, then you need some sort of Visual Studio add-on (or whatever IDE) like this.

I've tried "convincing" other developers and showing them how awesome it is--turning a huge list of private items to public getter/setters should have been enough--but no one seems to care! For me: incorporating, LINQ and extension methods in 3.0 is the best part. For months I dealt with all the broken [looking] LINQ queries with ReSharper 3.1--but no more!

So to anyone that hasn't tried it for Visual Studio 2008... here are the ReSharper 4.0 nightly builds for your pleasure...

And for anyone else I say: remember your digits... and I give thee this.

broken developer finger

kick it on DotNetKicks.com

Whether you're into test driven development (TDD) or test after development (TAD), or you're into having your code get br0xored by not testing (doh!)... unit testing is all over the development world. You're a silly-goose if you haven't heard about it. In any case, using Visual Studio's post-build event process is a nice way of making sure your tests are always executed after a build. Though this isn't news to most developer 'dudes,' it surely made me all hot and steamy when I did it!

To do it you'll need the following:

  • Visual Studio (no duh)
  • Some sort of command line unit test app... like nunit console
  • A new pair of pants after you see how rad this is.

So, you go here:
Visual Studio -> Project Properties -> Build Events

And add this line, pointing nunit-console to the DLL of your project:

"C:\Program Files\nunit\nunit-console.exe" "C:\SVN\Proj\trunk\ProjTestProj\bin\Release\ProjTestProj.dll"

And that's it! Get ready for the hotness!

But wait! There's more!

As an added bonus... I add this line before the line above...

copy /Y "$(ProjectDir)Web.config" "C:\SVN\Proj\trunk\ProjTestProj\App.config"

This enables "Unit testing" (or more like expectation testing) of the Web.config file by copying it over to the Unit Test project as App.config. When this happens, you would be able to talk to it in your Test project via the ConfigurationManager. For example:

Assert.AreEqual("666", ConfigurationManager.AppSettings["SomeImportantNumber"]);

kick it on DotNetKicks.com

Heavy Metal Rock and Roll.

Tired of seeing 10,343 error emails when your application blows up? So you finally took a hint and got around to logging your web application. Good work, you're another step closer to being a rock and roll geek dude.

Log4Net is a great choice for all of your logging needs. I'll assume that you have log4net correctly installed and it's giving you some sort of output. If not, the mighty Phil Haack has written about configuring log4net numerous times. Rock your Loggin'

I have two Log4Net xml config files that I switch between using debug and release preprocessor directives (Too lazy to change one for releases [They're virtually the same except for priority value]). Having the log4net config outside of web.config won't make the app restart if you need to make a change to it while it's in the wild (hot) (though won't show updates until app restart).

There are a bunch of log4net example configs available for download on the Log4Net website. I have included here the log4net config file that I am using on my latest project.

The Reasons:

Here is why I like the following log4net setup:

  • The current log keeps its static name of "log-file.txt." Paired with something like Log4Net Viewer or baretail (my preference) and the scrolling appender option, it is WICKED easy to watch the logging action as it happens in real time.
  • It will create a new log for each day or if the max size is reached (I have it set to 15mb here and 14 logs).
  • Logs are named in such a way that viewing past logs is easy... log-file.txtYYYYMMDD is what I have here where YYYYMMDD will be replaced by the actual year, month, day. (In the case where you have might have multiple logs per day, a number will be appended to the file name log-file.txtYYYYMMDD.1, log-file.txtYYYYMMDD.2, etc.).
  • What is sexier than logging?

On to the goodies...

The Config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<root>
<priority value="Info"/>
<appender-ref ref="RollingFileAppender"/>
</root>

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\\Path\\To\\Your\\log-file.txt" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="14" />
<maximumFileSize value="15000KB" />
<datePattern value="yyyyMMdd" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="{%level}%date{MM/dd HH:mm:ss} - %message%newline"/>
</layout>
</appender>
</log4net>
</configuration>

The End:

In closing, I hope you have some sort of logging strategy for your application, using my log4net config or not, it will lead you even closer to being rocktaclar, and that is veddie nice.

Thumbs Up!
I like the log! Niiiiice.

kick it on DotNetKicks.com

About Brian


Brian Canzanella brings you nifty tips and tricks for most things .NET. read more...

Readers / Stuff