IIS7 FTP Issues

27. June 2009

I was installing IIS7 FTP on a server, and I ran into a couple of problems connecting with FileZilla. I am really posting this for archive purposes, but perhaps someone will get some use out of it.

I used the following articles to set up my ftp:


After those installations, I ran into these issues:

530 Valid Hostname is expected
I first encountered this. I found that when you log in by default, the site name is normal (ex: ftp.whatever.com), but the username should be site|username (ex: ftp.whatever.com|myUser). The reasoning behind all of it resides in the link; IIS7 wants full hostname in with the username to discern the site to use.

150 Opening BINARY mode data connection failure
This was the second issue I ran into. I found out pretty quickly that it is because of the Windows Firewall, but it took a while to find the command to open the dynamic port range.

netsh advfirewall set global StatefulFtp enable

I ran that command which tells the Windows Firewall to open up dynamic ports as needed. It all worked great from there. Note: I first opened port 21 for general ftp.



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

IIS7 , ,

Building ClickOnce with CruiseControl.Net

14. May 2009

I was configuring automated builds with CruiseControl.Net which went relatively good until publishing ClickOnce applications. Since I didn’t have Visual Studio installed on the development machine, I was getting the error:

error MSB3147: Could not find required file 'setup.bin' in 'ProjectFolder\Engine'

After searching for the answer for hours online, this article showed me the solution. It was in with some other office building stuff, so I am going to highlight the actual ClickOnce steps.

  1. Copy the bootstrapper files from Visual Studio to the same directory on the build server ‘Program Files\Microsoft SDKs\Windows\v6.0a\Bootstrapper’
  2. Create a registry setting to point to the location:
    Key: HKEY_LOCAL_MACHINE\Software\Microsoft\GenericBootstrapper\3.5\
    Value: Path
    Type: REG_SZ
    Data: C:\Program Files\Microsoft SDKs\Windows\v6.0a\Bootstrapper\

 

Hope this helps. Thank you Rinat Abdullin for the solution.



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

CruiseControl.Net ,

Silverlight Zooming and Panning a Canvas

12. May 2009

Zooming and Panning seems to be in great demand for Silverlight projects. I myself searched around through numerous articles trying to figure out good ways to do it. I came up with a solution that hopefully can satisfy some of the demand here on the internets.

First thing I did was make a control that is the zooming and panning canvas. I called it DesignRender as it applied to the particular project I was developing.

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="SilverlightApplication2.DesignRender">
    
    <ScrollViewer x:Name="scrollRoot" VerticalScrollBarVisibility="Disabled" 
                  HorizontalScrollBarVisibility="Disabled">
        <Canvas x:Name="canvasRoot">
            <Canvas Background="#FF00FBF2" x:Name="canvasContainer"
                    Width="1000" Height="800">
                <!-- This is dummy stuff for zooming/panning -->
                <Rectangle Width="90" Height="90" Fill="#FFCA1F1F"
                           Canvas.Left="0" Canvas.Top="0" 
                           RadiusX="2" RadiusY="2" />
                <Canvas.RenderTransform>
                    <ScaleTransform x:Name="scaler" 
                                    CenterX="0" CenterY="0" 
                                    ScaleX="1" ScaleY="1" />
                </Canvas.RenderTransform>
            </Canvas>
        </Canvas>
    </ScrollViewer>
</UserControl>

I am using a scrollviewer so I can place the UserControl effectively in a parent control. You can change this as desired. The canvasRoot acts as your background and the canvasContainer is the actual content residing in your background. If this was photoshop, the canvasRoot would be the greyed out background and the canvasContainer would be your actual document. Hence the static sizing of the canvasContainer. Now for the code behind.

public partial class DesignRender : UserControl
{
    private bool isDragging = false;
    private Point offset;
    
    public DesignRender()
    {
        InitializeComponent();

        // Handle the mouse click events within the control
        // for panning.
        this.canvasContainer.MouseLeftButtonUp += 
            new MouseButtonEventHandler(canvasContainer_MouseLeftButtonUp);
        this.canvasContainer.MouseLeftButtonDown +=
            new MouseButtonEventHandler(canvasContainer_MouseLeftButtonDown);
        this.canvasContainer.MouseMove += 
            new MouseEventHandler(canvasContainer_MouseMove);
        
        // Handle the scroll wheel events. They are different
        // per browser so we have to attach to a couple of events.     
        HtmlPage.Window.AttachEvent("DOMMouseScroll", OnMouseWheel);
        HtmlPage.Window.AttachEvent("onmousewheel", OnMouseWheel);
        HtmlPage.Document.AttachEvent("onmousewheel", OnMouseWheel);
    }

