Blog Home  Home Feed your aggregator (RSS 2.0)  
kevin Mocha - Thursday, May 22, 2008
Bookmarks collected from web.
 
 Thursday, May 22, 2008
        /// <summary>
        /// Information about the currently executing assembly, this is used to determine
        /// our version, etc.
        /// </summary>
        private System.Reflection.Assembly m_assemblyInfo;

        public string version
        {
            get
            {
                string ourVersion = string.Empty;
                //if running the deployed application, you can get the version
                //  from the ApplicationDeployment information. If you try
                //  to access this when you are running in Visual Studio, it will not work.
                if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
                    ourVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
                else
                    if (m_assemblyInfo != null)
                        ourVersion = m_assemblyInfo.GetName().Version.ToString();
                return ourVersion;
            }
        }

 
Thursday, May 22, 2008 8:14:17 PM UTC  #    Comments [0]    |  Trackback
 Wednesday, May 21, 2008
 Monday, April 21, 2008

http://www.developerfusion.co.uk/show/2936/4/

   1:  using System;
   2:  using System.IO;
   3:  using System.Runtime.Serialization.Formatters.Soap;
   4:  using System.Reflection;
   5:  using System.Collections;
   6:   
   7:  [Serializable]
   8:  public class User{
   9:      [ValidLength(4,8,Message="UserID should be between 4 and 8 characters long")]
  10:      public string userID;
  11:   
  12:      [ValidLength(4,8,Message="Password should be between 4 and 6 characters long")]
  13:      public string password;
  14:   
  15:      [ValidLength(4,60)]
  16:      public string email;
  17:      public string city;
  18:   
  19:      public void Save(string fileName){
  20:           FileStream s=new FileStream(fileName,FileMode.Create);
  21:           SoapFormatter sf=new SoapFormatter();
  22:           sf.Serialize(s,this);
  23:      }
  24:   
  25:      static void Main(string[] args){
  26:           User u=new User();
  27:           u.userID="first";
  28:           u.password="Zxfd12Qs";
  29:           u.email=".com";
  30:           u.city="";
  31:           Validator v=new Validator();
  32:           if(!v.IsValid(u)){
  33:                foreach(string message in v.Messages)
  34:                     Console.WriteLine(message);
  35:           }
  36:           else {u.Save("user.txt");}
  37:      }
  38:  }
 
   1:  [AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]
   2:  public class ValidLengthAttribute : Attribute{
   3:      private int _min;
   4:      private int _max;
   5:      private string _message;
   6:   
   7:      public ValidLengthAttribute(int min,int max){
   8:           _min=min;
   9:           _max=max;
  10:      }
  11:   
  12:      public string Message{
  13:           get {return(_message);}
  14:           set {_message=value;}
  15:      }
  16:   
  17:      public string Min{
  18:           get{return _min.ToString();}
  19:      }
  20:   
  21:      public string Max{
  22:           get{return _max.ToString();}
  23:      }
  24:   
  25:      public bool IsValid(string theValue){
  26:           int length=theValue.Length;
  27:           if(length >= _min && length <= _max) return true;
  28:           return false;
  29:      }
  30:  }

 

   1:  public class Validator{
   2:      public ArrayList Messages=new ArrayList();
   3:   
   4:      public bool IsValid(object anObject){
   5:           bool isValid=true;
   6:           FieldInfo[] fields = anObject.GetType().GetFields(BindingFlags.Public|BindingFlags.Instance);
   7:                foreach (FieldInfo field in fields)
   8:                     if(!isValidField(field,anObject)) isValid=false;
   9:                return isValid;
  10:      }
  11:   
  12:      private bool isValidField(FieldInfo aField,object anObject){
  13:           object[] attributes=aField.GetCustomAttributes(typeof(ValidLengthAttribute),true);
  14:           if(attributes.GetLength(0) ==0) return true;
  15:           return isValidField(aField,anObject,(ValidLengthAttribute)attributes[0]);
  16:      }
  17:   
  18:      private bool isValidField(FieldInfo aField, object anObject,ValidLengthAttribute anAttr){
  19:           string theValue=(string)aField.GetValue(anObject);
  20:           if (anAttr.IsValid(theValue)) return true;
  21:           addMessages(aField,anAttr);
  22:           return false;
  23:      }
  24:   
  25:      private void addMessages(FieldInfo aField,ValidLengthAttribute anAttr){
  26:           if(anAttr.Message !=null){
  27:                Messages.Add(anAttr.Message);
  28:                return;
  29:           }
  30:           Messages.Add("Invalid range for "+aField.Name+". Valid range is between "+anAttr.Min+" and "+anAttr.Max);
  31:      }
  32:  }
 
