Ejemplo n.º 1
0
 private IEnumerator UpdateRunningSession()
 {
     while (isWindowEnabled)
     {
         if (isRunwayRunning && runningSession != null)
         {
             this.StartCoroutine(RunwayHub.getSession(runningSession.id, (session) =>
             {
                 runningSession = session;
             }));
         }
         yield return(new WaitForSeconds(1));
     }
 }
Ejemplo n.º 2
0
        public void  CreateSession(String rawSessionData)
        {
            string[] times = rawSessionData.Split(',');

            for (int i = 0; i < times.Length / 2; i++)
            {
                ModelSession session = new ModelSession();
                session.From = DateTime.Parse(times[i * 2]);
                session.To   = DateTime.Parse(times[(i * 2) + 1]);
                TimeSpan span = session.To - session.From;
                session.NoOfSlots = (int)span.TotalMinutes / SlotLengthInMinutes;
                Sessions.Add(session);
            }
        }
Ejemplo n.º 3
0
 private IEnumerator DiscoverRunningSessions()
 {
     while (isWindowEnabled)
     {
         if (isRunwayRunning)
         {
             this.StartCoroutine(RunwayHub.listSessions((sessions) =>
             {
                 foreach (ModelSession s in sessions)
                 {
                     if (s.application.Equals("Unity"))
                     {
                         runningSession = s;
                     }
                 }
             }));
         }
         yield return(new WaitForSeconds(1));
     }
 }
Ejemplo n.º 4
0
        private static void AuthNewSession(ModelSmb2Status status, ModelSessionSetupRequest sessionSetupRequest)
        {
            ModelHelper.Log(LogType.Requirement, "3.3.5.5.1: A session object MUST be allocated for this request. ");

            ModelSession   session   = new ModelSession();
            ModelSessionId?sessionId = null;

            if (!GlobalSessionTable.ContainsKey(ModelSessionId.MainSessionId))
            {
                sessionId = ModelSessionId.MainSessionId;
            }
            else
            {
                sessionId = ModelSessionId.AlternativeSessionId;
            }

            // Update sessionId to new created one from zero
            sessionSetupRequest.sessionId = sessionId.Value;

            ModelHelper.Log(LogType.Requirement, "The other values MUST be initialized as follows:");
            session.Dialect = ConnectionList[sessionSetupRequest.connectionId].NegotiateDialect;

            ModelHelper.Log(LogType.Requirement, "Session.State is set to InProgress.");
            session.State     = ModelSessionState.InProgress;
            session.SessionId = sessionId.Value;

            ModelHelper.Log(LogType.Requirement,
                            "The session MUST be inserted into the GlobalSessionTable and a unique Session.SessionId is assigned to serve as a lookup key in the table. ");
            GlobalSessionTable.Add(sessionSetupRequest.sessionId, session);

            ModelHelper.Log(LogType.Requirement, "The session MUST be inserted into Connection.SessionTable. ");
            ConnectionList[sessionSetupRequest.connectionId].Session = session;

            ModelHelper.Log(LogType.Requirement, "Using this session, authentication is continued as specified in section 3.3.5.5.3.");
            HandleGssApiAuth(status, sessionSetupRequest);
        }
        internal static void LogoutSessionImp(string sessionToken, bool keepSession)
        {
            ModelSession session = CheckSessionImp(sessionToken);

            if (keepSession)
            {
                ModelSession ms = new ModelSession(sessionToken);
                ms.User = new ModelUser("Everyone");
                ms.Update();
            }
            else
            {
                session.Delete();
            }
        }
        internal static string LoginImp(string userName, string password)
        {
            SetupImp();

            if (System.Web.HttpContext.Current != null)
            {
                Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName);
                IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress);

                ipr = AddIPImp(s);

                // ipr.SessionsCreated = ipr.SessionsCreated + 1;
                // ipr.Update();
                // IPSessionRegistration

                CheckIPImp(s, ipr);
            }

            ModelSession ms = new ModelSession(GenerateSessionTokenImp());
            CreateSessionImp(ref ms, userName, password);

            return ms.SessionToken;
        }
        internal static string LoginAnonymousImp()
        {
            SetupImp();

            Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName);

            if (!s.AllowAnonymousAccess)
                return null;

            if (System.Web.HttpContext.Current != null)
            {
                IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress);

                ipr = AddIPImp(s);

                // ipr.SessionsCreated = ipr.SessionsCreated + 1;
                // ipr.Update();
                // IPSessionRegistration

                CheckIPImp(s, ipr);
            }

            ModelSession ms = new ModelSession(GenerateSessionTokenImp());
            ms.User = new ModelUser("Everyone");
            ms.TimeIssued = DateTime.Now;
            ms.TimeIssuedFor = s.TimeSessionIsIssued;
            ms.Create();

            return ms.SessionToken;
        }
        internal static void CreateSessionImp(ref ModelSession ms, string userName, string password)
        {
            if (userName.ToLowerInvariant() == "everyone")
                throw new InvalidOperationException("Wrong API call for anonymous access.");

            Securable s = new Securable(typeof(ApplicationExceptionSecureService).FullName);

            ModelUser mu = new ModelUser(userName);
            if (!mu.Exists)
            {
                if (System.Web.HttpContext.Current != null)
                {
                    IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress);
                    RegisterIPFailureImp(s, ipr);
                }

                throw new UnauthorizedAccessException("Access Denied");
            }

            if (!Platform.Runtime.Security.Hash.VerifyHash(password, "SHA512", mu.PasswordHash))
            {
                if (System.Web.HttpContext.Current != null)
                {
                    IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress);
                    RegisterIPFailureImp(s, ipr);
                }

                throw new UnauthorizedAccessException("Access Denied");
            }

            if (!mu.Enabled && !ApplicationExceptionSecureService.CheckUserRightsImp(userName, "CannotBeDisabled"))
            {
                if (System.Web.HttpContext.Current != null)
                {
                    IPRegistered ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress);
                    RegisterIPFailureImp(s, ipr);
                }

                throw new UnauthorizedAccessException("Access Denied"); // LoginDisabledException
            }

            ms.User = mu;
            ms.TimeIssued = DateTime.Now;
            ms.TimeIssuedFor = s.TimeSessionIsIssued;
            ms.Create();
        }
        internal static ModelSession CheckSessionImp(string sessionToken)
        {
            // Mark IP first
            Securable s = null;
            IPRegistered ipr = null;
            if (System.Web.HttpContext.Current != null)
            {
                s = new Securable(typeof(ApplicationExceptionSecureService).FullName);
                ipr = new IPRegistered(System.Web.HttpContext.Current.Request.UserHostAddress);

                CheckIPImp(s, ipr);
            }
            else
            {
                // What other unique data can be gathered?
            }

            if (String.IsNullOrEmpty(sessionToken))
            {
                // Invalid data is a security error
                if (s != null)
                    RegisterIPFailureImp(s, ipr);

                throw new UnauthorizedAccessException("The session is invalid");
            }

            // Check the consistency of the session
            ModelSession session = new ModelSession(sessionToken.ToLowerInvariant());
            if (!session.Exists)
            {
                if (s != null)
                    RegisterIPFailureImp(s, ipr);

                throw new UnauthorizedAccessException("The session is invalid");
            }

            if (session.User == null)
            {
                if (s != null)
                    RegisterIPFailureImp(s, ipr);

                session.Delete();
                throw new UnauthorizedAccessException("The session is invalid");
            }

            DateTime until = session.TimeIssued.AddMinutes(session.TimeIssuedFor);
            if (until < DateTime.Now)
            {
                session.Delete();
                throw new UnauthorizedAccessException("Your session has expired");
            }

            return session;
        }