    /// <summary>
    /// Called when the mouse wheel is used. Zooms
    /// in our out depending.
    /// </summary>
    private void OnMouseWheel(object sender, HtmlEventArgs e)
    {
        double mouseDelta = 0;
        ScriptObject obj = e.EventObject;
        
        // Get what the mouseDelta was in
        // the particular browser being used
        if (obj.GetProperty("detail") != null)
            mouseDelta = ((double)obj.GetProperty("detail"));
        else if (obj.GetProperty("wheelDelta") != null)
            mouseDelta = ((double)obj.GetProperty("wheelDelta"));
        
        // Quick mouse translation
        mouseDelta = Math.Sign(mouseDelta);

        // calculate the new scale for the canvas
        double newScale = this.scaler.ScaleX + (mouseDelta * .25);

        // Don't allow scrolling too big or small
        if (newScale < 0.25)
            return;
        if (newScale > 10)
            return;

        // Set the zoom!
        this.scaler.ScaleX = newScale;
        this.scaler.ScaleY = newScale;
    }
    
    /// <summary>
    /// Called when user presses mouse down. Start
    /// panning.
    /// </summary>
    private void canvasContainer_MouseLeftButtonDown(
        object sender, MouseButtonEventArgs e)
    {
        // Say we are dragging
        this.isDragging = true;
        this.canvasContainer.CaptureMouse();
        // Calculate the place where they clicked
        offset = e.GetPosition(this.canvasContainer);
        offset.X *= this.scaler.ScaleX;offset.Y *= this.scaler.ScaleY;
    }
    
    /// <summary>
    /// Called when user releases mouse. End panning
    /// </summary>
    private void canvasContainer_MouseLeftButtonUp(
        object sender, MouseButtonEventArgs e)
    {
        if (this.isDragging)
        {
            // Say we are done dragging
            this.isDragging = false;
            this.canvasContainer.ReleaseMouseCapture();
        }
    }
    
    /// <summary>
    /// Called when the user moves there mouse. If
    /// they have the mouse button pressed then we
    /// pan.
    /// </summary>
    private void canvasContainer_MouseMove(
        object sender, MouseEventArgs e)
    {
        if (this.isDragging)
        {
            // Calculate the new drag distance
            Point newPosition = e.GetPosition(this.canvasRoot);
            Point newPoint = 
                new Point(newPosition.X - offset.X,newPosition.Y - offset.Y);
            
            // Set the values
            this.canvasContainer.SetValue(Canvas.LeftProperty,newPoint.X);
            this.canvasContainer.SetValue(Canvas.TopProperty,newPoint.Y);
        }
    }
}

The code itself should be pretty self explanatory. I use scaling to do the zooming and mouse down events for panning. Now just host this control in your Page.xaml whatever way you would like. This should get everyone started in the right direction. Hope this helps.



Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C#, Silverlight , , ,

Error performing inpage operation

2. May 2009

I have an external harddrive to which I thought I lost all of the information on. Whenever I plugged it in, the light would come on like it was going to read and then turn back off again. Whenever I tried to access the volume, I would get an error message saying “Error performing inpage operation.” After looking extensively online, I ran

chkdsk l: /f 
substitute l: for your volume label

It repaired the drive and works great. Off to buy another terabyte hdd for backups. Hope this can be useful for someone.



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Serializing and Deserializing XML to files

7. April 2009

This is a simple class for serializing a type to a file and deserializing a type from a file. This code shouldn’t be considered production, but it will show you a very simple way to do it.

    /// <summary>
    /// Class for saving xml serializable types 
    /// to a file.
    /// </summary>
    /// <typeparam name="T">The generic serializable
    /// type that is going to be serialized or deserialized</typeparam>
    public class TypeSerializer<T>
    {
        /// <summary>
        /// Serializes and saves the specified item
        /// to a file specified.
        /// </summary>
        /// <param name="item">The item to serialize.</param>
        /// <param name="path">The path to the file.</param>
        public void Save(T item, string path)
        {
            // Create the serializer
            XmlSerializer s = new XmlSerializer(typeof(T));
            // Create the writer
            TextWriter w = new StreamWriter(path);
            // Do the work
            s.Serialize(w, item);
            // Clean up
            w.Close();
        }

        /// <summary>
        /// Loads the specified file and serializes it.
        /// </summary>
        /// <param name="path">The path to the item.</param>
        /// <returns>The serialized type.</returns>
        public T Load(string path)
        {
            // Create the serializer
            XmlSerializer s = new XmlSerializer(typeof(T));
            // The item we are returning
            T item;
            // The text reader that puts the text in the stream
            TextReader r = new StreamReader(path);
            // Deserialize the item and cast it
            item = (T)s.Deserialize(r);
            // Clean up
            r.Close();
            // return the item
            return item;
        }
    }
