Cinchoo – Bulk Files & Folders rename utility

ChoBulkFileRenameTool

Download Binary (Zip)

Download Source (Zip)

This tool helps to rename bulk files and folders recursively. It was written in using WPF/C#/VS.NET 2010.

Features

  • Bulk file and folders rename matching either wildcard or regular expression patterns
  • Runs on Windows 95/98/ME/NT4/2k/2k3/2k8/XP/Vista/7

How to use

  • Click ‘Start’ whenever you are ready to rename files. Any time you can can start this process.
  • Type a full path of the file or folder in ‘Choose a File / Folder’ text box, then click ‘Add’ button to add it to ‘File(s) / Folder(s)’ list box. Or you can click ‘Browse’ button, to choose the file/folder for rename.
  • At any time, you can select an item in ‘File(s) / Folder(s)’ list box, remove it using ‘Remove’ button.
  • In ‘Find/Replace’ text boxes, you can specify either the wildcard or regular expression to identify files and folders for rename. (Please visit Regular Expression Cheat Sheet for help in creating regular expression)
  • Check ‘Match Files’ or ‘Match Folders’ check boxes, in order to include them for rename process respectively.
  • Check ‘Preview Mode’ option, if you just want to see the files and folders are renamed in the ‘Status’ box or in the log file under ‘Logs’ folder. This option will not rename the files or folder names.
  • Check ‘Include Sub Dir’ option, to include all sub directories for rename process.
  • In ‘Status’ box, you can view the statues of the file renames.
  • Click ‘Clear’ button anytime to clear the ‘Status’ box.

Tips

  • You can drag and drop file(s) or folder(s) to this tool for easy cleanup process.

Cinchoo – Configuration framework, part 24

Binding to WinForm controls

Download Source Files (ZIP)

In this section, I’ll talk about binding your configuration object to WinForm controls. WinForm has rich binding infrastructure, Cinchoo framework works closely with WinForms to bind the configuration object to them seamlessly. Lets walk over how you can do this.

For a sample configuration object below

[ChoNameValueConfigurationSection("sample")]
public class SampleConfigSection : ChoConfigurableObject
{
    [ChoPropertyInfo("name", DefaultValue = "Mark")]
    public string Name
    {
        get;
        set;
    }

    [ChoPropertyInfo("message", DefaultValue = "Hello World!")]
    public string Message
    {
        get;
        set;
    }
}

PS: WinForm controls only binds to public Properties only. Please make sure you define them accordingly in your configuration object.

You can bind the above configuration object to your WinForm window in either constructor or window load event handler as below.

private void MainForm_Load(object sender, EventArgs e)
{
    SampleConfigSection settings = new SampleConfigSection();
    textBox1.DataBindings.Add("Text", settings, "Name");
    textBox2.DataBindings.Add("Text", settings, "Message");
}

That’s all. Now the changes made to configuration source will be reflected in the controls as well as the changes made to controls will be persisted automatically to underlying source based on the binding nature. Try for yourself.

Cinchoo – Configuration framework, part 23

Passing Configuration FilePath Programmatically

UPDATED: In this topic, I’m going to show you how to pass configuration object filepath programmatically. Cinchoo framework addresses this feature through IChoConfigurationParametersOverridable interface. When you define a configuration object, implement this interface as below to override the configuration file path.

