public void Returns_false_when_items_exist()
        {
            var dict = new Dictionary<string, object>()
            {
                ["foo"] = new object()
            };

            dict.IsNullOrEmpty().ShouldBeFalse();
        }
        public void NotifyEverybodyInChatAboutProfileChanges(int playerId, Dictionary<string, object> properties)
        {
            if (properties.IsNullOrEmpty())
                return;

            var info = new UserPropertiesChangedInfo();
            info.Properties = properties.Select(i => new PropertyValuePair(i.Key, i.Value)).ToArray();
            info.UserId = playerId;
            _sessionManager.SendToEachChatSessions(info);
        }
        public Generator(Project project, Dictionary<Template, List<TemplateOutputDefinitionFilenameResult>> templateOutputs) {
            if (project == null)
                throw new ArgumentNullException("project");

            if (templateOutputs.IsNullOrEmpty())
                throw new ArgumentNullException("templateOutputs");

            this.Project = project;
            this.TemplateOutputs = templateOutputs;
            this.CancellationTokenSource = new CancellationTokenSource();
        }
Example #4
0
        /// <summary>
        /// Creates a new DBObject of a given GraphType inserts its UUID into all indices of the given GraphType.
        /// </summary>
        /// <param name="myGraphDBType">The GraphType of the DBObject to create</param>
        /// <param name="myDBObjectAttributes">A dictionary of attributes for the new DBObject</param>
        /// <param name="mySpecialTypeAttributes">Special values which should be set to a object</param>
        /// <param name="myCheckUniqueness">check for unique constraints</param> 
        /// <returns>The UUID of the new DBObject</returns>
        public Exceptional<DBObjectStream> CreateNewDBObjectStream(GraphDBType myGraphDBType, Dictionary<AttributeUUID, IObject> myDBObjectAttributes, Dictionary<String, IObject> myUndefAttributes, Dictionary<ASpecialTypeAttribute, Object> mySpecialTypeAttributes, SessionSettings mySessionSettings, Boolean myCheckUniqueness)
        {
            #region Input validation

            if (myGraphDBType == null)
                return new Exceptional<DBObjectStream>(new Error_ArgumentNullOrEmpty("The parameter myGraphType must not be null!"));

            if (myDBObjectAttributes == null)
                return new Exceptional<DBObjectStream>(new Error_ArgumentNullOrEmpty("The parameter myDBObjectAttributes must not be null!"));

            #endregion

            #region Check uniqueness

            if (myCheckUniqueness)
            {

                var parentTypes = _DBContext.DBTypeManager.GetAllParentTypes(myGraphDBType, true, false);
                var CheckVal = _DBContext.DBIndexManager.CheckUniqueConstraint(myGraphDBType, parentTypes, myDBObjectAttributes);

                if (CheckVal.Failed())
                    return new Exceptional<DBObjectStream>(CheckVal);

            }

            #endregion

            #region Create a new DBObjectStream

            DBObjectStream        _NewDBObjectStream               = null;
            ObjectUUID            _NewObjectUUID                   = null;
            ASpecialTypeAttribute _SpecialTypeAttribute_UUID_Key   = new SpecialTypeAttribute_UUID();
            Object                _SpecialTypeAttribute_UUID_Value = null;

            #region Search for an user-defined ObjectUUID

            if (mySpecialTypeAttributes != null)
            {
                if (mySpecialTypeAttributes.TryGetValue(_SpecialTypeAttribute_UUID_Key, out _SpecialTypeAttribute_UUID_Value))
                {

                    // User-defined ObjectUUID of type UInt64
                    var _ValueAsUInt64 = _SpecialTypeAttribute_UUID_Value as UInt64?;
                    if (_ValueAsUInt64 != null)
                        _NewObjectUUID = new ObjectUUID(_ValueAsUInt64.Value);

                    // User-defined ObjectUUID of type String or anything else...
                    else
                    {

                        var _String = _SpecialTypeAttribute_UUID_Value.ToString();
                        if (_String == null || _String == "")
                            return new Exceptional<DBObjectStream>(new Error_InvalidAttributeValue(SpecialTypeAttribute_UUID.AttributeName, _String));

                        _NewObjectUUID = new ObjectUUID(_SpecialTypeAttribute_UUID_Value.ToString());

                    }

                    mySpecialTypeAttributes[_SpecialTypeAttribute_UUID_Key] = _NewObjectUUID;

                }
            }

            #endregion

            // If _NewObjectUUID == null a new one will be generated!
            _NewDBObjectStream                = new DBObjectStream(_NewObjectUUID, myGraphDBType, myDBObjectAttributes);
            _NewDBObjectStream.ObjectLocation = new ObjectLocation(_NewDBObjectStream.ObjectPath, _NewDBObjectStream.ObjectUUID.ToString());

            #endregion

            #region Check for duplicate ObjectUUIDs... maybe resolve duplicates!

            var _DBObjectStreamAlreadyExistsResult = ObjectExistsOnFS(_NewDBObjectStream);

            if (_DBObjectStreamAlreadyExistsResult.Failed())
                return new Exceptional<DBObjectStream>(_DBObjectStreamAlreadyExistsResult);

            while (_DBObjectStreamAlreadyExistsResult.Value == Trinary.TRUE)
            {

                if (_NewObjectUUID != null)
                    return new Exceptional<DBObjectStream>(new Error_DBObjectCollision(_NewDBObjectStream));

                _NewDBObjectStream                = new DBObjectStream(ObjectUUID.NewUUID, myGraphDBType, myDBObjectAttributes);
                _NewDBObjectStream.ObjectLocation = new ObjectLocation(_NewDBObjectStream.ObjectPath, _NewDBObjectStream.ObjectUUID.ToString());

                _DBObjectStreamAlreadyExistsResult = ObjectExistsOnFS(_NewDBObjectStream);

                if (_DBObjectStreamAlreadyExistsResult.Failed())
                    return new Exceptional<DBObjectStream>(_DBObjectStreamAlreadyExistsResult);

            }

            #endregion

            #region Check for ExtractSetting attributes unlike UUID

            if (mySpecialTypeAttributes != null && mySpecialTypeAttributes.Any())
            {
                foreach (var _SpecialAttribute in mySpecialTypeAttributes)
                {
                    // Skip SpecialTypeAttribute_UUID!
                    if (!(_SpecialAttribute.Key is SpecialTypeAttribute_UUID))
                    {
                        var result = _SpecialAttribute.Key.ApplyTo(_NewDBObjectStream, _SpecialAttribute.Value);
                        if (result.Failed())
                        {
                            return new Exceptional<DBObjectStream>(result);
                        }
                    }
                }
            }

            #endregion

            // Flush new DBObject
            var flushResult = FlushDBObject(_NewDBObjectStream);

            if (flushResult.Failed())
                return new Exceptional<DBObjectStream>(flushResult);

            #region Check for existing object - might be removed at some time

            //var exists = ObjectExistsOnFS(_NewDBObjectStream);

            //if (exists.Failed())
            //    return new Exceptional<DBObjectStream>(exists);

            //if (exists.Value != Trinary.TRUE)
            //{
            //    return new Exceptional<DBObjectStream>(new Error_UnknownDBError("DBObject with path " + _NewDBObjectStream.ObjectLocation + " does not exist."));
            //}

            #endregion

            #region Add UUID of the new DBObject to all indices of myGraphType

            foreach (var _GraphDBType in _DBContext.DBTypeManager.GetAllParentTypes(myGraphDBType, true, false))
            {
                foreach (var _AAttributeIndex in _GraphDBType.GetAllAttributeIndices(false))
                {
                    //Find out if the dbobject carries all necessary attributes
                    if (_NewDBObjectStream.HasAtLeastOneAttribute(_AAttributeIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs, _GraphDBType, mySessionSettings))
                    {
                        //valid dbo for idx
                        _AAttributeIndex.Insert(_NewDBObjectStream, _GraphDBType, _DBContext);
                    }
                }
            }

            #endregion

            #region add undefined attributes to the object

            if (!myUndefAttributes.IsNullOrEmpty())
            {
                foreach (var item in myUndefAttributes)
                {
                    var addExcept = _NewDBObjectStream.AddUndefinedAttribute(item.Key, item.Value, this);

                    if (addExcept.Failed())
                    {
                        return new Exceptional<DBObjectStream>(addExcept);
                    }
                }
            }

            #endregion

            return new Exceptional<DBObjectStream>(_NewDBObjectStream);
        }
 public void ItShouldBeFalse()
 {
     IDictionary<string, bool> blah = new Dictionary<string, bool>();
     blah.Add(Guid.NewGuid().ToString(), true);
     Assert.IsFalse(blah.IsNullOrEmpty());
 }
