Replace as in batch replace
So I once again needed to replace several patterns in multiple files with something new... Instead of doing this all in my favorite text editor by using repeatedly find/replace, I decided that something more handy was needed. Of course I could have done all that replace stuff with xslt, but hey, who actually likes xslt.
The result of my disapproval of the above mentioned options is the Batch Replacer. As always it is released under the gpl. I also used git for the first time and published the source code on github.
Navigate to those... out of the box with firefox
Ok well, this doesn' seem to be new at all, but nevertheless I missed that. Firefox has the great functionality to assign shortcuts to certain bookmarks and supply a parameter to the URL. This leads to really great quick searches (aka. the art of bookmarking).
What I have now are shortcuts to all my often used search sites. To search in wikipedia e.g. I type CTRL + L (shortcut for placing the cursor in the URL bar in firefox), then type wp asdf and there I go.
I guess this fact renders my previously posted quick link access tool obsolete...
Navigate to those URLs over and over again...
I've written a tool that allows to define commonly used URLs for repeated access, varying only by a defined parameter-part. When you call one of those URLs, you just need to pass a parameter and it opens in the browser. That way you get quick access to often used URLs, e.g. your preffered search engine, your ticketing system or whatever. For even faster access the URLs are bound to predefined global hotkeys.
More infos can be found on the project page.
SharePoint list item and its ItemAdding event
I've found many solutions and discussions trying to find one about the ItemAdding event for a SharePoint list item on the internet, neither of which fixed my problem. Actually I've had two.
The first one was that you have to set the changes made to the ChangedProperties property that belongs the AfterProperties property. If you try to set them on the AfterProperties directly (why you can do this I don't know) the changes will be ignored when creating the item.
The second problem was that all values at the point of that event are stored as strings, they are not yet converted to their respective classes. In my case I needed to set the end date of an event list item 45 minutes after the event date. The following code snippets shows how to achive this. Basically you first have to convert the string into a DateTime object, add the 45 minutes to it and convert the DateTime object back to a valid string representation.
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
DateTime eventDate =
SPUtility.CreateDateTimeFromISO8601DateTimeString(properties.AfterProperties["EventDate"].ToString());
properties.AfterProperties.ChangedProperties["EndDate"] =
eventDate.AddMinutes(45).ToString("o");
}
Nullable average in LINQ
The following code is one possibility (there may be more elegant solutions to this) to handle a nullable average from a linq query. The problem arises when the linq query does not return a result, thus the average being null. If you don't use a nullable type, you'll get an exception. To get a nullable average from an integer value you'll need to provide a transform function to the Average funtion.
double? nullableAverage = (from m in dataContext.Moods join g in dataContext.Groups on m.GroupGUID equals g.GUID where g.GUID == groupGUID select m.Level) .Average<int>(x => new double?(x)); int average = (int)Math.Round(nullableAverage.HasValue ? nullableAverage.Value : 0, 0); // ...
Custom application settings
Within a c# winform application I needed to store a generic collection to my settings, which I found out was not possible out of the box. It is possible though to set the required type in the properties designer dialog, but the serialization's output is always nothing.
On my research on the internet for a solution i stumbled upon the post Tips for C# .NET Software Developers, which described that the attribute [SettingsSerializeAs(SettingsSerializeAs.Binary)] was required for the settings property, and to set it accordingly in the Settings.Designer.cs file. The problem here is that modifying designer generated code file is not the best of all ideas, as the manual changes are overwritten every time the settings are modified by the designer. Thus, I followed the msn article on how to create application settings, which told me to create a custom settings class. The drawback with this solution is that I now have two settings classes, and not only one single to cover it all.
Here's an example of the settings class. Note the use of the SettingsSerializeAs attribute, as it is the key to the successful serialization.
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
namespace Koffeinfrei
{
/// <summary>
/// This class provides extended settings. Use this class for types that need to have special
/// attributes for serialization, that cannot be set using the config designer dialog.
/// </summary>
internal class ExtendedSettings : ApplicationSettingsBase
{
private static ExtendedSettings defaultInstance =
((ExtendedSettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new ExtendedSettings())));
/// <summary>
/// Returns the default instance of this class.
/// </summary>
/// <remarks>Get the value of the <see name="defaultInstance"/> member.</remarks>
public static ExtendedSettings Default
{
get
{
return defaultInstance;
}
}
/// <summary>
/// The <see cref="SomeCustomClass"/>s stored in the user scoped settings.
/// </summary>
/// <remarks>Get / set the value of the <c>CustomClasses</c> property.</remarks>
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SettingsSerializeAs(
global::System.Configuration.SettingsSerializeAs.Binary)]
public global::System.Collections.Generic.Queue<SomeCustomClass> CustomClasses
{
get
{
return ((global::System.Collections.Generic.Queue<SomeCustomClasses>)(this["CustomClasses"]));
}
set
{
this["CustomClasses"] = value;
}
}
}
}
Rubyblood through your .NET veins with a vengeance
In my last blog entry i totally neglected the fact that there are lamda expressions. This nice little C# 3.0 feature makes anonymous methods much more readable. With that in mind, we can make our Times method much nicer.
Example 1: Ruby style iterator with lambda expression
2.Times(
number => { Console.WriteLine("> " + number); }
);
Compared to the former syntax, it increases readability considerably.
Example 2: Ruby style iterator with bare delegate
2.Times(
delegate(int number)
{
Console.WriteLine("> " + number);
}
);
- 0 comments
Fatal error: Cannot redeclare getpagecooserlinkhtml() (previously declared in /home/www/web261/html/koffeinfrei5/modules/Blogs/action.showblog.php:11) in /home/www/web261/html/koffeinfrei5/modules/Blogs/action.showblog.php on line 11