Ejemplo n.º 1
0
    // process incoming commands for edit mode
    public void ProcessEditCommand()
    {
        reply = w.RecvString();
        if (reply != null && reply != "Null")
        {
            Debug.Log("Processing Command");
            FlowEvent incoming = JsonUtility.FromJson <FlowEvent>(reply);
            if (incoming.command >= Commands.Project.MIN && incoming.command <= Commands.Project.MAX)
            {
                CommandProcessor.processProjectCommand(JsonUtility.FromJson <FlowProjectCommand>(reply));
            }
            else
            {
                CommandProcessor.processCommand(incoming);
            }
        }
//         if (w.error != null)
//             {
//                 Debug.Log("[unity] Error: " + w.error);
//                 connected = false;

//                 yield return new WaitForSeconds(5);
// #if !UNITY_WSA || UNITY_EDITOR
//                 DoOnMainThread.ExecuteOnMainThread.Enqueue(() =>
//                 {
//                     StartCoroutine(ConnectWebsocket());
//                 });
//                 Debug.Log("Connect connection");
//                 CommandProcessor.sendCommand(Commands.LOGIN, uid.ToString());
//                 loggedIn = false;
// #endif
//             }
//             yield return 0;
    }
Ejemplo n.º 2
0
        public override void Handle(FlowEvent @event, FlowContext context)
        {
            if (@event.Equals(FlowEvent.LoginCompleted))
            {
                var externalUserUuid = GetUserExternalUuid();
                var cvrNumber        = _parser.MatchCvrNumber();
                if (externalUserUuid.IsNone)
                {
                    _logger.Warning("No external UUID passed from STS Adgangsstyring");
                    context.TransitionTo(_stateFactory.CreateErrorState(), _ => _.HandleUnknownError());
                }
                else if (cvrNumber.IsNone)
                {
                    _logger.Warning("CVR number not provided from STS Adgangsstyring");
                    context.TransitionTo(_stateFactory.CreateErrorState(), _ => _.HandleUnknownError());
                }
                else if (CurrentUserHasKitosPrivilege())
                {
                    _logger.Debug("User with UUID {uuid} and CVR {cvr} did have privilege", externalUserUuid.Value, cvrNumber.Value);
                    context.TransitionTo(_stateFactory.CreatePrivilegeVerifiedState(externalUserUuid.Value, cvrNumber.Value), _ => _.HandleUserPrivilegeVerified());
                }
                else
                {
                    var privileges = GetPrivilegesString();
                    _logger.Information("Missing privilege for user with UUID {uuid} and CVR {cvr}. Failed with XML privileges {xmlPrivilegesBase64}", externalUserUuid.Value, cvrNumber.Value, privileges);

                    context.TransitionTo(_stateFactory.CreateErrorState(), _ => _.HandleUserPrivilegeInvalid());
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建工作流运行时
        /// </summary>
        /// <param name="IsPer">是否使用持久化</param>
        /// <returns></returns>
        public static WorkflowRuntime CreateWorkFlowRuntime(bool IsPer)
        {
            try
            {
                WorkflowRuntime WfRuntime = new WorkflowRuntime();


                if (IsPer)
                {
                    ConnectionStringSettings defaultConnectionString = ConfigurationManager.ConnectionStrings["OracleConnection"];
                    WfRuntime.AddService(new AdoPersistenceService(defaultConnectionString, true, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));
                    WfRuntime.AddService(new AdoTrackingService(defaultConnectionString));
                    WfRuntime.AddService(new AdoWorkBatchService());
                }

                FlowEvent ExternalEvent = new FlowEvent();
                ExternalDataExchangeService objService = new ExternalDataExchangeService();
                WfRuntime.AddService(objService);
                objService.AddService(ExternalEvent);

                ManualWorkflowSchedulerService scheduleService = new ManualWorkflowSchedulerService();
                WfRuntime.AddService(scheduleService);

                TypeProvider typeProvider = new TypeProvider(null);
                WfRuntime.AddService(typeProvider);
                WfRuntime.StartRuntime();
                return(WfRuntime);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("CreateWorkFlowRuntime异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 4
0
        public override void Handle(FlowEvent @event, FlowContext context)
        {
            _logger.Information("SSO entered {errorStateName} with error: {errorEvent}", nameof(ErrorState), @event);

            switch (@event)
            {
            case FlowEvent.UserPrivilegeInvalid:
                ErrorCode = SsoErrorCode.MissingPrivilege;
                break;

            case FlowEvent.NoOrganizationAndRole:
                ErrorCode = SsoErrorCode.NoOrganizationAndRole;
                break;

            case FlowEvent.UnableToResolveUserInStsOrganization:
                ErrorCode = SsoErrorCode.UserNotFoundInSTS;
                break;

            case FlowEvent.UnableToLocateUser:
                ErrorCode = SsoErrorCode.UnableToCreateUserWithUnknownOrganization;
                break;

            default:
                ErrorCode = SsoErrorCode.Unknown;
                break;
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <string> > FlowEventStart([FromBody] FlowEvent message, [FromServices] DaprClient daprClient)
        {
            _logger.LogInformation(message.Id);
            await daprClient.PublishEventAsync(PubSubName, PubSubTopic, message);

            return(Ok("Thanks"));
        }
Ejemplo n.º 6
0
    public static int processCommand(FlowEvent incoming)
    {
        int retValue = 0;

        if (cmdCbDictionary.ContainsKey(incoming.command))
        {
            delegate_flow_cmd cb;
            cmdCbDictionary.TryGetValue(incoming.command, out cb);
            cb(incoming);
            cmdCbDictionary.Remove(incoming.command);
        }
        if (listenerCmdDictionary.ContainsKey(incoming.command))
        {
            List <delegate_flow_cmd> callbacks;
            listenerCmdDictionary.TryGetValue(incoming.command, out callbacks);
            foreach (delegate_flow_cmd cb in callbacks)
            {
                cb(incoming);
            }
        }

        string debug_updates = recieveEvents[incoming.command]();

        if (FlowNetworkManager.debug)
        {
            Debug.Log(debug_updates);
        }

        return(retValue);
    }
Ejemplo n.º 7
0
        /// <summary>
        /// 创建工作流运行时
        /// </summary>
        /// <param name="IsPer">是否使用持久化</param>
        /// <returns></returns>
        public static WorkflowRuntime CreateWorkFlowRuntime(bool IsPer)
        {
            try
            {
                WorkflowRuntime WfRuntime = new WorkflowRuntime();


                if (IsPer)
                {
                    String connStringPersistence = ConfigurationManager.ConnectionStrings["SqlPersistenceConnection"].ConnectionString;//Data Source=172.30.50.110;Initial Catalog=WorkflowPersistence;Persist Security Info=True;User ID=sa;Password=fbaz2012;MultipleActiveResultSets=True";
                    SqlWorkflowPersistenceService persistence = new SqlWorkflowPersistenceService(connStringPersistence, true, new TimeSpan(0, 0, 30), new TimeSpan(0, 1, 0));
                    WfRuntime.AddService(persistence);
                    WfRuntime.WorkflowPersisted           += new EventHandler <WorkflowEventArgs>(WfRuntime_WorkflowPersisted);
                    WfRuntime.ServicesExceptionNotHandled += new EventHandler <ServicesExceptionNotHandledEventArgs>(WfRuntime_ServicesExceptionNotHandled);
                    //    ConnectionStringSettings defaultConnectionString = ConfigurationManager.ConnectionStrings["OracleConnection"];
                    //    WfRuntime.AddService(new AdoPersistenceService(defaultConnectionString, true, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));
                    //    WfRuntime.AddService(new AdoTrackingService(defaultConnectionString));
                    //    WfRuntime.AddService(new AdoWorkBatchService());
                }

                FlowEvent ExternalEvent = new FlowEvent();
                ExternalDataExchangeService objService = new ExternalDataExchangeService();
                WfRuntime.AddService(objService);
                objService.AddService(ExternalEvent);
                TypeProvider typeProvider = new TypeProvider(null);
                WfRuntime.AddService(typeProvider);
                WfRuntime.StartRuntime();
                return(WfRuntime);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("CreateWorkFlowRuntime异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 从持久化库在恢复实例
        /// </summary>
        /// <param name="WfRuntime"></param>
        /// <param name="INSTANCEID"></param>
        /// <returns></returns>
        public static WorkflowInstance GetWorkflowInstance(WorkflowRuntime WfRuntime, string INSTANCEID)
        {
            try
            {
                WfRuntime = new WorkflowRuntime();

                if (WfRuntime.GetService(typeof(AdoPersistenceService)) == null)
                {
                    ConnectionStringSettings defaultConnectionString = ConfigurationManager.ConnectionStrings["OracleConnection"];
                    WfRuntime.AddService(new AdoPersistenceService(defaultConnectionString, true, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));
                    WfRuntime.AddService(new AdoTrackingService(defaultConnectionString));
                    WfRuntime.AddService(new AdoWorkBatchService());
                }

                FlowEvent ExternalEvent = new FlowEvent();
                ExternalDataExchangeService objService = new ExternalDataExchangeService();
                WfRuntime.AddService(objService);
                objService.AddService(ExternalEvent);
                TypeProvider typeProvider = new TypeProvider(null);
                WfRuntime.AddService(typeProvider);
                WfRuntime.StartRuntime();

                WorkflowInstance instance = null;
                try
                {
                    instance = WfRuntime.GetWorkflow(new Guid(INSTANCEID));
                }
                catch
                {
                    instance = null;
                }
                if (instance == null) //try find instance in sql server persistence
                {
                    WfRuntime     = new WorkflowRuntime();
                    ExternalEvent = new FlowEvent();
                    objService    = new ExternalDataExchangeService();
                    WfRuntime.AddService(objService);
                    objService.AddService(ExternalEvent);
                    typeProvider = new TypeProvider(null);
                    WfRuntime.AddService(typeProvider);

                    String connStringPersistence = ConfigurationManager.ConnectionStrings["SqlPersistenceConnection"].ConnectionString;//Data Source=172.30.50.110;Initial Catalog=WorkflowPersistence;Persist Security Info=True;User ID=sa;Password=fbaz2012;MultipleActiveResultSets=True";
                    SqlWorkflowPersistenceService persistence = new SqlWorkflowPersistenceService(connStringPersistence, true, new TimeSpan(0, 2, 0), new TimeSpan(0, 0, 5));
                    WfRuntime.AddService(persistence);
                    WfRuntime.StartRuntime();
                    instance = WfRuntime.GetWorkflow(new Guid(INSTANCEID));
                }
                //WfRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                //{
                //    instance = null;

                //};
                return(instance);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetWorkflowInstance异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
        public override void Handle(FlowEvent @event, FlowContext context)
        {
            switch (@event)
            {
            case FlowEvent.UnableToLocateUser:
                var organizationByCvrResult = _organizationRepository.GetByCvr(_stsBrugerInfo.MunicipalityCvr);
                if (organizationByCvrResult.HasValue)
                {
                    var organization = organizationByCvrResult.Value;
                    var user         = CreateAutoProvisonedUser();
                    _organizationRoleService.MakeUser(user, organization);

                    context.TransitionTo(_ssoStateFactory.CreateUserLoggedIn(user),
                                         _ => _.HandleUserAutoProvisioned());
                }
                else
                {
                    context.TransitionTo(_ssoStateFactory.CreateErrorState(),
                                         _ => _.HandleUnableToLocateUser());
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(@event), @event, null);
            }
        }
Ejemplo n.º 10
0
 public override void Handle(FlowEvent @event, FlowContext context)
 {
     if (@event.Equals(FlowEvent.UserHasNoRoleInOrganization))
     {
         _organizationRoleService.MakeUser(_user, _ssoOrganization);
         context.TransitionTo(_ssoStateFactory.CreateUserLoggedIn(_user), _ => _.HandleRoleAssigned());
     }
 }
Ejemplo n.º 11
0
    public static void processCommand(FlowEvent incoming)
    {
        // runs the receive delegate that corresponds to the incoming command and stores any debug logs in debug_updates
        string debug_updates = receiveEvents[incoming.command]();

        // logs debug updates
        FlowNetworkManager.log(debug_updates);
    }
Ejemplo n.º 12
0
        public async Task <ActionResult <string> > FlowEventReceive([FromBody] FlowEvent message, [FromServices] DaprClient daprClient)
        {
            _logger.LogInformation($"Received message with Id: {message.Id}");

            await daprClient.SaveStateAsync(StateStoreName, message.Id, message.Content);

            return(Ok("Thanks"));
        }
Ejemplo n.º 13
0
        public static FlowNode getFlowNode(string tmpkey, string nodeKey, FlowEvent endFlow)
        {
            FlowNode flo = GetNodeByNodeType(tmpkey, nodeKey);

            flo.NodeKey  = nodeKey;
            flo.TmpKey   = tmpkey;
            flo.endFlow += endFlow;
            return(flo);
        }
Ejemplo n.º 14
0
    public void CreateText()
    {
        FlowEvent createCubeEvent = new FlowEvent();

        createCubeEvent.cmd   = Commands.Droplet.types.TEXT;
        createCubeEvent.value = new FlowPayload(Commands.Droplet.types.TEXT.ToString());
        //        CommandProcessor.EditorCommandProcessor(createCubeEvent);
        CommandProcessor.sendCommand(createCubeEvent);
    }
Ejemplo n.º 15
0
    public static void sendCommand(int command, string value)
    {
        FlowEvent newCmd = new FlowEvent();

        newCmd.command    = command;
        newCmd.value      = new FlowPayload();
        newCmd.value.data = value;
        cmdBuffer.Add(newCmd);
    }
Ejemplo n.º 16
0
        public void Execute(FlowEvent initialEvent)
        {
            var links = flowClass.GetTypeInfo().GetCustomAttributes <LinkEventToCommandAttribute>();

            foreach (var link in links)
            {
                AddEventMapping(link);
            }

            eventStore.AddEvent(initialEvent);
        }
Ejemplo n.º 17
0
    public void OnApplicationQuit()
    {
        FlowEvent closeEvent = new FlowEvent();

        closeEvent.cmd = -1;
        CommandProcessor.sendCommand(closeEvent);
        Debug.Log("Closing!!");
        if (w != null && w.connected)
        {
            w.Close();
        }
    }
Ejemplo n.º 18
0
 public override void Handle(FlowEvent @event, FlowContext context)
 {
     if (@event.Equals(FlowEvent.UserFirstTimeSsoVisit))
     {
         AssociateUserWithExternalIdentity();
         HandleUserWithSsoIdentity(context);
     }
     else if (@event.Equals(FlowEvent.ExistingSsoUserWithoutRoles))
     {
         HandleUserWithSsoIdentity(context);
     }
 }
Ejemplo n.º 19
0
    private static void sendCommand(int command, string value, delegate_flow_cmd callback)
    {
        FlowEvent newCmd = new FlowEvent();

        newCmd.command    = command;
        newCmd.value.data = value;
        cmdBuffer.Add(newCmd);
        if (cmdCbDictionary.ContainsKey(command))
        {
            cmdCbDictionary.Remove(command);
        }
        cmdCbDictionary.Add(command, callback);
    }
Ejemplo n.º 20
0
        private void OnEventRaised(FlowEvent flowEvent)
        {
            if (flowEvent == null)
            {
                return;
            }

            IList <Tuple <string, ICommand> > commands = GetCommands(flowEvent);

            foreach (var command in commands)
            {
                if (!(flowEvent is CommandProcessingEvent))
                {
                    eventStore.AddEvent(new OnStartProcessingCommand(flowEvent.ContextOfEvent, command.Item2));
                }

                var observableEvents = command.Item2.Execute();

                Action onComplete = () =>
                {
                    if (!(flowEvent is CommandProcessingEvent))
                    {
                        eventStore.AddEvent(new OnEndProcessingCommand(flowEvent.ContextOfEvent, command.Item2));
                    }
                };

                observableEvents.IgnoreElements().Subscribe((e) => { }, onComplete);

                string commandName = command.Item1;// This is needed to capture variable also, we should use command variable in this lambda

                observableEvents.Subscribe(currentEvent =>
                {
                    if (currentEvent == null)
                    {
                        return;
                    }

                    if (currentEvent.ContextOfEvent == null)
                    {
                        currentEvent.ContextOfEvent = flowEvent.ContextOfEvent;
                    }

                    if (currentEvent.CommandName == DEFAULT_COMMAND_NAME && commandName != DEFAULT_COMMAND_NAME)
                    {
                        currentEvent.CommandName = commandName;
                    }

                    eventStore.AddEvent(currentEvent);
                }, ex => Console.WriteLine(ex));
            }
        }
Ejemplo n.º 21
0
 public override void Handle(FlowEvent @event, FlowContext context)
 {
     if (@event.Equals(FlowEvent.UserPrivilegeVerified))
     {
         var userResult = _ssoUserIdentityRepository.GetByExternalUuid(_userUuid);
         if (userResult.HasValue) // User has used the same SSO identity before and exists
         {
             var user = userResult.Value.User;
             if (user.CanAuthenticate())
             {
                 context.TransitionTo(_ssoStateFactory.CreateUserLoggedIn(user),
                                      _ => _.HandleUserSeenBefore());
             }
             else
             {
                 var stsBrugerInfo = _stsBrugerInfoService.GetStsBrugerInfo(_userUuid, _cvrNumber);
                 if (!stsBrugerInfo.HasValue)
                 {
                     context.TransitionTo(_ssoStateFactory.CreateErrorState(), _ => _.HandleUnableToResolveUserInStsOrganisation());
                 }
                 else
                 {
                     context.TransitionTo(_ssoStateFactory.CreateUserIdentifiedState(user, stsBrugerInfo.Value),
                                          _ => _.HandleExistingSsoUserWithoutRoles());
                 }
             }
         }
         else // Try to find the user by email
         {
             var stsBrugerInfo = _stsBrugerInfoService.GetStsBrugerInfo(_userUuid, _cvrNumber);
             if (!stsBrugerInfo.HasValue)
             {
                 context.TransitionTo(_ssoStateFactory.CreateErrorState(), _ => _.HandleUnableToResolveUserInStsOrganisation());
             }
             else
             {
                 var userByKitosEmail = FindUserByEmail(stsBrugerInfo);
                 if (userByKitosEmail.HasValue)
                 {
                     context.TransitionTo(_ssoStateFactory.CreateUserIdentifiedState(userByKitosEmail.Value, stsBrugerInfo.Value),
                                          _ => _.HandleUserFirstTimeSsoVisit());
                 }
                 else
                 {
                     context.TransitionTo(_ssoStateFactory.CreateFirstTimeUserNotFoundState(stsBrugerInfo.Value),
                                          _ => _.HandleUnableToLocateUser());
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
        private IList <Tuple <string, ICommand> > GetCommands(FlowEvent flowEvent)
        {
            var eventType = flowEvent.GetType();

            if (eventToCommandMapping.ContainsKey(eventType))
            {
                IEnumerable <EventToCommand> filteredEventToCommands = GetFilteredEvents(flowEvent.CommandName, eventType);
                return(commandFactory.Get(flowEvent.ContextOfEvent, filteredEventToCommands));
            }
            else
            {
                return(new List <Tuple <string, ICommand> >());
            }
        }
Ejemplo n.º 23
0
 public override void Handle(FlowEvent @event, FlowContext context)
 {
     if (@event.Equals(FlowEvent.OrganizationNotFound))
     {
         if (_user.CanAuthenticate())
         {
             context.TransitionTo(_stateFactory.CreateUserLoggedIn(_user), _ => _.HandleUserHasRoleInOrganization());
         }
         else
         {
             context.TransitionTo(_stateFactory.CreateErrorState(), _ => _.HandleNoRoleAndOrganization());
         }
     }
 }
Ejemplo n.º 24
0
 public override void Handle(FlowEvent @event, FlowContext context)
 {
     if (@event.Equals(FlowEvent.OrganizationFound))
     {
         var rolesInOrganization = _organizationRoleService.GetRolesInOrganization(_user, _ssoOrganization.Id);
         if (rolesInOrganization.Any())
         {
             context.TransitionTo(_ssoStateFactory.CreateUserLoggedIn(_user), _ => _.HandleUserHasRoleInOrganization());
         }
         else
         {
             context.TransitionTo(_ssoStateFactory.CreateAssigningRoleState(_user, _ssoOrganization), _ => _.HandleUserHasNoRoleInOrganization());
         }
     }
 }
Ejemplo n.º 25
0
        public override void Handle(FlowEvent @event, FlowContext context)
        {
            switch (@event)
            {
            case FlowEvent.UserSeenBefore:
            case FlowEvent.UserHasRoleInOrganization:
            case FlowEvent.RoleAssigned:
            case FlowEvent.UserAutoProvisioned:
                _authenticationState.SetAuthenticatedUser(User, AuthenticationScope.Session);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(@event), @event, null);
            }
        }
Ejemplo n.º 26
0
    public virtual void Send(WebSocket w, FlowEvent evt)
    {
        timestamp = DateTime.UtcNow.Ticks;
        string stringCmd = JsonUtility.ToJson(evt);

        FlowNetworkManager.log("Sending " + stringCmd);

        try
        {
            w.SendString(stringCmd);
        }
        catch
        {
            FlowNetworkManager.log("The update didnt send, and the websocket connection status is: " + w.connected +
                                   "\nthe json is: " + stringCmd);
        }
    }
Ejemplo n.º 27
0
    IEnumerator ConnectWebsocket()
    {
        log("Connecting...");
        yield return(StartCoroutine(w.Connect()));

        log("Connecting...2");
        while (w.error == "Closed")
        {
            yield return(StartCoroutine(ReconnectWebsocket()));

            log("Closed connection");
        }

        connected = true;
        log("CONNECTED WEBSOCKET");

        while (true)
        {
            reply = w.RecvString();
            if (reply != null && reply != "Null")
            {
                FlowEvent incoming = JsonUtility.FromJson <FlowEvent>(reply);
                CommandProcessor.processCommand(incoming);
            }
            if (w.error != null)
            {
                log("[unity] Error: " + w.error);
                connected = false;

                yield return(new WaitForSeconds(5));

#if !UNITY_WSA
                DoOnMainThread.ExecuteOnMainThread.Enqueue(() =>
                {
                    StartCoroutine(ConnectWebsocket());
                });
#endif
            }
            yield return(0);
        }
    }
Ejemplo n.º 28
0
    public virtual void Send(WebSocket w, FlowEvent evt)
    {
        timestamp = DateTime.UtcNow.Ticks;
        string stringCmd = JsonUtility.ToJson(evt);

        if (FlowNetworkManager.debug)
        {
            Debug.Log(stringCmd);
        }

        try
        {
            w.SendString(stringCmd);
        }
        catch
        {
            Debug.Log("The update didnt send, and the websocket connection status is: " + w.connected);
            Debug.Log("the json is: " + stringCmd);
        }

        Debug.Log("Sent successfully! Json: " + stringCmd);
    }
Ejemplo n.º 29
0
 private void Handle(FlowEvent eventToHandle)
 {
     CurrentState.Handle(eventToHandle, this);
 }
Ejemplo n.º 30
0
 public static void sendCommand(FlowEvent evt)
 {
     cmdBuffer.Add(evt);
 }