Пример #1
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Any(obj => obj == DependencyProperty.UnsetValue))
                return DependencyProperty.UnsetValue;

            if ((string)parameter == "ganttLine")
            {
                var length = ((DateTime)values[0] - (DateTime)values[1]).TotalMinutes / 30;
                var interval = (double)values[2];
                return length * interval;
            }
            else
            {
                var vals = new List<double>();
                foreach (object val in values)
                    //box化されたintがdoubleへ直接キャストできないのでいったんunbox化した後にdoubleにする
                    vals.Add(val is int ? (double)(int)val : (double)val);
                switch ((string)parameter)
                {
                    case "sum":
                        return vals.Cast<double>().Sum();
                    case "product":
                        return vals.Aggregate((val, tmp) => val * tmp);
                    default:
                        throw new NotImplementedException();
                }
            }
        }
Пример #2
0
        private void _mrec_ParseUpdated(MathRecognition source, Recognition chchanged, bool updateMath)
        {
            /* Evaluate math if necessary */
            if (updateMath)
                try
                {
                    Evaluator.UpdateMath(_mrec.Ranges.Select((Parser.Range r) => r.Parse));
                }
                catch { }

            /* reset geometry displayed: range displays, etc */
            underlay.Children.Clear();
            inqCanvas.Children.Clear();

            /* set up to draw background yellow thing for range displays */
            Brush fill3 = new SolidColorBrush(Color.FromArgb(50, 255, 255, 180));
            Brush fill2 = new SolidColorBrush(Color.FromArgb(75, 255, 255, 180));
            Brush fill1 = new SolidColorBrush(Color.FromArgb(100, 255, 255, 180));
            Brush sqr3 = new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
            Brush sqr2 = new SolidColorBrush(Color.FromArgb(75, 0, 255, 0));
            Brush sqr1 = new SolidColorBrush(Color.FromArgb(100, 0, 255, 0));
            foreach (Parser.Range rrr in _mrec.Ranges)
            {
                Rct rangebbox = bbox(rrr.Strokes);
                CurrentStrokesBoudningBox = rangebbox;

                Rct box = rangebbox.Inflate(8, 8);

                /* draw yellow box */
                DrawingVisual dv = new DrawingVisual();
                DrawingContext dc = dv.RenderOpen();
                dc.DrawRoundedRectangle(fill3, null, box, 4, 4);
                dc.DrawRoundedRectangle(fill2, null, box.Inflate(-4, -4), 4, 4);
                dc.DrawRoundedRectangle(fill1, null, box.Inflate(-8, -8), 4, 4);
                dc.Close();
                underlay.Children.Add(dv);

                if (rrr.Parse != null)
                {
                    /* draw interpretation of entry */
                    if (rrr.Parse.expr != null)
                    {
                        dv = new DrawingVisual();
                        dc = dv.RenderOpen();
                        // this is an example of normal drawing of an expr
                        Rct nombb = starPadSDK.MathExpr.ExprWPF.EWPF.DrawTop(rrr.Parse.expr, 22, dc, Colors.Blue, new Pt(box.Left, box.Bottom + 24), true);
                        dc.Close();
                        underlay.Children.Add(dv);
                    }

                    /* draw result of computation, if any */
                    if (rrr.Parse.finalSimp != null)
                    {
                        Rct nombb;
                        Expr result = rrr.Parse.matrixOperationResult == null ? rrr.Parse.finalSimp : rrr.Parse.matrixOperationResult;
                        // this is an example of drawing an expr by getting a geometry of it first, so can be used for special effects, etc.
                        Geometry g = starPadSDK.MathExpr.ExprWPF.EWPF.ComputeGeometry(result, 22, out nombb);
                        System.Windows.Shapes.Path p = new System.Windows.Shapes.Path();
                        p.Data = g;
                        p.Stroke = Brushes.Red;
                        p.Fill = Brushes.Transparent;
                        p.StrokeThickness = 1;
                        p.RenderTransform = new TranslateTransform(box.Right + 10, box.Center.Y);
                        inqCanvas.Children.Add(p);
                    }

                    /* colorize ink. Ideally we would have kept track of which ink strokes had changes and only update colorization in those ranges affected
                     * by the changes. */
                    if (rrr.Parse.root != null) _colorizer.Colorize(rrr.Parse.root, rrr.Strokes, _mrec);
                }
            }

            /* Update alternates menu if user wrote a char */
            if (chchanged != null)
            {
                showSidebarAlts(new[] { chchanged }, new StroqCollection(_mrec.Sim[chchanged.strokes]));
            }
#if false
            /* print out log of current 1st-level parse, for debugging */
            List<string> resstrs = new List<string>();
            foreach(Parser.Range r in _mrec.Ranges) {
                Parser.ParseResult p = r.Parse;
                if(p != null && p.root != null)
                    resstrs.Add(p.root.Print());
            }
            if(resstrs.Count > 0) Console.WriteLine(resstrs.Aggregate((string a, string b) => a + " // " + b));
            foreach(Parser.Range r in _mrec.Ranges) {
                Parser.ParseResult pr = r.Parse;
                if(pr != null && pr.expr != null) Console.WriteLine(Text.Convert(pr.expr));
            }
#endif
        }
