Exemplo n.º 1
0
        public static IntTag[] GetLSResourceTags(string guid)
        {
            List<IntTag> tags = new List<IntTag>();
            //create a connection
            DbConnection connection = FactoryDB.GetConnection();
            //create a command
            DbCommand cmd = FactoryDB.CreateCommand("Resource_GetTagsByGuid", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            //populate the parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd, "@guid", guid, DbType.AnsiString, 50));

            // execute the command
            try
            {
                connection.Open();
                DbDataReader dataReader = null;
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    IntTag tag = new IntTag();
                    tag.id = dataReader.GetInt32(0);
                    tag.tag = dataReader.GetString(1);
                    tags.Add(tag);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception thrown in add permitted experiment", ex);
            }
            finally
            {
                connection.Close();
            }
            return tags.ToArray();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return the ProcessAgent Tag, with type, for the specified processAgentID.
        /// </summary>
        /// <param name="paIds"></param>
        /// <returns></returns>
        public IntTag GetProcessAgentTagWithType(int paId)
        {
            IntTag tag = null;
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();
            DbCommand cmd = connection.CreateCommand();
            cmd.CommandText = "GetProcessAgentTagsWithTypeById";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd, "@agentID", paId, DbType.AnsiString, 50));

            DbDataReader dataReader = null;
            try
            {
                    // execute the command
                    connection.Open();
                    dataReader = cmd.ExecuteReader();
                    while (dataReader.Read())
                    {
                        tag = new IntTag();
                        tag.id = dataReader.GetInt32(0);
                        tag.tag = dataReader.GetString(1) + ": " + dataReader.GetString(2);

                    }
                    dataReader.Close();
            }
            catch (DbException)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }
            return tag;
        }
Exemplo n.º 3
0
        public static IntTag[] GetLSResourceTags()
        {
            List<IntTag> tags = new List<IntTag>();
            //create a connection
            DbConnection connection = FactoryDB.GetConnection();
            //create a command
            DbCommand cmd = FactoryDB.CreateCommand("Resource_GetTags", connection);
            cmd.CommandType = CommandType.StoredProcedure;

            // execute the command
            try
            {
                connection.Open();
               DbDataReader dataReader = null;
                    dataReader=cmd.ExecuteReader();
                    while (dataReader.Read())
                    {
                        IntTag tag = new IntTag();
                        tag.id = dataReader.GetInt32(0);
                        tag.tag = dataReader.GetString(1);
                        tags.Add(tag);
                    }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception thrown in GetResourceTags", ex);
            }
            finally
            {
                connection.Close();
            }
            return tags.ToArray();
        }
Exemplo n.º 4
0
        /// <summary>
        /// This examines the specified parameters to resove the next action.
        /// This may only be called after a user is Authenticated.
        /// </summary>
        public IntTag ResolveAction(int clientID, int  userID, int groupID, DateTime start, long duration, bool autoStart)
        {
            int user_ID = -1;
                    int group_ID = -1;
                    int client_ID = -1;
                    string groupName;
                    IntTag result = new IntTag(-1,"Access Denied");
                    StringBuilder buf = new StringBuilder();
                    int[] userGroups = AdministrativeAPI.ListGroupIDsForUserRecursively(userID);
                    if (groupID > 0)
                    {
                            if (AdministrativeAPI.IsUserMember(groupID, userID))
                            {
                                group_ID = groupID;
                            }
                            else
                            {
                                // user is not a member of the group
                                result.tag = "The user is not a member of the requested group!";
                                return result;
                            }

                    }
                    else
                    {
                        result.tag = "You must specifiy a group name!";
                        return result;
                    }

                    // parameters are parsed, do we have enough info to launch
                    int[] clientGroupIDs = null;
                    int[] userGroupIDs = null;

                    // Try and resolve any unspecified parameters
                    if (client_ID <= 0 && group_ID <= 0)
                    {
                        userGroupIDs = AdministrativeAPI.ListGroupIDsForUserRecursively(user_ID);
                        Group[] groups = AdministrativeAPI.GetGroups(userGroupIDs);
                        Dictionary<int, int[]> clientMap = new Dictionary<int, int[]>();
                        foreach (Group g in groups)
                        {
                            if ((g.groupType.CompareTo(GroupType.REGULAR) == 0) )
                            {
                                int[] clientIDs = AdministrativeUtilities.GetGroupLabClients(g.groupID);
                                if (clientIDs != null & clientIDs.Length > 0)
                                {
                                    clientMap.Add(g.groupID, clientIDs);
                                }
                            }
                        }
                        if (clientMap.Count > 1) //more than one group with clients
                        {
                            //modifyUserSession(group_ID, client_ID);
                            buf.Append("myGroups.aspx");
                        }
                        else if (clientMap.Count == 1) // get the group with clients
                        {
                            Dictionary<int, int[]>.Enumerator en = clientMap.GetEnumerator();
                            int gid = -1;
                            int[] clients = null;
                            while (en.MoveNext())
                            {
                                gid = en.Current.Key;
                                clients = en.Current.Value;
                            }
                            if (AdministrativeAPI.IsUserMember(gid, user_ID))
                            {
                                group_ID = gid;
                                groupName = AdministrativeAPI.GetGroupName(gid);

                                if (clients == null || clients.Length > 1)
                                {
                                   // modifyUserSession(group_ID, client_ID);
                                    buf.Append("myLabs.aspx");
                                }
                                else
                                {
                                    client_ID = clients[0];
                                }
                            }
                        }
                    }

                    else if (client_ID > 0 && group_ID <= 0)
                    {
                        int gid = -1;
                        clientGroupIDs = AdministrativeUtilities.GetLabClientGroups(client_ID);
                        if (clientGroupIDs == null || clientGroupIDs.Length == 0)
                        {
                            //modifyUserSession(group_ID, client_ID);
                            buf.Append("myGroups.aspx");
                        }
                        else if (clientGroupIDs.Length == 1)
                        {
                            gid = clientGroupIDs[0];
                        }
                        else
                        {
                            userGroupIDs = AdministrativeAPI.ListParentGroupsForGroupRecursively(user_ID);
                            int count = 0;
                            foreach (int ci in clientGroupIDs)
                            {
                                foreach (int ui in userGroupIDs)
                                {
                                    if (ci == ui)
                                    {
                                        count++;
                                        gid = ui;
                                    }
                                }
                            }
                            if (count != 1)
                            {
                                gid = -1;
                            }
                        }
                        if (gid > 0 && AdministrativeAPI.IsUserMember(gid, user_ID))
                        {
                            group_ID = gid;

                        }
                        else
                        {
                            //modifyUserSession(group_ID, client_ID);
                        }
                    }
                    else if (client_ID <= 0 && group_ID > 0)
                    {
                        int[] clients = AdministrativeUtilities.GetGroupLabClients(group_ID);
                        if (clients == null || clients.Length != 1)
                        {
                            //modifyUserSession(group_ID, client_ID);
                            buf.Append("myLabs.aspx");
                        }
                        else
                        {
                            client_ID = clients[0];
                        }
                    }
                    if (user_ID > 0 && group_ID > 0 && client_ID > 0)
                    {
                        int gid = -1;
                        clientGroupIDs = AdministrativeUtilities.GetLabClientGroups(client_ID);
                        foreach (int g_id in clientGroupIDs)
                        {
                            if (g_id == group_ID)
                            {
                                gid = g_id;
                                break;
                            }
                        }
                        if (gid == -1)
                        {
                            result.tag = "The specified group does not have permission to to run the specified client!";
                            return result;
                        }
                        if (!AdministrativeAPI.IsUserMember(group_ID, user_ID))
                        {
                            result.tag = "The user does not have permission to to run the specified client!";
                            return result;
                        }

                        // is authorized ?

                        //modifyUserSession(group_ID, client_ID);
                        //launchLab(user_ID, group_ID, client_ID, duration, autoStart);
                        result.id = 1;
                        return result;

                    }
                    return result;
        }
