Monday, November 29, 2010

Migrate vm from vmware workstation to vmware esxi

Use Case

Migrate VM from VMWare Workstation v 7.xx to VMWare ESXi v 4.xx

Solution

1. Install and configure VMWare ESXi v4.xx using instructions from official site. The only one thing, I have to change is to allow CPU Virtualization feature in BIOS.

2. Enable local and / or remote administration shell using instructions here: http://itknowledgeexchange.techtarget.com/it-consultant/enabling-ssh-on-a-vmware-esxi-server/

3. Copy your VMs files (*.vmdk)
For weird reason I was not been able to mount additional SATA drive with old virtual machines. The only way to copy files was to use scp and copy files over network.

4. Convert old VMs using vmkfstools utility.
 vmkfstools -i "old_virtual_machine_disk.vmdk" -d thin "new_virtual_machine_disk.vmdk"

5. Create new VM in advanced mode and specify existing drive to newly converted disk.

Friday, November 26, 2010

LDIFDE - Export / Import data from Active Directory

Use Case

Need to migrate Active Directory from one server to another.

Solution

Follow great article at: LDIFDE - Export / Import data from Active Directory - LDIFDE commands

Thursday, November 25, 2010

spring.net activemq integration

Use Case

Attach to ActiveMQ messaging system from c#.

Solution

Follow great example at: http://remark.wordpress.com/articles/messaging-with-net-and-activemq/

Wednesday, November 17, 2010

Ext.net custom panel header

Use Case

You need to place custom controls (e.g. text box, drop down list, buttons, etc) on your panel header.

Solution

As was explained in http://thelampposts.blogspot.com/2008/05/custom-extjs-header-buttons.html, we can simply hide standard panel header and create toolbar element and give it correct style, Cls="x-panel-header".

Tuesday, November 16, 2010

Dictionary xml serialization

Use Case

Serialize dictionary (preferrable generic) to xml.

Solution

Thanks to Paul Welter for solution: http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx


using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Xml.Serialization;

    [XmlRoot("dictionary")]
    public class SerializableDictionary<TKey, TValue>
        : Dictionary<TKey, TValue>, IXmlSerializable
    {
        #region IXmlSerializable Members
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            XmlSerializer keySerializer = newXmlSerializer(typeof(TKey));
            XmlSerializer valueSerializer = newXmlSerializer(typeof(TValue));

            bool wasEmpty = reader.IsEmptyElement;
            reader.Read();

            if (wasEmpty)
                return;

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                reader.ReadStartElement("item");

                reader.ReadStartElement("key");
                TKey key = (TKey)keySerializer.Deserialize(reader);
                reader.ReadEndElement();

                reader.ReadStartElement("value");
                TValue value = (TValue)valueSerializer.Deserialize(reader);
                reader.ReadEndElement();

                this.Add(key, value);

                reader.ReadEndElement();
                reader.MoveToContent();
            }
            reader.ReadEndElement();
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            XmlSerializer keySerializer = newXmlSerializer(typeof(TKey));
            XmlSerializer valueSerializer = newXmlSerializer(typeof(TValue));

            foreach (TKey key in this.Keys)
            {
                writer.WriteStartElement("item");

                writer.WriteStartElement("key");
                keySerializer.Serialize(writer, key);
                writer.WriteEndElement();

                writer.WriteStartElement("value");
                TValue value = this[key];
                valueSerializer.Serialize(writer, value);
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
        }
        #endregion
    }

Wednesday, November 10, 2010

Creating custom composite activity

Use Case

Create custom composite activity to be used in sequential workflow.

Solution

Follow excellent guide at: http://msdn.microsoft.com/en-us/library/ms734576(VS.90).aspx and http://msdn.microsoft.com/en-us/library/aa480200.aspx

Pay your attention on how Execute and OnEvent methods are handled. Just filling collection of Activities in constructor won't force child activities to work.

Tuesday, November 9, 2010

View oracle objects compile errors

Use Case

Check if there were any errors during oracle objects compilation (procedures, functions, packages, triggers, or package).

Solution

Oracle stores information about errors occured during objects compilation in system tables (e.g. USER_ERRORS). To view error run following sql statement:

select * from sys.user_errors where name = 'object name' and type = 'object type'

Please refer following resources for more information:

asp.net dynamic embedded resources

Use Case

You have an embedded css stylesheet (main.css) and background image (bg.gif). In css you would like to have smth like:


#header {
    background : #7F99BE url('reference to bg.gif') repeat-x scroll center center;
    border     : solid 1px #122A59;
}

Solution

First, make sure, that main.css and bg.gif are marked as Embedded Resources in property editor.
Then, make sure that they're registered to be included into assembly manifest using commands below:

[assembly: WebResource("XXX.YYY.Content.css.main.css", "text/css", PerformSubstitution=true)]
[assembly: WebResource("XXX.YYY.Content.images.bg.gif", "image/gif")]

Note, 3rd parameter PerformSubsitution=true.

Now in main.css you can use reference to bg.gif as shown below:

#header { 
    background : #7F99BE url('<%= WebResource("XXX.YYY.Content.images.bg.gif") %>') repeat-x scroll center center; 
    border     : solid 1px #122A59;
}

For more information, refer to excellent article about embedding resources into assembly at: 

Wednesday, November 3, 2010

spring.net send messages to multiply locations using MessageQueueGatewaySupport

Use Case

My service utilizing MessageQueueGatewaySupport need to send messages to multiply locations (queues) which are not known at design time.

Solution

Prepare generic application context configuration (see post: spring.net dynamic configuration. Configure IApplicationContext from GenericApplicationContext and file stream. for more details).

On runtime, you can programmatically register queues as shown below:


            // Get template
            var template = Context["messageQueueTemplate"] as MessageQueueTemplate;

            template.MessageQueueFactory.RegisterMessageQueue(requestQueueName,
                 delegate
                 {
                       var mq = new MessageQueue();
                       mq.Path = requestQueuePath;
                       return mq;
                 }
            );



            template.ConvertAndSend(requestQueueName, request, delegate(Message message)
            {
                   // do smth with your message
                   return message;
            });

spring.net dynamic configuration. Configure IApplicationContext from GenericApplicationContext and file stream.

Use Case

Configure ApplicationContext from stream. This can be helpful when you don't know exact object configuration on designtime and have to create application context on runtime.

Solution

Spring.net gives us ability to manually configure configuration sources.

IApplicationContext ctx = null;
using (var sr = File.OpenRead("some config file")) {
               ctx = new GenericApplicationContext();
               var objectDefinitionReader = new XmlObjectDefinitionReader(ctx);
               objectDefinitionReader.LoadObjectDefinitions(new InputStreamResource(sr, "MsmqSendServiceGatewayConfiguration"));

               ctx.Refresh();
}

var svc = ctx["myService"] as IMyService;

The most important line in the code above is: ctx.Refresh(); By doing this, ApplicationContext is propagates to all objects supporting IApplicationContextAware interface. Without this line, invoking any object from context may throw error, because they require ApplicationContext to be defined on that stage.

You may easily change the code above to get configuration from dynamically built xml, database and any other source.