Ejemplo n.º 1
0
    void CmdValidateNameUnique(string name)
    {
        this.ClientName   = name;//Server side synchronisation
        this.NameIsUnique = PropertyBag.GlobalChatManager.ValidateNameIsNew(this.ClientName) ? Uniqueness.UNIQUE : Uniqueness.NONUNIQUE;

        TargetSetNameUniquness(this.connectionToClient, this.NameIsUnique);
    }
Ejemplo n.º 2
0
 public TestBestFirstSelectorFactory(PathExpander expander, PathInterest <int> interest, Uniqueness uniqueness, string[] expectedResult)
 {
     this._expander       = expander;
     this._uniqueness     = uniqueness;
     this._expectedResult = expectedResult;
     _factory             = new BestFirstSelectorFactoryAnonymousInnerClass(this, interest);
 }
Ejemplo n.º 3
0
        protected async override Task <JArray> ExecuteAsync(AsyncCodeActivityContext context)
        {
            var encrypt = EncryptFields.Get(context);

            if (encrypt == null)
            {
                encrypt = "";
            }
            var collection = Collection.Get(context);

            if (string.IsNullOrEmpty(collection))
            {
                collection = "entities";
            }
            var type       = Type.Get(context);
            var uniqueness = Uniqueness.Get(context);

            var dt = DataTable.Get(context);

            var items = new List <JObject>();

            foreach (DataRow row in dt.Rows)
            {
                if (row.RowState == DataRowState.Deleted)
                {
                    var _id = row["_id", DataRowVersion.Original].ToString();
                    await global.webSocketClient.DeleteOne(collection, _id);
                }
                else if (row.RowState == DataRowState.Added || row.RowState == DataRowState.Modified)
                {
                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                        Converters        = { new DataRowConverter() },
                    };
                    var rowJson = JsonConvert.SerializeObject(row, Formatting.Indented, settings);
                    var result  = JObject.Parse(rowJson);
                    if (!string.IsNullOrEmpty(encrypt))
                    {
                        result["_encrypt"] = encrypt;
                    }
                    var name = result.GetValue("name", StringComparison.OrdinalIgnoreCase)?.Value <string>();
                    result["name"] = name;
                    if (!string.IsNullOrEmpty(type))
                    {
                        result["_type"] = type;
                    }
                    items.Add(result);
                }
            }
            await global.webSocketClient.InsertOrUpdateMany <JObject>(collection, 1, false, uniqueness, true, items.ToArray());

            dt.AcceptChanges();
            System.Windows.Forms.Application.DoEvents();
            return(new JArray(results));
        }
Ejemplo n.º 4
0
        protected async override Task <JObject> ExecuteAsync(AsyncCodeActivityContext context)
        {
            var ignoreErrors = IgnoreErrors.Get(context);
            var encrypt      = EncryptFields.Get(context);

            if (encrypt == null)
            {
                encrypt = "";
            }
            var collection = Collection.Get(context);

            if (string.IsNullOrEmpty(collection))
            {
                collection = "entities";
            }
            var type       = Type.Get(context);
            var uniqeness  = Uniqeness.Get(context);
            var uniqueness = Uniqueness.Get(context);

            if (string.IsNullOrEmpty(uniqueness))
            {
                uniqueness = uniqeness;
            }
            JObject result = null;
            var     o      = Item.Get(context);

            if (o.GetType() != typeof(JObject))
            {
                var t = Task.Factory.StartNew(() =>
                {
                    result = JObject.FromObject(o);
                });
                t.Wait();
            }
            else
            {
                result = (JObject)o;
            }

            if (!string.IsNullOrEmpty(encrypt))
            {
                result["_encrypt"] = encrypt;
            }
            var name = result.GetValue("name", StringComparison.OrdinalIgnoreCase)?.Value <string>();

            result["name"] = name;
            if (!string.IsNullOrEmpty(type))
            {
                result["_type"] = type;
            }
            result = await global.webSocketClient.InsertOrUpdateOne(collection, 1, false, uniqeness, result);

            System.Windows.Forms.Application.DoEvents();
            return(result);
        }
Ejemplo n.º 5
0
        public void Should_exclude_duplicate_urls()
        {
            var results = new List <ResultInfo>();

            results.AddRange(ResultInfoBuilder.GenerateUnique("random", 10));
            results.Add(results.Choice().UsingIndex(0));
            var sut       = new Uniqueness(null);
            var processed = sut.Process(results);

            processed.Should().NotBeEmpty()
            .And.HaveCount(results.Count() - 1);
        }
