Quick batch file to monitor a server for any port 25 activity

November 16, 2009

:section
netstat -n  | find "25"

goto section


Setting web application settings from the same web application, without hard coded file locations.

November 16, 2009

April 09

I have often wanted the ability to be able to change settings within a web application, but have not found a simple way to achieve that without having some sort of path setting somewhere.

How I currently use this, is creating a page to configure the system from. We often have to develop in staging and production environments. The biggest cause of exceptions and errors, in my humble opinion, is usually configuration. Having to use GUID’s for most of these settings it is time consuming to validate all of the GUID’s manually.

Using this approach of having a web page to configure and test all of the settings that is currently in the system, I can provide the administrators of the servers a simple and effective way to test the system, without having any specific knowledge about the application.

 

 /// <summary>
    /// Updates the configuration file, if the key that you are updating is within the appSettings section.
    /// It also refreshes the AppSetting Cache so that the applied setting, is availible in your web application.
    /// The keys needs to have been created within the config file before hand, but it could be empty.  example of an
    /// application key, that will be able to be set.
    /// <code>
    /// <add key="SupportQueueId" value=""/>
    /// </code>
    /// </summary>
    /// <param name="key">The key</param>
    /// <param name="value">The value</param>
    public static void UpdateConfigurationFile(string key, string value)
    {
        string configurationFile = getConfigurationFilePath();
        XmlDocument xmldoc = new XmlDocument();
        if (configurationFile == null)
        {
            throw new ConfigurationErrorsException(Resource.ConfigurationErrorFileNotFound);
        }

        xmldoc.Load(configurationFile);
        XmlNode node = xmldoc.DocumentElement.SelectSingleNode("//appSettings//add[@key='" + key + "']");

        if (!string.IsNullOrEmpty(node.Attributes[1].Value))
        {
            node.Attributes[1].Value = value;
            xmldoc.Save(configurationFile);
        }

        //update the cached setting
        ConfigurationManager.AppSettings.Set(key, value);
    }
    private static string getConfigurationFilePath()
    {
        string configFileLocation;
        if (HttpContext.Current.Request.PhysicalApplicationPath != null)
        {
            configFileLocation = string.Concat(HttpContext.Current.Request.PhysicalApplicationPath, Resource.ConfigurationFile);
        }
        else
        {
            throw new ConfigurationErrorsException(Resource.ConfigurationErrorHttpContextNotFound);
        }
        return configFileLocation;
    }
    /// <summary>
    /// Write exceptions to the event logs.
    /// The most useful information is within the InnerException, if CRM had a problem with the web request.  Other than that, all errors are unexpected.
    /// Examples of potential errors that might originate from CRM, is if somebody is trying to import a email, that another person has deleted just before
    /// the import is executed.
    ///
    /// </summary>
    public static void LogErrorMessage(Exception errorHandler)
    {
        if (!EventLog.SourceExists(AppDomain.CurrentDomain.FriendlyName))
        {
            EventLog.CreateEventSource(AppDomain.CurrentDomain.FriendlyName, Resource.DestinationEventLog);
        }

        EventLog myLog = new EventLog();
        myLog.Source = AppDomain.CurrentDomain.FriendlyName;
        try
        {
            myLog.WriteEntry(errorHandler.InnerException.Data.ToString(), EventLogEntryType.Error);
        }
        catch (NullReferenceException)
        {
            myLog.WriteEntry(errorHandler.Message, EventLogEntryType.Warning);
        }
    }
    /// <summary>
    /// Creates credentials based on settings in the web.config
    /// If UseIntegratedAuthentication is set to false, it use the configured Service Account Settings.  This is mainly for debugging
    /// and by not using integrated authentication, all the action's and records that the system has a effect on will be owned by the configured user.
    /// When using integrated authentication, records will be owned by user executing the function.
    /// </summary>
    /// <returns></returns>
    private static NetworkCredential getNetworkCredential()
    {
        NetworkCredential credential;

        if (ConfigurationManager.AppSettings[Resource.AppSettingsUseIntegratedAuthentication].ToLower().Contains("true"))
        {
            credential = CredentialCache.DefaultNetworkCredentials;
        }
        else
        {
            string userName = ConfigurationManager.AppSettings[Resource.ServiceAccountUserName];
            string password = ConfigurationManager.AppSettings[Resource.ServiceAccountPassword];
            string domain = ConfigurationManager.AppSettings[Resource.ServiceAccountDomain];

            credential = new NetworkCredential(userName, password, domain);
        }
        return credential;
    }
    /// <summary>
    /// The web service proxy, had to be over ridden, in order to enable multiple calls to the web service, to not drop the connection and
    /// impacting a potential separate thread, that might be waiting for the results.  It fails with a error message
    /// </summary>
    /// <returns></returns>
    /// <seealso cref="WebServiceKeptAlive"/>
    public static CrmService CrmWebServiceProxy()
    {
        CrmService service = new WebServiceKeptAlive();
        service.Credentials = getNetworkCredential();

        return service;
    }
}

 
 

