locked
How to add a custom field shema to metadata? RRS feed

  • Question

  • Hi all,

    I use  a simple provider (FullEnumerationSimpleSyncProvider ) that synchronize the data of outlook 2007 with a webservice.

    But when I want to add a custom field schema to metadata ( with InitializeReplicaMetadata method) , a Microsoft.Synchronization.FrameworkVersionMismatchException was throwed.

    Exception Message:"The metadata store cannot be opened because it has been updated by synchronization components that are newer than those installed on this computer".

    StackTrace:

       à Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, ChangeDataAdapter callbackChangeDataAdapter, SyncDataConverter conflictDataConverter, Int32& changesApplied, Int32& changesFailed)
       à Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncDataConverter sourceConverter, SyncDataConverter destinationConverter, SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)
       à Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()
       à Microsoft.Synchronization.SyncOrchestrator.Synchronize()
       à Sync101SimpleSync.MyTestProgram.DoBidirectionalSync(String nameA, MySimpleDataStore storeA, String nameB, MySimpleDataStore storeB) dans C:\Program Files\Microsoft SDKs\Microsoft Sync Framework\2.0\Samples\Sync101SimpleSync\CS\MyTestProgram\MyTestProgram.cs:ligne 199
       à Sync101SimpleSync.MyTestProgram.Main(String[] args) dans C:\Program Files\Microsoft SDKs\Microsoft Sync Framework\2.0\Samples\Sync101SimpleSync\CS\MyTestProgram\MyTestProgram.cs:ligne 60
       à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()

    Thanks,

    RealTn

     

    Friday, March 19, 2010 7:51 AM

Answers

  • Hi,

    The only solution that i founded is to use KnowledgeSyncProvider that allow the creation of field schema in the metadata.

    Thanks All,

    RealTn

    • Marked as answer by realtn Wednesday, March 24, 2010 3:47 PM
    Wednesday, March 24, 2010 3:46 PM