Simple to use. Just call new TypeSerializer<YourClass>().Save(item, path); to save it or TypeSerializer<YourClass>().Load(path); to load it. Thank you CodeProjectfor the step in the right direction. I just wanted a simpler example to start people out. I hope this helps.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# , ,

Excel Importer

17. March 2009

I wrote this little WPF application as the demonstration for my previous article on reading excel spreadsheets. I figured everyone should be able to test it and play around with it. Just a note: The code was written very fast and inefficiently so don’t consider it anything more than proof of concept. At any rate, here you go.

ExcelImporter.zip (18.51 kb)



Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C#, Excel , , ,

Blogging with BlogEngine.Net

25. February 2009

I found a few simple applications that make blogging in BlogEngine.Net very easy and convenient. Hopefully you will as well.

Windows Live Writer
http://get.live.com/writer/overview
I didn’t know Live had a blogging application let alone one that will automatically connect to my Blog for me to post on. This application makes things very easy as I prefer desktop applications over web applications.

Paste From Visual Studio
http://gallery.live.com/liveItemDetail.aspx?li=d8835a5e-28da-4242-82eb-e1a006b083b9&l=8
This little number is my replacement to CodeToHtml plugin I used on VOX. It is a plugin for Windows Live Writer that can paste in things from your Visual Studio clipboard and keep them formatted nicely for your blog. Plus, it is a plugin for Live Writer and not visual studio keeping things on the development end nice and tidy.

Happy Coding :)



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Visual Studio, BlogEngine.Net

Reading Excel with C#

25. February 2009

Overview

This article explains how to read Excel documents with C#. After two or three projects dealing with copying and pasting data from sql server to excel, I decided that it would be a good time to write some code to help with the process. Here is the basic code for reading an excel spreadsheet.

Code

// Create the connection string
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
    location + @";Extended Properties=""Excel 8.0;HDR=YES;""";

// Create a factory
DbProviderFactory factory =
       DbProviderFactories.GetFactory("System.Data.OleDb");

// Create an adapter
DbDataAdapter adapter = factory.CreateDataAdapter();

// Create a select command to get the dataset
DbCommand selectCommand = factory.CreateCommand();
selectCommand.CommandText = "SELECT * FROM [" + sheetName + "$]";

// Set up the connection and the connection string
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
selectCommand.Connection = connection;

// Set up the command
adapter.SelectCommand = selectCommand;

// Create the dataset
DataSet ds = new DataSet();

// Load the results
adapter.Fill(ds);

return ds;
Basically, I am just passing in a location of the document and the sheet name for the particular excel spreadsheet. OLEDB supports Outlook so bringing it into a dataset isn’t that much work. I realize that the article is relatively slim, but I hope it gets viewers pointed in the right direction. Thank you Dave Hayden for my step.

Happy Coding



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Excel, C#

Automating builds and publishing with CruiseControl.Net

24. February 2009

Overview 

A lot of people like the idea of continuous integration within their company. I have found it to be necessary for more than just testing builds on check-in. My primary use for it is publishing builds to servers and deployment. This article explains how to set up CruiseControl.Net with an Asp.Net solution and two projects. One verifying builds and automatically building on check-in; the second which requires the build to be forced and publishes the application to a server.

Installation

We need a few things on the build server to start out. Download the tools below if you don't have them.

* CruiseControl.Net - http://sourceforge.net/projects/ccnet/ 
* NAnt - http://sourceforge.net/project/showfiles.php?group_id=31650&package_id=23704
* Web Deployment Project – Download Here

Note: My particular configuration has .Net Framework 3.5 as well as some other build specific applications. Verify that you have all of the software required for command line builds installed on your integration server.

Run the CruiseControl.Net installer as well as the NAnt installer.

Configuration

Once both installers are done, find the location where you installed CruiseControl.Net and open up the ccnet.config file. Here is a good start for a configuration.

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
    
