/// <summary> /// Execute the specified statement synchronously, returning the set of results. /// </summary> internal RowSet ExecuteResults(Cql type, Statement statement) { switch (type) { case Cql.Insert: case Cql.Update: case Cql.Delete: // if there are no pending queries that will not return results _batchLock.Take(); if (_batchReturnsResults || _batch.Count == 0) { _batchLock.Release(); return(_session.Execute(statement)); } _batchPageSize = statement.PageSize; // add this statement _batch.Add(statement); // execute the batch - releases the lock return(ExecuteBatch(false)); default: // execute the statement synchronously return(_session.Execute(statement)); } }
//-------------------------------------------// /// <summary> /// Derive a collection of one type from another, optionally with a predicate. /// </summary> public static ArrayRig <B> Derive <A, B>(this IEnumerable <A> collection, Func <A, B> mapper, Func <A, bool> predicate = null) { ArrayRig <B> rig = new ArrayRig <B>(); // was the predicate supplied? if (predicate == null) { // no, perform the mapping without foreach (A item in collection) { rig.Add(mapper(item)); } } else { // yes, perform the mapping with the predicate foreach (A item in collection) { if (predicate(item)) { rig.Add(mapper(item)); } } } return(rig); }
/// <summary> /// Move all current branches to the next search node that corresponds to the specified key. /// Returns if there is at least one value on the current branches. /// </summary> public bool Next(TKey key) { // skip if no branches if (!_root.leavesSet) { return(false); } // reset the current values Values.Reset(); // get the branches to iterate int count = Branches.Count; // always check the root branch foreach (Branch leaf in _root.leaves) { // if key equals search key if (leaf.key.Equals(key)) { // add next branch Branches.Enqueue(leaf); // if value - add it if (leaf.valueSet) { Values.Add(leaf.value); } } } // iterate branches to search while (--count >= 0) { Branches.Dequeue(); if (Branches.Current.leavesSet) { // iterate leaves of current branches foreach (Branch leaf in Branches.Current.leaves) { // if key equals search key if (leaf.key.Equals(key)) { // add next branch to the end of the queue Branches.Enqueue(leaf); // if value - add it if (leaf.valueSet) { Values.Add(leaf.value); } } } } } return(Values.Count != 0); }
/// <summary> /// Seek the stream. /// </summary> public override long Seek(long offset, SeekOrigin origin) { if (_initialize) { Initialize(true); } switch (origin) { case SeekOrigin.Begin: if (_position + _sectionPosition == offset) { return(offset); } _position = offset; break; case SeekOrigin.Current: _position += offset; break; case SeekOrigin.End: if (_position + _sectionPosition == _length - offset) { return(_position + _sectionPosition); } _position = _length - offset; break; } // determine the section index var sectionIndex = (int)(_position / _sectionSize); if (sectionIndex != _sectionIndex) { _sectionIndex = sectionIndex; if (_sectionIndex >= _sectionCount) { while (_sectionIndex >= _sections.Count) { _sections.Add(new BlobSection()); } _sectionCount = _sectionIndex + 1; } _section = _sections[_sectionIndex]; } // update the position within the current section _sectionPosition = (int)(_position % _sectionSize); // update the overrall section position _position -= _sectionPosition; return(_position + _sectionPosition); }
/// <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); }
/// <summary> /// Add a cluster to the current cluster connections. /// </summary> public static MetaCluster AddCluster(ArrayRig <string> entryPointAddresses, int port = 0, string username = null, string password = null) { var cluster = new MetaCluster(entryPointAddresses, port, username, password); // if the default cluster has not been set assign the new cluster if (_defaultCluster == null) { DefaultCluster = cluster; } Clusters.Add(cluster); return(cluster); }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { var array = new ArrayRig <object>(); foreach (KeyValuePair <string, HttpPostParam <string> > entry in ParamsStrings) { array.Add(entry); } foreach (KeyValuePair <string, HttpPostParam <ArrayRig <byte> > > entry in ParamsBytes) { array.Add(entry); } return(array.GetEnumerator()); }
/// <summary> /// Creates an iterator for split string with the possibility of escaping /// with two separators which will be reduced to one. /// </summary> public static ArrayRig <string> SplitEscaped(this string str, char separator) { // the collection of strings ArrayRig <string> split = new ArrayRig <string>(); int indexStart = 0; int indexEnd = 0; bool removeEscape = false; while (true) { // get the next index indexEnd = str.IndexOf(separator, indexStart); if (indexEnd > -1 && indexEnd + 1 < str.Length) { // check the next character if (str[indexEnd + 1] == separator) { removeEscape = true; } else { // do we have to escape double characters in this string? if (removeEscape) { split.Add(str.Section(indexStart, indexEnd).Replace(separator + separator.ToString(), separator.ToString())); } else { split.Add(str.Section(indexStart, indexEnd)); } } indexStart = indexEnd + 1; } else { // add the last string to the collection if (removeEscape) { split.Add(str.Section(indexStart, str.Length).Replace(separator + separator.ToString(), separator.ToString())); } else { split.Add(str.Section(indexStart, str.Length)); } break; } } return(split); }
/// <summary> /// Add a cql keyword to the query. /// </summary> public void Add(Cql cql) { if (Keywords.Count == 0) { _type = cql; } Keywords.Add(cql); // if the last set of values is not empty if (_currentSetCount != 0) { // add the last set count Sets.Add(_currentSetCount); _currentSetCount = 0; } }
/// <summary> /// Get all headers. /// </summary> public ArrayRig <Teple <string, string> > GetAll() { ArrayRig <Teple <string, string> > collection = new ArrayRig <Teple <string, string> >(); if (Accept != null) { collection.Add(new Teple <string, string>("Accept", Accept)); } foreach (object key in Headers) { collection.Add(new Teple <string, string>(key.ToString(), Headers[key.ToString()])); } return(collection); }
/// <summary> /// Dispose of the data cluster and all related resources. /// </summary> public void Dispose() { ArrayRig <Keyspace> keyspaces = new ArrayRig <Keyspace>(); // iterate and dispose of Keyspaces foreach (var keyspace in Keyspaces) { keyspaces.Add(keyspace.Value); } foreach (var keyspace in keyspaces) { keyspace.Dispose(); } _lock.Take(); Keyspaces.Clear(); Keyspaces = null; _lock.Release(); // remove the cluster from the manager ManagerCql.RemoveCluster(this); // dispose of the cassandra cluster Cluster.Shutdown(); Cluster.Dispose(); }
/// <summary> /// Add a root path and callback for the sub path. /// </summary> public void Add(string path, HttpMethod methods, IAction <string, HttpRequest> callback) { if (string.IsNullOrEmpty(path)) { throw new InvalidOperationException("Null or empty paths aren't allowed. Use the DefaultCallback field."); } path = path.ToLowercase(); if (path[0] == Chars.ForwardSlash) { path = path.Substring(1); } _lock.Take(); ArrayRig <Route> routes; if (_routes.TryGetValue(path, out routes)) { foreach (var route in routes) { if (route.Methods.Is(methods)) { throw new Exception("Route methods cannot be defined twice."); } } routes.Add(new Route(methods, callback)); } else { routes = new ArrayRig <Route>(); routes.Add(new Route(methods, callback)); _routes.Add(path, routes); } _lock.Release(); }
/// <summary> /// Add an item to be considered for the average. /// </summary> virtual public void Add(double _item) { // add the item to the batch batch.Add(_item); if (batch.Count == batchSize) { // calculate the current batch average average = 0; foreach (double item in batch) { average += item; } average /= batch.Count; batch.Reset(); if (filled) { // set a batch average batches[index] = average / batch.Count; ++index; if (index == batches.Count) { index = 0; } } else { // add a new batch average batches.Add(average / batch.Count); filled = batches.Count == batchCount; } } refresh = true; }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public virtual void Dispose() { if (_stopped) { return; } _stopped = true; try { // get a collection of the current connections var connections = new ArrayRig <UdpConnection>(); foreach (var entry in _connections.TakeItem()) { connections.Add(entry.Value); } _connections.Release(); // dispose of each connection foreach (var connection in connections) { connection.Dispose(); } // dispose of the listenning socket AsyncSocket.Dispose(); _socket.Dispose(); } catch (Exception ex) { Log.Error("Exception disposing of UDP server connections.", ex); } }
/// <summary> /// Add a new prototype. /// </summary> internal void Add(JsPrototype prototype) { if (!Prototypes.Contains(prototype)) { Prototypes.Add(prototype); } }
//-------------------------------------------// /// <summary> /// Initialize an element rule with a tag to parse and parameters to return. /// </summary> public ParseLine(ExtractLine extract) { _extract = extract; _line = new char[_extract.CharBuffer]; _reqParsersSet = extract.ReqExtracts != null; if (_reqParsersSet) { _reqParsers = new ArrayRig <Parse>(); foreach (Extract req in extract.ReqExtracts) { _reqParsers.Add(req.GetParser()); } } _subParsersSet = extract.SubExtracts != null; if (_subParsersSet) { _subParsers = new ArrayRig <Parse>(); foreach (Extract sub in extract.SubExtracts) { _subParsers.Add(sub.GetParser()); } } }
//----------------------------------// //----------------------------------// internal JsMethod(JsClass jsClass, MethodInfo method) { Parameters = new Dictionary <string, Js>(); Commands = new ArrayRig <JsCommand>(); // does the method return a string? if (method.ReturnType != typeof(string)) { throw new InvalidOperationException("JsMethod '" + method.Name + "' doesn't return a string."); } // iterate the parameters foreach (var parameter in method.GetParameters()) { // ensure each parameter is a Js type if (!Js.IsAncestor(parameter.ParameterType)) { throw new InvalidOperationException("Parameter '" + parameter.Name + "' of method '" + method.Name + "' in class '" + method.DeclaringType.Name + "' doesn't inherit from Js."); } // add the parameter Parameters.Add(parameter.Name, parameter.HasDefaultValue ? (Js)parameter.DefaultValue : null); } // add the string returned from the method as the javascript command Commands.Add(new JsCommandString((string)method.Invoke(jsClass, new object[Parameters.Count]))); }
/// <summary> /// Add a child style. /// </summary> public void Add(Style child) { if (_children == null) { _children = new ArrayRig <Style>(); } _children.Add(child); }
/// <summary> /// Add a sub extract that must exist within this section for it to be /// parsed successfully. /// </summary> public void AddRequirement(Extract extract) { if (ReqExtracts == null) { ReqExtracts = new ArrayRig <Extract>(); } ReqExtracts.Add(extract); }
/// <summary> /// Add a sub extract that will be parsed on a successful /// section. /// </summary> public void AddSubExtract(Extract extract) { if (SubExtracts == null) { SubExtracts = new ArrayRig <Extract>(); } SubExtracts.Add(extract); }
/// <summary> /// Construct a new identity. Optionally the identity will be added to the internal /// collection. /// </summary> public Identity(bool persist) { if (persist) { _identitiesLock.Take(); _identities.Add(this); _identitiesLock.Release(); } }
/// <summary> /// Add a sub extract to act on the body of the element if it exists. /// </summary> public void AddSubExtract(Extract extract) { if (!SubExtractSet) { SubExtractSet = true; SubExtract = new ArrayRig <Extract>(); } SubExtract.Add(extract); }
/// <summary> /// Add or Set a search node to the current search branches. /// </summary> public void Add(TValue value, ArrayRig <Struct <TKey[], bool> > keySets) { var sets = new ArrayRig <Struct <ArrayRig <TKey>, bool> >(keySets.Count); foreach (var s in keySets) { sets.Add(new Struct <ArrayRig <TKey>, bool>(new ArrayRig <TKey>(s.ArgA), s.ArgB)); } Add(value, sets); }
/// <summary> /// Add or Set a search node to the current search branches. /// </summary> public void Add(TValue value, params Struct <TKey[], bool>[] keySets) { var sets = new ArrayRig <Struct <ArrayRig <TKey>, bool> >(keySets.Length); foreach (var s in keySets) { sets.Add(new Struct <ArrayRig <TKey>, bool>(new ArrayRig <TKey>(s.ArgA), s.ArgB)); } Add(value, sets); }
/// <summary> /// Add the next value at the specified delta time. /// </summary> public void Add(double delta, B value) { switch (Values.Count) { case 0: Values.Add(value); Deltas.Add(delta); break; case 1: if (delta > Deltas[0]) { Values.Add(value); Deltas.Add(delta); } else { Values.Insert(value, 0); Deltas.Insert(delta, 0); } break; default: int index = Values.Count + 1; while (--index > 0) { if (Deltas[index] < delta) { Values.Insert(value, index); Deltas.Insert(delta, index); return; } if (Deltas[index].Equal(delta)) { Values[index] = value; return; } } break; } }
/// <summary> /// Get a copy of the current collection of values in the cache. /// </summary> public ArrayRig <TValue> GetValues() { ArrayRig <TValue> collection = new ArrayRig <TValue>(); _lock.Take(); foreach (var entry in _lookup) { collection.Add(entry.Value.ArgC); } _lock.Release(); return(collection); }
/// <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(); }
/// <summary> /// Add an old url that has been parsed. /// </summary> public void AddOld(Url url) { _lock.Take(); _oldUrls.Add(url); _changed = true; if (_oldUrls.Count + _newUrls.Count == MaxUrls && !_committing) { _commit.Run(); _committing = true; } _lock.Release(); }
//-------------------------------------------// /// <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); } } } } }
/// <summary> /// Split a path into its components. /// </summary> public static ArrayRig <string> Split(string path) { ArrayRig <string> split; if (path.Contains(Chars.ForwardSlash)) { split = new ArrayRig <string>(path.Split(Chars.ForwardSlash)); for (int i = split.Count - 1; i >= 0; --i) { if (string.IsNullOrEmpty(split[i])) { split.Remove(i); if (i > 0) { string part = split[i - 1]; if (part.Length > 1 && part[part.Length - 1] == Chars.Colon) { split[i - 1] = part + Chars.ForwardSlash; } } } } } else if (path.Contains(Chars.BackSlash)) { split = new ArrayRig <string>(path.Split(Chars.BackSlash)); for (int i = split.Count - 1; i >= 0; --i) { if (string.IsNullOrEmpty(split[i])) { split.Remove(i); if (i > 0) { string part = split[i - 1]; if (part.Length > 1 && part[part.Length - 1] == Chars.Colon) { split[i - 1] = part + Chars.BackSlash; } } } } } else { split = new ArrayRig <string>(); split.Add(path); } return(split); }