Example #6
0
        /// <summary>
        /// Recursively traverse the schema's extends to verify that it or one of it's parents
        /// has at least one property
        /// </summary>
        /// <param name="properties">The schema's properties</param>
        /// <param name="extends">The schema's extends</param>
        /// <returns>True if one or more properties found in this schema or in it's ancestors. False otherwise</returns>
        private bool AncestorsHaveProperties(Dictionary<string, Schema> properties, string extends)
        {
            if (properties.IsNullOrEmpty() && string.IsNullOrEmpty(extends))
            {
                return false;
            }

            if (!properties.IsNullOrEmpty())
            {
                return true;
            }

            Debug.Assert(!string.IsNullOrEmpty(extends) && ServiceDefinition.Definitions.ContainsKey(extends));
            return AncestorsHaveProperties(ServiceDefinition.Definitions[extends].Properties,
                ServiceDefinition.Definitions[extends].Extends);
        }
 public void ItShouldBeTrue()
 {
     IDictionary<string, bool> blah = new Dictionary<string, bool>();
     Assert.IsTrue(blah.IsNullOrEmpty());
 }
        /// <summary>
        /// Create a readout based on the passed <paramref name="attributes"/>, <paramref name="undefinedAttributes"/>, <paramref name="specialTypeAttributes"/> which are all optional
        /// </summary>
        /// <param name="myDBObjectStreamExceptional"></param>
        /// <param name="attributes"></param>
        /// <param name="undefinedAttributes"></param>
        /// <param name="specialTypeAttributes"></param>
        /// <returns></returns>
        private Exceptional<Vertex> GetManipulationResultSet(DBContext myDBContext, Exceptional<DBObjectStream> myDBObjectStreamExceptional, GraphDBType myGraphDBType, Dictionary<TypeAndAttributeDefinition, IObject> attributes = null, Dictionary<String, IObject> undefinedAttributes = null, Dictionary<ASpecialTypeAttribute, Object> specialTypeAttributes = null)
        {
            Vertex _Vertex = null;

            #region Return inserted attributes

            #region attributes

            if (!attributes.IsNullOrEmpty())
            {
                _Vertex = new Vertex(attributes.ToDictionary(key => key.Key.Definition.Name, value => value.Value.GetReadoutValue()));
            }
            else
            {
                _Vertex = new Vertex();
            }

            #endregion

            #region UndefinedAttributes

            if (!undefinedAttributes.IsNullOrEmpty())
            {

                foreach (var undefAttr in undefinedAttributes)
                {
                    _Vertex.AddAttribute(undefAttr.Key, undefAttr.Value.GetReadoutValue());
                }

            }

            #endregion

            #region SpecialTypeAttributes

            if (!specialTypeAttributes.IsNullOrEmpty())
            {

                foreach (var specAttr in specialTypeAttributes)
                {
                    _Vertex.AddAttribute(specAttr.Key.Name, specAttr.Value);
                }

            }

            #endregion

            #region UUID

            if (!_Vertex.HasAttribute(SpecialTypeAttribute_UUID.AttributeName))
            {

                var extractedValue = new SpecialTypeAttribute_UUID().ExtractValue(myDBObjectStreamExceptional.Value, myGraphDBType, myDBContext);

                if (extractedValue.Failed())
                {
                    return new Exceptional<Vertex>(extractedValue);
                }

                _Vertex.AddAttribute(SpecialTypeAttribute_UUID.AttributeName, extractedValue.Value.GetReadoutValue());

            }

            #endregion

            #region REVISION

            if (!_Vertex.HasAttribute(SpecialTypeAttribute_REVISION.AttributeName)) // If it was updated by SpecialTypeAttributes we do not need to add them again
            {

                var extractedValue = new SpecialTypeAttribute_REVISION().ExtractValue(myDBObjectStreamExceptional.Value, myGraphDBType, myDBContext);
                if (extractedValue.Failed())
                {
                    return new Exceptional<Vertex>(extractedValue);
                }
                _Vertex.AddAttribute(SpecialTypeAttribute_REVISION.AttributeName, extractedValue.Value.GetReadoutValue());

            }

            #endregion

            #endregion

            return new Exceptional<Vertex>(_Vertex);
        }
