예제 #1
0
        private bool DoReplicationForPriority(ReplicationPriority priority)
        {
            bool dataSent = false;

            // loop through all registered entities
            lock (Registrations)
            {
                foreach (var registration in Registrations.GetNameRegistrations(priority))
                {
                    var items = m_source.Select(registration.LocalName).Take(MaxReplicationBatchSize);

                    foreach (var item in items)
                    {
                        item.EntityName = registration.ReplicatedName;
                        m_destination.Insert(item);

                        item.EntityName = registration.LocalName;
                        m_source.Delete(item);

                        // increment the count
                        m_nameCounts[registration.LocalName]++;

                        dataSent = true;

                        // yield so we're not chewing up processor time
                        Thread.Sleep(0);
                    }
                }

                foreach (var registration in Registrations.GetTypeRegistrations(priority))
                {
                    var items = m_source.Select(registration.Type).Take(MaxReplicationBatchSize);

                    foreach (var item in items)
                    {
                        m_destination.Insert(item);

                        m_source.Delete(item);

                        // increment the count
                        m_typeCounts[registration.Type]++;

                        dataSent = true;

                        // yield so we're not chewing up processor time
                        Thread.Sleep(0);
                    }
                }

                return(dataSent);
            }
        }
예제 #2
0
        public void AddType(Type type, ReplicationPriority priority)
        {
            lock (m_typeRegistrations)
            {
                var existing = m_typeRegistrations.FirstOrDefault(r => r.Type.Equals(type));

                if (existing != null)
                {
                    existing.Priority = priority;
                }
                else
                {
                    m_typeRegistrations.Add(new ReplicationTypeRegistration(type, priority));
                }

                m_typeRegistrations.Sort(CompareTypeRegistrationPriorities);
            }
        }
예제 #3
0
        internal void AddName(string localName, string replicatedName, ReplicationPriority priority)
        {
            lock (m_nameRegistrations)
            {
                var existing = m_nameRegistrations.FirstOrDefault(r => string.Compare(r.LocalName, localName, StringComparison.InvariantCultureIgnoreCase) == 0);

                if (existing != null)
                {
                    existing.Priority = priority;
                }
                else
                {
                    m_nameRegistrations.Add(new ReplicationNameRegistration(localName, replicatedName, priority));
                }

                m_nameRegistrations.Sort(CompareNameRegistrationPriorities);
            }
        }
예제 #4
0
        public void RegisterEntity(Type entityType, ReplicationPriority priority)
        {
            lock (Registrations)
            {
                Registrations.AddType(entityType, priority);

                lock (m_typeCounts)
                {
                    if (!m_typeCounts.ContainsKey(entityType))
                    {
                        m_typeCounts.Add(entityType, 0);
                    }
                }

                // TODO: look for failure and cache if it does (e.g. not connected scenarios)
                m_destination.AddType(entityType);
            }
        }
예제 #5
0
        public void RegisterEntity(string entityName, string replicatedName, ReplicationPriority priority)
        {
            lock (Registrations)
            {
                Registrations.AddName(entityName, replicatedName, priority);

                lock (m_nameCounts)
                {
                    if (!m_nameCounts.ContainsKey(entityName))
                    {
                        m_nameCounts.Add(entityName, 0);
                    }
                }

                // TODO: look for failure and cache if it does (e.g. not connected scenarios)
                var definition = m_source.DiscoverDynamicEntity(entityName);

                definition.EntityName = replicatedName;

                // the replicated entity cannot use the same auto-increment field as the local table or we'll end up with replication problems where local IDs don't match remote IDs
                if (CreateIdentityFieldInReplicatedTable)
                {
                    var existing = definition.Fields.KeyField;
                    if (existing != null)
                    {
                        existing.IsPrimaryKey = false;
                    }

                    definition.EntityAttribute.KeyScheme = KeyScheme.Identity;
                    definition.Fields.Add(new FieldAttribute("ReplID", System.Data.DbType.Int32, true), true);
                }
                else
                {
                    definition.EntityAttribute.KeyScheme = KeyScheme.None;
                }

                m_destination.RegisterDynamicEntity(definition, true);
            }
        }
예제 #6
0
 public IEnumerable <ReplicationNameRegistration> GetNameRegistrations(ReplicationPriority priority)
 {
     return(m_nameRegistrations.Where(r => r.Priority == priority));
 }
예제 #7
0
 internal void AddName(string localName, ReplicationPriority priority)
 {
     AddName(localName, null, priority);
 }
예제 #8
0
 public ReplicationTypeRegistration(Type type, ReplicationPriority priority)
 {
     Type     = type;
     Priority = priority;
 }
예제 #9
0
 public ReplicationNameRegistration(string localName, string replicatedName, ReplicationPriority priority)
 {
     LocalName      = localName;
     ReplicatedName = replicatedName ?? localName;
     Priority       = priority;
 }
예제 #10
0
 public ReplicationNameRegistration(string localName, ReplicationPriority priority)
     : this(localName, localName, priority)
 {
 }
예제 #11
0
 public void RegisterEntity(string entityName, ReplicationPriority priority)
 {
     RegisterEntity(entityName, null, priority);
 }
예제 #12
0
 public void RegisterEntity <T>(ReplicationPriority priority)
 {
     RegisterEntity(typeof(T), priority);
 }