Пример #1
0
 internal TruncateState(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
     foreach (SyncContainer sc in StateOwner.Children)
     {
         sc.Truncate();
     }
 }
Пример #2
0
        //Konstruktor
        internal SyncContainer(ISerializableObject iso, Serializer syncSerializer, Serializer sourceSerializer)
        {
            SyncState = new PrematureState(this);

            _synchronizedType = iso.GetType();
            _sourceGuid       = AttributeWorker.RowGuid(iso);

            _syncSerializer   = syncSerializer;
            _sourceSerializer = sourceSerializer;

            _parents  = new List <SyncContainer>();
            _children = new List <SyncContainer>();
        }
Пример #3
0
 internal SynchronizedState(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
 }
Пример #4
0
 internal ConflictResolvedState(SyncContainer owner, ISerializableObject resolved, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, sourceSyncItem, previous)
 {
     _resolved = resolved;
 }
Пример #5
0
 internal UpdateState(SyncContainer owner, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, previous)
 {
     _sourceSyncItem = sourceSyncItem;
     _fieldLock      = new FieldLock(_sourceSyncItem.GetType());
 }
Пример #6
0
 internal WritingStates(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
     _doSynchronizing = true;
 }
Пример #7
0
 internal SyncState(SyncContainer owner, SyncState previousState)
 {
     _StateOwner    = owner;
     _PreviousState = previousState;
 }
 internal ConflictResolvedState(SyncContainer owner, ISerializableObject resolved, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, sourceSyncItem, previous)
 {
     _resolved = resolved;
 }
Пример #9
0
 internal IgnoreState(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
 }
Пример #10
0
 internal WritingStates(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
     _doSynchronizing = true;
 }
Пример #11
0
 internal UpdateState(SyncContainer owner, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, previous)
 {
     _sourceSyncItem = sourceSyncItem;
     _fieldLock = new FieldLock(_sourceSyncItem.GetType());
 }
Пример #12
0
 internal TruncateState(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
     foreach (SyncContainer sc in StateOwner.Children)
     {
         sc.Truncate();
     }
 }
Пример #13
0
 internal SyncState(SyncContainer owner, SyncState previousState)
 {
     _StateOwner = owner;
     _PreviousState = previousState;
 }
Пример #14
0
 public SyncState(SyncContainer owner)
 {
     _StateOwner = owner;
     _PreviousState = null;
 }
Пример #15
0
 internal SynchronizedState(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
 }
Пример #16
0
 public SyncState(SyncContainer owner)
 {
     _StateOwner    = owner;
     _PreviousState = null;
 }
Пример #17
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!");
                }
            }
        }
Пример #18
0
 internal IgnoreState(SyncContainer owner, SyncState previous)
     : base(owner, previous)
 {
 }