Exemplo n.º 5
0
Arquivo: LabDB.cs Projeto: tordf/iLabs
        public IntTag[] GetLabAppTags()
        {
            ArrayList list = new ArrayList();
            DbConnection connection = FactoryDB.GetConnection();

               // create sql command
            DbCommand cmd = FactoryDB.CreateCommand("GetLabAppTags", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            DbDataReader dataReader = null;
            try
            {
                connection.Open();
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    IntTag tag = new IntTag();
                    tag.id = dataReader.GetInt32(0);
                    tag.tag = dataReader.GetString(1);
                    list.Add(tag);
                }
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally{
                connection.Close();
            }
            IntTag temp = new IntTag();
            return  ( IntTag[]) list.ToArray(temp.GetType());
        }
Exemplo n.º 6
0
        /*
                private IntTag launchLabClient(int c_id, int u_id, int g_id, DateTime startEx, long dur)
                {
                    bool addReturn = true;
                    IntTag results = new IntTag(-1, "Access Denied");
                    StringBuilder message = new StringBuilder();
                    LabClient client = AdministrativeAPI.GetLabClient(c_id);
                    if (client != null)
                    {
                        string effectiveGroupName = null;
                        int effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(g_id, c_id,
                            Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType);
                        if (effectiveGroupID >0)
                        {
                            effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID);
                        }

                        // [GeneralTicketing] get lab servers metadata from lab server ids
                        ProcessAgentInfo labServer = GetClientLabServer(client.clientID, effectiveGroupID);
                        if (labServer != null)
                        {
                            TicketLoadFactory factory = TicketLoadFactory.Instance();
                            // 1. Create Coupon for ExperimentCollection
                            Coupon coupon = CreateCoupon();

                            iLabProperties properties = new iLabProperties();
                            properties.Add("sb", ProcessAgentDB.ServiceAgent);
                            properties.Add("ls", labServer);
                            properties.Add("op", coupon);

                            //Session["ClientID"] = client.clientID;

                            DateTime start = DateTime.UtcNow;
                            long duration = -1L; // default is never timeout

                            //Check for Scheduling:
                            //The scheduling Ticket should exist and been parsed into the session
                            if (client.needsScheduling)
                            {
                                start = startEx;
                                duration = dur;
                            }

                            //payload includes username and current group name & client id.
                            string sessionPayload = factory.createRedeemSessionPayload(u_id, g_id,
                                       client.clientID, (string)Session["UserName"], (string)Session["GroupName"]);
                            // SB is the redeemer, ticket type : session_identifcation, no expiration time, payload,SB as sponsor ID, redeemer(SB) coupon
                            Ticket sessionTicket = AddTicket(coupon, TicketTypes.REDEEM_SESSION, ProcessAgentDB.ServiceGuid,
                                         ProcessAgentDB.ServiceGuid, duration, sessionPayload);

                            AdministrativeAPI.ModifyUserSession(Convert.ToInt64(Session["SessionID"]), g_id, client.clientID, Session.SessionID);

                            if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                            {
                                // execute the "experiment execution recipe
                                RecipeExecutor executor = RecipeExecutor.Instance();
                                string redirectURL = null;

                                // loaderScript not parsed in Recipe
                                redirectURL = executor.ExecuteExperimentExecutionRecipe(coupon, labServer, client,
                                 start, duration, Convert.ToInt32(Session["UserTZ"]), u_id,
                                 effectiveGroupID, effectiveGroupName);

                                // Add the return url to the redirect
                                if(addReturn){
                                    if (redirectURL.IndexOf("?") == -1)
                                        redirectURL += "?";
                                    else
                                        redirectURL += "&";
                                    redirectURL += "sb_url=" + Utilities.ExportUrlPath(Request.Url);
                                }
                                // Parse & check that the default auth tokens are added
                                string tmpUrl = iLabParser.Parse(redirectURL, properties, true);

                                // Now open the lab within the current Window/frame
                                //Response.Redirect(tmpUrl, true);
                                results.id = 1;
                                results.tag = tmpUrl;
                                return results;
                            }

                            else if (client.clientType == LabClient.INTERACTIVE_APPLET)
                            {

                                // Note: Currently Interactive applets
                                // use the Loader script for Batch experiments
                                // Applets do not use default query string parameters, parametes must be in the loader script
                                Session["LoaderScript"] = iLabParser.Parse(client.loaderScript, properties);
                                Session.Remove("RedirectURL");

                                string jScript = @"<script language='javascript'>parent.theapplet.location.href = '"
                                    + "applet.aspx" + @"'</script>";
                                Page.RegisterStartupScript("ReloadFrame", jScript);
                            }

                            // Support for Batch 6.1 Lab Clients
                            else if (client.clientType == LabClient.BATCH_HTML_REDIRECT)
                            {
                                // use the Loader script for Batch experiments

                                //use ticketing & redirect to url in loader script

                                // [GeneralTicketing] retrieve static process agent corresponding to the first
                                // association lab server

                                // New comments: The HTML Client is not a static process agent, so we don't search for that at the moment.
                                // Presumably when the interactive SB is merged with the batched, this should check for a static process agent.
                                // - CV, 7/22/05
                                {
                                    Session.Remove("LoaderScript");

                                    // This is the original batch-redirect using a pop-up
                                    // check that the default auth tokens are added
                                    string jScript = @"<script language='javascript'> window.open ('" + iLabParser.Parse(client.loaderScript, properties, true) + "')</script>";
                                    Page.RegisterStartupScript("HTML Client", jScript);

                                    // This is the batch-redirect with a simple redirect, this may not work as we need to preserve session-state
                                    //string redirectURL = lc.loaderScript + "?couponID=" + coupon.couponId + "&passkey=" + coupon.passkey;
                                    //Response.Redirect(redirectURL,true);
                                }
                            }
                            // use the Loader script for Batch experiments
                            else if (client.clientType == LabClient.BATCH_APPLET)
                            {
                                // Do not append defaults
                                Session["LoaderScript"] = iLabParser.Parse(client.loaderScript, properties);
                                Session.Remove("RedirectURL");

                                string jScript = @"<script language='javascript'>parent.theapplet.location.href = '"
                                    + ProcessAgentDB.ServiceAgent.codeBaseUrl + @"/applet.aspx" + @"'</script>";
                                ClientScript.RegisterClientScriptBlock(this.GetType(), "ReloadFrame", jScript);
                            }
                        } // labserver != null
                    }
                    else
                    {
                        message.Append(" LabServer = null");
                    }

                    return results;
                }
        */
        public IntTag launchLab(int userID, int groupID, int clientID, long duration, bool autoLaunch)
        {
            // Currently there is not a good solution for checking for an AllowExperiment ticket, will check the USS for reservation
            IntTag results = new IntTag();
            StringBuilder buf = new StringBuilder();
            buf.Append("myClient.aspx");
            if(autoLaunch)
                buf.Append("?auto=t");

            string userName = null;
            string groupName = null;
            Coupon opCoupon = null;
            Ticket allowTicket = null;
            int effectiveGroupID = 0;

            userName = AdministrativeAPI.GetUserName(userID);

            LabClient client = AdministrativeAPI.GetLabClient(clientID);
            if (client != null && client.clientID > 0) // need to test for valid value
            {
                DateTime start = DateTime.UtcNow;
                long _duration = 36000L; // default is ten hours
                ProcessAgentInfo[] labServers = null;
                labServers = AdministrativeAPI.GetLabServersForClient(clientID);
                if (labServers.Length > 0)
                {
                    //labServer = labServers[0];
                }
                else
                {
                    throw new Exception("The lab server is not specified for lab client " + client.clientName + " version: " + client.version);
                }
                groupName = AdministrativeAPI.GetGroupName(groupID);
                // Find efective group
                string effectiveGroupName = null;
                effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID,
                    Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType);
                if (effectiveGroupID == groupID)
                {
                        effectiveGroupName = groupName;
                }
                else if (effectiveGroupID > 0)
                {
                    effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID);
                }

                //Check for Scheduling: Moved to myClient

                //Session["ClientID"] = client.clientID;
                //Response.Redirect(Global.FormatRegularURL(Request, "myClient.aspx"), true);
                //Response.Redirect(buf.ToString(), true);
                results.id = 1;
                results.tag = buf.ToString();
            } // End if valid client
            else
            {
                throw new Exception("The specified lab client could not be found");
            }
            return results;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Should handle all requests to launch a lab, produces a releative URL or error message 
        /// and a status code which are returned in the IntTag. This does not make use of the 'Context'.
        /// This should only be called after the original request has been authorized since the
        /// user is assummed to have been authenticated and authorized.
        /// </summary>
        /// <param name="opCoupon">An initial operationCoupon</param>
        /// <param name="clientID"></param>
        /// <param name="labServerID"></param>
        /// <param name="groupID">specified by SCO, may not be the users group</param>
        /// <param name="userID"></param>
        /// <returns>A negative value for errrors or a bitmapped value indicating what should be done with the result.tag</returns>
        public IntTag ProcessLaunchClientRequest(Coupon opCoupon, int clientID, int labServerID,
            int groupID, int userID, int userTZ //, string authorityUrl, long duration, int autoStart
            )
        {
            int effectiveGroupID = -1;
            int userGroupID = -1;
            string groupName = null;
            string effectiveGroupName = null;
            string userName = null;
            DateTime startExecution =DateTime.MinValue;
            long duration = -1L;

            ProcessAgentInfo labServer = null;
            StringBuilder buf = new StringBuilder();
            LabClient client = AdministrativeAPI.GetLabClient(clientID);
            iLabParser parser = new iLabParser();
            IntTag result = new IntTag(-1, "Access Denied");

            if (client == null)
            {
               result.tag = "LabClient was not found";
               return result;
            }
            userName = AdministrativeAPI.GetUserName(userID);
            if(String.IsNullOrEmpty(userName)){
                result.tag = "User was not found";
                return result;
            }
            // Check if user is a member of the specified group
            List<int> allGroups = new List<int>(AdministrativeAPI.ListGroupIDsForUserRecursively(userID));
            if(!allGroups.Contains(groupID)){
                result.tag = "User does not have access to the specified group";
                return result;
            }
            //TODO
            int qualID = AuthorizationAPI.GetQualifierID(clientID, Qualifier.labClientQualifierTypeID);
            int[] clientGroups = AuthorizationAPI.FindGrants(-1, Function.useLabClientFunctionType, qualID);
            // Find the users actual group and run as that group

            List<int> userGroups = new List<int>(AdministrativeAPI.ListGroupIDsForUser(userID));
            if (userGroups.Count == 1)
            {
                groupName = AdministrativeAPI.GetGroupName(userGroups[0]);
            }
            else if (userGroups.Count > 1)
            {

            }
            //TODO This does not seem to be working
            effectiveGroupID = AuthorizationAPI.GetEffectiveGroupID(groupID, clientID,
               Qualifier.labClientQualifierTypeID, Function.useLabClientFunctionType);
            if (effectiveGroupID == groupID)
            {
                effectiveGroupName = groupName;
            }
            else if (effectiveGroupID > 0)
            {
                effectiveGroupName = AdministrativeAPI.GetGroupName(effectiveGroupID);
            }

            ProcessAgentInfo[] paInfos = AdministrativeAPI.GetLabServersForClient(clientID);
            if (paInfos != null && paInfos.Length > 0)
            {
                labServer = paInfos[0];
            }

            if (client.needsScheduling)
            {
                  Ticket allowExperimentExecutionTicket = null;
                        if (opCoupon != null)
                        {
                            // First check for an Allow Execution Ticket
                            allowExperimentExecutionTicket = RetrieveTicket(
                                opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION);
                        }
                        if (allowExperimentExecutionTicket == null)
                        {
                            // Try for a reservation
                            int ussId = FindProcessAgentIdForClient(client.clientID, ProcessAgentType.SCHEDULING_SERVER);
                            if (ussId > 0)
                            {
                                ProcessAgent uss = GetProcessAgent(ussId);
                                // check for current reservation

                                //create a collection & redeemTicket
                                string redeemPayload = TicketLoadFactory.Instance().createRedeemReservationPayload(DateTime.UtcNow,
                                    DateTime.UtcNow, userName, userID,
                                    groupName, client.clientGuid);

                                 Coupon redeemCoupon = CreateCoupon();

                                AddTicket(redeemCoupon, TicketTypes.REDEEM_RESERVATION, uss.agentGuid,
                                    ProcessAgentDB.ServiceGuid, 600, redeemPayload);

                                UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                                OperationAuthHeader op = new OperationAuthHeader();
                                op.coupon = redeemCoupon;
                                ussProxy.Url = uss.webServiceUrl;
                                ussProxy.OperationAuthHeaderValue = op;
                                Reservation reservation = ussProxy.RedeemReservation(ProcessAgentDB.ServiceGuid,
                                    userName, labServer.agentGuid, client.clientGuid);
                                if (reservation != null)
                                {

                                    // create the allowExecution Ticket
                                    DateTime start = reservation.Start;
                                    duration = reservation.Duration;
                                    string payload = TicketLoadFactory.Instance().createAllowExperimentExecutionPayload(
                                        start, duration, effectiveGroupName,client.clientGuid);
                                    DateTime tmpTime = start.AddTicks(duration * TimeSpan.TicksPerSecond);
                                    DateTime utcNow = DateTime.UtcNow;
                                    long ticketDuration = (tmpTime.Ticks - utcNow.Ticks) / TimeSpan.TicksPerSecond;
                                    allowExperimentExecutionTicket = AddTicket(opCoupon, TicketTypes.ALLOW_EXPERIMENT_EXECUTION,
                                            ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, ticketDuration, payload);
                                }
                            }
                        }
                        if (allowExperimentExecutionTicket != null)
                        {
                            XmlDocument payload = new XmlDocument();
                            payload.LoadXml(allowExperimentExecutionTicket.payload);
                            startExecution = DateUtil.ParseUtc(payload.GetElementsByTagName("startExecution")[0].InnerText);
                            duration = Int64.Parse(payload.GetElementsByTagName("duration")[0].InnerText);
                        }
                        else{ // No current scheduled reservations
                            result.id = -8;
                            result.tag = "Go to USS";
                            return result;
                        }

            }
            else // Not Scheduled
            {
            }
                ///////////////////////////

                if (labServer != null)
                {
                    if (client.IsReentrant)
                    {
                        long[] ids = InternalDataDB.RetrieveActiveExperimentIDs(userID,
                                       effectiveGroupID, labServer.agentId,client.clientID);
                        foreach (long id in ids)
                        {
                            InternalDataDB.CloseExperiment(id, StorageStatus.CLOSED_USER);
                        }
                    }
                    TicketLoadFactory factory = TicketLoadFactory.Instance();
                    // 1. Create Coupon for ExperimentCollection
                    Coupon expCoupon = CreateCoupon();

                    iLabProperties properties = new iLabProperties();
                    properties.Add("sb", ProcessAgentDB.ServiceAgent);
                    properties.Add("ls", labServer);
                    properties.Add("op", expCoupon);

                    DateTime start = DateTime.UtcNow;
                    duration = 7L * 24L * 60L * 60L; // default is one week
                     RecipeExecutor executor = null;
                    string redirectURL = null;

                    //Create a redeemSession ticket for the experiment
                    //payload includes username and current group name & client id.
                    string sessionPayload = factory.createRedeemSessionPayload(userID, groupID,
                               clientID, userName, groupName);
                    // SB is the redeemer, ticket type : session_identifcation, no expiration time, payload,SB as sponsor ID, redeemer(SB) coupon
                    AddTicket(expCoupon, TicketTypes.REDEEM_SESSION, ProcessAgentDB.ServiceGuid,
                                  ProcessAgentDB.ServiceGuid, duration, sessionPayload);

                   // AdministrativeAPI.ModifyUserSession(Convert.ToInt64(Session["SessionID"]), groupID, clientID, Session.SessionID);

                    if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT)
                    {
                        // execute the "interactive experiment execution recipe
                        executor = RecipeExecutor.Instance();

                        // loaderScript not parsed in Recipe
                        redirectURL = executor.ExecuteExperimentExecutionRecipe(expCoupon, labServer, client,
                         start, duration, userTZ, userID,
                         effectiveGroupID, effectiveGroupName);
                        //Do not add the returnURL

                        // Parse & check that the default auth tokens are added
                        result.tag = parser.Parse(redirectURL, properties, true);
                        result.id = LabClient.INTERACTIVE_BIT | LabClient.REDIRECT_BIT;
                    }

                    else if (client.clientType == LabClient.INTERACTIVE_APPLET)
                    {
                          // execute the "interactive experiment execution recipe
                        executor = RecipeExecutor.Instance();

                        // loaderScript not parsed in Recipe
                        redirectURL = executor.ExecuteExperimentExecutionRecipe(expCoupon, labServer, client,
                         start, duration, userTZ, userID,
                         effectiveGroupID, effectiveGroupName);
                        // Applets do not use default query string parameters, parameters must be in the loader script
                        result.tag = parser.Parse(redirectURL, properties);
                        result.id = LabClient.INTERACTIVE_BIT | LabClient.APPLET_BIT;

                        //string jScript = @"<script language='javascript'>parent.theapplet.location.href = '"
                        //    + "applet.aspx" + @"'</script>";
                        //Page.RegisterStartupScript("ReloadFrame", jScript);
                    }

                    // Support for Batch 6.1 Lab Clients
                    else if (client.clientType == LabClient.BATCH_HTML_REDIRECT)
                    {
                        // use the Loader script for Batch experiments, for now check for default properties
                        result.tag = parser.Parse(client.loaderScript, properties,true);
                        result.id = LabClient.BATCH_BIT | LabClient.REDIRECT_BIT;
                    }
                    // use the Loader script for Batch experiments
                    else if (client.clientType == LabClient.BATCH_APPLET)
                    {
                        // Do not append defaults
                        result.tag = parser.Parse(client.loaderScript, properties);
                        result.id = LabClient.BATCH_BIT | LabClient.APPLET_BIT;
                    }
                } // labserver != null
                else
                {
                    buf.Append(" LabServer = null");
                }

            Logger.WriteLine(buf.ToString());

            ////////////////
            return result;
        }