Ejemplo n.º 6
0
            /// <summary>
            /// DeleteRule: typeof(UniquenessIsForUniquenessConstraint)
            /// </summary>
            private static void UniquenessBridgeDetachedRule(ElementDeletedEventArgs e)
            {
                Uniqueness uniqueness = ((UniquenessIsForUniquenessConstraint)e.ModelElement).Uniqueness;

                if (!uniqueness.IsDeleted)
                {
                    // We don't want to rebuild the model for this case. Any significant
                    // change that affects the absorption pattern will remove it, and
                    // there are no cases where we need to keep it. Just propagate.
                    uniqueness.Delete();
                }
            }
        public void CheckUniqueness()
        {
            Uniqueness uniqueA1 = new Uniqueness();
            Uniqueness uniqueA2 = new Uniqueness();

            Assert.AreNotEqual(uniqueA1.UniqueID, uniqueA2.UniqueID);
            Assert.AreNotEqual(uniqueA1.GetHashCode(), uniqueA2.GetHashCode());

            Assert.AreEqual(uniqueA1, (object)uniqueA1);
            Assert.AreEqual((IUniqueID)uniqueA1, (object)uniqueA1);
            Assert.AreEqual(uniqueA1.UniqueID, uniqueA1.GetHashCode());
        }
Ejemplo n.º 8
0
        // [TestCase(1000000000, Result = -1)] // Turns out an Int[] can't handle 1,000,000,000 items, the max is 268435456
        public int LargeNonUniqueNumbers(int count)
        {
            int[] A;

            var items = new List <int>();

            for (int i = 1; i < count; i++)
            {
                items.Add(2);
            }

            A = items.ToArray();

            var underTest = new Uniqueness();

            return(underTest.findUniqueItem(A));
        }
Ejemplo n.º 9
0
            /// <summary>
            /// DeletingRule: typeof(ORMSolutions.ORMArchitect.ORMAbstraction.UniquenessIncludesConceptTypeChild)
            /// Remove a column in a uniqueness constraint when a concept type child is removed from the
            /// corresponding abstraction construct
            /// </summary>
            private static void UniquenessConstraintRoleDeleting(ElementDeletingEventArgs e)
            {
                UniquenessIncludesConceptTypeChild link = (UniquenessIncludesConceptTypeChild)e.ModelElement;
                Uniqueness uniqueness = link.Uniqueness;
                LinkedElementCollection <UniquenessConstraint> constraints;
                int constraintCount;

                if (!uniqueness.IsDeleting &&
                    !link.ConceptTypeChild.IsDeleting &&
                    0 != (constraintCount = (constraints = UniquenessConstraintIsForUniqueness.GetUniquenessConstraint(uniqueness)).Count))
                {
                    int removeAtIndex = UniquenessIncludesConceptTypeChild.GetLinksToConceptTypeChildCollection(uniqueness).IndexOf(link);
                    for (int i = 0; i < constraintCount; ++i)
                    {
                        constraints[i].ColumnCollection.RemoveAt(removeAtIndex);
                    }
                }
            }
