Using C# in PowerShell to move files

 

Screedump form Windows PowerShell ISE

 

image

 

Code

$source = @"

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Rvl.Demo.Common
{
    public class MoveFiles
    {
        public static void Move()
        {
            string sourceFolder = @"C:\BDATA\Test\Source"; // Source folder
            string destinationFolder = @"C:\BDATA\Test\Destination"; // Destination folder
            DateTime checkDateTime = new DateTime(2010, 12, 29, 13, 0, 0); // 27-dec-2010 13:00:00
            // Loop all files in source folder
            foreach (string file in Directory.GetFiles(sourceFolder))
            {
                // Calculate difference between checkDateTime and file last modified datetime in days
                DateTime fileLastModifiedDate = File.GetLastWriteTime(file);

                // Move files if difference in days == 0
                if (checkDateTime.Year == fileLastModifiedDate.Year && checkDateTime.Month == fileLastModifiedDate.Month && checkDateTime.Day == fileLastModifiedDate.Day)
                {
                    string destinationFilePath = Path.Combine(destinationFolder, Path.GetFileName(file));
                    Console.WriteLine(string.Format("Moving file [{0}] to [{1}]", file, destinationFilePath));

                    File.Move(file, destinationFilePath);
                }
            }
        }
    }
}
"@

Add-Type -TypeDefinition $source

[Rvl.Demo.Common.MoveFiles]::Move()

How to enable logging for Dts.Log statements in a SSIS Script Task

If you want to log from a script task, you can use the Dts.Log function.

This function can log to the system table: dbo.sysssislog. If you configure you’re package logging correctly.

 

Notes

Most importantly, if you want to log from a script task by using the function Dts.Log, enable logging for the specific script task and enable "ScriptTaskLogEntry"

 

Steps to enable logging from within you SSIS script task
Make sure you’re Script Task contains a Dts.Log function call, like:

