private void CheckContextDataUpdates()
        {
            if (_contextTreeTraversalHelperQueue.Count > 0)
            {
                throw new RDataException("CheckContextDataUpdates() was called in the middle of the context tree traversal. That is a bug and should never happen.");
            }

            // Traverse the context tree breadth-first and find new changes in the context data
            _contextTreeTraversalHelperQueue.Enqueue(_authorizationContext);
            while (_contextTreeTraversalHelperQueue.Count > 0)
            {
                RDataBaseContext current = _contextTreeTraversalHelperQueue.Dequeue();
                foreach (var kvp in current.GetUpdatedFields())
                {
                    if (RData.RDataLogging.DoLog)
                    {
                        Debug.Log("<color=teal>Data updated in context " + current.Name + " , key=" + kvp.Key + ", value=" + kvp.Value + " </color>");
                    }
                    UpdateContextData(current, kvp.Key, kvp.Value);
                }

                foreach (var child in current.Children)
                {
                    if (child.Status == RDataContextStatus.Started)
                    {
                        _contextTreeTraversalHelperQueue.Enqueue(child);
                    }
                }
            }
        }
 public EndContextRequest(RDataBaseContext context) : base()
 {
     Params = new Parameters()
     {
         Id        = context.Id,
         TimeEnded = Tools.Time.DateTimeToUnixTimeMilliseconds(context.TimeEnded)
     };
 }
Exemple #3
0
 public RestoreContextRequest(RDataBaseContext context) : base()
 {
     Params = new Parameters()
     {
         Id           = context.Id,
         TimeRestored = Tools.Time.DateTimeToUnixTimeMilliseconds(DateTime.UtcNow)
     };
 }
 public UpdateContextDataVariableRequest(RDataBaseContext context, string key, object value, long?timeUpdated = null) : this()
 {
     Params = new Parameters()
     {
         Id          = context.Id,
         Key         = key,
         Value       = value,
         TimeUpdated = timeUpdated.HasValue ? timeUpdated.Value : Tools.Time.UnixTimeMilliseconds
     };
 }
        public void UpdateContextData(RDataBaseContext context, string key, object value, bool immediately = false)
        {
            if (!CheckAuthorized("update data for context " + context.Name))
            {
                return;
            }

            var request = new Requests.Contexts.UpdateContextDataVariableRequest(context, key, value, Tools.Time.UnixTimeMilliseconds);

            CoroutineManager.StartCoroutine(Send <Requests.Contexts.UpdateContextDataVariableRequest, BooleanResponse>(request, immediately));
        }
        public void RestoreContext(RDataBaseContext context, bool immediately = false)
        {
            if (!CheckAuthorized("restore context " + context.Name))
            {
                return;
            }

            var request = new Requests.Contexts.RestoreContextRequest(context);

            CoroutineManager.StartCoroutine(Send <Requests.Contexts.RestoreContextRequest, BooleanResponse>(request, immediately));
        }
        public void EndContext(RDataBaseContext context, bool immediately = false)
        {
            if (!CheckAuthorized("end context " + context.Name))
            {
                return;
            }

            CheckContextDataUpdates(); // Check the updates of the context data first

            context.End();             // Then, end the context

            var request = new Requests.Contexts.EndContextRequest(context);

            CoroutineManager.StartCoroutine(Send <Requests.Contexts.EndContextRequest, BooleanResponse>(request, immediately));
        }
        public void StartContext <TContextData>(RDataContext <TContextData> context, RDataBaseContext parentContext = null, bool immediately = false)
            where TContextData : class, new()
        {
            if (!CheckAuthorized("start context " + context.Name))
            {
                return;
            }

            if (parentContext == null)
            {
                parentContext = _authorizationContext;
            }

            parentContext.AddChild(context);

            var request = new Requests.Contexts.StartContextRequest <TContextData>(context);

            CoroutineManager.StartCoroutine(Send <Requests.Contexts.StartContextRequest <TContextData>, BooleanResponse>(request, immediately));
        }
 public RDataEvent(TEventData data, RDataBaseContext context = null)
     : this(System.Guid.NewGuid().ToString(), System.DateTime.UtcNow, data, (context != null ? context.Id : null))
 {
 }