Пример #3
0
        private void RunAllTests(object sender, RoutedEventArgs e)
        {
            


            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();
            dialog.Description = "Please select a folder.";
            dialog.UseDescriptionForTitle = true; // This applies to the Vista style dialog only, not the old dialog.
          
           

            if ((bool)dialog.ShowDialog(this))
            {
              
          
                var filename = dialog.SelectedPath; // will switch to .Url later
                                                   //				var newText = File.ReadAllText (filename);
                                                   //				CSharpFilename.StringValue = Path.GetFileName (filename);
                                                   //				CSharpTextEditor.Replace (new NSRange (0, CSharpTextEditor.Value.Length), newText);
                                                   //				ViewModel.SourceCode = newText;
                                                   //				ViewModel.RecompileSource ();

                Func<string, string> strip = i => Regex.Replace(i ?? "", "[\r\n \t]+", " ").Trim();

                ViewModel.CompilerErrors = "\r\r" + ("Running all tests in : " + filename) + "\r\r";
                int passCount = 0;
                //			if (ResetStatus != null)
                //				ResetStatus.Stop();
                List<string> failedTestNames = new List<string>();
                ThreadPool.QueueUserWorkItem((h) =>
                    {

                        var allTests = Directory.EnumerateFiles(filename).Where(u => Path.GetExtension(u) == ".cs");
                        var count = 0;
                        foreach (var file in allTests)
                        {

                            var shortName = Path.GetFileName(file);
                            Console.WriteLine("-------------------------Running Test: " + shortName + "-------------------------");
                            ViewModel.CompilerErrors += "-------------------------Running Test: " + shortName + "-------------------------";

                            var text = FileExtensions.ReadFile(file);

                            if (text == "-1")
                                break;

                            Dispatcher.Invoke(() =>
                            {
                                CurrentSourceFile = file;
                                  TextEditor.Text = text;
//                                ViewModel.Recompile(CurrentSourceFile);

//                                CSharpFilename.StringValue = Path.GetFileName(file);

//                                CSharpTextEditor.Value = Extensions.ReadFile(file);
                            });

                            CSharpOutput = "Z..)";
                            CppOutput = "A..)";
                            //							ViewModel.CompileAndRunCode(shortName,File.ReadAllText(file));
                            CompileCSharp(false);
                            CompileD();
                            count++;

                            if (count % 20 == 0)
                            {
                                GC.Collect();
                            }

                            if (strip(CSharpOutput) == strip(CppOutput))
                            {
                                passCount++;
                                Dispatcher.Invoke(() =>
                                {
                                   

                                    ViewModel.CompilerErrors += String.Format("-------------------------Test {0} Passed:-------------------------\n", shortName);
                                });
                            }
                            else
                            {
                                Dispatcher.Invoke(() =>
                                {
                               
                                    ViewModel.CompilerErrors += String.Format("Test {0} Failed:\n", shortName);
                                    failedTestNames.Add(Path.GetFileNameWithoutExtension(shortName));

                                });
                            }
                           
                        }

                        ViewModel.CompilerErrors += String.Format("Summary \nTotal:{0} \nPass Rate:{1} \nPassed: {2} \nFailed: {3} {4}\n", allTests.Count(), (passCount * 100) / ((float)allTests.Count()), passCount, allTests.Count() - passCount, (allTests.Count() - passCount == 0) ? "" : failedTestNames.Aggregate((k, j) => k + " , " + j));

                    });



            }
        }
Пример #4
0
        private string CheckRawReportFolder()
        {
            var checkResults = new List<string>();

            NameValueCollection rawFilesPattern = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("RawFilesPattern");

            var bdreportFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["BDReport"].ToString());

            if (bdreportFiles.Length == 0)
                checkResults.Add("Miss BD Report File");
            else if (bdreportFiles.Length > 1)
                checkResults.Add("Exist duplicated BD Report Files");
            else
                _bdReportFileName = bdreportFiles[0];

            var projectidcFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["ProjectIDCReport"].ToString());
            if (projectidcFiles.Length == 0)
                checkResults.Add("Miss IDC Report By Project File");
            else if (projectidcFiles.Length > 1)
                checkResults.Add("Exist duplicated IDC Report By Project Files");
            else
                _idcProjectReportFileName = projectidcFiles[0];

            var employeeidcFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["EmployeeIDCReport"].ToString());

            if (employeeidcFiles.Length == 0)
                checkResults.Add("Miss IDC Report By Employee File");
            else if (employeeidcFiles.Length > 1)
                checkResults.Add("Exist duplicated IDC Report By Employee Files");
            else
                _idcEmployeeReportFileName = employeeidcFiles[0];

            var projectcontributionMTDFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["ProjectContributionMTDReport"].ToString());

            if (projectcontributionMTDFiles.Length == 0)
                checkResults.Add("Miss Project contribution report MTD File");
            else if (projectcontributionMTDFiles.Length > 1)
                checkResults.Add("Exist duplicated Project contribution report MTD Files");
            else
                _projectContributionMTDReportFileName = projectcontributionMTDFiles[0];

            var projectcontributionYTDFiles = Directory.GetFiles(_inputFolderName, rawFilesPattern["ProjectContributionYTDReport"].ToString());

            if (projectcontributionYTDFiles.Length == 0)
                checkResults.Add("Miss Project contribution report YTD File");
            else if (projectcontributionYTDFiles.Length > 1)
                checkResults.Add("Exist duplicated contribution report YTD Files");
            else
                _projectContributionYTDReportFileName = projectcontributionYTDFiles[0];

            if (checkResults.Count == 0)
                return string.Empty;
            else if (checkResults.Count == 1)
                return checkResults[0];
            else
                return checkResults.Aggregate<string>((i, j) => i + "; " + j);
        }