Ejemplo n.º 10
0
    void RenderRunModel()
    {
        GUILayout.Space(10);
        GUILayout.Label("RUN OPTIONS", sectionTitleStyle);
        GUILayout.Space(5);

        GUILayout.BeginHorizontal("box");

        GUILayout.BeginVertical();

        GUILayout.Space(5);

        GUILayout.BeginHorizontal(horizontalStyle);
        GUILayout.Label("Run Location");
        GUILayout.FlexibleSpace();
        runLocationIndex = EditorGUILayout.Popup(runLocationIndex, runLocations);
        GUILayout.EndHorizontal();

        GUILayout.Space(5);
        GUILayout.BeginHorizontal(horizontalStyle);
        GUILayout.Label("Run Continuously");
        GUILayout.FlexibleSpace();
        this.continuousInference = EditorGUILayout.Toggle(this.continuousInference, GUILayout.Width(20));
        GUILayout.EndHorizontal();


        GUILayout.Space(5);
        GUILayout.BeginHorizontal(horizontalStyle);
        GUILayout.FlexibleSpace();

        if (modelIsRunning())
        {
            if (this.continuousInference && !this.isProcessingInput)
            {
                this.isProcessingInput = true;
                try
                {
                    this.RunInference();
                }
                catch
                {
                    this.isProcessingInput = false;
                }
            }
            using (new EditorGUI.DisabledScope(this.isProcessingInput))
            {
                if (GUILayout.Button("Process"))
                {
                    this.isProcessingInput = true;
                    try
                    {
                        this.RunInference();
                    }
                    catch
                    {
                        this.isProcessingInput = false;
                    }
                }
            }
        }

        string buttonText;
        bool   buttonDisabled;

        if (modelIsRunning())
        {
            buttonText     = "Stop Model";
            buttonDisabled = false;
        }
        else if (modelIsStarting())
        {
            buttonText     = "Starting Model...";
            buttonDisabled = true;
        }
        else
        {
            buttonText     = "Start Model";
            buttonDisabled = false;
        }
        buttonDisabled = buttonDisabled || this.isMakingRequest;

        using (new EditorGUI.DisabledScope(buttonDisabled))
        {
            if (GUILayout.Button(buttonText))
            {
                if (modelIsRunning())
                {
                    this.isMakingRequest = true;
                    this.StartCoroutine(RunwayHub.stopModel(runningSession.id, (response) =>
                    {
                        this.runningSession    = null;
                        this.isMakingRequest   = false;
                        this.isProcessingInput = false;
                        Repaint();
                    }));
                }
                else
                {
                    ProviderOptions providerOptions = new ProviderOptions();
                    providerOptions.runLocation = runLocations[runLocationIndex];
                    this.isMakingRequest        = true;
                    int versionId = getFilteredModels()[selectedModelIndex].defaultVersionId;
                    this.StartCoroutine(RunwayHub.runModel(versionId, getOptions(), providerOptions, (error, session) =>
                    {
                        this.isMakingRequest = false;
                        if (error != null)
                        {
                            EditorUtility.DisplayDialog("Error starting model", error, "OK");
                            return;
                        }
                        this.runningSession = session;
                        Repaint();
                    }));
                }
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        GUILayout.Space(15);
    }