Ejemplo n.º 1
0
 public void Dispose()
 {
     foreach (Teple <IEnumerator <Node>, bool> e in _nodeEnumerators)
     {
         e.ArgA.Dispose();
     }
     _nodeEnumerators.Clear();
     _currentEnumerator.Dispose();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the element with a callback.
        /// </summary>
        public void Get(IAction <Element> onGet)
        {
            _lock.Take();

            _callbacks.Add(onGet);

            if (_processing)
            {
                _lock.Release();
                return;
            }

            _processing = true;

            // check if the link has or should be updated
            if (_element == null)
            {
                if (_path == null)
                {
                    ManagerUpdate.Control.AddSingle(OnRetrieved, _getElement.Run());
                }
                else
                {
                    new ElementParser(_path, Act.New(OnParsed, (ElementParser)null)).Run();
                }
            }
            else
            {
                if (_nextUpdate < Time.Milliseconds)
                {
                    if (_path == null)
                    {
                        ManagerUpdate.Control.AddSingle(OnRetrieved, _getElement.Run());
                    }
                    else
                    {
                        new ElementParser(_path, Act.New(OnParsed, (ElementParser)null)).Run();
                    }
                }
                else
                {
                    _processing = false;
                    foreach (var callback in _callbacks)
                    {
                        callback.ArgA = _element.Clone();
                        ManagerUpdate.Control.AddSingle(callback);
                    }
                    _callbacks.Clear();
                }
            }

            _lock.Release();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Set the content of the element the builder represents.
 /// </summary>
 public ElementBuilder SetContent(string content)
 {
     if (Content == null)
     {
         Content = new ArrayRig <Teple <string, IFunc <string> > >(1);
     }
     else
     {
         Content.Clear();
     }
     Content.Add(new Teple <string, IFunc <string> >(content, null));
     return(this);
 }
Ejemplo n.º 4
0
        //----------------------------------//

        /// <summary>
        /// Reset the double arrays.
        /// </summary>
        protected override void Reset()
        {
            Left.Clear();
            if (Right != null)
            {
                Right.Clear();
            }
        }
Ejemplo n.º 5
0
        //-------------------------------------------//

        /// <summary>
        /// Update the form with children elements.
        /// </summary>
        protected void Update()
        {
            _update = false;
            _forms.Clear();
            _input.Clear();
            // iterate the elements
            HashSet <Element> hashSet = new HashSet <Element>(_elements.TakeItem());

            _elements.Release();
            foreach (var element in hashSet)
            {
                if (element.Tag == Tag.Input)
                {
                    Element parent = element.Parent;
                    while (parent != null && parent != this && parent.Tag != Tag.Form)
                    {
                        parent = parent.Parent;
                    }

                    if (parent == this)
                    {
                        var input = element as ElementInput;
                        if (input == null || input["name"] == null)
                        {
                            continue;
                        }
                        if (!_input.ContainsKey(input["name"]))
                        {
                            _input.Add(input["name"], input);
                        }
                    }
                }
                else if (element.Tag == Tag.Form)
                {
                    Element parent = element.Parent;
                    while (parent != null && parent != this && parent.Tag != Tag.Form)
                    {
                        parent = parent.Parent;
                    }

                    if (parent == this)
                    {
                        var form = element as ElementForm;
                        if (form != null && !_forms.Contains(form))
                        {
                            _forms.Add(form);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Clear all actions from this instance.
 /// </summary>
 public void Clear()
 {
     Actions.Clear();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Execute the current collection of statements.
        /// The batch lock should be taken when this is called and is released during execution.
        /// </summary>
        protected RowSet ExecuteBatch(bool takeLock = true)
        {
            // is the lock to be used? yeah, take it
            if (takeLock)
            {
                _batchLock.Take();
            }

            // reset the timer
            _batchTimer.Reset(BatchInterval);
            _batchTimer.Run = false;

            // create a new batch statement
            BatchStatement batchStatement = new BatchStatement();

            batchStatement.SetReadTimeoutMillis(BatchTimeout);

            // add all current statements
            for (int i = 0; i < _batch.Count; ++i)
            {
                batchStatement.Add(_batch[i]);
            }

            // set the batch page size
            batchStatement.SetPageSize(_batchPageSize);

            // reset the batch
            _batch.Reset();
            _batchReturnsResults = false;

            // copy the collection of callbacks
            ArrayRig <IAction> callbacks = new ArrayRig <IAction>(_onExecuted);

            _onExecuted.Clear();

            // release the batch lock
            _batchLock.Release();

            RowSet rowSet;

            try {
                // execute the batch statement
                rowSet = _session.Execute(batchStatement);
            } catch (Exception ex) {
                var builder = StringBuilderCache.Get();
                builder.Append("An exception occured executing a batch statement '");
                var obj = typeof(BatchStatement).GetProperty("Queries",
                                                             System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.NonPublic)
                          .GetValue(batchStatement);
                if (obj == null)
                {
                    builder.Append("Unknown");
                }
                else
                {
                    var  statements = (List <Statement>)obj;
                    bool first      = true;
                    foreach (var statement in statements)
                    {
                        if (statement.OutgoingPayload == null)
                        {
                            continue;
                        }
                        foreach (var query in statement.OutgoingPayload.Keys)
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                builder.Append(", ");
                            }
                            builder.Append(query);
                        }
                    }
                }

                builder.Append("'. ");
                Log.Error(builder.ToString(), ex);

                return(null);
            }

            // run callback with results
            if (_onExecutedResults != null)
            {
                _onExecutedResults.ArgA = rowSet;
                _onExecutedResults.Run();
                _onExecutedResults = null;
            }

            // run callbacks
            foreach (IAction callback in callbacks)
            {
                callback.Run();
            }
            callbacks.Dispose();

            return(rowSet);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Clear all actions from this instance.
 /// </summary>
 public void Clear()
 {
     _lock.Take();
     Actions.Clear();
     _lock.Release();
 }