Career direction and advancing my craft

November 10, 2009

I find it is so easy to get, distracted, and become bogged down in the urgent things in life and forget the important things in life.  As such I am publish my intended reading list for the next 6 months

This list is what a entry level developer must read at Construct software, so it is from there that I am basing this.

 

http://www.construx.com/Page.aspx?hid=948

  • Code Complete, Steve McConnell                                                   – Done
  • Programming Pearls 2nd Edition, Jon Bentley                                – In Progress
  • Applying UML & Patterns 2nd Ed, Craig Larman
  • Conceptual Blockbusting, James Adams
  • Software Creativity, Robert Glass
  • Rapid Development, Steve McConnell
  • Software Project Survival Guide, Steve McConnell
  • UML Distilled, Martin Fowler et all


  • Documentation regarding the searching

    August 4, 2009

    You need the Java SE Development KIT (JDK)

    image

    Go to this url

     

    image

    image

    Downloading file

    Setting options on Netbeans

    image

    image

    image

    All the default screens

     image


    Free recovery tools

    June 24, 2009

    This article was written by Jason Fitzpatrick and the full version can be seen at http://lifehacker.com/5237503/five-best-free-data-recovery-tools

    TestDisk (Windows/Mac/Linux)

    Recuva (Windows)

    PhotoRec (Windows/Mac/Linux)

    Restoration (Windows)

    Undelete Plus (Windows)

    I knew of TestDisk but the others look really good.

     

    Thanks Jason ! 


    Enabling, and checking if full text search works on SQL 2005 or SQL 2008

    May 12, 2009

    image

    image

    image

    To verify full text catalog

    Exec SP_help_fulltext_catalogs ‘TableName’

    The status codes is the following:

    Full-text index population status of the catalog:

    0 = Idle

    1 = Full population in progress

    2 = Paused

    3 = Throttled

    4 = Recovering

    5 = Shutdown

    6 = Incremental population in progress

    7 = Building index

    8 = Disk is full. Paused

    9 = Change tracking

    NULL = User does not have VIEW permission on the full-text catalog, or database is not full-text enabled, or full-text component not installed.


    WMV file does not play, audio codec “Sipro Lab Telecom ACELP.net (130)” not found

    April 19, 2009

    You can find the codec here:

    http://www.voiceage.com/acelp_eval_eula.php

    I tried the 64bit one, did not seem to work, but the “All other windows users” one seem to do the trick.

    It can be found at:

    http://www.voiceage.com/media/acelp_net.exe


    Useful commands for power shell

    March 30, 2009
     
    Get the list of running services on your machine:

    get-service | where-object {$_.Status -eq “Running”}

    Get all the SQL Services on your machine

    get-service -displayName “*sql*”

    But I did say useful and that is not very useful. So how about stopping all the running services on your machine that contain “sql” in the name including their dependant services?

    get-service -displayName “*sql*” |
    where-object {$_.Status -eq “Running”} |
    ForEach-Object -process {Stop-Service $_.name -force }

     

    Add Event Viewer to the the My Computer context menu

    March 9, 2009

    Screen shot of event viewer on the context menu

    This is what the registry file will do –>

     

     

     

    Create a text file that contains the following text

    Windows Registry Editor Version 5.00

    ;Adds Add/Remove to right click of MY Computer
    [HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\Event Viewer\command]
    @=”eventvwr”


    IIS on 64bit platform settings to run 32bit code

    March 3, 2009

    I am assuming that you would not want to do this out of your own free will, that somebody is standing behind you with a gun, or that your working with brown fields applications, and have not other choice.

    GUI (for noobs)

    Screenshot

     

    Powershell (for lazy people)

    PS IIS:\> Set-ItemProperty IIS:\AppPools\DefaultAppPool -name enable32BitAppOnWin64 -value True

    Usefull links

    The IIS extension that is for this functionality –> Power shell snap in