Beispiel #1
0
 /// <summary>
 /// Initial again when all of the digits have been used.
 /// </summary>
 public static void SetReInitial()
 {
     // Set 3 status to false
     lock (LockUnusedSet)
     {
         UnusedSetStatus = false;
     }
     lock (LockUsedSet)
     {
         UsedSetStatus = false;
     }
     lock (LockExceptionSet)
     {
         ExceptionSetStatus = false;
     }
     // Clear nodes of 3 Sets
     lock (LockUsedSet)
     {
         if (_UsedSet == null)
         {
             _UsedSet = ObjectBuildFactory <PINs.Algorithm.ISet <int> > .Instance(SystemConfiguration.AlgorithmClassName);
         }
         else
         {
             _UsedSet.Clear(SystemConfiguration.UsedDigitDataSet);
         }
     }
     lock (LockUnusedSet)
     {
         if (_UnusedSet == null)
         {
             _UnusedSet = ObjectBuildFactory <PINs.Algorithm.ISet <int> > .Instance(SystemConfiguration.AlgorithmClassName);
         }
         else
         {
             _UnusedSet.Clear(SystemConfiguration.UnusedDigitDataSet);
         }
     }
     lock (LockExceptionSet)
     {
         if (_ExceptionSet == null)
         {
             _ExceptionSet = ObjectBuildFactory <PINs.Algorithm.ISet <int> > .Instance(SystemConfiguration.AlgorithmClassName);
         }
         else
         {
             _ExceptionSet.Clear(SystemConfiguration.ExceptionDigitDataSet);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Initial 3 Set
        /// </summary>
        public static void Initial()
        {
            //create 3 Set Objects by DIP,dynamic create class
            lock (LockUsedSet)
            {
                if (_UsedSet == null)
                {
                    _UsedSet = ObjectBuildFactory <PINs.Algorithm.ISet <int> > .Instance(SystemConfiguration.AlgorithmClassName);
                }
            }
            lock (LockUnusedSet)
            {
                if (_UnusedSet == null)
                {
                    _UnusedSet = ObjectBuildFactory <PINs.Algorithm.ISet <int> > .Instance(SystemConfiguration.AlgorithmClassName);
                }
            }
            lock (LockExceptionSet)
            {
                if (_ExceptionSet == null)
                {
                    _ExceptionSet = ObjectBuildFactory <PINs.Algorithm.ISet <int> > .Instance(SystemConfiguration.AlgorithmClassName);
                }
            }
            //Juage: if 1st execute this program
            if (!_UnusedSet.IsInitial(SystemConfiguration.UnusedDigitDataSet) ||
                !_UsedSet.IsInitial(SystemConfiguration.UsedDigitDataSet) ||
                !_ExceptionSet.IsInitial(SystemConfiguration.ExceptionDigitDataSet)

                )
            {
                //1st time execute this program
                //generated 3 Set
                //......
                Debug("prepare unused set ...\r\n");
                for (int i = SystemConfiguration.MinDigit; i <= SystemConfiguration.MaxDigit; i++)
                {
                    lock (LockExceptionSet)
                    {
                        _UnusedSet.Insert(i);
                    }
                }
                Debug("Unused set is OK ...\r\n");
                lock (LockUnusedSet)
                {
                    UnusedSetStatus = true;
                }
                lock (LockUsedSet)
                {
                    UsedSetStatus = true;  //UsedSet contains 0 data.
                }
                lock (LockExceptionSet)
                {
                    ExceptionSetStatus = true; //ExceptionSet contains 0 data.
                }
                Debug("All of digit Set is OK ...\r\n");
                LoggerHelper.Info("Digits' Set is prepared.\r\n");

                //Save node to somewhere, now they are physical files.
                _UnusedSet.Save(SystemConfiguration.UnusedDigitDataSet);
                Debug("Unused set is saved  to file...\r\n");
                _ExceptionSet.Save(SystemConfiguration.ExceptionDigitDataSet);
                Debug("exception set is saved to file...\r\n");
                _UsedSet.Save(SystemConfiguration.UsedDigitDataSet);
                Debug("used set is saved to file...\r\n");
            }
            else
            {
                //not first execute this program
                if ((UsedSetStatus == false) && (UnusedSetStatus == false) && (ExceptionSetStatus == false))
                {
                    //not initial
                    //Load data to 3 Set from somewhere ,now they are physical files.
                    _ExceptionSet.Load(SystemConfiguration.ExceptionDigitDataSet);
                    lock (LockExceptionSet)
                    {
                        ExceptionSetStatus = true;
                    }
                    Debug("excepiton set is loaded ...\r\n");

                    _UsedSet.Load(SystemConfiguration.UsedDigitDataSet);
                    lock (LockUsedSet)
                    {
                        UsedSetStatus = true;
                    }
                    Debug("used set is loaded ...\r\n");

                    _UnusedSet.Load(SystemConfiguration.UnusedDigitDataSet);
                    lock (LockUnusedSet)
                    {
                        UnusedSetStatus = true;
                    }
                    Debug("unused set id loaded ...\r\n");
                }
            }
        }