Exemplo n.º 8
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (Request.Params["paguid"] != null)
            {
                string paGuid = Request.Params["paguid"];
                ProcessAgentDB ticketing = new ProcessAgentDB();
                paTag = ticketing.GetProcessAgentTag(paGuid);
            }

            if (!Page.IsPostBack)			// populate with all the group IDs
            {
                // populate ticket type drop down
                PopulateTicketTypeDropDown();

                refreshUrlRepeater();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Generic get IntTag
        /// </summary>
        /// <param name="procedure">The string name of the procedure to call</param>
        /// <param name="param">an optional prarameter, with the value set, null for no parameter</param>
        /// <returns></returns>
        public IntTag GetIntTag2(String procedure, DbParameter param)
        {
            IntTag tag = null;
            DbConnection connection = FactoryDB.GetConnection();

            DbCommand cmd = FactoryDB.CreateCommand(procedure, connection);
            cmd.CommandType = CommandType.StoredProcedure;
            if (param != null)
            {
                cmd.Parameters.Add(param);
            }
            try
            {
                connection.Open();
                DbDataReader dataReader = cmd.ExecuteReader();
                if (dataReader.HasRows)
                {
                    tag = new IntTag();
                    while (dataReader.Read())
                    {
                        tag.id = dataReader.GetInt32(0);
                        tag.tag = dataReader.GetString(1) + ": " + dataReader.GetString(2);

                    }
                }
                dataReader.Close();
            }
            catch (DbException e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                // close the sql connection
                connection.Close();
            }
            return tag;
        }
Exemplo n.º 10
0
 private List<IntTag> ParseReservationTags(DbDataReader dataReader, CultureInfo culture, int userTZ)
 {
     string temp = culture.DateTimeFormat.ShortDatePattern;
     if (temp.Contains("MM"))
         ;
     else
         temp = temp.Replace("M", "MM");
     if (temp.Contains("dd"))
         ;
     else
         temp = temp.Replace("d", "dd");
     string dateF = temp + " HH" + culture.DateTimeFormat.TimeSeparator + "mm";
     List<IntTag> tags = new List<IntTag>();
     while (dataReader.Read())
     {
         //t R.Reservation_Info_ID,R.Start_Time, R.End_Time, E.Lab_Client_Name, C.Group_Name,C.Service_Broker_Name
         IntTag t = new IntTag();
         StringBuilder buf = new StringBuilder();
         t.id = dataReader.GetInt32(0);
         buf.Append(DateUtil.ToUserTime(DateUtil.SpecifyUTC(dataReader.GetDateTime(1)), culture, userTZ, dateF) + " - ");
         buf.Append(DateUtil.ToUserTime(DateUtil.SpecifyUTC(dataReader.GetDateTime(2)), culture, userTZ, dateF) + " ");
         buf.Append(dataReader.GetString(3) + " ");
         buf.Append(dataReader.GetString(4) + ":");
         buf.Append(dataReader.GetString(5));
         //buf.Append(" " +dataReader.GetInt32(6));
         t.tag = buf.ToString();
         tags.Add(t);
     }
     return tags;
 }
Exemplo n.º 11
0
        public static IntTag[] SelectLabClientTags()
        {
            List<IntTag> clients = new List<IntTag>();
            DbConnection myConnection = FactoryDB.GetConnection();
            DbCommand myCommand = FactoryDB.CreateCommand("Client_RetrieveTags", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;

            try
            {
                myConnection.Open();

                // get labclient ids from table lab_clients
                DbDataReader myReader = myCommand.ExecuteReader();
                while (myReader.Read())
                {
                    IntTag tag = new IntTag();
                    tag.id = myReader.GetInt32(0);
                    if (!myReader.IsDBNull(1))
                    {
                        tag.tag = myReader.GetString(1);
                    }
                    clients.Add(tag);
                }
                myReader.Close();

            }
            catch (Exception ex)
            {
                throw new Exception("Exception thrown SelectLabClientTagss", ex);
            }
            finally
            {
                myConnection.Close();
            }
            clients.Sort();
            return clients.ToArray();
        }
        public IntTag ModifyUser(string userName, string authorityKey, string firstName, string lastName,
            string email, string affiliation, bool autoCreate)
        {
            IntTag tag = new IntTag(-1,"User Not Found");
            int authID = 0;
            int userID = -1;
            Authority auth = brokerDB.AuthorityRetrieve(authorityKey);
            if (auth != null)
            {

                userID = AdministrativeAPI.GetUserID(userName, auth.authorityID);
                if (userID > 0)
                {
                    User user = AdministrativeAPI.GetUser(userID);
                    if (user != null)
                    {
                        string fName = user.firstName;
                        string lName = user.lastName;
                        string eMail = user.email;
                        string affil = user.affiliation;
                        if (firstName != null && firstName.Length > 0)
                            fName = firstName;
                        if (lastName != null && lastName.Length > 0)
                            lName = firstName;
                        if (email != null && email.Length > 0)
                            eMail = email;
                        if (affiliation != null && affiliation.Length > 0)
                            affil = affiliation;
                        try
                        {
                            AdministrativeAPI.ModifyUser(userID, userName, auth.authorityID, auth.authTypeID, fName, lName, eMail, affil, user.reason, user.xmlExtension, false);
                        }
                        catch
                        {
                            tag.tag = "Error Updating User";
                        }
                        tag.id = 0;
                        tag.tag = "User Updated";
                    }
                }
                else
                {
                    if (autoCreate)
                    {
                        int newID = AdministrativeAPI.AddUser(userName, auth.authorityID, auth.authTypeID, firstName, lastName, email,
                            auth.authName, null, null, auth.defaultGroupID, false);
                        if (newID > 0)
                        {
                            tag.id = 1;
                            tag.tag = "User Created";
                        }
                    }
                }
            }
            return tag;
        }
        public IntTag LaunchLabClient(string clientGuid, string groupName,
            string userName, string authorityKey, DateTime start, long duration)
        {
            IntTag result = new IntTag(-1, "");
            StringBuilder buf = new StringBuilder("LaunchClient Called: ");
            int userID = -1;
            int clientID = -1;
            int groupID = -1;
            Authority authority = null;
            try
            {
                Ticket clientAuthTicket = null;

                // Need to check opHeader
                if (opHeader != null && opHeader.coupon != null)
                {
                    buf.AppendLine("found opHeader");
                    authority = brokerDB.AuthorityRetrieve(authorityKey);
                    if (authority != null)
                        buf.AppendLine("authority: " + authority.authName);
                    // Coupon is from the client SCORM
                    clientAuthTicket = brokerDB.RetrieveIssuedTicket(opHeader.coupon,
                        TicketTypes.AUTHORIZE_CLIENT, ProcessAgentDB.ServiceGuid);
                    if (authority == null || clientAuthTicket == null)
                    {
                         result.tag = buf.ToString();
                        return result;
                    }
                    if (!clientAuthTicket.IsExpired() && !clientAuthTicket.isCancelled)
                    {
                        XmlQueryDoc xDoc = new XmlQueryDoc(clientAuthTicket.payload);
                        string cGuid = xDoc.Query("AuthorizeClientPayload/clientGuid");
                        string gName = xDoc.Query("AuthorizeClientPayload/groupName");
                        buf.AppendLine("AuthGroup: " + gName);
                        if ((cGuid.CompareTo(clientGuid) == 0) && (gName.CompareTo(groupName) == 0))
                        {
                            userID = AdministrativeAPI.GetUserID(userName, authority.authorityID);
                            if (userID <= 0)
                            { //User does not exist
                                buf.AppendLine("user: "******" doesnot exist");
                                //Check if Authority has a default group
                                if (authority.defaultGroupID > 0)
                                {
                                    //Should try & Query Authority for more information
                                    string firstName = null;
                                    string lastName = null;
                                    string email = null;
                                    string reason = null;
                                    userID = AdministrativeAPI.AddUser(userName, authority.authorityID, authority.authTypeID,
                                        firstName, lastName, email, authority.authName, reason, null, authority.defaultGroupID, false);
                                }
                            }
                            if (userID > 0)
                            {
                                buf.AppendLine("found userID: " + userID);
                                if (cGuid != null && clientGuid != null && cGuid.Length > 0 && (cGuid.CompareTo(clientGuid) == 0))
                                {
                                    clientID = AdministrativeAPI.GetLabClientID(clientGuid);
                                    buf.AppendLine("ClientID: " +clientID);
                                }
                                else
                                {
                                    result.tag = buf.ToString();
                                    return result;
                                }
                                if (gName != null && groupName != null && gName.Length > 0 && (gName.CompareTo(groupName) == 0))
                                {
                                    groupID = AdministrativeAPI.GetGroupID(groupName);
                                     buf.AppendLine("GroupID "+ groupID);
                                }
                                else
                                {
                                     result.tag = buf.ToString();
                                    return result;
                                }
                            }
                            else
                            { result.tag = buf.ToString();
                                return result;
                            }

                            if (userID > 0 && clientID > 0 && groupID > 0)
                            {

                                //Check for group access & User
                                //THis is the planned future need to deal with Session varables before it works
                                //result = brokerDB.ResolveAction(Context, clientID, userID, groupID, DateTime.UtcNow, duration, autoStart > 0);

                                Coupon coupon = brokerDB.CreateCoupon();
                                string ss = Utilities.RandomStr(10000);
                                TicketLoadFactory tlc = TicketLoadFactory.Instance();
                                string payload = tlc.createLaunchClientPayload(clientGuid, null, groupName, authority.authGuid, userID, userName, coupon.passkey, ss);
                                Ticket tt = brokerDB.AddTicket(coupon, TicketTypes.LAUNCH_CLIENT, ProcessAgentDB.ServiceGuid, ProcessAgentDB.ServiceGuid, 600L, payload);
                                StringBuilder urlbuf = new StringBuilder();
                                urlbuf.Append(ProcessAgentDB.ServiceAgent.codeBaseUrl);
                                urlbuf.Append("/LaunchClient.aspx?cid=" + coupon.couponId);
                                urlbuf.Append("&ss=" + ss);
                                result.id = 1;
                                result.tag = urlbuf.ToString();

                             }
                        }
                    }
                }

            }
            catch (Exception e)
            {
                result.id = -1;
                result.tag = buf.ToString() + e.Message;
            }
            Context.Response.AddHeader("Access-Control-Allow-Origin", authority.Origin);
            return result;
        }
 public IntTag GetUserStatus(string userName, string authorityKey)
 {
     IntTag tag = new IntTag(-1,"Not Found");
     int authID = 0;
     int userID = -1;
     Authority auth = brokerDB.AuthorityRetrieve(authorityKey);
     if(auth != null){
         authID = auth.authorityID;
     }
     userID = AdministrativeAPI.GetUserID(userName, authID);
     if (userID > 0)
     {
         User [] users =  AdministrativeAPI.GetUsers(new int[]{userID});
         if (users != null && users.Length > 0)
         {
             int status = 0;
             tag.tag = "User Found";
             if (users[0].firstName == null || users[0].firstName.Length == 0)
             {
                 status |= 1;
             }
             if (users[0].lastName == null || users[0].lastName.Length == 0)
             {
                 status |= 2;
             }
             if (users[0].email == null || users[0].email.Length == 0)
             {
                 status |= 4;
             }
             if (users[0].affiliation == null || users[0].affiliation.Length == 0)
             {
                 status |= 8;
             }
             tag.id = status;
         }
     }
     return tag;
 }
Exemplo n.º 15
0
        public static IntTag[] ListReservations(int expId, int credId, DateTime start, DateTime end, CultureInfo culture, int userTZ)
        {
            string temp = culture.DateTimeFormat.ShortDatePattern;
             if (temp.Contains("MM"))
                 ;
             else
                 temp = temp.Replace("M", "MM");
             if (temp.Contains("dd"))
                 ;
             else
                 temp = temp.Replace("d", "dd");
            string dateF = temp + " HH" + culture.DateTimeFormat.TimeSeparator + "mm";
            List<IntTag> tags = new List<IntTag>();
            DbConnection connection = FactoryDB.GetConnection();

            // create sql command
            // command executes the "Reserva" stored procedure
            DbCommand cmd = FactoryDB.CreateCommand("ReservationTags_Retrieve", connection);
            cmd.CommandType = CommandType.StoredProcedure;

             if(expId <1)
                 cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@expid", null, DbType.Int32));
             else
                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@expid", expId, DbType.Int32));
             if(credId < 1)
                 cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@credid", null, DbType.Int32));
             else
               cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@credid",credId, DbType.Int32));
            if(start == DateTime.MinValue)
                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@start", null, DbType.DateTime));
            else
                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@start", start, DbType.DateTime));
            if (end == DateTime.MinValue)
                 cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@end", null, DbType.DateTime));
            else
                 cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@end", end, DbType.DateTime));
            DbDataReader dataReader = null;
            try
            {
                connection.Open();
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    //t R.Reservation_Info_ID,R.Start_Time, R.End_Time, E.Lab_Client_Name, C.Group_Name,C.Service_Broker_Name
                    IntTag t = new IntTag();
                    StringBuilder buf = new StringBuilder();
                    t.id = dataReader.GetInt32(0);
                    buf.Append(DateUtil.ToUserTime( DateUtil.SpecifyUTC(dataReader.GetDateTime(1)),culture,userTZ,dateF) + " - ");
                    buf.Append(DateUtil.ToUserTime(DateUtil.SpecifyUTC(dataReader.GetDateTime(2)), culture, userTZ,dateF) + " ");
                    buf.Append(dataReader.GetString(3) + " ");
                    buf.Append(dataReader.GetString(4) + ":");
                    buf.Append(dataReader.GetString(5));
                    //buf.Append(" " +dataReader.GetInt32(6));
                    t.tag = buf.ToString();
                    tags.Add(t);
                }
            }
            catch {
                throw;
            }
            finally
            {
                connection.Close();
            }
            return tags.ToArray();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Return all processAgent tags, agentName is the tag, local processAgent ID is the id.
        /// </summary>
        /// <returns></returns>
        public IntTag[] GetProcessAgentTags()
        {
            ArrayList list = new ArrayList();
            IntTag tag = new IntTag();
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();
            try
            {
                // create sql command
                // command executes the "RetrieveTickets" stored procedure
                DbCommand cmd = connection.CreateCommand();
                cmd.CommandText = "GetProcessAgentTags";
                cmd.CommandType = CommandType.StoredProcedure;

                // execute the command
                DbDataReader dataReader = null;
                connection.Open();
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    tag = new IntTag();
                    tag.id = dataReader.GetInt32(0);
                    tag.tag = dataReader.GetString(1);
                    list.Add(tag);
                }
            }
            catch( DbException)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }
            IntTag[] info = (IntTag[])list.ToArray(tag.GetType());
            return info;
        }