All replies

  • Friday, March 19, 2010 4:29 PM
  • Hi June,

    No, it isn't my situation.

    My problem in the first creation of metadata not when upgrading to new version.

    Thanks,

    RealTn

    Friday, March 19, 2010 4:56 PM
  • would you mind posting the piece of code where you're adding the custom field?
    Friday, March 19, 2010 5:18 PM
  • Hi June,

            private void InitializeMetadataStore()
            {
                SyncId id = ReplicaId;
    
                // Create or open the metadata store, initializing it with the ID formats 
                // that are used to reference items and replicas.
                if (!File.Exists(_replicaMetadataFile))
                {
                    _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile);
                    
                    
                    List<FieldSchema> fieldShema = new List<FieldSchema>();
                    fieldShema.Add(new FieldSchema("timestamp", typeof(ulong)));
                    List<IndexSchema> indexSchema = new List<IndexSchema>();
                    indexSchema.Add(new IndexSchema("timestamp", true));
    
                    _metadataStore.BeginTransaction();
                    ReplicaMetadata _metadata = _metadataStore.InitializeReplicaMetadata(IdFormats,new SyncId(Guid.NewGuid()),fieldShema,indexSchema);
                    _metadata.SaveReplicaMetadata();
                    _metadataStore.CommitTransaction();
                    _replicaId = _metadata.ReplicaId;
                    
                    
                     
                }
                else
                {
                    _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile);
                }
            }

    Thanks,

    RealTn

    Friday, March 19, 2010 5:25 PM
  • Hi,

    If you using SimpleProviders you should add your custom fields in the MetadataSchema:

            public override ItemMetadataSchema MetadataSchema
            {
                get
                {
                    CustomFieldDefinition[] customFields = new CustomFieldDefinition[2];
                    customFields[0] = new CustomFieldDefinition(CUSTOM_FIELD_ID, typeof(ulong));
                    customFields[1] = new CustomFieldDefinition(CUSTOM_FIELD_TIMESTAMP, typeof(ulong));
    
                    IdentityRule[] identityRule = new IdentityRule[1];
                    identityRule[0] = new IdentityRule(new uint[] { CUSTOM_FIELD_ID });
    
                    return new ItemMetadataSchema(customFields, identityRule);
                }
            }

    This was taken from the following sample:

    http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=3414

    -Jesse

    • Proposed as answer by JuneT Saturday, March 20, 2010 1:05 AM
    • Unproposed as answer by realtn Saturday, March 20, 2010 5:03 PM
    Friday, March 19, 2010 10:39 PM
  • Hello RealTn,

    I think the problem might be that you are initializing replica.

    You need to use SimpleProvider API to describe the schema during GetSchema API, not during when you create a new meatadata store.

    This is by design to abstract applying schema to metadata store. So, the code where you create schema and initialize replica metadata should be done during SimpleProvider::MetadataSchema. Accordingly, you need to pass SimpleProvider construct called ItemMetadataSchema.

    Then, SimpleProvider framework will internally apply the schema.

    So, the metadata store instance provider passes does not have to be initialized with schema.

    Hope this helps,

    Patrick  

     

    Friday, March 19, 2010 10:40 PM
  • Hi Patrick,

    when apply your solution, i cant do this task:
    "you need to pass SimpleProvider construct called ItemMetadataSchema."

    Can you Patrick post a piece of code for example for these methods:

    1. MetadataSchema
    2. GetMetadataStore
    3. the constructor.

    Thanks,

    RealTn

    Saturday, March 20, 2010 5:13 PM
  • Please see my previous post as well as the sample I linked to where you will find examples of all those methods.

    http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=3414

    -Jesse

    Monday, March 22, 2010 5:28 PM
  • Hi,

    The sample in the previous post not include a field schema definition.

    My problem is:

    My application log all conflicts with MemoryConflictLog and after the sync session was ended , the appliction process the conflicts resolution

    1. Increments the tick count of the replica.

    2. Updates the change version of the item or change unit to reflect that the change is made by the local replica with the updated tick count.

    3. Combines the knowledge of the replica with the knowledge of the conflict by using Combine , and saves the combined knowledge as the new knowledge of the replica.

    4. Applies the change data to the replica.

    5. Removes the conflict from the conflict log.

    this process is demonstrated here: http://msdn.microsoft.com/en-us/library/dd918556%28SQL.105%29.aspx

    In the step 4:

    when the conflicts is an update:

    I must modify the item conflicting, but when updating: the timestamp field changed and the conflict occur in the next sync session.

    The solution is to update the ItemMetaData with the new timestamp value.

    to do that ,you must use:

    ItemMetaData.SetCustomField(String fieldName,Int64 value);

     

    The probleme that i cant define a field schema with a FullEnumerationSimpleSyncProvider .

    Any ideas please.

    Tuesday, March 23, 2010 8:36 AM
  • The FullEnumerationSimpleSyncProvider does not support logging conflicts, you will need to implement a KnowledgeSyncProvider to do this.  With a simple provider many lower level sync concepts such as Knowledge are abstracted away, reducing complexity but also some functionality like conflict logging.

    -Jesse

    Tuesday, March 23, 2010 7:00 PM
  • I should point out that while the simple provider does not support conflict logging it does support extensive conflict resolving that can be found on the ISimpleSyncProviderConcurrencyConflictResolver and ISimpleSyncProviderConstraintConflictResolver interfaces.

    -Jesse

    Tuesday, March 23, 2010 7:04 PM
  • Hi,

    My problem isnt in loggin conflicts but how to create a field schema in the metadata .

    Thanks,

    RealTn

    Wednesday, March 24, 2010 7:44 AM
  • Hi,

    The only solution that i founded is to use KnowledgeSyncProvider that allow the creation of field schema in the metadata.

    Thanks All,

    RealTn

    • Marked as answer by realtn Wednesday, March 24, 2010 3:47 PM
    Wednesday, March 24, 2010 3:46 PM
  • Hello realtn,

    is it possible that you contact me? I have a question to the Outlook-Provider

    Thanks
    Michael

    Tuesday, May 11, 2010 10:07 AM
  • I am confused about your field schema problem and how it differs from my sample code above with the implementation of MetadataSchema.  You can add custom fields in there.  From what I can see, you can solve this with a SimpleSyncProvider and don't require a KnowledgeSyncProvider, saving a ton of work.  (Keeping in mind though, that you cannot log conflicts with the SimpleSyncProvider).

     

    -Jesse

    • Proposed as answer by liranmoto Sunday, September 12, 2010 10:03 AM
    Thursday, May 13, 2010 11:32 PM
  • Hello realtn,

    i have answert to your email that you send to me. Please response me (i hope you was the real "realtn" that send me a contact mail *ggg* )

    Thanks
    Michael

    Thursday, May 20, 2010 8:58 AM