<!-- Basic project to verify build on every checkin -->
<project name="(Build) MyProject" queue="MyProjectQueue" queuePriority="1">
    <workingDirectory>C:\ccnet\projects\MyProject\work</workingDirectory>
    <artifactDirectory>C:\ccnet\projects\MyProjectBuild\artifact</artifactDirectory>
    
    <sourcecontrol type="svn">
        <executable>C:\Program Files\SlikSvn\bin\svn.exe</executable>
        <trunkUrl>svn://pathToSvnRepo/MyProject/trunk</trunkUrl>
        <username>SubversionUser</username>
        <password>Password</password>
    </sourcecontrol>
    
    <tasks>
        <msbuild>
            <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
            <projectFile>MyProject.sln</projectFile>
            <buildArgs>/p:Configuration=Debug</buildArgs>
            <targets>Clean;Build</targets>
            <logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
        </msbuild>
    </tasks>
</project>

<!-- Publish project using web depoloyment and move to server -->
<project name="(Publish) MyProject" queue="MyProjectQueue" queuePriority="2">
    <workingDirectory>C:\ccnet\projects\MyProject\work</workingDirectory>
    <artifactDirectory>C:\ccnet\projects\MyProjectPublish\artifact</artifactDirectory>
    
    <triggers />

    <sourcecontrol type="svn">
        <executable>C:\Program Files\SlikSvn\bin\svn.exe</executable>
        <trunkUrl>svn://pathToSvnRepo/MyProject/trunk</trunkUrl>
        <username>SubversionUser</username>
        <password>Password</password>
    </sourcecontrol>

    <tasks>
        <msbuild>
            <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
            <projectFile>MyProject.sln</projectFile>
            <buildArgs>/p:Configuration=Release</buildArgs>
            <targets>Clean;Build</targets>
            <logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
        </msbuild>
        <msbuild>
            <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
            <projectFile>MyProject.Deployment.wdproj</projectFile>
            <buildArgs>/p:Configuration=Release</buildArgs>
            <logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
        </msbuild>
        <nant>
            <executable>C:\nant-0.86-beta1\bin\nant.exe</executable>
            <nologo>true</nologo>
            <buildFile>C:\ccnet\projects\antscripts\Publish.build</buildFile>
            <buildArgs>-D:sourceDir=C:\Inetpub\MyProject -D:targetDir=PathToServer</buildArgs>
            <logger>NAnt.Core.XmlLogger</logger>
        </nant>
    </tasks>
</project>
    
</cruisecontrol>

Here is the rundown. The first project pulls the source down and builds it automatically whenever it detects a commit to the subversion server. This allows you to see whenever a build is broken. The second project is pretty cool. The <triggers /> tag says that this build must be forced. It pulls from the same repository, except it builds for release. It then runs the web deployment project which changes the web.config to be configured for release. The build is published, and the ant script moves the publish from local IIS to the hosting server.

A few notes. Notice the queuePriority tag? Since both projects use the same source control, I put them in a queue so they don’t try to build off of the same folder at the same time. Also, it is worth looking into the web deployment project. It allows you to configure different application settings for different build types.

As for the ant script? Here you go:

<?xml version="1.0"?>
<project name="Publish to server" default="publish-to-server">
    <target name="publish-to-server">
        <echo message="Connecting with server" />
        <exec program="net.exe" 
                    commandline="use \\server\location /user:un pw" />
        
        <echo message="Publish ${sourceDir} to ${targetDir}" />
        <delete dir="${targetDir}" />
        <mkdir dir="${targetDir}" />

        <move todir="${targetDir}">
            <fileset basedir="${sourceDir}">
                <include name="**" />
            </fileset>
        </move>
    </target>
</project>

This is assuming that you have network access to your server. If you need to do ftp or something of the like, you should look into ftp with ant scripts. Basically this script connects to the server, removes the current directory, and copies over the publish information.

Thanks to Joe Lombrozo for figuring out the ant script.



Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# and the G15 Display

14. October 2008

Overview

I just purchased the Logitech G15 Keyboard; being the geek that I am the first thing that I had to do with it today was develop something for the LCD Display. There are a lot of tutorials around on developing for the C++ SDK, but there were very few on developing with C#. This article explains how to do so.

Hello World (Of Course)

I found that there was a managed library for the LCD display, so I decided to use it. You can find it here. Note that you should probably finish the article because the library isn't perfectly straightforward. Once you have the library unzipped, you do the following steps:

  • Open up Visual Studio (I used 2008)
  • Create a new Windows Forms Application
  • Right click on the project file and click Add Reference
  • Click the browse tab
  • Look for the directory that you unzipped the managed library to. Navigate to the lgLcdClassLibrary/Release folder and ad the lgLCDNETWrapper.dll file.