Exemplo n.º 17
0
        public Hashtable GetResourceStringTags(int target, int type)
        {
            Hashtable resources = null;
            Hashtable results = null;

            DbConnection connection = FactoryDB.GetConnection();
            DbCommand cmd = FactoryDB.CreateCommand("ResourceMapTypeStrings_Retrieve", connection);
            cmd.CommandType = CommandType.StoredProcedure;

            // populate parameters

            cmd.Parameters.Add(FactoryDB.CreateParameter( "@type", type, DbType.Int32));
            cmd.Parameters.Add(FactoryDB.CreateParameter( "@target", target, DbType.Int32));

            try
            {
                connection.Open();
                DbDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    resources = new Hashtable();
                    int mid = 0;
                    while (reader.Read())
                    {
                        mid = reader.GetInt32(0);
                        resources.Add(mid, reader.GetString(1));
                    }
                    if (reader.NextResult())
                    {
                        results = new Hashtable();
                        while (reader.Read())
                        {
                            int id = reader.GetInt32(0);
                            if (resources.ContainsKey(id))
                            {
                                IntTag tag = new IntTag();
                                tag.id = reader.GetInt32(1);
                                tag.tag = reader.GetString(2);
                                results.Add(resources[id], tag);
                            }
                        }
                    }
                }
                reader.Close();
            }

            catch (Exception ex)
            {
                Logger.WriteLine(ex.Message);
                throw;
            }
            finally
            {
                connection.Close();

            }
            if (results != null && results.Count > 0)
                return results;
            else
                return null;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Returns all ProcessAgent tags for the specified typeIDs.
        /// </summary>
        /// <param name="typeIDs"></param>
        /// <returns></returns>
        public IntTag[] GetProcessAgentTagsByType(int[] typeIDs)
        {
            List<IntTag> list = new List<IntTag>();

            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();
            try
            {
                // create sql command
                // command executes the "RetrieveTickets" stored procedure
                DbCommand cmd = connection.CreateCommand();
                cmd.CommandText =  "GetProcessAgentTagsByTypeID";
                cmd.CommandType = CommandType.StoredProcedure;
                DbParameter typeParam = FactoryDB.CreateParameter(cmd,"@typeID", null, DbType.Int32);
                cmd.Parameters.Add(typeParam);

                // execute the command
                DbDataReader dataReader = null;
                connection.Open();
                foreach( int i in typeIDs)
                {
                    typeParam.Value = i;
                    dataReader = cmd.ExecuteReader();
                    while (dataReader.Read())
                    {
                        IntTag tag = new IntTag();
                        tag.id = dataReader.GetInt32(0);
                        tag.tag = dataReader.GetString(1);
                        list.Add(tag);
                    }
                }
            }
            catch( DbException)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }
            return list.ToArray();
        }