Ejemplo n.º 10
0
		/// <summary>
		/// Generages the <see cref="ConceptType"/> objects along with any relationships that they have and adds them to the
		/// model.
		/// </summary>
		/// <param name="factTypeMappings">A dictionary of all the final decided FactTypeMapping objects.</param>
		private void GenerateConceptTypes(FactTypeMappingDictionary factTypeMappings)
		{
			ORMModel model = this.ORMModel;
			LinkedElementCollection<ObjectType> modelObjectTypes = model.ObjectTypeCollection;
			AbstractionModel oialModel = this.AbstractionModel;

			// For each object type in the model...
			foreach (ObjectType objectType in modelObjectTypes)
			{
				if (ShouldIgnoreObjectType(objectType))
				{
					continue;
				}
				// If it should have a conctpt type...
				if (ObjectTypeIsConceptType(objectType, factTypeMappings))
				{
					// Create the ConceptType object.
					PropertyAssignment name = new PropertyAssignment(ConceptType.NameDomainPropertyId, objectType.Name);
					ConceptType conceptType = new ConceptType(Store, name);
					ConceptTypeIsForObjectType conceptTypeIsForObjectType = new ConceptTypeIsForObjectType(conceptType, objectType);

					// Add it to the model.
					oialModel.ConceptTypeCollection.Add(conceptType);

					// If this conceptType is for a ValueType...
					if (objectType.IsValueType)
					{
						InformationTypeFormat valueTypeInformationTypeFormat = InformationTypeFormatIsForValueType.GetInformationTypeFormat(objectType);

						RoleAssignment conceptTypeRole = new RoleAssignment(InformationType.ConceptTypeDomainRoleId, conceptType);
						RoleAssignment informationTypeFormat = new RoleAssignment(InformationType.InformationTypeFormatDomainRoleId, valueTypeInformationTypeFormat);
						RoleAssignment[] roleAssignments = { conceptTypeRole, informationTypeFormat };
						PropertyAssignment isMandatory = new PropertyAssignment(InformationType.IsMandatoryDomainPropertyId, true);
						PropertyAssignment informationTypeNameProperty = new PropertyAssignment(InformationType.NameDomainPropertyId, String.Concat(objectType.Name, "Value"));
						PropertyAssignment[] informationTypePropertyAssignments = { isMandatory, informationTypeNameProperty };

						// ConceptType for conceptType gets an InformationType that references InformationTypeFormat for conceptType.
						InformationType informationType = new InformationType(Store, roleAssignments, informationTypePropertyAssignments);

						PropertyAssignment uniquenessNameProperty = new PropertyAssignment(Uniqueness.NameDomainPropertyId, String.Concat(objectType.Name, "Uniqueness"));
						PropertyAssignment isPreferred = new PropertyAssignment(Uniqueness.IsPreferredDomainPropertyId, true);
						PropertyAssignment[] uniquenessPropertyAssignments = { uniquenessNameProperty, isPreferred };

						// Uniqueness constraint
						Uniqueness uniqueness = new Uniqueness(Store, uniquenessPropertyAssignments);
						UniquenessIncludesConceptTypeChild uniquenessIncludesConceptTypeChild = new UniquenessIncludesConceptTypeChild(uniqueness, informationType);

						conceptType.UniquenessCollection.Add(uniqueness);
					}
				}
			}
		}
