<%@ WebService Language="VB" Class="VPS" %>

Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports MachSol.MachPanel.DBCore
Imports MachSol.MachPanel.RemoteServer.VPS.HyperV
Imports System.Data
Imports System.Data.SqlClient

Imports System.Collections.Generic
Imports BusinessObjects.BusinessObjectsExtension

<WebService(Namespace:="http://machsol.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class VPS
    Inherits System.Web.Services.WebService


    <WebMethod(EnableSession:=True)> _
    Public Function GetAsyncDefaultTheme(byval body_color_in_cookie as string) As String
        Try
            body_color_in_cookie = MachSol.MachPanel.Utility.Utility.Sanitize(body_color_in_cookie)
            Dim cookieThemeFoundInDb as boolean = false
            dim defaultThemeInDb as string = ""

            Dim DT As DataTable = MachSol.MachPanel.DBCore.SystemSettings.GetCompanySkins(Session("CompanyId"))

            If DT.Rows.Count > 0 Then

                For Each row As DataRow In DT.Rows

                    if Convert.ToBoolean(row("IsAllowed"))

                        Dim skinTheme As String = row("SkinTheme")
                        Dim IsDefault As Boolean = Convert.ToBoolean(row("IsDefault"))

                        'check weather cookie theme exists in db
                        if body_color_in_cookie = skinTheme
                            cookieThemeFoundInDb = true
                        End If

                        If IsDefault Then
                            defaultThemeInDb = skinTheme
                        End If
                    End If
                Next
            End If

            'if the value in cookie is not empty and it is existed in skin dropdown then this one should selected else defualt theme
            if cookieThemeFoundInDb
                return body_color_in_cookie
            else
                return defaultThemeInDb
            End If

        Catch ex As Exception
            Return ""
        End Try
    End Function

    <WebMethod(EnableSession:=True)> _
    Public Function GetSearchPanelCollapsed(ByVal SearchPanelURL As String, Id As String) As SearchPanelStateResult
        SearchPanelURL = MachSol.MachPanel.Utility.Utility.Sanitize(SearchPanelURL)
        Id = MachSol.MachPanel.Utility.Utility.Sanitize(Id)
        Dim Result As New SearchPanelStateResult
        Result.Id = Id
        Result.IsCollapsed = SystemSettings.GetSearchPanelCollapsed(SearchPanelURL, Session("AuditAccount"))

        Return Result

    End Function

    Public Structure SearchPanelStateResult
        Public Id As String
        Public IsCollapsed As Boolean
    End Structure

    <WebMethod(EnableSession:=True)> _
    Public Sub SaveSearchPanelCollapsed(ByVal SearchPanelURL As String, IsCollapsed As Boolean)
        SearchPanelURL = MachSol.MachPanel.Utility.Utility.Sanitize(SearchPanelURL)

        SystemSettings.SaveSearchPanelCollapsed(SearchPanelURL, Session("AuditAccount"), IsCollapsed)

    End Sub

    <WebMethod(EnableSession:=False)>
    Public Sub MSCBURLForAP(State As String, CallbackURL As String)
        State = MachSol.MachPanel.Utility.Utility.Sanitize(State)
        CallbackURL = MachSol.MachPanel.Utility.Utility.Sanitize(CallbackURL)
        Application(State) = CallbackURL
    End Sub

    <WebMethod(EnableSession:=True)>
    Public Function getVPSState(ByVal VPSId As Long, ByVal State As String) As String
        State = MachSol.MachPanel.Utility.Utility.Sanitize(State)
        Dim RetVal As String = ""

        Dim vps As New VPSAccount(VPSId)

        If (vps.VPSState = VPSAccount.VPSStateOptions.Provisioning) Then
            RetVal = "0|" & Resources.Content.M0125 & "|" & vps.VPSStateDescription
        ElseIf (vps.VPSState = VPSAccount.VPSStateOptions.Blocked) Then
            RetVal = "1|" & Resources.Content.SPT002527 & "|" & vps.VPSStateDescription
        ElseIf (vps.VPSState = VPSAccount.VPSStateOptions.Ready) Then
            RetVal = "2|" & Resources.Content.SPT002209 & "|" & vps.VPSStateDescription
        ElseIf (vps.VPSState = VPSAccount.VPSStateOptions.ErrorCase) Then
            RetVal = "3|" & "Error" & "|" & vps.VPSStateDescription
        Else
            RetVal = "3|" & "Error" & "|" & vps.VPSStateDescription
        End If

        If (State = "State") Then
            Dim VPSProv As New VPSProvisioning(vps.VPSServerId)

            Try
                Dim MS As MachineEnabledStates = VPSProv.GetVirtualMachineState(vps.VMID)
                RetVal += " Current State """ & MS.ToString() & """"
            Catch ex As Exception
                RetVal = "3|" & "Error" & "|" & vps.VPSStateDescription
            End Try

        End If

        If (State = "Migrate") Then
            Dim VPSProv As New VPSProvisioning(vps.VPSServerId)

            Dim Result As New Dictionary(Of String, Object)

            Dim VPServerGroupId As Long = 0

            VPServerGroupId = VPSServerDataProxy.SelectVPSServerById(vps.VPSServerId).Tables(0).Rows(0)("VPSServerGroupId")

            Dim DT As DataTable = VPSServerDataProxy.VPSServerSelectByVPSServerGroupID(VPServerGroupId).Tables(0)

            For Each Row As DataRow In DT.Rows
                Try
                    VPSProv = New VPSProvisioning(Row("VPSServerId"))
                    Result = VPSProv.GetVMDetails(vps.VMName)

                    If Result("Status").ToString.ToLower = "operating normally" Then 'Move completed successfully
                        vps.VPSState = VPSAccount.VPSStateOptions.Ready
                        vps.VPSStateDescription = ""
                        vps.VPSServerId = Row("VPSServerId")
                        RetVal = "2|" & Resources.Content.SPT002209 & "|" & Resources.Content.EGN0000011
                        Exit For
                    ElseIf Result("Status").ToString.ToLower.Contains("migrating") Or Result("Status").ToString.ToLower.Contains("in service") _
                        Or Result("Status").ToString.ToLower.Contains("saving") Then 'Move under process
                        'Still migrating
                        RetVal = "1|" & Resources.Content.SPT002527 & "|" & Resources.Content.VPS1002
                        Exit For
                    Else 'Error case
                        vps.VPSState = VPSAccount.VPSStateOptions.ErrorCase
                        vps.VPSStateDescription = Result("Status").ToString
                        vps.VPSServerId = Row("VPSServerId")
                        RetVal = "3|" & "Error" & "|" & vps.VPSStateDescription
                        Exit For
                    End If

                Catch err As Exception
                    'Move to next item
                End Try
            Next

            vps.Commit()


        End If

        Return RetVal

    End Function

    <WebMethod(EnableSession:=True)> _
    Public Function UpdateAlertViewedOn(ByVal EmployeeId As Long, ByVal IsEmployee As Boolean) As Boolean
        Dim Success As Boolean = False
        Try
            MachSol.MachPanel.DBCore.SystemSettings.UpdateAlertViewedOn(DateTime.Now, EmployeeId, IsEmployee)
            Success = True
        Catch ex As Exception
            Success = False
        End Try
        Return Success
    End Function

    <WebMethod(EnableSession:=False)> _
    Public Function SynchAlertOperations(ByVal Data As string) As String
        Data = MachSol.MachPanel.Utility.Utility.Sanitize(Data)
        Dim Success As String = 0
        Dim DSet As New DataSet
        Dim LogFile As String = MachSol.MachPanel.Utility.Utility.GetLogFolder() & "SyncAllAlerts" & Date.Now.Date.ToString("_dd-MM-yyyy") & ".Log"
        Dim DoLogging As Boolean = False

        Try
            dim Details As string() = MachSol.MachPanel.Utility.Utility.Decrypt(Data).Split("×")
            Dim CompanyId As String = Details(0)
            Dim EmployeeId As String = Details(1)
            dim IsEmployee as Boolean = Details(2)

            Try
                DoLogging = CType(MachSol.MachPanel.Utility.Utility.GetMainLoggingValues(), Boolean)
            Catch Err As Exception
                DoLogging = False
            End Try

            Dim DS As New DataSet

            MachSol.MachPanel.DBCore.SystemSettings.GetAlertOperations(CompanyId, EmployeeId, IsEmployee, DS, "Alerts")

            If DS.Tables.Count > 0 AndAlso DS.Tables("Alerts").Rows.Count > 0 Then
                Success = DS.Tables("Alerts").Rows(0)("NewAlertsCount")
            End If

            Dim RowFilter As String = "1=1"

            Dim MDLInfo As new ModuleInfo(CompanyId)

            If MDLInfo.IsBillingEnabled = False Then
                RowFilter &= " And ModuleTypeID<>1"
            End If

            If MDLInfo.IsHelpDeskEnabled = False Then
                RowFilter &= " And ModuleTypeID<>2"
            End If

            DS.Tables("Alerts").DefaultView.RowFilter = RowFilter

            Dim DT As New DataTable("Alerts")
            DT.Columns.Add("Description")
            DT.Columns.Add("Success")
            Dim DisplayCount As Integer = 0

            'With new notification we want a new badge so that a user can see which notification is new.
            'currently we have SP which return the success, success is the number of new notification. it does not tell which one is new, 
            'as we know the top notification are new one. so we will put badge with top no. i.e if success=2 then top 2 notificaion are new.
            Dim newNotificationsCounter As Integer = Convert.ToInt32(Success)
            Dim notificationBadge As String = ""

            For Each DR As DataRow In DS.Tables("Alerts").DefaultView.ToTable.Rows
                If (newNotificationsCounter > 0) Then
                    notificationBadge = " <span class='pull-right badge btn-primary'>New</span>"
                    'decrement the newNotificationsCounter by 1
                    newNotificationsCounter = newNotificationsCounter - 1
                Else
                    notificationBadge = ""
                End If
                Dim DRow As DataRow = DT.NewRow

                Dim Param As String = DR("URLInfo")
                Dim Description As String = DR("Description")
                Description = Description.Replace("Trans_Id:AM002", Resources.Content.AM002)
                Description = Description.Replace("Trans_Id:AM003", Resources.Content.AM003)
                Description = Description.Replace("Trans_Id:AM004", Resources.Content.AM004)
                Description = Description.Replace("Trans_Id:AM005", Resources.Content.AM005)
                Description = Description.Replace("Trans_Id:AM006", Resources.Content.AM006)
                Description = Description.Replace("Trans_Id:AM007", Resources.Content.AM007)
                Description = Description.Replace("Trans_Id:AM008", Resources.Content.AM008)
                Description = Description.Replace("Trans_Id:AM009", Resources.Content.AM009)
                Description = Description.Replace("Trans_Id:AM010", Resources.Content.AM010)
                Description = Description.Replace("Trans_Id:AM011", Resources.Content.AM011)
                Description = Description.Replace("Trans_Id:AM012", Resources.Content.AM012)
                Description = Description.Replace("Trans_Id:AM013", Resources.Content.AM013)
                Description = Description.Replace("Trans_Id:AM014", Resources.Content.AM014)
                Description = Description.Replace("Trans_Id:AM015", Resources.Content.AM015)
                Description = Description.Replace("Trans_Id:AM016", Resources.Content.AM016)
                Description = Description.Replace("Trans_Id:AM017", Resources.Content.AM017)
                Description = Description.Replace("Trans_Id:AM018", Resources.Content.AM018)
                Description = Description.Replace("Trans_Id:USM0188", Resources.Content.USM0188)
                Description = Description.Replace("Trans_Id:AM019", Resources.Content.AM019)
                Description = Description.Replace("Trans_Id:AM020", Resources.Content.AM020)
                Description = Description.Replace("Trans_Id:AM021", Resources.Content.AM021)
                Description = Description.Replace("Trans_Id:AMOO90", Resources.Content.AMOO90)
                Description = Description.Replace("Trans_Id:AM022", Resources.Content.AM022)

                Dim DateCreated As DateTime = DR("DateCreated")
                Dim TimeEllapsed As String = DateTime.Now.Subtract(DateCreated).TotalMinutes
                TimeEllapsed = Convert.ToInt32(Convert.ToDouble(TimeEllapsed))


                If TimeEllapsed < 1 Then
                    TimeEllapsed = "Less then a Minute"
                ElseIf TimeEllapsed >= 1 And TimeEllapsed < 30 Then
                    TimeEllapsed = TimeEllapsed & " Minute(s) Ago"
                ElseIf TimeEllapsed = 30 Then
                    TimeEllapsed = "Half an Hour Ago"
                ElseIf TimeEllapsed > 30 And TimeEllapsed < 60 Then
                    TimeEllapsed = TimeEllapsed & " Minute(s) Ago"
                ElseIf TimeEllapsed = 60 Then
                    TimeEllapsed = "1 Hour Ago"
                ElseIf TimeEllapsed > 60 And TimeEllapsed < 1440 Then
                    TimeEllapsed = Convert.ToInt32(Convert.ToInt32(TimeEllapsed) / 60)
                    TimeEllapsed = TimeEllapsed & " Hour(s) Ago"
                ElseIf TimeEllapsed = 1440 Then
                    TimeEllapsed = "1 Day Ago"
                ElseIf TimeEllapsed > 1440 And TimeEllapsed < 43200 Then
                    Dim tempDays As String = TimeEllapsed / 1440

                    TimeEllapsed = tempDays.Split(".")(0) & " Day(s) "

                    If (tempDays.Split(".").Length = 2) Then

                        Dim temp As Integer = tempDays * 1440
                        Dim temp2 As Integer = tempDays.Split(".")(0) * 1440

                        Dim tempHours As String = (temp - temp2) / 60

                        If (tempHours.Split(".")(0) <> 0) Then
                            TimeEllapsed = TimeEllapsed & "& " & tempHours.Split(".")(0) & " Hour(s) Ago"
                        Else
                            TimeEllapsed = TimeEllapsed & "Ago"
                        End If
                    Else
                        TimeEllapsed = tempDays.Split(".")(0) & " Day(s) Ago"
                    End If
                ElseIf TimeEllapsed = 43200 Then
                    TimeEllapsed = "1 Month Ago"
                ElseIf TimeEllapsed > 43200 Then
                    TimeEllapsed = Convert.ToInt32(Convert.ToInt32(TimeEllapsed) / 43200)
                    TimeEllapsed = TimeEllapsed & " Month(s) Ago"
                End If

                Dim BaseURL As String = Helper.GetAppUrl(HttpContext.Current.Request.Url.AbsoluteUri, HttpContext.Current.Request.Url.AbsolutePath) 'MachSol.MachPanel.DBCore.Common.GetBaseURL(CompanyId) 'Session("CWURL")
                BaseURL = BaseURL.TrimEnd("/")
                If DR("ModuleTypeID") = "1" Then
                    DRow("Description") = "<div class='menu-info' style='width: 100%; padding-right:6px;'><h4><a class='text no-padding' href='" & BaseURL & "/RCC/Billing/Documents.aspx'>" & Description & notificationBadge & "</a></h4><p>" & TimeEllapsed & "</p></div>"
                ElseIf DR("ModuleTypeID") = "2" Then
                    DRow("Description") = "<div class='menu-info' style='width: 100%; padding-right:6px;'<h4><a class='text no-padding' href='" & BaseURL & "/RCC/HelpDesk/ViewTicketDetail.aspx?TicketId=" & Param.Split("|")(0) & "' >" & Description & notificationBadge & "</a></h4><p>" & TimeEllapsed & "</p></div>"
                ElseIf DR("ModuleTypeID") = "3" Then
                    Dim SubsURL As String = BaseURL & "/RCC/Clients/Subscriptions.aspx"
                    Dim PackageTypeID As String = Param.Split("|")(1)
                    If PackageTypeID = 1 Then
                        SubsURL = BaseURL & "/RCC/Clients/SH.aspx?Id=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 2 Then
                        SubsURL = BaseURL & "/RCC/Clients/NH.aspx?Id=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 3 Then
                        SubsURL = BaseURL & "/RCC/Clients/AD.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 5 Then
                        SubsURL = BaseURL & "/RCC/Clients/DH.aspx?Id=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 8 Then
                        SubsURL = BaseURL & "/RCC/Clients/SSL.aspx?Id=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 10 Then
                        SubsURL = BaseURL & "/RCC/Clients/Domain.aspx?Id=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 14 Then
                        SubsURL = BaseURL & "/RCC/Clients/CRM.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 15 Then
                        SubsURL = BaseURL & "/RCC/Clients/AddOn.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 16 Then
                        SubsURL = BaseURL & "/RCC/Clients/ExH.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 17 Then
                        SubsURL = BaseURL & "/RCC/Clients/SP.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 18 Then
                        SubsURL = BaseURL & "/RCC/Clients/OCS.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 19 Then
                        SubsURL = BaseURL & "/RCC/Clients/VPS.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 21 Then
                        SubsURL = BaseURL & "/RCC/O365/O365Sub.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 22 Then
                        SubsURL = BaseURL & "/RCC/RDS/Manage.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 23 Then
                        SubsURL = BaseURL & "/RCC/Clients/WFH.aspx?SubId=" & Param.Split("|")(0)
                    ElseIf PackageTypeID = 24 Then
                        SubsURL = BaseURL & "/RCC/Clients/SIP.aspx?SubId=" & Param.Split("|")(0)
                    End If
                    DRow("Description") = "<div class='menu-info' style='width: 100%; padding-right:6px;'<h4><a class='text no-padding' href='" & SubsURL & "' >" & Description & notificationBadge & "</a></h4><p>" & TimeEllapsed & "</p></div>"
                ElseIf DR("ModuleTypeID") = "4" Then
                    If Param.Split("|")(1) = 0 Then
                        DRow("Description") = "<div class='menu-info' style='width: 100%; padding-right:6px;'<h4><a class='text no-padding' href='" & BaseURL & "/RCC/Clients/ClientDetail.aspx?cID=" & Param.Split("|")(0) & "&Src=C' >" & Description & notificationBadge & "</a></h4><p>" & TimeEllapsed & "</p></div>"
                    Else
                        DRow("Description") = "<div class='menu-info' style='width: 100%; padding-right:6px;'<h4><a class='text no-padding' href='" & BaseURL & "/RCC/Clients/ClientDetail.aspx?RD=1&CID=" & Param.Split("|")(0) & "' >" & Description & notificationBadge & "</a></h4><p>" & TimeEllapsed & "</p></div>"
                        DRow("Description") = DRow("Description").ToString.Replace("customer", "reseller")
                    End If
                ElseIf DR("ModuleTypeID") = "5" Then
                    'DRow("Description") = "<a class='text no-padding' href='" & BaseURL & "/RCC/Network/ServiceDirector/ServiceQueue.aspx' ><img src='" & BaseURL & "/App_Themes/Default/Images/icons/icon_service_q.png' alt='Customer Manager'>&nbsp;" & Description & "</a><br />&nbsp;<img src='" & BaseURL & "/App_Themes/Default/Images/icons/alert.png' alt=''>&nbsp;" & TimeEllapsed
                    Dim PackageTypeId As String = Param.Split("|")(1)
                    Dim ActionType As String = Param.Split("|")(2)
                    Dim AccountID As String = Param.Split("|")(3)
                    Dim ActionText As String = "", Hosting As String = ""
                    If ActionType = "0" Then
                        ActionText = "Provision"
                    ElseIf ActionType = "1" Then
                        ActionText = "Cancel"
                    ElseIf ActionType = "3" Then
                        ActionText = "Suspend"
                    ElseIf ActionType = "4" Then
                        ActionText = "Resume"
                    ElseIf ActionType = "5" Then
                        ActionText = "Edit"
                    ElseIf ActionType = "8" Then
                        ActionText = "Add organization"
                    End If

                    If PackageTypeId = "1" Then
                        Hosting = "Shared Hosting"
                    ElseIf PackageTypeId = "2" Then
                        Hosting = "Reseller Hosting"
                    ElseIf PackageTypeId = "3" Then
                        Hosting = "Active Directory Hosting"
                    ElseIf PackageTypeId = "5" Then
                        Hosting = "Dedicated Server Hosting"
                    ElseIf PackageTypeId = "8" Then
                        Hosting = "SSL Hosting"
                    ElseIf PackageTypeId = "10" Then
                        Hosting = "Domain Name Product"
                    ElseIf PackageTypeId = "14" Then
                        Hosting = "CRM Hosting"
                    ElseIf PackageTypeId = "16" Then
                        Hosting = "Exchange Hosting"
                    ElseIf PackageTypeId = "17" Then
                        Hosting = "Sharepoint Hosting"
                    ElseIf PackageTypeId = "18" Then
                        Hosting = "SfB (Lync) Hosting"
                    ElseIf PackageTypeId = "19" Then
                        Hosting = "VPS Hosting"
                    ElseIf PackageTypeId = "21" Then
                        Hosting = "Office 365 Hosting"
                    ElseIf PackageTypeId = "22" Then
                        Hosting = "RDS Hosting"
                    ElseIf PackageTypeId = "23" Then
                        Hosting = "Work Folders Hosting"
                    ElseIf PackageTypeId = "24" Then
                        Hosting = "Voice"
                    End If

                    Dim DomainName As String = ""
                    If PackageTypeId <> 15 Then
                        Try
                            Using SDR2 As SqlDataReader = MachSol.MachPanel.DBCore.SystemSettings.GetHostingByPackageTypeID(PackageTypeId, AccountID)
                                SDR2.Read()
                                If PackageTypeId = 3 Or PackageTypeId = 14 Or PackageTypeId = 16 Or PackageTypeId = 18 Or PackageTypeId = 22 Or PackageTypeId = 23 Then
                                    DomainName = Resources.Content.DGN1110608 & ": " & SDR2("OrgName") & ", " & Resources.Content.GN000125 & ": " & SDR2("DomainName")
                                ElseIf PackageTypeId = 5 Then
                                    DomainName = Resources.Content.GN0000980 & ": " & SDR2("ReferenceID")
                                ElseIf PackageTypeId = 2 Then
                                    DomainName = ""
                                ElseIf PackageTypeId = 17 Then
                                    DomainName = Resources.Content.String521 & ": " & SDR2("PortalName") & ", " & Resources.Content.GN000125 & ": " & SDR2("DomainName")
                                ElseIf PackageTypeId = 19 Then
                                    DomainName = Resources.Content.VPS002 & ": " & SDR2("VPSName")
                                ElseIf PackageTypeId = 21 Then
                                    DomainName = Resources.Content.GN000125 & ": " & SDR2("PrimaryDomainName")
                                ElseIf PackageTypeId = 24 Then
                                    DomainName = Resources.Content.DGN1110608 & ": " & SDR2("OrganizationName") & ", " & Resources.Content.GN000125 & ": " & SDR2("DomainName")
                                Else
                                    DomainName = Resources.Content.GN000125 & ": " & SDR2("DomainName")
                                End If
                                SDR2.Close()
                            End Using
                        Catch ex As Exception
                            DomainName = ""
                        End Try
                    End If
                    Description = Resources.Content.AM013 & "," & ActionText & " " & Hosting & " AccountID: " & AccountID & ", " & DomainName
                    Description = Description.Trim(",")
                    DRow("Description") = "<div class='menu-info' style='width: 100%; padding-right:6px;'<h4><a class='text no-padding' href='" & BaseURL & "/RCC/Network/ServiceDirector/ServiceQueue.aspx' >" & Description & notificationBadge & "</a></h4><p>" & TimeEllapsed & "</p></div>"
                ElseIf DR("ModuleTypeID") = "6" Then
                    If CompanyId = "1" OrElse CompanyId = DR("CompanyId") Then
                        Dim SubsURL As String = BaseURL & "/RCC/Clients/Subscriptions.aspx"
                        Dim PackageTypeID As String = Param.Split("|")(1)
                        If PackageTypeID = 1 Then
                            SubsURL = BaseURL & "/RCC/Clients/SH.aspx?Id=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 2 Then
                            SubsURL = BaseURL & "/RCC/Clients/NH.aspx?Id=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 3 Then
                            SubsURL = BaseURL & "/RCC/Clients/AD.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 5 Then
                            SubsURL = BaseURL & "/RCC/Clients/DH.aspx?Id=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 8 Then
                            SubsURL = BaseURL & "/RCC/Clients/SSL.aspx?Id=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 10 Then
                            SubsURL = BaseURL & "/RCC/Clients/Domain.aspx?Id=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 14 Then
                            SubsURL = BaseURL & "/RCC/Clients/CRM.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 16 Then
                            SubsURL = BaseURL & "/RCC/Clients/ExH.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 3 Then
                            SubsURL = BaseURL & "/RCC/Clients/AD.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 17 Then
                            SubsURL = BaseURL & "/RCC/Clients/SP.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 18 Then
                            SubsURL = BaseURL & "/RCC/Clients/OCS.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 19 Then
                            SubsURL = BaseURL & "/RCC/Clients/VPS.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 21 Then
                            SubsURL = BaseURL & "/RCC/O365/O365Sub.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 22 Then
                            SubsURL = BaseURL & "/RCC/RDS/Manage.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 23 Then
                            SubsURL = BaseURL & "/RCC/Clients/WFH.aspx?SubId=" & Param.Split("|")(0)
                        ElseIf PackageTypeID = 24 Then
                            SubsURL = BaseURL & "/RCC/Clients/SIP.aspx?SubId=" & Param.Split("|")(0)
                        End If
                        DRow("Description") = "<div class='menu-info' style='width: 100%; padding-right:6px;'<h4><a class='text no-padding' href='" & SubsURL & "' >" & Description & notificationBadge & "</a></h4><p>" & TimeEllapsed & "</p></div>"
                    Else
                        'skip and go to next row
                        Continue For
                    End If
                End If
                DRow("Success") = Success
                DT.Rows.Add(DRow)

                'Display top 10 Records only
                DisplayCount = DisplayCount + 1
                If DisplayCount >= 10 Then
                    Exit For
                End If
            Next
            DSet.Tables.Add(DT)
        Catch ex As Exception
            Success = 0
            MachSol.MachPanel.Utility.Utility.LogEvent(LogFile, "0", "0", "SynchAlertOperations", Nothing, Nothing, "Error in syncing alerts operations in service. Details = " & ex.Message, DoLogging)
            Throw ex
        End Try
        Return DSet.GetXml()
    End Function

End Class