Exemplo n.º 19
0
        public IntTag LaunchLabClient(Coupon coupon, string clientGuid, string groupName,
            string userName, string authorityUrl, long duration, int autoStart)
        {
            IntTag result = new IntTag(-1, "Access Denied");
                    StringBuilder buf = new StringBuilder();
                    int userID = -1;
                    int clientID = -1;
                    int groupID = -1;

                    try
                    {
                        Ticket clientAuthTicket = null;
                        Authority authority = null;
                        // Need to check opHeader
                        if (coupon != null)
                        {

                            authority = AuthorityRetrieveByUrl(authorityUrl);
                            // Coupon is from the client SCORM
                            clientAuthTicket = RetrieveIssuedTicket(coupon, TicketTypes.AUTHORIZE_CLIENT, ProcessAgentDB.ServiceGuid);
                            if (authority == null || clientAuthTicket == null)
                            {
                                return result;
                            }
                            if (!clientAuthTicket.IsExpired() && !clientAuthTicket.isCancelled)
                            {
                                XmlQueryDoc xDoc = new XmlQueryDoc(clientAuthTicket.payload);
                                string cGuid = xDoc.Query("AuthorizeClientPayload/clientGuid");
                                string gName = xDoc.Query("AuthorizeClientPayload/groupName");
                                if ((cGuid.CompareTo(clientGuid) == 0) && (gName.CompareTo(groupName) == 0))
                                {
                                    userID = AdministrativeAPI.GetUserID(userName, authority.authorityID);
                                    if (userID <= 0)
                                    { //User does not exist
                                        //Check if Authority has a default group
                                        if (authority.defaultGroupID > 0)
                                        {
                                            //Should try & Query Authority for more information
                                            string firstName = null;
                                            string lastName = null;
                                            string email = null;
                                            string reason = null;
                                            userID = AdministrativeAPI.AddUser(userName, authority.authorityID, authority.authTypeID,
                                                firstName, lastName, email, authority.authName, reason, null, authority.defaultGroupID, false);
                                        }
                                    }
                                    if (userID > 0)
                                    {
                                        if (cGuid != null && clientGuid != null && cGuid.Length > 0 && (cGuid.CompareTo(clientGuid) == 0))
                                        {
                                            clientID = AdministrativeAPI.GetLabClientID(clientGuid);
                                        }
                                        else
                                        {
                                            return result;
                                        }
                                        if (gName != null && groupName != null && gName.Length > 0 && (gName.CompareTo(groupName) == 0))
                                        {
                                            groupID = AdministrativeAPI.GetGroupID(groupName);
                                        }
                                        else
                                        {
                                            return result;
                                        }
                                    }
                                    else
                                    {
                                        return result;
                                    }

                                    if (userID > 0 && clientID > 0 && groupID > 0)
                                    {

                                        //Check for group access & User
                                        result = ResolveAction(clientID, userID, groupID, DateTime.UtcNow, duration, autoStart > 0);
                                        //http://your.machine.com/iLabServiceBroker/default.aspx?sso=t&amp;usr=USER_NAME&amp;key=USER_PASSWD&amp;cid=CLIENT_GUID&amp;grp=GROUP_NAME"
                                    }
                                }
                            }
                        }
                        //    Coupon coupon = brokerDB.CreateCoupon();
                        //    TicketLoadFactory tlc = TicketLoadFactory.Instance();
                        //    string payload = tlc.createAuthenticateAgentPayload(authorityGuid, clientGuid, userName, groupName);
                        //    brokerDB.AddTicket(coupon, TicketTypes.AUTHENTICATE_AGENT, ProcessAgentDB.ServiceGuid, authorityGuid, 600L, payload);
                        //    buf.Append(ProcessAgentDB.ServiceAgent.codeBaseUrl);
                        //    buf.Append("/default.aspx?sso=t");
                        //    buf.Append("&usr="******"&cid=" + clientGuid);
                        //    buf.Append("&grp=" + groupName);
                        //    buf.Append("&auth=" + authorityUrl);
                        //    buf.Append("&key=" + coupon.passkey);
                        //    if (autoStart > 0)
                        //        buf.Append("&auto=t");

                        //    tag.id = 1;
                        //    tag.tag = buf.ToString();
                        //    //
                        //    //
                        //    //if (test.id > 0)
                        //    //{
                        //    //    string requestGuid = Utilities.MakeGuid("N");
                        //    //

                        //    //}
                        //    //else
                        //    //{
                        //    //    tag.tag = "Access Denied";
                        //    //}
                        //}

                    }
                    catch (Exception e)
                    {
                        result.id = -1;
                        result.tag = e.Message;
                    }
                    //context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                    return result;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Return the ProcessAgent Tags, with type, for the specified processAgentIDs.
        /// </summary>
        /// <param name="paIds"></param>
        /// <returns></returns>
        public IntTag[] GetProcessAgentTagsWithType(int []paIds)
        {
            List<IntTag> list = new List<IntTag>();

            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();
            DbCommand cmd = connection.CreateCommand();
            cmd.CommandText = "GetProcessAgentTagsWithTypeById";
            cmd.CommandType = CommandType.StoredProcedure;
            DbParameter processAgentIdParam = FactoryDB.CreateParameter(cmd,"@agentID", null, DbType.AnsiString, 50);
            cmd.Parameters.Add(processAgentIdParam);

            DbDataReader dataReader = null;
            try
            {
                for (int i = 0; i < paIds.Length; i++)
                {
                    processAgentIdParam.Value = paIds[i];

                    // execute the command
                    connection.Open();
                    dataReader = cmd.ExecuteReader();
                    while (dataReader.Read())
                    {
                        IntTag tag = new IntTag();
                        tag.id = dataReader.GetInt32(0);
                        tag.tag = dataReader.GetString(1) + ": " + dataReader.GetString(2);
                        list.Add(tag);
                    }
                    dataReader.Close();
                }
            }
            catch (DbException)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }
            return list.ToArray();
        }
