Method WriteToDataSource
WriteToDataSource(WriteOperation)
Responsible for atomic write operations on the data source.
Declaration
OperationResult WriteToDataSource(WriteOperation operation)
Parameters
Type | Name | Description |
---|---|---|
WriteOperation | operation | Write operation applied on the data source. |
Returns
Type | Description |
---|---|
OperationResult | Failed operations, null otherwise. |
Examples
The following 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 the 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 the data source. |
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<OperationResult> | Array of failed operations. |
Examples
The following example performs multiple operations on the 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 datatype 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;
}