예제 #1
0
        internal void Analyze()
        {
            SyncItem            sourceSyncItem = FetchSyncItem(_sourceGuid);
            SyncItem            sinkSyncItem;
            ISerializableObject source = FetchObject(_sourceSerializer, _sourceGuid);


            if (sourceSyncItem == null)//In der Synchronisationstabelle gibt es keinen korrepondierenden Eintrag
            {
                #if DEBUG
                logger.Debug(source.GetType().Name + ", guid=" + AttributeWorker.RowGuid(source) + " is not synchronized and will be inserted");
                #endif

                SyncState = new InsertState(this);
            }
            else //in der Synchronisationstabelle ist ein Eintrag vorhanden
            {
                sinkSyncItem = sourceSyncItem.CounterPart;
                _sinkGuid    = sinkSyncItem.SyncGuid;

                ISerializableObject sink = FetchObject(_sinkSerializer, _sinkGuid); //Das korrepondierende Objekt wird aus der Zieldatenbankgeholt

                if (sink == null)                                                   //Wenn es nicht vorhanden ist wurde es gelöscht
                {
                    #if DEBUG
                    logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " does not exist, the conflict has to be resolved");
                    #endif

                    SyncState = new DeletedState(this, sourceSyncItem);
                }
                else
                {
                    String h1           = sinkSyncItem.Hashcode;
                    String sinkHashCode = ComputeHashCode(_sinkSerializer.Target, sink);


                    if (h1 != sinkHashCode)//Änderung der Daten in der Zieldatenbank--warum ist das schon ein Konflikt?
                    {
                        #if DEBUG
                        logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " is involved in a conflict, which has to be resolved");
                        #endif
                        SyncState = new ConflictState(this, sourceSyncItem);
                    }
                    else //zieldatenbank unverändert
                    {
                        String sourceHashCode = ComputeHashCode(SourceSerializer.Target, source);

                        if (sourceHashCode == sourceSyncItem.Hashcode)//Quelldatenbank unverändert
                        {
                            #if DEBUG
                            logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " has not changed and will not be synchronized");
                            #endif
                            SyncState = new IgnoreState(this);
                        }
                        else//Quelldatenbank verändert-Zieldatenbank unverändert ->update
                        {
                            #if DEBUG
                            logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " has changed on the sourceside and will be updated");
                            #endif
                            SyncState = new UpdateState(this, sourceSyncItem);
                        }
                    }
                }
            }

            AttributeWorker   w   = AttributeWorker.GetInstance(_sinkSerializer.Target);
            IList <FieldInfo> fis = w.GetFieldByAttribute <CheckForeingKeyConstraintAttribute>(_synchronizedType);


            foreach (FieldInfo fi in fis)
            {
                Object val = fi.GetValue(source);
                if (val == null)
                {
                    continue;
                }

                CheckForeingKeyConstraintAttribute attr = w.GetAttribute <CheckForeingKeyConstraintAttribute>(fi);
                String table  = attr.UnmappedTable;
                String column = attr.ExternColumn;
                if (column == null)
                {
                    column = w.GetColumnMapping(fi);
                }

                if (!_sinkSerializer.Connector.Exists(column, val, table))
                {
                    //Hier kann man einen neuen Status einführen, der dieses Problem abfängt
                    throw new InvalidOperationException("Insertion of " + _synchronizedType.Name + " will fail. Unmapped foreign key " + column + "=" + val + " does not exist in target database!");
                }
            }
        }