Exemplo n.º 21
0
        public IntTag ResolveAction(string clientGuid, int authID, string userName, string groupName, DateTime start, long duration, bool autoStart)
        {
            int userID = -1;
                    int clientID = -1;
                    int groupID = -1;
                    IntTag result = new IntTag(-1,"Access Denied");

                    if (userName != null && userName.Length > 0)
                    {
                        userID = AdministrativeAPI.GetUserID(userName, authID);
                        if (userID <= 0)
                        {
                            result.tag = "The user '" + userName + "' does not exist!";
                            return result;
                        }

                    }
                    else
                    {
                        result.tag = "You must specifiy a user name!";
                        return result;
                    }
                    //Get Client_ID
                    if (clientGuid != null && clientGuid.Length > 0)
                    {
                        clientID = AdministrativeAPI.GetLabClientID(clientGuid);
                        if (clientID <= 0)
                        {
                            result.tag = "The clientGUID '" + clientGuid + "' does not exist!";
                            return result;
                        }
                    }
                    else
                    {
                        result.tag = "You must specifiy a clientGuid!";
                        return result;
                    }
                    // Check that the user & is a member of the group
                    if (groupName != null && groupName.Length > 0)
                    {
                        groupID = AdministrativeAPI.GetGroupID(groupName);
                        if (groupID <= 0)
                        {
                            result.tag = "The group '" + groupName + "' does not exist!";
                            return result;
                        }
                    }
                    else
                    {
                        result.tag = "You must specifiy a group name!";
                        return result;
                    }
                    result = ResolveAction(clientID, userID, groupID, start, duration, autoStart);

                    return result;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Return all ProcessAgent tags from the specified domain with Type
        /// </summary>
        /// <returns></returns>
        public IntTag[] GetProcessAgentTagsWithTypeForDomain(string domainGuid)
        {
            ArrayList list = new ArrayList();
            IntTag tag = new IntTag();
            // create sql connection
            DbConnection connection = FactoryDB.GetConnection();

            try
            {
                // create sql command
                // command executes the "RetrieveTickets" stored procedure
                DbCommand cmd = connection.CreateCommand();
                cmd.CommandText = "GetDomainProcessAgentTagsWithType";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@domain",domainGuid,DbType.AnsiString, 50));

                // execute the command
                DbDataReader dataReader = null;
                connection.Open();
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    tag = new IntTag();
                    tag.id = dataReader.GetInt32(0);
                    tag.tag = dataReader.GetString(1) + ": " + dataReader.GetString(2);
                    list.Add(tag);
                }
            }
            catch (DbException)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }
            IntTag[] info = (IntTag[])list.ToArray(tag.GetType());
            return info;
        }