Example #9
0
        public IEnumerable<Vertex> GetTypeIndependendResult()
        {

            //_DBOs = new IEnumerable<Vertex>();
            var Attributes = new Dictionary<string, object>();

            #region Go through all _SelectionElementsTypeIndependend

            foreach (var selection in _SelectionElementsTypeIndependend)
            {
                if (selection is SelectionElementFunction)
                {
                    var func = ((SelectionElementFunction)selection);
                    Exceptional<FuncParameter> funcResult = null;
                    var alias = func.Alias;

                    while (func != null)
                    {
                        funcResult = func.Function.Execute(null, null, null, _DBContext);
                        if (funcResult.Success())
                        {

                            if (funcResult.Value.Value == null)
                            {
                                break; // no result for this object because of not set attribute value
                            }
                            else
                            {
                                func = func.FollowingFunction;
                                if (func != null)
                                {
                                    func.Function.Function.CallingObject = funcResult.Value.Value;
                                }
                            }
                            
                        }
                        else
                        {
                            //return new Exceptional<IEnumerable<Vertex>>(res.Errors);
                            throw new GraphDBException(funcResult.IErrors);
                        }
                    }

                    if (funcResult.Value.Value == null)
                    {
                        continue; // no result for this object because of not set attribute value
                    }

                    Attributes.Add(alias, ((FuncParameter)funcResult.Value).Value.GetReadoutValue());
                }
            }

            #endregion

            if (!Attributes.IsNullOrEmpty())
            {
                yield return new Vertex(Attributes);
            }

        }