Monday, April 21, 2008 3:35:05 PM UTC  #    Comments [0]    |  Trackback
 Thursday, April 17, 2008

Databinding issue in WPF: with solution

http://www.lhotka.net/weblog/DataBindingIssueInWPFWithSolution.aspx#a89bf0c78-2bfc-4872-89b3-5499c4cbd0ae

(Important: set UpdateSourceTrigger to LostFocus for textbox)

Thursday, April 17, 2008 7:56:42 PM UTC  #    Comments [0]    |  Trackback
Thursday, April 17, 2008 4:16:48 AM UTC  #    Comments [0]    |   |  Trackback
 Tuesday, April 15, 2008
 Tuesday, April 08, 2008

First, make sure the OpenHandCursor.cur file is marked as Resource (not EmbeddedResource) in the referenced assembly.

 

Code Block

 

// use resource in local assembly

// new Uri("pack://application:,,,/folder/filename.cur")

// use resource in referenced assembly

// new Uri("yourAssemblyName;component/folder/filename.cur"
// ,UriKind.Relative)

Stream cursorStream =

Application.GetResourceStream(new Uri    ("CursorLib;component/cursors/help.cur",
UriKind.Relative)).Stream;

this.Cursor = new Cursor(cursorStream);

Tuesday, April 08, 2008 6:11:08 PM UTC  #    Comments [0]    |  Trackback
 Friday, April 04, 2008

Windows 2003 Server SP1 Firewall Modification for Passive or PASV FTP Connections

(Portions of this document are parphrased from or directly copied from Microsoft KB article 555022 by Bernard Cheah, MVP.)

Passive Mode FTP connections are normally required by clients connecting through a NAT firewall or router. The client connects on port 21 and issues a PASV command, the server responds with a port in the 1024-65535 range for the data connection. After a data connection command is issued by the client, the server connects to the client using the port immediately above the client-side port of the control connection. The Windows 2003 SP1 Firewall will prevent PASV FTP from working properly unless exceptions for the ports are created. A metabase property key named PassivePortRange can be configured to specify the port range the server will respond with. This can be used to limit the security risk for the FTP server. The property key only exists in IIS 6.0. Support for IIS 5.0 on Windows 2000 can be added, but the system administrator will need to install Service Pack 4 and add the PassivePortRange key in the system registry. Two ports must be opened for each concurrent FTP connection.

On Windows 2003 Server with IIS6

  • To Enable Direct Metabase Edit
    1. Open the IIS Microsoft Management Console (MMC).
    2. Right-click on the Local Computer node.
    3. Select Properties.
    4. Make sure the Enable Direct Metabase Edit checkbox is checked.
  • Configure PassivePortRange via ADSUTIL script
    1. Click Start, click Run, type cmd, and then click OK.
    2. Type cd Inetpub\AdminScripts and then press ENTER.
    3. Type the following command where the range is specified in "..". cscript.exe adsutil.vbs set /MSFTPSVC/PassivePortRange "5001-5201"
    4. Restart the FTP Publishing Service.
    You'll see the following output, when you configure via ADSUTIL script:
    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
    PassivePortRange : (STRING) "5001-5201"

 

It's crazy to add 201 exceptions rules. Just disable the windows firewall temporarily.

  • Add each port to the Windows Firewall
    1. Click Start, click Control Panel, open Windows Firewall, and select the Exceptions tab.
    2. Click the Add Port button.
    3. Enter a Name for the Exception and the first number in the port range.
    4. Click TCP if not already selected and click OK.
    5. Repeat for each port in the range - for large ranges see the end of the document.
    6. Enable the Windows Firewall on the General Tab.
Friday, April 04, 2008 8:28:55 PM UTC  #    Comments [0]    |  Trackback

IIS 6 doesn't handle extensionless URLs. You'll need to change your routes to use the .mvc extension.

For example,

  routes.Add(new Route("Links.mvc/{categoryName}",...

Make sure that IIS 6 maps .mvc to the aspnet_isapi.dll.

Friday, April 04, 2008 8:26:40 PM UTC  #    Comments [0]    |  |   |  Trackback
 Thursday, April 03, 2008

Tame Your Software Dependencies for More Flexible Apps

http://msdn2.microsoft.com/en-us/magazine/cc337885.aspx

Thursday, April 03, 2008 8:34:30 PM UTC  #    Comments [0]    |   |  Trackback
Copyright © 2009 Kevin Mocha. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: