/// <summary>
        /// Initializes a new session and adds it to the dictionary. Does not begin streaming data.
        /// </summary>
        /// <param name="args"></param>
        /// <returns>A string container with the SessionKey or a failure message</returns>
        public static Container <string> InitializeSession(SessionInitializer args)
        {
            var validation = args.Validate();

            if (validation.Success)
            {
                // Construct new session from args
                var session = new Session(GetRandomKey().Data[0], args);
                // Create instrument on CHORDS and set session's instrument ID
                var createInstContainer = ChordsBot.CreateInstrument(session.SessionKey);
                if (!createInstContainer.Success)
                {
                    return(new Container <string>("", false, createInstContainer.Message));
                }
                int id = createInstContainer.Data[0];
                session.SetInstrument(id);
                // Map session streams to CHORDS variables
                var confVarsContainer = ChordsBot.ConfigureVariables(session);
                if (!confVarsContainer.Success)
                {
                    return(new Container <string>("", false, confVarsContainer.Message));
                }
                // Add session to dict
                SessionDict.Add(session.SessionKey, session);
                return(new Container <string>(session.SessionKey, true));
            }
            else
            {
                return(new Container <string>("", false, validation.Message));
            }
        }
Beispiel #2
0
        public static void AddUserIdToSession(string sessionCode, string loginId, string userGuid, string legacyAvatarUrl)
        {
            foreach (var item in SessionDict.Where(kvp => kvp.Value.TimeStamp < DateTime.Now.AddMinutes(-60)).ToList())
            {
                SessionDict.Remove(item.Key);
            }

            SessionDict[sessionCode] = new TimedSession(loginId, userGuid, legacyAvatarUrl);
        }
Beispiel #3
0
        public static bool HasLegacyAvatar(string userGuid, out string LegacyAvatarUrl)
        {
            LegacyAvatarUrl = null;
            var x = SessionDict.Where(kvp => kvp.Value.UserGuid == userGuid).ToList();

            if (x != null && x.Count > 0)
            {
                LegacyAvatarUrl = x[0].Value.LegacyAvatarUrl;
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Gets a Session by its key from the dictionary.
        /// </summary>
        /// <param name="key"></param>
        /// <returns>A session Container with the Session designated by the SessionKey or a failure message</returns>
        public static Container <Session> GetSession(string key)
        {
            Session session;

            if (SessionDict.TryGetValue(key.ToUpper(), out session))
            {
                return(new Container <Session>(session));
            }
            else
            {
                return(new Container <Session>("Session key not found."));
            }
        }
        /// <summary>
        /// Generates a random unused session key
        /// </summary>
        /// <returns>String Container with generated session key</returns>
        public static Container <string> GetRandomKey()
        {
            Random rand = new Random();
            string key;

            do
            {
                key = "";
                for (int i = 0; i < SessionManager.KeyLength; i++)
                {
                    key += (char)rand.Next('A', 'Z');
                }
            } while (SessionDict.ContainsKey(key));

            return(new Container <string>(key, true));
        }
Beispiel #6
0
        public static bool TryGetUserIdFromSessionCode(string sessionCode, out string userId)
        {
            userId = null;
            TimedSession vcode = null;

            if (sessionCode != null && SessionDict.TryGetValue(sessionCode, out vcode))
            {
                if (vcode.TimeStamp > DateTime.Now.AddMinutes(-60))
                {
                    userId = vcode.Code;
                    //refresh timestamp:
                    vcode.TimeStamp          = DateTime.Now;
                    SessionDict[sessionCode] = vcode;

                    return(true);
                }
            }
            return(false);
        }