Thursday, February 16, 2012

CTI Client in C#

I try set agent desktop state through a custom CTI Client in C#.

The code is shown below:

 
   public static void Main(string[] args)
        {
            Int32 port = 12028;
            String server = "127.0.0.1";

            TcpClient client = new TcpClient(server, port);
            NetworkStream stream = client.GetStream();

            byte[] message = new byte[ 8 + 17 + extension.Length + 3 + agentID.Length + 3];

            int len = 0;
            //header 
            UInt32[] length = { IntToNetworkOrder(34) };
            Buffer.BlockCopy(length, 0, message, len, sizeof(UInt32));
            len += sizeof(UInt32);

            UInt32[] msgTypeID = { IntToNetworkOrder(38) };
            Buffer.BlockCopy(msgTypeID, 0, message, len, sizeof(UInt32));
            len += sizeof(UInt32);

            //fix part (17)
            UInt32[] invokeID = { IntToNetworkOrder(100) };
            Buffer.BlockCopy(invokeID, 0, message, len, sizeof(UInt32));
            len += sizeof(UInt32);

            UInt32[] reserved1 = { IntToNetworkOrder(1) };
            Buffer.BlockCopy(reserved1, 0, message, len, sizeof(UInt32));
            len += sizeof(UInt32);

            ushort[] agentState = { ShortToNetworkOrder(3) };
            Buffer.BlockCopy(agentState, 0, message, len, sizeof(ushort));
            len += sizeof(ushort);

            ushort[] reserved2 = { ShortToNetworkOrder(0) };
            Buffer.BlockCopy(reserved2, 0, message, len, sizeof(ushort));
            len += sizeof(ushort);

            ushort[] reserved3 = { ShortToNetworkOrder(0) };
            Buffer.BlockCopy(reserved3, 0, message, len, sizeof(ushort));
            len += sizeof(ushort);

            ushort[] eventReasonCode = { ShortToNetworkOrder(32760) };
            Buffer.BlockCopy(eventReasonCode, 0, message, len, sizeof(ushort));
            len += sizeof(ushort);

            byte[] forcedFlag = new byte[] { 0 };
            Buffer.BlockCopy(forcedFlag, 0, message, len, sizeof(byte));
            len += sizeof(byte);

            //floating part
            //agent instrument
            byte[] agentInstrumentID = new byte[] { 6 };
            Buffer.BlockCopy(agentInstrumentID, 0, message, len, sizeof(byte));
            len += sizeof(byte);

            byte[] agentInstrumentLen = new byte[] { (byte)(extension.Length + 1) };
            Buffer.BlockCopy(agentInstrumentLen, 0, message, len, sizeof(byte));
            len += sizeof(byte);

            byte[] agentInstrumentData = System.Text.Encoding.ASCII.GetBytes(extension);
            Buffer.BlockCopy(agentInstrumentData, 0, message, len, agentInstrumentData.Length);
            len += agentInstrumentData.Length;

            Buffer.BlockCopy(forcedFlag, 0, message, len, sizeof(byte));
            len += sizeof(byte);

            //agent id
            byte[] agentIdID = new byte[] { 194 };
            Buffer.BlockCopy(agentIdID, 0, message, len, sizeof(byte));
            len += sizeof(byte);

            byte[] agentIdLen = new byte[] { (byte)(agentID.Length + 1) };
            Buffer.BlockCopy(agentIdLen, 0, message, len, sizeof(byte));
            len += sizeof(byte);

            byte[] agentIdData = System.Text.Encoding.ASCII.GetBytes(agentID);
            Buffer.BlockCopy(agentIdData, 0, message, len, agentIdData.Length);
            len += (agentIdData.Length);

            Buffer.BlockCopy(forcedFlag, 0, message, len, sizeof(byte));
            len += sizeof(byte);

            stream.Write(message, 0, message.Length);

            stream.Close();
            client.Close();
        }

        public static UInt32 IntToNetworkOrder(UInt32 source)
        {
            if (BitConverter.IsLittleEndian)
            {
                return (uint)(source >> 24) |
                             ((source << 8) & 0x00FF0000) |
                             ((source >> 8) & 0x0000FF00) |
                              (source << 24);
            }

            return source;
        }

        public static ushort ShortToNetworkOrder(ushort source)
        {
            if (BitConverter.IsLittleEndian)
            {
                return (ushort)(source >> 8 | source << 8);
            }
            return source;
        }

Saturday, February 4, 2012

CTI Protocol: Set Agent Desktop State

I try to use CTI protocol to update state of agent desktop and download a sample client which written in C++ from  http://developer.cisco.com/c/portal/agreement?fileEntryId=147817.

Then, I run cticlient\msclient\Debug\msclient.exe with following commands:

1. Open socket
    connect -s 172.20.32.144 -n 12028

2. Set agent state ready
    setagentstatereq -s 3 -e 32760 -f 0 -p 112233 -c Testing_CSQ -d agent11  -a 2011


References:

Monday, January 30, 2012

Enable basic authentication in IIS

Only basic authentication is available for connecting SharePoint Rest Interface in vCenter Orchestrator. Then, I go to IIS Manager and enable basic authentication under SharePoint website. But, the authentication method does not work actually. 


However, it works fine when I disable windows authentication. For your reference, 



Monday, January 2, 2012

PowerShell: Add-PSSnapin WebAdministration in Windows Server 2008

An error occurred when I execute Add-PSSnapin WebAdministration.

After Goggling, I discover that I forgot to install IIS 7.0 PowerShell Snap-in as the OS is Windows Server 2008. On the other hand, it is no need to install the snap-in if your OS is Windows Server 2008 R2.


Thursday, December 8, 2011

REST: Post XML to Update List Item

I need to use vCenter orchestrator to update item in SharePoint list.

Using rest plugin, I post the following XML to SharePoint.

 


   
   http://172.20.34.33/_vti_bin/listdata.svc/Rest(4)
    1
    2011-11-07T17:39:56+08:00
    
      
    
    
      
        0x0100B0118C4AF8B98C408EDC3A87238E73F5
        4
        4
  haha
        Item
        /Lists/rest
      
    

Tuesday, December 6, 2011

HTML in Calculated Column

In a SharePoint list, it looks up a Hyperlink column in another list. After my investigation, Lookup column only supports Text column and Calculated column. 

I decide to use Calculated column and render its content as html. Based on below references link, I add a script file to a content editor. But, it still failed.


After some time, I modify the script file and it works file.

Sunday, December 4, 2011

SPFieldUrl: Open URL in a New Window

When I add a hyperlink column in a list and add an item, I click its hyperlink. Then, it redirects current page to the link. But, I want to open a new window when clicking these links.

In fact, I cannot configure it inside SharePoint. After Googling, I discover it can be done by the following steps:

1. Go to folder "Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL"
2. Open fldtypes.xsl
3. Change line '<a href="{$url}" >' to '<a target="_blank" href="{$url}" >'
3. Save the file and restart IIS

After that, I create a new hyperlink column, it opens a new window when clicking its link.

RenderPattern Element (Field Types)
SharePoint: Creating Custom SharePoint 2010 Field Types
How to: Create a Custom Field Type
Customizing the Rendering of a Custom SPField
What's New: Custom Field Rendering Enhancements