Ejemplo n.º 11
0
		/// <summary>
		/// Generates the <see cref="Uniqueness"/> objects for the <see cref="AbstractionModel"/>.
		/// </summary>
		/// <param name="factTypeMappings">The decided <see cref="FactTypeMapping"/> objects.</param>
		private void GenerateUniqueness(FactTypeMappingDictionary factTypeMappings)
		{
			// TODO: clean this up.
			AbstractionModel oialModel = this.AbstractionModel;

			// For each concept type in the model...
			foreach (ConceptType conceptType in oialModel.ConceptTypeCollection)
			{
				ObjectType objectType = ConceptTypeIsForObjectType.GetObjectType(conceptType);

				// For each role played by its object type...
				foreach (Role role in objectType.PlayedRoleCollection)
				{
					if (ShouldIgnoreFactType(role.BinarizedFactType))
					{
						continue;
					}

					Role oppositeRole = role.OppositeRoleAlwaysResolveProxy.Role;

					// For each constraint on the opposite role...
					foreach (ConstraintRoleSequence constraintRoleSequence in oppositeRole.ConstraintRoleSequenceCollection)
					{
						UniquenessConstraint uninquenessConstraint = constraintRoleSequence as UniquenessConstraint;

						// If it is a uniqueness constraint...
						if (uninquenessConstraint != null && uninquenessConstraint.Modality == ConstraintModality.Alethic)
						{
							if (UniquenessIsForUniquenessConstraint.GetUniqueness(uninquenessConstraint) != null)
							{
								continue;
							}

							bool hasFactTypeThatShouldBeIgnored = false;
							bool allChildrenMapTowardObjectType = true;
							IList<FactType> factTypes = new List<FactType>();

							foreach (Role childRole in uninquenessConstraint.RoleCollection)
							{
								FactType binarizedFactType = childRole.BinarizedFactType;
								if (ShouldIgnoreFactType(binarizedFactType))
								{
									hasFactTypeThatShouldBeIgnored = true;
									break;
								}
								FactTypeMapping factTypeMapping = factTypeMappings[binarizedFactType];

								if (factTypeMapping.TowardsRole != childRole.OppositeRoleAlwaysResolveProxy.Role)
								{
									allChildrenMapTowardObjectType = false;
									break;
								}
								else
								{
									factTypes.Add(binarizedFactType);
								}
							}
							if (hasFactTypeThatShouldBeIgnored)
							{
								continue;
							}

							if (allChildrenMapTowardObjectType)
							{
								IList<ConceptTypeChild> conceptTypeChildren = new List<ConceptTypeChild>();
								bool skipThisUniquenessConstraint = false;

								foreach (FactType factType in factTypes)
								{
									bool childWasAssimilation = false;
									bool missedChild = true;
									foreach (ConceptTypeChild conceptTypeChild in ConceptTypeChildHasPathFactType.GetConceptTypeChild(factType))
									{
										if (conceptTypeChild.Parent != conceptType)
										{
											// This ConceptTypeChild is of a different ConceptType, so go on to the next ConceptTypeChild.
											continue;
										}
										if (conceptTypeChild is ConceptTypeAssimilatesConceptType)
										{
											childWasAssimilation = true;
											break;
										}

										missedChild = false;
										conceptTypeChildren.Add(conceptTypeChild);
									}

									if (childWasAssimilation)
									{
										skipThisUniquenessConstraint = true;
										break;
									}
									if (missedChild)
									{
										// We couldn't find a ConceptTypeChild for this FactType, so just bail out.
										skipThisUniquenessConstraint = true;
										break;
									}
								}

								if (!skipThisUniquenessConstraint)
								{
									PropertyAssignment name = new PropertyAssignment(Uniqueness.NameDomainPropertyId, uninquenessConstraint.Name);
									PropertyAssignment isPreferred = new PropertyAssignment(Uniqueness.IsPreferredDomainPropertyId, uninquenessConstraint.IsPreferred);
									PropertyAssignment[] propertyAssignments = { name, isPreferred };

									// Create uniquenesss
									Uniqueness uniqueness = new Uniqueness(Store, propertyAssignments);
									uniqueness.ConceptType = conceptType;
									new UniquenessIsForUniquenessConstraint(uniqueness, uninquenessConstraint);

									foreach (ConceptTypeChild conceptTypeChild in conceptTypeChildren)
									{
										UniquenessIncludesConceptTypeChild uniquenessIncludesConceptTypeChild = new UniquenessIncludesConceptTypeChild(uniqueness, conceptTypeChild);
									}
								}
							}
						}
					}
				}
			}
		}
Ejemplo n.º 12
0
        public int SimpleNumbers(int[] A)
        {
            var underTest = new Uniqueness();

            return(underTest.findUniqueItem(A));
        }
Ejemplo n.º 13
0
 public ScimTypeAttributeDefinitionBuilder <T, TAttribute> SetUniqueness(Uniqueness uniqueness)
 {
     Uniqueness = uniqueness;
     return(this);
 }
Ejemplo n.º 14
0
        public static HttpStatusCode Traverse(string dbUrl, long nodeId, Order order, Uniqueness uniqueness,
											  IEnumerable<TraverseRelationship> relationships,
											  PruneEvaluator pruneEvaluator, ReturnFilter returnFilter, int? maxDepth,
											  ReturnType returnType, out string response)
        {
            var jo = new JObject
                         {
                             order == null ? Order.DepthFirst.ToJson() : order.ToJson(),
                             uniqueness == null ? Uniqueness.NodePath.ToJson() : uniqueness.ToJson()
                         };

            var ja = new JArray();
            foreach (var r in relationships)
            {
                ja.Add(r.ToJson());
            }
            jo.Add(new JProperty("relationships", ja));

            jo.Add(pruneEvaluator == null ? PruneEvaluator.None.ToJson() : pruneEvaluator.ToJson());

            jo.Add(returnFilter == null ? ReturnFilter.AllButStartNode.ToJson() : returnFilter.ToJson());

            if (maxDepth == null)
            {
                maxDepth = 1;
            }

            jo.Add("max_depth", maxDepth.Value);

            return
                HttpRest.Post(
                    string.Concat(dbUrl, "/node/", nodeId, "/traverse/",
                                  returnType == null ? ReturnType.Node.ToString() : returnType.ToString()),
                    jo.ToString(Formatting.None, new IsoDateTimeConverter()), out response);
        }
Ejemplo n.º 15
0
 void TargetSetNameUniquness(NetworkConnection connection, Uniqueness uniqueness)
 {
     this.NameIsUnique = uniqueness;//Client side synchronisation
 }