Beispiel #1
0
 /// <summary>
 /// Gets the comparer for the field.
 /// </summary>
 /// <returns></returns>
 public IComparer GetComparerStrategy(CultureInfo culture)
 {
     // mbr - 2011-02-17 - this is wrong... it should use the type of the property...
     //return ComparerBase.GetComparer(this.DBType, culture);
     if (PropertyInfo == null)
     {
         throw new InvalidOperationException("'PropertyInfo' is null.");
     }
     return(ComparerBase.GetComparer(this.PropertyInfo.PropertyType, culture));
 }
Beispiel #2
0
 /// <summary>
 /// Adds sorting comparer to exiting DataRow comparer.
 /// </summary>
 /// <param name="orderBy">The existing DataRow comparer.</param>
 /// <param name="thenBy">The sorting comparer to add.</param>
 /// <returns>The result DataRow comparer.</returns>
 public static IDataRowComparer ThenBy(this IDataRowComparer orderBy, IDataRowComparer thenBy)
 {
     orderBy.VerifyNotNull(nameof(orderBy));
     thenBy.VerifyNotNull(nameof(thenBy));
     if (orderBy.ModelType != thenBy.ModelType)
     {
         throw new ArgumentException(DiagnosticMessages.DataRowComparer_DifferentDataRowModel, nameof(thenBy));
     }
     return(ComparerBase.Create(orderBy, thenBy));
 }
Beispiel #3
0
        /// <summary>
        /// Adds additional sorting column to existing DataRow comparer.
        /// </summary>
        /// <typeparam name="T">Data type of column.</typeparam>
        /// <param name="orderBy">The existing DataRow comparer.</param>
        /// <param name="column">The additional sorting column.</param>
        /// <param name="direction">The sorting direction.</param>
        /// <param name="comparer">Data value comparer.</param>
        /// <returns>The result DataRow comparer.</returns>
        public static IDataRowComparer ThenBy <T>(this IDataRowComparer orderBy, Column <T> column, SortDirection direction = SortDirection.Ascending, IComparer <T> comparer = null)
        {
            orderBy.VerifyNotNull(nameof(orderBy));
            var thenBy = DataRow.OrderBy(column, direction, comparer);

            if (orderBy.ModelType != thenBy.ModelType)
            {
                throw new ArgumentException(DiagnosticMessages.DataRowComparer_DifferentDataRowModel, nameof(column));
            }
            return(ComparerBase.Create(orderBy, thenBy));
        }
Beispiel #4
0
        /// <summary>
        /// Sorts by the given column index.
        /// </summary>
        /// <param name="header"></param>
        private void Sort(EntityListViewColumnHeader header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            // property...
            PropertyDescriptor property = header.Property;

            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            // get a comparer...
            IComparer comparer = null;

            if (property is EntityFieldPropertyDescriptor)
            {
                comparer = ((EntityFieldPropertyDescriptor)property).Field.GetComparer(Cultures.User);
            }
            else
            {
                comparer = ComparerBase.GetComparer(property.PropertyType, Cultures.User);
            }

            // check...
            SortOrder useOrder = SortOrder.Ascending;

            if (this.SortColumn == header)
            {
                if (this.Sorting == SortOrder.Ascending)
                {
                    useOrder = SortOrder.Descending;
                }
                else
                {
                    useOrder = SortOrder.Ascending;
                }
            }

            // sort...
            SortDirection direction = SortDirection.Ascending;

            if (useOrder == SortOrder.Descending)
            {
                direction = SortDirection.Descending;
            }
            this.ListViewItemSorter = new EntityListViewComparer(header, comparer, direction);
            this.Sorting            = useOrder;
            _sortColumn             = header;
        }