[ChoNameValueConfigurationSection("applicationSettings")]
public class ApplicationSettings : ChoConfigurableObject
{
    [ChoPropertyInfo("path", DefaultValue = @"C:\")]
    public string Path;

    [ChoPropertyInfo("OS", DefaultValue = "Windows")]
    public string OS;

    protected override void OverrideMetaDataInfo(ChoBaseConfigurationMetaDataInfo metaDataInfo)
    {
        ChoStandardConfigurationMetaDataInfo info = metaDataInfo as ChoStandardConfigurationMetaDataInfo;
        info.ConfigFilePath = @"C:\Test\ApplicationSettings.xml";
    }
}

Cinchoo – Configuration framework, part 22

Binding to WPF Controls

Download Source Files (ZIP)

In this section, I’ll talk about binding your configuration object to WPF controls. As WPF provides rich binding infrastructure, Cinchoo framework take a step closer to bind the configuration object to WPF controls seamlessly. Lets walk over how you can achieve this.

For a sample configuration object below

[ChoNameValueConfigurationSection("sample")]
public class SampleConfigSection : ChoConfigurableObject
{
	[ChoPropertyInfo("name", DefaultValue="Mark")]
	public string Name;

	[ChoPropertyInfo("message", DefaultValue="Hello World!")]
	public string Message;
}

You can bind the configuration object to your WPF window in either constructor or window loaded event handler as below.

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    ChoWPFBindableConfigObject<SampleConfigSection> bindObj = new ChoWPFBindableConfigObject<SampleConfigSection>();
    this.DataContext = bindObj;
}

That’s it. Now you can bind each control to this context object members. For example, the below snippet binds a text box to ‘Name’ property of above configuration object.

<TextBox Name="txtValidExts" Text="{Binding Path=Name}" />

Now the changes made to configuration source will be reflected in the controls as well as the changes made to controls will be persisted automatically to underlying source based on the binding nature. Try for yourself.

Cinchoo – Configuration framework, part 21

Configuration Storage Plug-in

This article is the continuation of Cinchoo configuration framework series. So far you learned and used various configuration section handler provided by Cinchoo framework in your applications. But it limits the accessibility of the underlying configuration data source somehow. Now Cinchoo framework opens the possiblity of extending the configuration framework by creating your own plug-ins to access various configuration sources by using IChoDictionaryConfigObjectAdapter interface.

Let say, you have configuration data available in Database, FTP, HTTP, WebService, WCF, email etc. Now those can be accessed easily using Cinchooframework. Here I’m going to walk you over in implementing one such configuration data source reside in database using ADO.NET interface. (You can try Linq to Sql, ADO.NET Entity Framework etc as well).

IChoDictionaryConfigObjectAdapter interface exploses the below members

public interface IChoDictionaryConfigObjectAdapter
{
    IDictionary GetData();
    void Save(IDictionary dict);
    DateTime LastUpdateDateTime
    {
        get;
    }
}

Here are the steps to create a new adapter class

  1. Create a new class (say, ChoMySqlADODictionaryConfigObjectAdapter) derived from IChoDictionaryConfigObjectAdapter interface. Implement the interface members.
  2. GetData() member will be called by framework to retrieve the configuration data. In here you establish connection to underlying source, retrieve the data and return them in IDictionary format.
  3. Save() method will be called by framework to save the snapshot (in IDictionary format) of configuration data back to underlying source. Here you establish the connection to the underlying source, save them. Important, while saving, make sure you update the modified timestamp with current timestamp.
  4. LastUpdateDateTime property will be invoked periodically by framework to identify the changes to the underlying configuration source. In here, you will have to establish the connection to the source and retrieve the modified datatime.
public class ChoMySqlADODictionaryConfigObjectAdapter : IChoDictionaryConfigObjectAdapter
{
    public IDictionary GetData()
    {
        Dictionary<string, object> dict = new Dictionary<string, object>();

        //Connect to the source, load the configuration object payload

        return dict;
    }

    public void Save(System.Collections.IDictionary dict)
    {
        if (dict != null && dict.Count > 0)
        {
            //Connect to the source, save the data
        }
    }

    public DateTime LastUpdateDateTime
    {
        get
        {
            //Connect to the source, get the last updated timestamp
            return DateTime.MinValue;
        }
    }
}

Now here is how to use the above adapter in your application

Define a configuration class ‘ApplicationSettings’, decorated with ChoDictionaryAdapterConfigurationSection attribute as below with sectionName, and the type of the adapter ChoMySqlADODictionaryConfigObjectAdapter. That’s all. Your configuration object is all set to use the configuration object data from database using ChoMySqlADODictionaryConfigObjectAdapter.

[ChoDictionaryAdapterConfigurationSection("mySqlDictionarySectionHandlerTest/applicationSettings", typeof(ChoMySqlADODictionaryConfigObjectAdapter))]
public class ApplicationSettings : ChoConfigurableObject
{
    #region Instance Data Members (Public)

