Esempio n. 1
0
        public CircuitState(int reserveState)
        {
            int seed = (int)DateTime.UtcNow.Ticks;

            //seed = -142808611;
            Tracer.FullInfo("CircuitState", "CircuitState.seed={0}", seed);
            this.dirty  = new DirtyList(seed);
            this.Random = new Random(seed);
            this.Count  = reserveState;
        }
Esempio n. 2
0
        private static void ValidateSettingsCulture()
        {
            SettingsStringCache cultureName = new SettingsStringCache(Settings.User, App.SettingsCultureName, App.DefaultCultureName());
            string name = App.ValidateCultureName(cultureName.Value);

            if (name != cultureName.Value)
            {
                Tracer.FullInfo("App.ValidateSettingsCulture", "Replacing current settings culture {0} with {1}", cultureName.Value, name);
                App.currentCultureName.Value = name;
            }
        }
        public IList <TruthState> BuildTruthTable(Action <double> reportProgress, Func <bool> keepGoing, Predicate <TruthState> include, int maxCount, out bool truncated)
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            if (this.chankList == null)
            {
                this.chank.BuildTruthTable(reportProgress, keepGoing, include, maxCount);
                truncated = this.chank.Trancated;
                if (this.chank.Oscillation)
                {
                    return(null);
                }
                watch.Stop();
                Tracer.FullInfo("CircuitTestSocket.BuildTruthTable", "Single threaded time: {0}", watch.Elapsed);
                return(this.chank.Results);
            }
            double[] progress = new double[this.chankList.Length];
            Parallel.For(0, this.chankList.Length, i =>
                         this.chankList[i].BuildTruthTable(
                             d => {
                progress[i] = d;
                reportProgress(progress.Sum() / progress.Length);
            },
                             () => keepGoing() && !this.chankList.Take(i).Any(c => c.Trancated) && !this.chankList.Any(c => c.Oscillation),
                             include,
                             maxCount
                             )
                         );
            truncated = this.chankList.Any(c => c.Trancated);
            if (this.chankList.Any(c => c.Oscillation))
            {
                return(null);
            }
            List <TruthState> list = new List <TruthState>();

            foreach (TableChank table in this.chankList)
            {
                if (table.Results != null)
                {
                    list.AddRange(table.Results);
                }
                if (maxCount <= list.Count)
                {
                    break;
                }
            }
            if (maxCount < list.Count)
            {
                list.RemoveRange(maxCount, list.Count - maxCount);
            }
            watch.Stop();
            Tracer.FullInfo("CircuitTestSocket.BuildTruthTable", "Multi threaded time: {0}", watch.Elapsed);
            return(list);
        }
Esempio n. 4
0
        public bool Evaluate(bool flipClock)
        {
            if (0 < this.updated.Count)
            {
                lock (this.updated) {
                    this.dirty.Add(this.updated);
                    this.updated.Clear();
                }
            }
            if (flipClock)
            {
                foreach (CircuitFunction c in this.clockList)
                {
                    if (((IFunctionClock)c).Flip())
                    {
                        this.dirty.Add(c);
                    }
                }
            }
            int maxRetry = 3;
            int attempt  = 0;

            this.dirty.Delay = attempt;
            long            oscillation = (long)this.state.Length * (long)this.state.Length;
            CircuitFunction function;

            while ((function = this.dirty.Get()) != null)
            {
                if (function.Evaluate())
                {
                    if (function.Dependent != null)
                    {
                        this.dirty.Add(function.Dependent);
                    }
                    if (oscillation-- < 0)
                    {
                        if (maxRetry <= attempt)
                        {
                            return(false);
                        }
                        oscillation      = (long)this.state.Length * (long)this.state.Length;
                        this.dirty.Delay = ++attempt;
                    }
                }
                                #if DUMP_STATE
                Tracer.FullInfo("CircuitState.Evaluate", "{0} {1}", this.ShowParam(function), function.ToString());
                Tracer.FullInfo("CircuitState.Evaluate", this.ToString());
                                #endif
            }
                        #if REPORT_STAT
            System.Diagnostics.Debug.Print(this.ReportStat);
                        #endif
            return(true);
        }
Esempio n. 5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            App.InitLogging();
            App.ValidateSettingsCulture();
            LogicCircuit.Properties.Resources.Culture = App.CurrentCulture;
            Tracer.FullInfo("App", "Starting with culture: {0}", App.CurrentCulture.Name);

            base.OnStartup(e);

            App.InitCommands();

            if (e != null && e.Args != null && 0 < e.Args.Length)
            {
                bool        showHelp    = false;
                CommandLine commandLine = new CommandLine()
                                          .AddFlag("help", "?", "Show this message", false, value => showHelp = value)
                                          .AddString("run", "r", "<script>", "IronPython script to run on startup", false, file => this.ScriptToRun = file)
                ;
                string errors = commandLine.Parse(e.Args, files => this.FileToOpen = files.FirstOrDefault());

                if (!string.IsNullOrEmpty(errors))
                {
                    Tracer.FullInfo("App", "Errors parsing command line parameters: {0}", errors);
                }
                if (showHelp || errors != null)
                {
                    this.CommandLineErrors = (
                        (errors ?? "") +
                        "\nLogicCircuit command line parameters:\n" + commandLine.Help() + "<CircuitProject file path> - open the file"
                        ).Trim();
                }
            }
            Tracer.FullInfo("App", "Application launched with file to open: \"{0}\"", this.FileToOpen);
            Tracer.FullInfo("App", "Application launched with script to run: \"{0}\"", this.ScriptToRun);
            EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent, new RoutedEventHandler(TextBoxGotKeyboardFocus));
            EventManager.RegisterClassHandler(typeof(TextBox), TextBox.PreviewMouseDownEvent, new RoutedEventHandler(TextBoxPreviewMouseDown));

            ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(UIElement), new FrameworkPropertyMetadata(10000));
        }