Example #10
0
        public IEnumerable<IVertexView> GetTypeIndependendResult(SecurityToken mySecurityToken, 
                                                                    Int64 myTransactionToken)
        {

            //_DBOs = new IEnumerable<Vertex>();
            var Attributes = new Dictionary<string, object>();

            #region Go through all _SelectionElementsTypeIndependend

            foreach (var selection in _SelectionElementsTypeIndependend)
            {
                if (selection is SelectionElementFunction)
                {
                    var func = ((SelectionElementFunction)selection);
                    FuncParameter funcResult = null;
                    var alias = func.Alias;
                    object CallingObject = null;
                    while (func != null)
                    {
                        var parameter = func.Function.Execute(null, null, null, _pluginManager, _graphdb, mySecurityToken, myTransactionToken);
                        funcResult = func.Function.Function.ExecFunc(null, CallingObject, null, _graphdb, mySecurityToken, myTransactionToken, parameter.ToArray());
                        if (funcResult.Value == null)
                        {
                            break; // no result for this object because of not set attribute value
                        }
                        else
                        {
                            func = func.FollowingFunction;
                            if (func != null)
                            {
                                CallingObject = funcResult.Value;
                            }
                        }

                    }

                    if (funcResult.Value == null)
                    {
                        continue; // no result for this object because of not set attribute value
                    }

                    Attributes.Add(alias, funcResult.Value);
                }
            }

            #endregion

            if (!Attributes.IsNullOrEmpty())
            {
                yield return new VertexView(Attributes, null);
            }

        }
Example #11
0
        /// <summary>
        /// 统计停车次数,过滤停车时长小于指定值的次数
        /// </summary>
        /// <param name="dicCodeAndLicenceNumber"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <param name="second"></param>
        /// <param name="tenantCode"></param>
        /// <returns></returns>
        public Dictionary<Guid, VCountStopCar> Count(Dictionary<Guid, string> dicCodeAndLicenceNumber, DateTime beginTime, DateTime endTime,
                                                     int second, string tenantCode)
        {
            if (dicCodeAndLicenceNumber.IsNullOrEmpty())
            {
                return new Dictionary<Guid, VCountStopCar>();
            }
            IList<Guid> ltVehicleCode = dicCodeAndLicenceNumber.Keys.ToList();

            return Count(ltVehicleCode, beginTime, endTime, second, tenantCode);
        }
        public void Returns_true_when_empty()
        {
            var dict = new Dictionary<string, object>();

            dict.IsNullOrEmpty().ShouldBeTrue();
        }