コード例 #1
0
        /// <summary>
        /// Performs an insert operation on the list of data that the <see cref="DataSourceView"/> object represents.
        /// </summary>
        /// <param name="values">An <see cref="IDictionary"/> of name/value pairs used during an insert operation.</param>
        /// <returns>The number of items that were inserted into the underlying data storage.</returns>
        protected override int ExecuteInsert(IDictionary values)
        {
            Guard.ArgumentNotNull(values, "values");

            ObjectContainerDataSourceInsertingEventArgs insertingEventArgs = new ObjectContainerDataSourceInsertingEventArgs(values);

            OnInserting(insertingEventArgs);
            if (insertingEventArgs.Cancel)
            {
                return(0);
            }

            object instance = CreateInstance();

            TypeDescriptionHelper.BuildInstance(values, instance);
            Add(instance);
            OnDataSourceViewChanged(EventArgs.Empty);

            int rowsAffected = 1;
            ObjectContainerDataSourceStatusEventArgs insertedEventArgs = new ObjectContainerDataSourceStatusEventArgs(instance, rowsAffected);

            OnInserted(insertedEventArgs);

            return(rowsAffected);
        }
コード例 #2
0
        public void BuildInstanceThrowsIfPropertyIsUnexistant()
        {
            OrderedDictionary values = new OrderedDictionary(1);

            values.Add("Unexistant", "unexistant");

            TypeDescriptionHelper.BuildInstance(values, new SimpleEntity());
        }
コード例 #3
0
        public void BuildInstanceThrowsIfPropertyIsReadOnly()
        {
            OrderedDictionary values = new OrderedDictionary(1);

            values.Add("Name", "name");

            TypeDescriptionHelper.BuildInstance(values, new SimpleEntityWithReadOnlyProperty());
        }
コード例 #4
0
        public void BuildInstance()
        {
            SimpleEntity      simpleEntity = new SimpleEntity();
            OrderedDictionary values       = new OrderedDictionary(3);

            values.Add("Id", 1);
            values.Add("Name", "name");
            values.Add("Age", 10);

            TypeDescriptionHelper.BuildInstance(values, simpleEntity);

            Assert.AreEqual(1, simpleEntity.Id);
            Assert.AreEqual("name", simpleEntity.Name);
            Assert.AreEqual(10, simpleEntity.Age);
        }
コード例 #5
0
        /// <summary>
        /// Performs an update operation on the list of data that the <see cref="DataSourceView"/> object represents.
        /// </summary>
        /// <param name="keys">An <see cref="System.Collections.IDictionary"/> of object or row keys to be updated by the update operation.</param>
        /// <param name="values">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their new values.</param>
        /// <param name="oldValues">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their original values.</param>
        /// <returns>The number of items that were updated in the underlying data storage.</returns>
        protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
        {
            Guard.CollectionNotNullNorEmpty(keys, String.Format(CultureInfo.CurrentCulture, Resources.NoKeysSpecified), "keys");
            Guard.ArgumentNotNull(values, "values");

            ObjectContainerDataSourceUpdatingEventArgs updatingEventArgs =
                new ObjectContainerDataSourceUpdatingEventArgs(DictionaryHelper.GetReadOnlyDictionary(keys), values, oldValues);

            OnUpdating(updatingEventArgs);
            if (updatingEventArgs.Cancel)
            {
                return(0);
            }

            object newInstance = CreateInstance();

            TypeDescriptionHelper.BuildInstance(keys, newInstance);
            TypeDescriptionHelper.BuildInstance(values, newInstance);
            int    rowsAffected;
            object oldInstance = FindInstance(keys);

            if (oldInstance != null)
            {
                int index = Data.IndexOf(oldInstance);
                Data[index]  = newInstance;
                rowsAffected = 1;
            }
            else
            {
                rowsAffected = 0;
            }
            OnDataSourceViewChanged(EventArgs.Empty);

            ObjectContainerDataSourceStatusEventArgs updatedEventArgs = new ObjectContainerDataSourceStatusEventArgs(newInstance, rowsAffected);

            OnUpdated(updatedEventArgs);

            return(rowsAffected);
        }
コード例 #6
0
        /// <summary>
        /// Performs a delete operation on the list of data that the <see cref="DataSourceView"/> object represents.
        /// </summary>
        /// <param name="keys">An <see cref="IDictionary"/> of object or row keys to be deleted by
        /// the <see cref="DataSourceView.ExecuteDelete(System.Collections.IDictionary,System.Collections.IDictionary)"/>
        /// operation.</param>
        /// <param name="oldValues">An <see cref="System.Collections.IDictionary"/> of name/value pairs that represent data elements and their original values.</param>
        /// <returns>The number of items that were deleted from the underlying data storage.</returns>
        protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues)
        {
            Guard.CollectionNotNullNorEmpty(keys, String.Format(CultureInfo.CurrentCulture, Resources.NoKeysSpecified), "keys");

            ObjectContainerDataSourceDeletingEventArgs deletingEventArgs =
                new ObjectContainerDataSourceDeletingEventArgs(DictionaryHelper.GetReadOnlyDictionary(keys), oldValues);

            OnDeleting(deletingEventArgs);
            if (deletingEventArgs.Cancel)
            {
                return(0);
            }

            int    rowsAffected;
            object instance = FindInstance(keys);

            if (instance == null)
            {
                rowsAffected = 0;
            }
            else
            {
                Data.Remove(instance);
                rowsAffected = 1;
            }
            instance = CreateInstance();
            TypeDescriptionHelper.BuildInstance(oldValues, instance);
            TypeDescriptionHelper.BuildInstance(keys, instance);
            OnDataSourceViewChanged(EventArgs.Empty);

            ObjectContainerDataSourceStatusEventArgs deletedEventArgs = new ObjectContainerDataSourceStatusEventArgs(instance, rowsAffected);

            OnDeleted(deletedEventArgs);

            return(rowsAffected);
        }
コード例 #7
0
 public void BuildInstanceThrowsIfExistingIsNull()
 {
     TypeDescriptionHelper.BuildInstance(new OrderedDictionary(), null);
 }
コード例 #8
0
 public void BuildInstanceThrowsIfValuesIsNull()
 {
     TypeDescriptionHelper.BuildInstance(null, new SimpleEntity());
 }