コード例 #1
0
ファイル: CountPiXThread.cs プロジェクト: xgalv/Cryptool2
        /*
         * long n = 2;
         * long counter = 0;
         * if (PrimesCountList.Initialzed)
         * {
         *  n = PrimesCountList.MaxNumber;
         *  counter = PrimesCountList.GetPrime(n);
         * }
         * m_FunctionPix_Executed(n);
         * m_FunctionPix.FunctionState = FunctionState.Running;
         *
         * while (n < m_To.LongValue)
         * {
         *  n++;
         *  counter = (long)m_FunctionPix.Execute(n);
         * }
         * m_FunctionPix.FunctionState = FunctionState.Stopped;
         * if (OnStopPiX != null) OnStopPiX();
         */

        protected override void OnDoWork()
        {
            if (OnFunctionStart != null)
            {
                OnFunctionStart(m_FunctionPiX);
            }
            if (m_FunctionPiX != null)
            {
                if (PrimesCountList.Initialzed)
                {
                    n       = PrimesCountList.MaxNumber;
                    counter = PrimesCountList.GetPrime(n);
                }
                m_objdelegate(n);
                m_FunctionPiX.FunctionState = FunctionState.Running;
                while (!HasTerminateRequest() && n < m_To.LongValue)
                //for (long i = m_From; i <= fe.Range.To * factor || !HasTerminateRequest(); i += inci)
                {
                    Boolean awokenByTerminate = SuspendIfNeeded();

                    if (awokenByTerminate)
                    {
                        return;
                    }
                    n++;
                    counter = (long)m_FunctionPiX.Execute(n);
                }
                m_FunctionPiX.Reset();
                m_FunctionPiX.FunctionState = FunctionState.Stopped;
                if (OnFunctionStop != null)
                {
                    OnFunctionStop(m_FunctionPiX);
                }
            }
        }
コード例 #2
0
ファイル: GraphControl.xaml.cs プロジェクト: xgalv/Cryptool2
 void m_FunctionPix_Executed(object obj)
 {
     if (PrimesCountList.Initialzed && m_To.LongValue <= PrimesCountList.MaxNumber)
     {
         ControlHandler.SetPropertyValue(lblCalcInfoPiX, "Text", Primes.Resources.lang.WpfControls.Distribution.Distribution.graph_pincountinfo);
         SetInfo(tbInfoPiX, PrimesCountList.GetPrime(m_To.LongValue));
     }
     else
     {
         SetInfo(tbInfoPiX, obj);
     }
 }
コード例 #3
0
ファイル: PrimesControl.xaml.cs プロジェクト: xgalv/Cryptool2
        public void Initialize()
        {
            ControlHandler.Dispatcher = this.Dispatcher;
            navigator.OnNavigate     += Navigate;

            PrimesCountList.LoadPrimes();
            m_History = new List <NavigationCommandType>();

            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (SendOrPostCallback) delegate
            {
                Navigate(NavigationCommandType.Start);
            }, null);
            (m_StartControl as StartControl).OnStartpageLinkClick += new Navigate(Navigate);
            this.MouseRightButtonDown += new MouseButtonEventHandler(PrimesControl_MouseRightButtonDown);
        }
コード例 #4
0
ファイル: GraphControl.xaml.cs プロジェクト: xgalv/Cryptool2
        private void CalculatePiX()
        {
            long n       = 2;
            long counter = 0;

            if (PrimesCountList.Initialzed)
            {
                n       = PrimesCountList.MaxNumber;
                counter = PrimesCountList.GetPrime(n);
            }
            m_FunctionPix_Executed(n);
            m_FunctionPix.FunctionState = FunctionState.Running;

            while (n < m_To.LongValue)
            {
                n++;
                counter = (long)m_FunctionPix.Execute(n);
            }
            m_FunctionPix.FunctionState = FunctionState.Stopped;
            if (OnStopPiX != null)
            {
                OnStopPiX();
            }
        }
コード例 #5
0
ファイル: FunctionPiX.cs プロジェクト: xgalv/Cryptool2
        public double Execute(double input)
        {
            long value = (long)input;

            if (usePrimesCountList)
            {
                usePrimesCountList = PrimesCountList.Initialzed;
            }
            if (PrimesCountList.Initialzed && usePrimesCountList)
            {
                if (value <= PrimesCountList.MaxNumber)
                {
                    m_FormerValue = m_Counter;
                    m_Counter     = PrimesCountList.GetPrime((long)input);
                    m_LastNumber  = value;
                }
                else
                {
                    m_Counter          = PrimesCountList.GetPrime(PrimesCountList.MaxNumber);
                    m_LastNumber       = PrimesCountList.MaxNumber;
                    usePrimesCountList = false;
                }
            }
            else
            {
                long i = value / 100000;
                if (i < PrimeNumbers.numberofprimes.Length)
                {
                    m_Counter    = PrimeNumbers.numberofprimes[i];
                    m_LastNumber = i * 100000;
                }
            }

            if (PrimesBigInteger.ValueOf(m_LastNumber).IsPrime(10))
            {
                m_LastNumber++;
            }
            while (m_LastNumber < value)
            {
                if (PrimesBigInteger.ValueOf(m_LastNumber).IsPrime(10))
                {
                    m_Counter++;
                    if (m_ShowIntermediateResult && Executed != null)
                    {
                        Executed(m_Counter);
                    }
                }
                m_LastNumber++;
            }
            if (PrimesBigInteger.ValueOf(value).IsPrime(10) && !usePrimesCountList)
            {
                m_FormerValue = m_Counter;
                m_Counter++;
            }
            m_LastNumber = value;
            if (Executed != null)
            {
                Executed(m_Counter);
            }

            return(m_Counter);
        }