Exemplo n.º 23
0
        public IntTag[] GetAdminProcessAgentTags(int groupID)
        {
            ArrayList list = new ArrayList();
            DbConnection connection = FactoryDB.GetConnection();
            try
            {
                DbCommand cmd = FactoryDB.CreateCommand("ProcessAgent_RetrieveAdminTags", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                // populate stored procedure parameters
                cmd.Parameters.Add(FactoryDB.CreateParameter( "@groupID", groupID, DbType.Int32));

                // read the result
                connection.Open();
                DbDataReader dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    int id = dataReader.GetInt32(0);
                    string name = dataReader.GetString(1);
                    list.Add(new IntTag(id, name));
                }
                dataReader.Close();
            }
            catch (DbException e)
            {
                Console.WriteLine(e);
                throw;
            }

            finally
            {
                // close the sql connection
                connection.Close();
            }

            IntTag dummy = new IntTag();
            IntTag[] tags = (IntTag[])list.ToArray(dummy.GetType());
            return tags;
        }
Exemplo n.º 24
0
Arquivo: LabDB.cs Projeto: tordf/iLabs
        public IntTag GetLabAppTag(string appKey)
        {
            IntTag tag = null;
            DbConnection connection = FactoryDB.GetConnection();
               // create sql command
            // command executes the "GetVI" stored procedure
            DbCommand cmd = FactoryDB.CreateCommand("GetLabAppTagByKey", connection);
            cmd.CommandType = CommandType.StoredProcedure;

            // populate parameters
            cmd.Parameters.Add(FactoryDB.CreateParameter(cmd, "@appKey", appKey, DbType.String, 100));

            DbDataReader dataReader = null;
            try
            {
                connection.Open();
                dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    tag = new IntTag();
                    tag.id = dataReader.GetInt32(0);
                    tag.tag = dataReader.GetString(1);
                }
            }
            catch (DbException e)
            {
                writeEx(e);
                throw;
            }

            finally
            {
                connection.Close();
            }
            return tag;
        }