• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Method WriteToDataSource

WriteToDataSource(WriteOperation)

Responsible for atomic write operations on data source.

Declaration
OperationResult WriteToDataSource(WriteOperation operation)
Parameters
Type Name Description
WriteOperation operation

write operation applied on data source

Returns
Type Description
OperationResult

failed operations, null otherwise

Examples

Example performs a single operation on data source

public OperationResult WriteToDataSource(WriteOperation operation)
{
    bool result = false;
    OperationResult operationResult = new OperationResult(operation, OperationResult.Status.Failure);
    object value = operation.ProviderItem.GetValue<object>();

    if (value.GetType().Equals(typeof(Customer)))
    {
        result = _source.SaveCustomer((Customer)value);
    }
    if (result) operationResult.OperationStatus = OperationResult.Status.Success;
    return operationResult;
}

WriteToDataSource(ICollection<WriteOperation>)

Responsible for bulk write operations on data source.

Declaration
ICollection<OperationResult> WriteToDataSource(ICollection<WriteOperation> operations)
Parameters
Type Name Description
System.Collections.Generic.ICollection<WriteOperation> operations

array of write operations applied on data source

Returns
Type Description
System.Collections.Generic.ICollection<OperationResult>

array of failed operations

Examples

Example performs multiple operations on data source

public ICollection<OperationResult> WriteToDataSource(ICollection<WriteOperation> operations)
{
    ICollection<OperationResult> operationResults = new OperationResult[operations.Count];

    foreach(WriteOperation operation in operations)
    {
        operationResults.Add(WriteToDataSource(operation));
    }

    return operationResults;
}

WriteToDataSource(ICollection<DataTypeWriteOperation>)

When collection is created or removed as bulk data source will be notified with this method.

Declaration
ICollection<OperationResult> WriteToDataSource(ICollection<DataTypeWriteOperation> dataTypeWriteOperations)
Parameters
Type Name Description
System.Collections.Generic.ICollection<DataTypeWriteOperation> dataTypeWriteOperations

operation containing properties

Returns
Type Description
System.Collections.Generic.ICollection<OperationResult>

OperationResult

Examples
public ICollection<OperationResult> WriteToDataSource(ICollection<DataTypeWriteOperation> operations)
{
    List<OperationResult> operationResult = new List<OperationResult>();

    foreach (DataTypeWriteOperation operation in operations)
    {
        var list = new List<Product>();
        ProviderDataTypeItem<object> cacheItem = operation.ProviderItem;
        Product product = (Product)cacheItem.Data;

        switch (operation.OperationType)
        {
            case DatastructureOperationType.CreateDataType:
                // Insert logic for creating a new List
                IList myList = new List<Product>();
                myList.Add(product.Id);
                break;

            case DatastructureOperationType.AddToDataType:
                // Insert logic for any Add operation 
                list.Add(product);
                break;

            case DatastructureOperationType.DeleteFromDataType:
                // Insert logic for any Remove operation
                list.Remove(product);
                break;

            case DatastructureOperationType.UpdateDataType:
                // Insert logic for any Update operation 
                list.Insert(0, product);
                break;
        }

        // Write Thru operation status can be set according to the result. 
        operationResult.Add(new OperationResult(operation, OperationResult.Status.Success));
    }

    return operationResult;
}
Back to top Copyright © 2017 Alachisoft