Esempio n. 1
0
        /// <summary>
        /// Puts the domain into sync queue for sync
        /// </summary>
        private void SyncDomain()
        {
            int retry = 10;

            while (true)
            {
                try
                {
                    // Get a connection object to the server.
                    connection = new SimiasConnection(hostDomain.ID, host.UserID, SimiasConnection.AuthType.PPK, hostDomain);

                    // We need to get a one time password to use to authenticate.
                    connection.Authenticate();
                    break;
                }
                catch
                {
                    Thread.Sleep(10000);
                    if (retry <= 0)
                    {
                        break;
                    }
                }
            }

            syncClient = new CollectionSyncClient(hostDomain.ID, new TimerCallback(TimerFired));
            while (true)
            {
                syncEvent.WaitOne();
                try
                {
                    syncClient.SyncNow();
                }
                catch {}
                syncClient.Reschedule(true, 30);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// sync the domain
        /// </summary>
        private void SyncDomain()
        {
            int retry = 10;

            log.Debug("Sync Domain entered..");

            lock (CollectionSyncClient.MapObject)
            {
                CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncStarted;
                CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncFinished;
            }

            while (true)
            {
                try
                {
                    // Get a connection object to the server.
                    connection = new SimiasConnection(hostDomain.ID, host.UserID, SimiasConnection.AuthType.PPK, hostDomain);

                    // We need to get a one time password to use to authenticate.
                    connection.Authenticate();
                    log.Debug("Connection successful....");
                    break;
                }
                catch (Exception ex)
                {
                    log.Debug("Domain Sync, Exception creating a SimiasConnection  {0}  {1}", ex.Message, ex.StackTrace);
                    Thread.Sleep(10000);
                    if (--retry <= 0)
                    {
                        break;
                    }
                }
            }

            syncClient = new CollectionSyncClient(hostDomain.ID, new TimerCallback(TimerFired));
            while (true)
            {
                syncEvent.WaitOne();
                retry = 3;
                while (retry-- > 0)
                {
                    try
                    {
                        lock (CollectionSyncClient.MapObject)
                        {
                            CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncStarted;
                            CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncFinished;
                        }
                        log.Debug("About to Start Domain Sync");
                        syncClient.SyncNow();
                        log.Debug("Domain Sync Completed");
                        lock (CollectionSyncClient.MapObject)
                        {
                            CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncStarted;
                            CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncFinished;
                            CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncOnce;
                        }
                        break;
                    }
                    catch (Exception ex) {
                        log.Debug("Domain Sync, got an exception.{0} {1}", ex.Message, ex.StackTrace);
                        Thread.Sleep(30 * 1000);
                        log.Debug("Domain Sync, Possibly connection lost. Setting simias connection again");
                        try
                        {
                            connection.ClearConnection();
                            connection = new SimiasConnection(hostDomain.ID, host.UserID, SimiasConnection.AuthType.PPK, hostDomain);
                            connection.Authenticate();
                        }
                        catch (Exception SimiasConnEx) {
                            log.Debug("Domain Sync, second Simias connection got exception.{0} {1}", SimiasConnEx.Message, SimiasConnEx.StackTrace);
                        }
                        log.Debug("Domain Sync, Simias authenticate for Domain Sync Connection successful....");
                    }
                    if (retry == 1)
                    {
                        // Going to exit while loop, before that unset the domain sync flag, so other syns get chance
                        lock (CollectionSyncClient.MapObject)
                        {
                            CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncStarted;
                            CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncFinished;
                            log.Debug("DomainSync: This was last retry, so unsetting the domainsync ON flag so that other sync threads will try...");
                        }
                    }
                }

                syncClient.Reschedule(true, 30);
            }
        }