This is the non-straightforward part. I did my development and found that my application was not working. You have to add another library to the bin directory of your application or it will not work. The reason is that the managed library is a wrapper around another unmanaged library and if you don't have both of the libraries the application will not work.

  • Open up Windows Explorer and navigate to the directory where you unzipped the managed SDK. 
  • Go into the CLDemo-CS/Release folder and copy the lgLcdLibWrapper.dll file. 
  • Paste this file into your bin/debug folder of your application.

Finally, we can get to coding. Open up the code behind file of your Form1.cs file and make it look like mine.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using lgLcdClassLibrary;
using System.Drawing.Imaging; 
namespace LogitechTest1
{    
    public partial class Form1 : Form    
    {        
        // The LCD interface class in the wrapper.        
        private LCDInterface lcd;        
        // A byte array we are going to convert a bitmap too        
        byte[] lcdTranslate;     
    
        // The text to write on the screen        
        string myText = "Hello World";        
        // The friendly applicaiton name        
        string appName = "Test LCD App";        
        // The font family used        
        string fontFamily = "Arial";
        
        // The font size of the text        
        float fontSize = 10.0f;        
        // The brush to write the font with        
        Brush myBrush;        
        // The font to use to write        
        Font myFont;
         
        // This is the width and height of the screen        
        int width = 160;        
        int height = 43;
        
        // Some offsets to position the text better        
        float col1Offset = 2;        
        float row1Offset = 1;
         
        // The bitmap placed on the screen        
        Bitmap bmp; 
       
        // The amazing GDI graphics object        
        Graphics g;  
       
        /// <summary>        
        /// Creates a new instance of the form        
        /// </summary>        
        public Form1()        
        {            
            // Visual Studio Generated            
            InitializeComponent(); 
            
            // Subscribe to the closing event for the form            
            // Note: It is better to do this in the designer            
            // but I wanted compileable code            
            this.FormClosing +=                 
                new FormClosingEventHandler(Form1_FormClosing);
             
            // Initialize the LCD            
            this.lcd = new LCDInterface();            
            // Open a connection to it            
            this.lcd.Open(this.appName, true);            
            // Initialize our byte array            
            this.lcdTranslate = new byte[this.width * this.height]; 
            
            // Initialize the font            
            this.myFont = new Font(this.fontFamily,                 
                this.fontSize, FontStyle.Regular);            
            // Initialize the brush            
            this.myBrush = new SolidBrush(Color.White);
             
            try            
            {                
                // Create the bitmap                
                this.bmp = new Bitmap(this.width, this.height,                     
                    PixelFormat.Format24bppRgb);
                 
                // Create a graphics object from the bitmap                
                this.g = Graphics.FromImage(this.bmp);
                 
                // Clear the graphics object               
                g.Clear(Color.Black);
                 
                // Draw our text onto the graphics object                
                g.DrawString(this.myText, this.myFont,                     
                    this.myBrush, this.col1Offset, this.row1Offset);
                 
                // Create temporary color and byte                
                Byte pixelValue;
                 
                // This is where we translate the bitmap to                
                // a byte array                
                for (int hIndex = 0; hIndex < this.height; ++hIndex)                
                {                    
                    for (int wIndex = 0; wIndex < this.width; ++wIndex)                    
                    {                        
                        // Get the green value of the current pixel                        
                        pixelValue = this.bmp.GetPixel(wIndex, hIndex).G;                        
                        // Place it in our translator                        
                        lcdTranslate[wIndex + (hIndex * this.width)] =                             
                            pixelValue;                    
                    }                
                }
                 
                // Send the lcd the translated information                
                this.lcd.DisplayBitmap(ref lcdTranslate[0],                     
                    LCDInterface.lglcd_PRIORITY_NORMAL);            
            }            
            catch (Exception e)            
            {                
                // Show any issues that arose                
                MessageBox.Show(e.Message);            
            }        
        }
         
        /// <summary>        
        /// Fired when the form closes. Closes the        
        /// connection to the LCD screen.        
        /// </summary>        
        private void Form1_FormClosing(           
            object sender, FormClosingEventArgs e)        
        {            
            // Close the connection to the screen            
            this.lcd.Close();        
        }    
    }
}

Now build and run the application. When the form pops up, press the black circle button to the left of the LCD until it says "Test LCD App" ... Amazing! Hello World should pop up on your screen.

Code Rundown

Basically, we are creating a bitmap that is the size in pixels of the Lcd screen. From there, we create a graphics object from the bitmap and draw text to it. The next part is a bit tricky. The managed library wants a byte array instead of the actual bitmap itself so we do a little translation of all of the pixels to get it into the correct format. Finally, we display the information.

Conclusion

I hope this article puts you in the right direction for developing amazing things with the Logitech G15.



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C#