Beispiel #5
0
        private void InitializeCurrentSet()
        {
            if (Keys == null)
            {
                throw new InvalidOperationException("Keys is null.");
            }
            if (KeyField == null)
            {
                throw new InvalidOperationException("KeyFields is null.");
            }

            // build some ids...
            ArrayList ids = new ArrayList();

            while (this.CurrentMasterPosition < this.Keys.Length && ids.Count < PageSize)
            {
                // add the current master position...
                ids.Add(this.Keys[this.CurrentMasterPosition][0]);

                // next...
                this.CurrentMasterPosition++;
            }

            // do we have anything?
            IList newSet = this.EntityType.CreateCollectionInstance();

            if (ids.Count > 0)
            {
                // create a statement to load that lot...
                SqlFilter filter = new SqlFilter(this.EntityType);

                // if the master defines fields, we'll need the same ones...
                if (this.Source.Fields.Count > 0)
                {
                    // add the fields - but we need to know if the key field is in there...
                    bool keyFound = false;
                    foreach (EntityField field in this.Source.Fields)
                    {
                        // found it?
                        if (field == this.KeyField)
                        {
                            keyFound = true;
                        }

                        // add it...
                        filter.Fields.Add(field);
                    }

                    // key?  we'll need that to get the items in the right order...
                    if (!(keyFound))
                    {
                        filter.Fields.Add(this.KeyField);
                    }
                }

                // build some sql...
                StringBuilder builder = new StringBuilder();
                builder.Append(filter.Dialect.FormatColumnName(this.KeyField.Name));
                builder.Append(" in (");
                for (int index = 0; index < ids.Count; index++)
                {
                    if (index > 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append(filter.Dialect.FormatVariableNameForQueryText(filter.ExtraParameters.Add(this.KeyField.DBType, ids[index])));
                }
                builder.Append(")");

                // add...
                filter.Constraints.AddFreeConstraint(builder.ToString());

                // run it...
                IList newEntities = filter.ExecuteEntityCollection();
                if (newEntities == null)
                {
                    throw new InvalidOperationException("newEntities is null.");
                }

                // comparer...
                IComparer comparer = ComparerBase.GetComparer(this.KeyField.DBType, Cultures.System);
                if (comparer == null)
                {
                    throw new InvalidOperationException("comparer is null.");
                }

                // we now have to get the data in the right order...
                object[] entities = new object[ids.Count];
                for (int index = 0; index < ids.Count; index++)
                {
                    // find it in the data set...
                    foreach (object newEntity in newEntities)
                    {
                        object[] newKeys = this.EntityType.Storage.GetKeyValues(newEntity);
                        if (newKeys == null)
                        {
                            throw new InvalidOperationException("newKeys is null.");
                        }
                        if (newKeys.Length != 1)
                        {
                            throw new InvalidOperationException("New keys length is invalid.");
                        }

                        // check...
                        if (comparer.Compare(ids[index], newKeys[0]) == 0)
                        {
                            entities[index] = newEntity;
                            break;
                        }
                    }
                }

                // create a new set from the ordered set...
                foreach (object entity in entities)
                {
                    if (entity != null)
                    {
                        newSet.Add(entity);
                    }
                    else
                    {
                        switch (Mode)
                        {
                        // do nothing if skip missing...
                        case OptimisticReadMode.SkipMissing:
                            break;

                        // add null in...
                        case OptimisticReadMode.ThrowIfMissing:
                            throw new InvalidOperationException("Item in keyset could not be found in the database.");

                        default:
                            throw new NotSupportedException(string.Format("Cannot handle '{0}' ({1}).", Mode, Mode.GetType()));
                        }
                    }
                }
            }

            // update...
            _currentSet = newSet;

            // position...
            _currentSetPosition = 0;
        }
		private void DrawConstCompareField(ComparerBase comparer)
		{
			if (comparer.ConstValue == null)
			{
				comparer.ConstValue = comparer.GetDefaultConstValue();
			}

			var so = new SerializedObject(comparer);
			var sp = so.FindProperty ("constantValueGeneric");
			if (sp != null)
			{
				EditorGUILayout.PropertyField (sp, new GUIContent("Constant"), true);
				so.ApplyModifiedProperties ();
			}
		}
		private void DrawObjectCompareField(ComparerBase comparer)
		{
			otherPathSelector.Draw(comparer.other, comparer, 
				comparer.otherPropertyPath, comparer.GetAccepatbleTypesForB(),
				go =>
				{
					comparer.other = go;
					AssertionExplorerWindow.Reload ();
				},
				s =>
				{
					comparer.otherPropertyPath = s;
					AssertionExplorerWindow.Reload ();
				}
				);
		}
		private void DrawCompareToType (ComparerBase comparer)
		{
			comparer.compareToType = (ComparerBase.CompareToType) EditorGUILayout.EnumPopup ("Compare to type",
																									comparer.compareToType,
																									EditorStyles.popup);

			if (comparer.compareToType == ComparerBase.CompareToType.CompareToConstantValue)
			{
				try
				{
					DrawConstCompareField(comparer);
				}
				catch (NotImplementedException)
				{
					Debug.LogWarning("This comparer can't compare to static value");
					comparer.compareToType = ComparerBase.CompareToType.CompareToObject;
				}
			}
			else if (comparer.compareToType == ComparerBase.CompareToType.CompareToObject)
			{
				DrawObjectCompareField(comparer);
			}
		}
Beispiel #9
0
 /// <summary>
 /// Gets the comparer for the field.
 /// </summary>
 /// <returns></returns>
 public IComparer GetComparerStrategy(CultureInfo culture)
 {
     return(ComparerBase.GetComparer(this.DBType, culture));
 }
Beispiel #10
0
 internal static IColumnComparer Create <T>(Column <T> column, SortDirection direction, IComparer <T> comparer)
 {
     return(ComparerBase.Create(column, direction, comparer));
 }