public void Main() { // Define log message string message = "This is my log text"; // Log the message Dts.Log(message, 999, null); Dts.TaskResult = (int)ScriptResults.Success; }

In the control flow right click and choose Logging…

Check all checkboxes in the treeview, make sure the script task is not grayed out or unchecked

Click on the top node in the treeview and add SSIS log provider for SQL Server:

 image

Enable ScriptTaskLogEntry in the details tab of the script task

image

When you run this package, you should see the logging in the table dbo.sysssislog

Using XBMC on my ASUS EEE Box 1012P

 

Because the ASUS EEE Box 1012P is shipped with Windows 7, I first installed XBMC 10.0 (released 19-dec-1010). on Windows 7.

Installation

– Download XBMC 10.0 from http://xbmc.org/download/

– Next Next Finish installation.

 

Network Share

– Create a network share, so all sources in the XBMC database will be pointed to the network share. This ensures you are able to use a shared MySQL database on all XBMC installations in you’re house.

– Created the following folders on the network share

  • Internet Radio (pls files)
  • Movie (Cinema movies)
  • Music (Constains a folder per album with the name Artist – Albumname)
  • Pictures (Contains all pictures)
  • Videos (contains home video’s)

 

 

XBMC > Settings

 

Setting Value
Add-Ons > Album information AllMusic
Add-Ons > Album information Last.FM
Add-Ons > Artist information AllMusic
Add-Ons > Artist information Last.FM
Add-Ons > Movie information IMDb
Add-Ons > Movie information Moviemeter
Add-Ons > Program Add-Ons XBMC Library Auto Update
Add-Ons > Skins Transparency!
Add-Ons > Subtitles XBMC Subtitles
Add-Ons > TV information The TVDB
Appearance > Skin Transparency!
Appearance > International > Region Central Europe
Appearance > File lists Allow file renaming and deletion
Appearance > Screensaver Use visualization if playing audio [Disable]
Music > Library Download additional information during updates
Music > Library Update library on startup
Music > Playback > Visualization None
Music > Audio CDS Play adio CDs automatically
Music > Audio CDS > Bitrate 320 kbs
Network > Services Share video and music libraries through UPnP
Network > Services Allow control of XBMC via UPnP
Network > Services Allow control of XBMC via HTTP
Network > Services Allow programs on other systems to control XBMC
Pictures > File Lists Show video files in listings
Pictures > Slideshow Disable "Use pan and zoom effects"
Skin Settings > General Enable auto scrolling for plot & review
Skin Settings > General Movies – Use extra fanart
Skin Settings > General Movies – Use extra thumbs
Skin Settings > General TV shows – Use posters
Skin Settings > General TV shows – Use extra fanart
Skin Settings > General Music – Use extra fanart
Skin Settings > General Show fanart slideshow instead of visualization
– Disable pan and zoom effects
Skin Settings > General Enable touchscreen modus
Skin Settings > Scripts Show subtitle script button in OSD
Select script: XBMC Subtitles
Skin Settings > Menu Favorites
System > Audio Ouput > Audio output Optical/Coax
System > Audio Ouput > Speaker Configuration 5.1
System > Audio Ouput > Audio output device default
System > Input devices Remote control sends keyboard presses
System > Video output Fullscreen
System > Power Saving Shutdown function: Suspend
Video > DVDs Play DVDs automatically
Video > DVDs Attempt to skip introduction before DVD menu
Weather Breda
Bergen op Zoom
De Bilt

 

 

 

.

Overwriting the msiexec property TARGETDIR for x86 and x64 application setups

If you want to remove a application from you’re system you can use:

msiexec /x {product_guid}
like: msiexec /x {2EAB2958-5675-4773-9BF6-2C8FB9DF9CC6}

 

If you want to install a *.msi package, but want don’t want to install the application to the default installation folder you can overwrite the TARGETDIR property, like

msiexec /i "C:\Temp\MyFirstApp.msi" TARGETDIR="D:\Programs\MyFirstApp"

But if you’re msi package is created with Microsoft Visual Studio and the property Targetplatform of the setup project is set to x86, you can’t overwrite the TARGETDIR to Program Files, when you execute the following line on a x64 machine:

msiexec /i "C:\Temp\MyFirstApp.msi" TARGETDIR="C:\Program Files"

 

The msiexec will change it back to "C:\Program Files (x86)"

 

Just so you know why the application is installed in the "C:\Program Files (x86)" folder instead of the "C:\Program Files" folder.

How to show the output of a *.bat or *.cmd file in a WPF application, without waiting for the *.bat file to end

Notes

  • The functions
    – process.StandardOutput.ReadToEnd();
    – process.StandardOutput.Read();
    – process.StandardOutput.ReadLine();
    will wait for the process to end and then output the result.
  • If you want to show the output during processing, you should use
    – process.OutputDataReceived += new DataReceivedEventHandler(ProcessOuputHandler);
    – and process.BeginOutputReadLine();
  • Because the BeginOutputReadLine will spawn a new thread, you can’t access the UI directly. If you want to update a textbox, you should use the control.Dispatcher.Invoke function.
  • With the control.Dispatcher.CheckAccess() you can determine if the functions is called from the UI thread or not.
  • [myWpfWindow] is a WPF window containing a textbox with the name [outputTextBox] and a button with the name [testButton].
  • The function [ShowingOutputOfBatFile] is called from a [testButton] click eventhandler

 

Code

 

public void ShowingOutputOfBatFile()
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Temp\Test.bat";
startInfo.Arguments = "firstParameter secondParamter";
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = @"C:\Temp";
// Use startInfo.CreateNoWindow = HideWindow; if you want to hide the window
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.OutputDataReceived += new DataReceivedEventHandler(ProcessOuputHandler);
process.Start();
process.BeginOutputReadLine();
while (!process.HasExited)
{
// Refresh you're WPF window here
myWpfWindow.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
Thread.Sleep(1000);
}
}
}
public void ProcessOuputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
{
if (!outputTextBox.Dispatcher.CheckAccess())
{
// Called from a none ui thread, so use dispatcher
ShowLoggingDelegate showLoggingDelegate = new ShowLoggingDelegate(ShowLogging);
outputTextBox.Dispatcher.Invoke(DispatcherPriority.Normal, showLoggingDelegate, outLine.Data);
}
else
{
// Called from UI trhead so just update the textbox
ShowLogging(outLine.Data);
};
}
}
private delegate void ShowLoggingDelegate(string text);
private static Action EmptyDelegate = delegate() { };
/// <summary>
/// Show the logging on screen
/// </summary>
/// <param name="text"></param>
private void ShowLogging(string text)
{
myWpfWindow.outputTextBox.AppendText(text);
myWpfWindow.outputTextBox.ScrollToEnd();
}

Setting 100% width and 100% height for a Textbox in WPF

If you want to stretch a textbox to the width of the window in WPF you can use the following code

 

Code

<Window x:Class="Ada.Eac.UI.DeployWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DeployWindow" Height="300" Width="988" SnapsToDevicePixels="True" UseLayoutRounding="True" WindowState="Maximized" WindowStartupLocation="CenterScreen" Icon="/Eac;component/Dashboard.ico">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Grid.Column="1" Content="Deploy" Height="30" Width="100" HorizontalAlignment="Left" Margin="10,10,10,10" Name="deployButton" Cursor="Hand" />
<TextBox Grid.Column="1" Grid.Row="2"  HorizontalAlignment="Stretch" Name="outputTextBox" Margin="10,10,10,10" VerticalAlignment="Stretch" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />
</Grid>
</Window>

 

 

Screendump

image