Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / ImportFileRequest.cs / 1 / ImportFileRequest.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.InfoCards
{
using System;
using System.Collections;
using System.IO;
using System.Collections.Generic;
using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace;
//
// Import a set of cards to the store:
// Saves a list of cards into the store and implements the overwrite logic for roaming
//
class ImportFileRequest :UIAgentRequest
{
public ImportFileRequest( IntPtr rpcHandle, Stream inArgs, Stream outArgs, ClientUIRequest parent )
: base( rpcHandle, inArgs, outArgs, parent )
{
}
//
// Summary
// Read the cards to be imported
//
protected override void OnMarshalInArgs()
{
}
//
// Summary
// Save the cards to the store. If a card already exists
// in the store, then the last card to be updated wins.
//
protected override void OnProcess()
{
RoamingStoreFile roamingFile = ParentRequest.GetContext();
if( null != roamingFile && null != roamingFile.Cards )
{
try
{
StoreConnection connection = StoreConnection.GetConnection();
try
{
connection.BeginTransaction();
try
{
foreach ( InfoCard card in roamingFile.Cards )
{
//
// check if the card needs to be overwritten
// The default overwrite logic overwrites the card based on time of last update
//
List param = new List();
param.Add( new QueryParameter(
SecondaryIndexDefinition.ObjectTypeIndex,
( Int32 )StorableObjectType.InfoCard ) );
param.Add( new QueryParameter(
SecondaryIndexDefinition.GlobalIdIndex,
GlobalId.DeriveFrom( card.Id.ToString() ) ) );
DataRow row = connection.GetSingleRow( QueryDetails.FullRow, param.ToArray() );
//
// If a card exists, compare the LastUpdate time
//
if ( null != row )
{
using ( MemoryStream ms = new MemoryStream( row.GetDataField() ) )
{
InfoCard existingCard = new InfoCard( ms );
if ( existingCard.LastUpdate < card.LastUpdate )
{
IDT.TraceDebug( "Overwrite the existing card with id {0}", card.Id.AbsoluteUri );
card.IsImported = true;
card.InstalledOn = DateTime.Now;
card.Save( connection );
}
}
}
else
{
IDT.TraceDebug( "Add a new card with id {0} to the store", card.Id.AbsoluteUri );
card.IsImported = true;
card.InstalledOn = DateTime.Now;
card.Save( connection );
}
}
connection.CommitTransaction();
AuditLog.AuditStoreImport();
}
catch( Exception e )
{
connection.RollbackTransaction();
if( IDT.IsFatal( e ) )
{
throw;
}
throw IDT.ThrowHelperError(
new ImportStoreException( SR.GetString( SR.InvalidImportFile ), e ) );
}
}
finally
{
connection.Close();
}
}
finally
{
//
// Clear the roaming store file on completion.
//
roamingFile.Clear();
}
}
}
protected override void OnMarshalOutArgs()
{
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IDispatchConstantAttribute.cs
- _DigestClient.cs
- _AutoWebProxyScriptWrapper.cs
- ArraySortHelper.cs
- CookieProtection.cs
- RefreshEventArgs.cs
- ELinqQueryState.cs
- ColorConverter.cs
- WindowCollection.cs
- ButtonBase.cs
- XmlSerializer.cs
- BamlRecordReader.cs
- DirectionalLight.cs
- Content.cs
- HtmlTextArea.cs
- TreeViewImageKeyConverter.cs
- SecurityTimestamp.cs
- WebPartEventArgs.cs
- XmlImplementation.cs
- FontStyle.cs
- Console.cs
- XmlTextReader.cs
- WhitespaceRule.cs
- CodeGenerator.cs
- RangeValuePattern.cs
- ColumnBinding.cs
- ToolStripCollectionEditor.cs
- PerformanceCountersBase.cs
- AppDomainFactory.cs
- XmlFormatWriterGenerator.cs
- JsonCollectionDataContract.cs
- SimpleType.cs
- CompilerWrapper.cs
- InternalConfigHost.cs
- NamedPermissionSet.cs
- RegexRunnerFactory.cs
- TransformConverter.cs
- TemplatePagerField.cs
- CompilerTypeWithParams.cs
- JavaScriptString.cs
- ServiceBusyException.cs
- DataBoundControlAdapter.cs
- PointAnimationClockResource.cs
- Translator.cs
- ListViewItemSelectionChangedEvent.cs
- Enum.cs
- Bezier.cs
- AsymmetricSignatureDeformatter.cs
- TabControlDesigner.cs
- pingexception.cs
- IncrementalCompileAnalyzer.cs
- ObjectSet.cs
- ArraySet.cs
- LinkDescriptor.cs
- ListCollectionView.cs
- NativeMethods.cs
- SchemaManager.cs
- CodeNamespaceImport.cs
- TemplateBindingExpression.cs
- DecimalConstantAttribute.cs
- DesignerForm.cs
- DeferredTextReference.cs
- ExpressionBuilder.cs
- Literal.cs
- srgsitem.cs
- BigInt.cs
- SafeNativeMethods.cs
- DesignerTransactionCloseEvent.cs
- oledbmetadatacolumnnames.cs
- EventLogPermissionEntryCollection.cs
- AddInControllerImpl.cs
- DataServiceQueryOfT.cs
- TextUtf8RawTextWriter.cs
- OracleException.cs
- DataGridViewColumnEventArgs.cs
- HwndAppCommandInputProvider.cs
- AssociationType.cs
- KerberosReceiverSecurityToken.cs
- ChangeDirector.cs
- _KerberosClient.cs
- DataServiceProcessingPipelineEventArgs.cs
- PermissionSet.cs
- DefaultWorkflowSchedulerService.cs
- StateItem.cs
- SortedDictionary.cs
- InputProcessorProfilesLoader.cs
- CachedFontFace.cs
- HttpCacheVaryByContentEncodings.cs
- DelimitedListTraceListener.cs
- LineServicesCallbacks.cs
- SingleObjectCollection.cs
- LinqDataSourceView.cs
- ConnectionPoolManager.cs
- PropertyInformation.cs
- SoapCodeExporter.cs
- XsltQilFactory.cs
- CellConstantDomain.cs
- InputReportEventArgs.cs
- DispatcherFrame.cs
- WriterOutput.cs