TeamWox HelpService DeskPublic Component.NET Example

Example of Public Component in .NET

In this section the detailed example of designing the public component of the "Service Desk" module using the .NET Framework 3.5 of higher is given. Three files are necessary for the implementation:

  • ServiceDesk.aspx — the main file using which the calling of the public part of the "Service Desk" module is performed.
  • User.cs — the example of file that contains the classes of information about the users.
  • ServiceDesk.cs — the auxiliary file containing classes with parameters for outputting the public component of the "Service Desk".

For working by this scheme, one should add the references to the "System.Runtime.Serialization" and "System.ServiceModel.Web" libraries at the Visual Studio project.

ServiceDesk.aspx

 <%@ Import Namespace="ServiceDeskIntegration"%>
    <%
        //--- here you must get the information about the user on your own
        User user = new User { ID = 111,Name = "testName",Email = "test@email.com",Company = "testCompany" };
        //--- form the parameters for the Service Desk component
        ServiceDeskParam serviceDeskParam = ServiceDeskTools.GetParameters(user);
    %>
    <script type="text/javascript">
       var tw_servicedesk_params=<%= ServiceDeskTools.JSON(serviceDeskParam) %>;
    </script>

User.cs

  //--- ............
  //--- your code
  //--- ............
  /// <summary>
  /// Example of class of user information
  /// </summary>
  public class User
    {
    public int ID { get; set; }              // identifier
    public string Name { get; set; }         // name
    public string Email { get; set; }        // e-mail
    public string Company { get; set; }      // company name
    }
  //--- ............
  //--- your code
  //--- ............

ServiceDesk.cs

using System.IO;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
namespace ServiceDeskIntegration
  {
  /// <summary>
  /// Class with parameters for outputting Service Desk component
  /// </summary>
  [DataContract]
  public class ServiceDeskParam
    {
    [DataMember]
    public string url { get; set; }               // domain name of your TeamWox
    [DataMember]
    public string sid { get; set; }               // hash from the like: keyword + identifier of website user
    [DataMember]
    public string container { get; set; }         // identifier of HTML element (for example, <div>), the list of requests will be displayed in
    [DataMember]
    public string user_name { get; set; }         // name of website user
    [DataMember]
    public string user_email { get; set; }        // e-mail of website user
    [DataMember]
    public string user_company { get; set; }      // name of company of website user
    [DataMember]
    public int incidents_per_page { get; set; }   // number of requests displayed at one page
    [DataMember]
    public int comments_per_page { get; set; }    // number of comments displayed at one page
    [DataMember]
    public int[] filter_groups { get; set; }      // identifiers of service groups at Service Desk in TeamWox
    [DataMember]
    public int[] filter_products { get; set; }    // identifiers of products in Service Desk groups in TeamWox
    [DataMember]
    public int[] filter_categories { get; set; }  // identifiers of categories in Service Desk groups in TeamWox
    [DataMember]
    public string logo { get; set; }              // logo of your company
    }
  /// <summary>
  /// Class with the set of methods for outputting the information
  /// </summary>
  public class ServiceDeskTools
    {
    /// <summary>
    /// get the MD5 hash for the line
    /// </summary>
    /// <param name="input">line the hash should be taken from</param>
    public static string GetMD5(string input)
      {
      MD5 hash = MD5.Create();
      //--- calculate hash
      byte[] retArray = Encoding.Unicode.GetBytes(input);
      retArray = hash.ComputeHash(retArray);
      //--- form the response line
      StringBuilder sBuilder = new StringBuilder();
      for(int i = 0;i < retArray.Length;i++)
        {
        sBuilder.Append(retArray[i].ToString("X2"));
        }
      //---
      return sBuilder.ToString();
      }
    /// <summary>
    /// form the line of JavaScript array with screening special symbols
    /// </summary>
    /// <param name="param">parameters of Service Desk components</param>
    public static string JSON(ServiceDeskParam param)
      {
      string json;
      //--- output paramters in JSOn format
      DataContractJsonSerializer serializer = new DataContractJsonSerializer(param.GetType());
      using(MemoryStream ms = new MemoryStream())
        {
        serializer.WriteObject(ms,param);
        json = Encoding.UTF8.GetString(ms.ToArray());
        }
      //---
      return json;
      }
    /// <summary>
    /// form parameters of displaying Service Desk Component
    /// </summary>
    /// <param name="user">user information</param>
    public static ServiceDeskParam GetParameters(User user)
      {
      ServiceDeskParam serviceDesckParam = new ServiceDeskParam();
      //--- domain name of your TeamWox
      serviceDesckParam.url = "https://team.yourdomain.com";
      //--- identification of website user
      serviceDesckParam.sid = GetMD5("Change_This_Secret_Word_" + user.ID);
      //--- identifier of HTML element HTML (for example, <div>), the list of requests will be displayed in
      serviceDesckParam.container = "service_desk";
      //--- information about website user
      serviceDesckParam.user_name    = user.Name;
      serviceDesckParam.user_email   = user.Email;
      serviceDesckParam.user_company = user.Company;
      //--- parameters of displaying requests and comments
      serviceDesckParam.incidents_per_page = 15;
      serviceDesckParam.comments_per_page  = 20;
      //--- identifiers of groups, products and categories of Service Desk
      serviceDesckParam.filter_groups     = new[] { 1003,1004,1007 };
      serviceDesckParam.filter_products   = new[] { 1020,1023 };
      serviceDesckParam.filter_categories = new[] { 2003,2007,2011 };
      //--- logo of your company
      serviceDesckParam.logo = "<img src=\"http://www.yourwebsite.com/company_logo.gif\" title=\"Your Company Name\" alt=\"Your Company Name\"/>";
      //---
      return serviceDesckParam;
      }
    }
  }