    [ChoPropertyInfo("path", DefaultValue = @"C:\")]
    public string Path;

    [ChoPropertyInfo("OS", DefaultValue = "Windows")]
    public string OS;

    [ChoPropertyInfo("singleInstanceApp", DefaultValue = false)]
    public bool SingleInstanceApp;

    #endregion
}

Here is how you can instantiate and use the above configuration object

static void Main(string[] args)
{
    ApplicationSettings applicationSettings = new ApplicationSettings();
    Console.WriteLine(applicationSettings.ToString());

    ChoFramework.Shutdown();
}

The corresponding configuration section will be created automatically in [appExeName].xml file under bin/Config folder

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <mySqlDictionarySectionHandlerTest>
    <applicationSettings cinchoo:configObjectAdapterType="Cinchoo.Core.Configuration.ChoMySqlADODictionaryConfigObjectAdapter, ChoMySqlADODictionaryConfigStorage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
  </mySqlDictionarySectionHandlerTest>
  <configSections>
    <sectionGroup name="mySqlDictionarySectionHandlerTest">
      <section name="applicationSettings" type="Cinchoo.Core.Configuration.ChoDictionarySectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
    </sectionGroup>
  </configSections>
</configuration>

Cinchoo – Configuration framework – SharedEnvironment, part 1

Shared Environment Configuration

In a situation, where you want to keep and maintain configurations for each  environment (DEV, UAT and PROD etc) separately in a centralized location, attach them to your application and/or switch them at run-time, all these can be done using Cinchoo configuration framework. This is the first of the series of articles about SharedEnvironment in this blog.

Cinchoo framework discover this file (SharedEnvironment.config) in the application base directory if not specified explicitly. It can be overridden by couple of ways

  • appFrxSettings – If you have a file contain shared environment xml in a different location, you can specify them here. Below is the sample
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<configSections>
		<section name="appFrxSettings" type="Cinchoo.Core.ChoAppFrxSettings, Cinchoo.Core" />
	</configSections>
	<appFrxSettings appFrxFilePath="" sharedEnvironmentConfigFilePath="" appEnvironment="QA" />
</configuration>
  • Run-Time – In cases where SharedEnvironment xml is not in a file or stored in different sources (Database, WebService etc), you can retrieve them and pass it to the framework by subscribing to ChoApplication.GetSharedEnvironmentConfigXml callback. Below is sample
class Program
{
    static void Main(string[] args)
    {
        ChoApplication.GetSharedEnvironmentConfigXml = new Func<string>(() =>
            {
                string xml = null;
                //Go to source and retrieve the xml
                return xml;
            });
    }
}
Your application can be configured to use particular environment by specifying at appFrxSettings as below
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<configSections>
		<section name="appFrxSettings" type="Cinchoo.Core.ChoAppFrxSettings, Cinchoo.Core" />
	</configSections>
	<appFrxSettings appFrxFilePath="" sharedEnvironmentConfigFilePath="c:\Temp\NewSharedEnvironments.config" appEnvironment="QA" />
</configuration>
Now lets walk over the specification of SharedEnvironment.Config file.
<?xml version="1.0"?>
<configuration>
  <sharedEnvironment baseAppSharedConfigDirectory="C:\Config" defaultEnvironment="DEV">
    <environment name="DEV" freeze="true" appFrxFilePath="DEVConfig" >
      <machine>WNYC12D10101</machine>
      <machine>WNYC12D10102</machine>
      <machine>WNYC12D10103</machine>
      <machine>WNYC12D10104</machine>
    </environment>
    <environment name="PROD" appFrxFilePath="C:\Config\PROD\TestApp.config.txt" freeze="true" >
      <machine>SNYC12D10101</machine>
      <machine>100.39.191.175</machine>
    </environment>
    <environment name="UAT" >
      <machine>WNYC1108054621</machine>
      <machine>SNYC*</machine>
    </environment>
  </sharedEnvironment>
</configuration>
  • baseAppSharedConfigDirectory – A configuration directory used by a environment whose appFrxFilePath is not specified or it contains relative file path. In the above samples, environment ‘UAT’ uses this directory to read / store configuration. If not specified, it will be defaulted to application binary base directory.
  • defaultEnvironment – An environment used by any host which is not listed in this xml.
Each environment can be created using ‘environment’ element. In the above sample, we have ‘DEV’, ‘PROD’, and ‘UAT’ environments.
  • name – Name of the environment, mandatory.
  • freeze – true, all the hosts belongs to the environment locked. Can not be overridden by specifying it in appFrxSettings/appEnvironment. False, it can be overridden. Default value is false. Optional.
  • appFrxFilePath – A file / directory path. Either absolute / relative path. In case of relative path, framework resolves the path in relative to ‘baseAppSharedConfigDirectory’ path. In the sample above, for the ‘DEV’ environment, this path resolved to ‘C:\Config\DEVConfig’. If missing/not specified, the path will be the environment ‘Name’ under ‘baseAppSharedConfigDirectory’. In the sample above, the ‘UAT’ environment will resolve this path to ‘C:\Config\UAT’. It is optional.
Then you can bind hosts to any environment using ‘machine’ element under ‘environment’. Host can be either MachineName or IP Address. Also the those host names can contain wild card characters as well.
Ex: SYNC*, WNYC1002340? etc

Cinchoo – Framework Tips

Here I’m going to talk about couple of tips on using Cinchoo framework in your project.

At the start of the application, you must call ChoFramework.Initialize() to initialize the framework and start necessary services. Usually you must place this statement in application Main entry point as below.

Calling ChoFramework.Shutdown() method is not mandatory to call. But it is safe to make this call for graceful shutdown of all the background services.

static void Main(string[] args)
{
    ChoFramework.Initialize();
    try
    {
        ChoApplication.ApplyFrxParamsOverrides += new EventHandler<ChoFrxParamsEventArgs>(ChoApplication_ApplyFrxParamsOverrides);

        SampleConfigSection ApplicationSettings = new SampleConfigSection();
    }
    catch (Exception ex)
    {
        Console.WriteLine("ERROR: " + ex.Message);
    }
    finally
    {
        ChoFramework.Shutdown();
    }
}

ChoAppDomain.

Cinchoo – Configuration framework, part 20

Include CDATA in Configuration

Here, I’m going to give you a tip on including CDATA in the configuration file. CDATA is a text data in XML that should not be parsed by the XML parser. For more information about CDATA, please visit the below link

W3Schools XML CDATA

1. Define the configuration section object decorated with ChoXmlSerializerConfigurationSectionAttribute as below. Declare a data member of type ChoCDATA.

[ChoXmlSerializerConfigurationSection("xmlSerializationSectionHandlerTest/applicationSettings")]
public class SampleConfigSection : ChoConfigurableObject
{
    #region Instance Data Members (Public)

    [ChoPropertyInfo("path", DefaultValue = @"C:\Log")]
    public string Path;

    [ChoPropertyInfo("commands")]
    public ChoCDATA CDATAItem = new ChoCDATA("Command1;Command2");

    #endregion

    [ChoAfterConfigurationObjectLoadedHandler]
    void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
    {
        Console.WriteLine(sender.ToString());
    }
}

2. Now instantiate and use it as below

class Program
{
	static void Main(string[] args)
	{
		SampleConfigSection sampleConfigSection = new SampleConfigSection();
		Console.WriteLine(sampleConfigSection.ToString());
	}
}

The configuration section will be generated automatically for the first time in HelloWorld.exe.xml as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="xmlSerializationSectionHandlerTest">
      <section name="applicationSettings" type="Cinchoo.Core.Configuration.ChoXmlSerializerSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
    </sectionGroup>
  </configSections>
  <xmlSerializationSectionHandlerTest>
    <applicationSettings>
      <Path>C:\Log</Path>
      <CDATAItem><![CDATA[Command1;Command2]]></CDATAItem>
    </applicationSettings>
  </xmlSerializationSectionHandlerTest>
</configuration>
The corresponding meta-data looks as below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <xmlSerializationSectionHandlerTest>
    <applicationSettings bindingMode="TwoWay" defaultable="true" silent="true">
      <configStorage>Cinchoo.Core.Configuration.ChoFileXmlSerializerConfigStorage, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de</configStorage>
      <logInfo condition="true" directory="Settings" fileName="Cinchoo.Core.Configuration.ChoXmlSerializerSectionHandlerTest.SampleConfigSection.log" />
    </applicationSettings>
  </xmlSerializationSectionHandlerTest>
</configuration>

Cinchoo – Configuration framework, part 19

Using ChoFireBirdConfigStorage

UPDATE:

This article is outdated. Please visit the below codeproject article for more updated information on this storage plug-ins

Cinchoo – Using FireBird database as configuration source

 

In this section, I’ll go over the details of using ChoFireBirdConfigStorage in your application. It provides name/value-pair configuration information from FireBird Database.  ChoFireBirdConfigurationSectionAttribute is the corresponding attribute used to decorate the configuration object class.

1. Define the configuration section object decorated with ChoFireBirdConfigurationSectionAttribute as below. You must provide ConnectionString and TableName where the configuration data stored. The table will be created if not exists. The table will have two columns (CONFIG_DATA varchar(250), LAST_UPDATTED_TIME TimeStamp). ConnectionString and TableName can be overridden through configuration file.

[ChoFireBirdConfigurationSection("sample", @"User=SYSDBA;Password=masterkey;Database=C:\Sample.fdb;DataSource=localhost; Port=3050;Dialect=3; Charset=NONE;",
    "APP_SETTINGS")]
public class SampleConfigSection : ChoConfigurableObject
{
    #region Instance Data Members (Public)

    [ChoPropertyInfo("name", DefaultValue = "Mark")]
    public string Name;

    [ChoPropertyInfo("message", DefaultValue = "Hello World!")]
    public string Message;

    #endregion

    [ChoAfterConfigurationObjectLoadedHandler]
    void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
    {
        Console.WriteLine(sender.ToString());
    }
}

2. Now instantiate and use it as below

class Program
{
	static void Main(string[] args)
	{
		SampleConfigSection sampleConfigSection = new SampleConfigSection();
		Console.WriteLine(sampleConfigSection.ToString());

		//Shutdown the framework to stop the background services...otherwise the application will not terminate
		ChoFramework.Shutdown();
	}
}

The configuration section will be generated automatically for the first time in HelloWorld.exe.xml as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="sample" type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
  </configSections>
  <sample cinchoo:connectionString="User=SYSDBA;Password=masterkey;Database=C:\Sample.fdb;DataSource=localhost; Port=3050;Dialect=3; Charset=NONE;" cinchoo:tableName="APP_SETTINGS" cinchoo:configDataColumnSize="250" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
</configuration>
The corresponding meta-data looks as below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <sample bindingMode="TwoWay" defaultable="true" silent="true">
    <configStorage>Cinchoo.Core.Configuration.ChoFireBirdConfigStorage, Cinchoo.Core.Configuration.Storage.FireBirdConfigStorage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</configStorage>
    <logInfo condition="true" directory="Settings" fileName="Cinchoo.Core.Configuration.ChoFireBirdClientSectionHandler.Test.SampleConfigSection.log" />
  </sample>
</configuration>

Cinchoo – Configuration framework, part 18

Using ChoSqlServerConfigStorage

UPDATE:

This article is outdated. Please visit the below codeproject article for more updated information on this storage plug-ins

Cinchoo – Using SQLServer database as configuration source

 

 

In this section, I’ll go over the details of using ChoSqlServerConfigStorage in your application. It provides name/value-pair configuration information from SqlServer Database.  ChoSqlServerConfigurationSectionAttribute is the corresponding attribute used to decorate the configuration object class.

1. Define the configuration section object decorated with ChoSqlServerConfigurationSectionAttribute as below. You must provide ConnectionString and TableName where the configuration data stored. The table will be created if not exists. The table will have two columns (CONFIG_DATA varchar(250), LAST_UPDATTED_TIME Timestamp). ConnectionString and TableName can be overridden through configuration file.

[ChoSqlServerConfigurationSection("sample", @"Data Source=shreeya-pc\SQLExpress;Initial Catalog=Cinchoo;Integrated Security=True", "APP_SETTINGS")]
public class SampleConfigSection : ChoConfigurableObject
{
    #region Instance Data Members (Public)

    [ChoPropertyInfo("name", DefaultValue = "Mark")]
    public string Name;

    [ChoPropertyInfo("message", DefaultValue = "Hello World!")]
    public string Message;

    #endregion

    [ChoAfterConfigurationObjectLoadedHandler]
    void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
    {
        Console.WriteLine(sender.ToString());
    }
}

2. Now instantiate and use it as below

class Program
{
	static void Main(string[] args)
	{
		SampleConfigSection sampleConfigSection = new SampleConfigSection();
		Console.WriteLine(sampleConfigSection.ToString());

		//Shutdown the framework to stop the background services...otherwise the application will not terminate
		ChoFramework.Shutdown();
	}
}

The configuration section will be generated automatically for the first time in HelloWorld.exe.xml as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <sample cinchoo:connectionString="Data Source=your-pc\SQLExpress;Initial Catalog=Cinchoo;Integrated Security=True" cinchoo:tableName="APP_SETTINGS" cinchoo:configDataColumnSize="250" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
  <configSections>
    <section name="sample" type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
  </configSections>
</configuration>
The corresponding meta-data looks as below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <sample bindingMode="TwoWay" defaultable="true" silent="true">
    <configStorage>Cinchoo.Core.Configuration.ChoSqlServerConfigStorage, Cinchoo.Core.Configuration.Storage.ChoSqlServerNameValueConfigStorage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</configStorage>
    <logInfo condition="true" directory="Settings" fileName="ChoSqlServerConfigStorageDemo.SampleConfigSection.log" />
  </sample>
</configuration>