Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports Plumtree.Remote.PRC
Imports Plumtree.Remote.PRC.Collaboration
Imports Plumtree.Remote.PRC.Collaboration.Project
Imports Plumtree.Remote.Portlet

Public Class ProjectSample
    Inherits System.Web.UI.Page

    'booleans for create, remove and search
    Public create As Boolean = False
    Public remove As Boolean = False
    Public search As Boolean = False

    'optional name and description for create
    Public name As String = Nothing
    Public description As String = Nothing

    'project id required for remove
    Public strProjectID As String = Nothing
    Public projectID As Integer = -1

    'search text required for search
    Public searchText As String = Nothing

    'gets the project manager
    Public Function GetProjectManager(ByVal req As HttpRequest, ByVal res As HttpResponse) As IProjectManager
        Dim projectManager As IProjectManager = Nothing
        Dim portletContext As IPortletContext = PortletContextFactory.CreatePortletContext(req, res)
        Dim portletRequest As IPortletRequest = portletContext.GetRequest()
        Dim loginToken As String = portletRequest.GetLoginToken()
        If loginToken Is Nothing Then
            res.Write("Unable to retrieve the login token. Confirm that the login token has been checked in the Advanced Settings page of the Web Service.")
        End If
        'get the remote session
        Dim portalSession As Plumtree.Remote.PRC.IRemoteSession = portletContext.GetRemotePortalSession()

        'get a collab factory and a project manager
        Dim collabFactory As ICollaborationFactory = portalSession.GetCollaborationFactory()
        projectManager = collabFactory.GetProjectManager()

        Return projectManager
    End Function
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Request.Params.Get("startPage")

        Dim selectStr As String = Request.Params.Get("projectMethod")
        If Not selectStr Is Nothing Then
            If selectStr.Equals("create") Then
                create = True
            ElseIf selectStr.Equals("remove") Then
                remove = True
            ElseIf selectStr.Equals("search") Then
                search = True
            End If
        End If
        'if any of these is true, set hosted display mode
        If create Or remove Or search Then
            Dim portletContext As IPortletContext = PortletContextFactory.CreatePortletContext(Request, Response)
            Dim portletResponse As IPortletResponse = portletContext.GetResponse()
            portletResponse.SetHostedDisplayMode(HostedDisplayMode.Hosted)
        End If
        'see if we have a project id- if so, convert it to an int.
        strProjectID = Request.Params.Get("projectID")
        If Not strProjectID Is Nothing Then
            projectID = Int32.Parse(strProjectID)
        End If
        name = Request.Params.Get("name")
        description = Request.Params.Get("description")
        searchText = Request.Params.Get("searchText")
    End Sub

End Class
