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
- ActivityDesignerResources.cs
- WebHttpBehavior.cs
- Hash.cs
- Pair.cs
- PenContext.cs
- wgx_sdk_version.cs
- WSSecurityPolicy.cs
- IPEndPointCollection.cs
- AtomMaterializer.cs
- HostingEnvironment.cs
- SamlDelegatingWriter.cs
- ErrorLog.cs
- MsmqIntegrationSecurityElement.cs
- DataServiceKeyAttribute.cs
- TimeBoundedCache.cs
- ColumnCollection.cs
- DataAdapter.cs
- FileLogRecordHeader.cs
- ProgressBarAutomationPeer.cs
- Relationship.cs
- RecognizerStateChangedEventArgs.cs
- TrackingProfileDeserializationException.cs
- _HTTPDateParse.cs
- TimerTable.cs
- Reference.cs
- FileChangesMonitor.cs
- SQLInt32Storage.cs
- ReflectEventDescriptor.cs
- Debugger.cs
- JoinCqlBlock.cs
- VerticalAlignConverter.cs
- DataGridParentRows.cs
- StrongTypingException.cs
- NativeMethods.cs
- MarshalByRefObject.cs
- TypedDataSetSchemaImporterExtension.cs
- DataServices.cs
- ExtentCqlBlock.cs
- Wizard.cs
- ComplexObject.cs
- MatrixCamera.cs
- EnumBuilder.cs
- Screen.cs
- AttachmentCollection.cs
- SiblingIterators.cs
- mactripleDES.cs
- MetadataSet.cs
- UICuesEvent.cs
- SQLBinary.cs
- Menu.cs
- FontFamilyConverter.cs
- ProtocolsConfigurationEntry.cs
- TemplateBindingExtension.cs
- MemberAssignment.cs
- JsonFormatGeneratorStatics.cs
- CompleteWizardStep.cs
- SqlMethodAttribute.cs
- HwndHostAutomationPeer.cs
- DetailsViewPageEventArgs.cs
- Asn1IntegerConverter.cs
- GridErrorDlg.cs
- KeyedQueue.cs
- MetadataWorkspace.cs
- Inflater.cs
- ResolvePPIDRequest.cs
- Point.cs
- ColumnResizeAdorner.cs
- ProgressiveCrcCalculatingStream.cs
- MaskedTextProvider.cs
- HttpResponseHeader.cs
- DoubleAnimationUsingKeyFrames.cs
- AppDomain.cs
- OciEnlistContext.cs
- Config.cs
- ColorBlend.cs
- RegionInfo.cs
- MetafileHeaderWmf.cs
- OperationPickerDialog.cs
- ScriptManager.cs
- GlobalizationAssembly.cs
- FastPropertyAccessor.cs
- DataGridViewLinkCell.cs
- DefaultHttpHandler.cs
- TextEditorThreadLocalStore.cs
- FormsIdentity.cs
- DayRenderEvent.cs
- Literal.cs
- CreateCardRequest.cs
- Deserializer.cs
- SecurityElement.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- RepeaterItem.cs
- InternalConfigRoot.cs
- HiddenFieldDesigner.cs
- FormatConvertedBitmap.cs
- XmlWrappingReader.cs
- _KerberosClient.cs
- Rethrow.cs
- SQLInt16Storage.cs
- ValidatorCollection.cs