Exemplo n.º 1
0
        /// <summary>
        ///     Returns a hash code for this value.
        /// </summary>
        /// <returns>
        ///     An integer that specifies a hash value for this value.
        /// </returns>
        public override int GetHashCode()
        {
            int hash = 1;

            hash ^= PatternFilter.GetHashCode();
            hash ^= EntryFilter.GetHashCode();
            return(hash);
        }
Exemplo n.º 2
0
        public void TestPatternInner()
        {
            var plus   = new PatternFilter("*.cs");
            var minus  = new NegatePatternFilter("*.cs");
            var filter = new AndFilter <string>(plus, minus);
            var data   = new[] { "hoge.cs", "barTest.cs", "foo.cpp", "bar.rb" };

            Assert.That(filter.Filter(data), Is.Empty);
        }
 public NewsProcessor()
 {
     Filter = new PatternFilter(new[] { "^http://www\\.cnblogs\\.com/$", "^http://www\\.cnblogs\\.com/news/$", "www\\.cnblogs\\.com/news/\\d+" });
 }
 public BlogSumaryProcessor()
 {
     RequestExtractor = new XPathRequestExtractor(".");
     Filter           = new PatternFilter(new[] { "^http://www\\.cnblogs\\.com/$", "http://www\\.cnblogs\\.com/sitehome/p/\\d+" });
 }
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SubclassedControlsUI));
     Rylogic.Common.Pattern pattern1 = new Rylogic.Common.Pattern();
     this.m_ts             = new System.Windows.Forms.ToolStrip();
     this.m_btn_test       = new System.Windows.Forms.Button();
     this.m_timer          = new System.Windows.Forms.Timer(this.components);
     this.m_lbl_vb_value   = new System.Windows.Forms.Label();
     this.m_vb_value       = new Rylogic.Gui.WinForms.ValueBox();
     this.m_browse_path    = new Rylogic.Gui.WinForms.BrowsePathUI();
     this.m_pb             = new Rylogic.Gui.WinForms.TextProgressBar();
     this.m_rtb            = new Rylogic.Gui.WinForms.RichTextBox();
     this.m_lb             = new Rylogic.Gui.WinForms.ListBox();
     this.m_dtp            = new Rylogic.Gui.WinForms.DateTimePicker();
     this.m_cb             = new Rylogic.Gui.WinForms.ComboBox();
     this.m_abtn_switch    = new Rylogic.Gui.WinForms.AnimCheckBox();
     this.m_abtn_images    = new System.Windows.Forms.ImageList(this.components);
     this.m_pattern_filter = new Rylogic.Gui.WinForms.PatternFilter();
     this.SuspendLayout();
     //
     // m_ts
     //
     this.m_ts.ImageScalingSize = new System.Drawing.Size(20, 20);
     this.m_ts.Location         = new System.Drawing.Point(0, 0);
     this.m_ts.Name             = "m_ts";
     this.m_ts.Size             = new System.Drawing.Size(380, 25);
     this.m_ts.TabIndex         = 4;
     this.m_ts.Text             = "toolStrip1";
     //
     // m_btn_test
     //
     this.m_btn_test.Location = new System.Drawing.Point(12, 206);
     this.m_btn_test.Name     = "m_btn_test";
     this.m_btn_test.Size     = new System.Drawing.Size(75, 23);
     this.m_btn_test.TabIndex = 5;
     this.m_btn_test.Text     = "Test";
     this.m_btn_test.UseVisualStyleBackColor = true;
     //
     // m_lbl_vb_value
     //
     this.m_lbl_vb_value.AutoSize = true;
     this.m_lbl_vb_value.Location = new System.Drawing.Point(245, 263);
     this.m_lbl_vb_value.Name     = "m_lbl_vb_value";
     this.m_lbl_vb_value.Size     = new System.Drawing.Size(33, 13);
     this.m_lbl_vb_value.TabIndex = 9;
     this.m_lbl_vb_value.Text     = "value";
     //
     // m_vb_value
     //
     this.m_vb_value.BackColorInvalid       = System.Drawing.Color.White;
     this.m_vb_value.BackColorValid         = System.Drawing.Color.White;
     this.m_vb_value.CommitValueOnFocusLost = true;
     this.m_vb_value.ForeColorInvalid       = System.Drawing.Color.Gray;
     this.m_vb_value.ForeColorValid         = System.Drawing.Color.Black;
     this.m_vb_value.Location           = new System.Drawing.Point(93, 260);
     this.m_vb_value.Name               = "m_vb_value";
     this.m_vb_value.Size               = new System.Drawing.Size(146, 20);
     this.m_vb_value.TabIndex           = 8;
     this.m_vb_value.UseValidityColours = true;
     this.m_vb_value.Value              = null;
     //
     // m_browse_path
     //
     this.m_browse_path.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                                                                       | System.Windows.Forms.AnchorStyles.Right)));
     this.m_browse_path.FileFilter = "";
     this.m_browse_path.History    = new string[0];
     this.m_browse_path.Location   = new System.Drawing.Point(12, 28);
     this.m_browse_path.Name       = "m_browse_path";
     this.m_browse_path.Padding    = new System.Windows.Forms.Padding(1);
     this.m_browse_path.Path       = "";
     this.m_browse_path.Size       = new System.Drawing.Size(356, 32);
     this.m_browse_path.TabIndex   = 7;
     this.m_browse_path.Title      = "Choose a file";
     this.m_browse_path.Type       = Rylogic.Gui.WinForms.BrowsePathUI.EType.OpenFile;
     //
     // m_pb
     //
     this.m_pb.ForeColor = System.Drawing.Color.Black;
     this.m_pb.Location  = new System.Drawing.Point(93, 206);
     this.m_pb.Name      = "m_pb";
     this.m_pb.Size      = new System.Drawing.Size(246, 48);
     this.m_pb.Style     = System.Windows.Forms.ProgressBarStyle.Continuous;
     this.m_pb.TabIndex  = 6;
     //
     // m_rtb
     //
     this.m_rtb.CaretLocation         = new System.Drawing.Point(0, 0);
     this.m_rtb.CurrentLineIndex      = 0;
     this.m_rtb.FirstVisibleLineIndex = 0;
     this.m_rtb.LineCount             = 0;
     this.m_rtb.Location = new System.Drawing.Point(139, 92);
     this.m_rtb.Name     = "m_rtb";
     this.m_rtb.Size     = new System.Drawing.Size(200, 108);
     this.m_rtb.TabIndex = 3;
     this.m_rtb.Text     = "";
     //
     // m_lb
     //
     this.m_lb.FormattingEnabled = true;
     this.m_lb.Location          = new System.Drawing.Point(12, 92);
     this.m_lb.Name     = "m_lb";
     this.m_lb.Size     = new System.Drawing.Size(121, 108);
     this.m_lb.TabIndex = 2;
     //
     // m_dtp
     //
     this.m_dtp.Kind     = System.DateTimeKind.Unspecified;
     this.m_dtp.Location = new System.Drawing.Point(139, 66);
     this.m_dtp.MaxDate  = new System.DateTime(9998, 12, 31, 0, 0, 0, 0);
     this.m_dtp.MinDate  = new System.DateTime(1753, 1, 1, 0, 0, 0, 0);
     this.m_dtp.Name     = "m_dtp";
     this.m_dtp.Size     = new System.Drawing.Size(200, 20);
     this.m_dtp.TabIndex = 1;
     this.m_dtp.Value    = new System.DateTime(2015, 5, 12, 11, 41, 16, 245);
     //
     // m_cb
     //
     this.m_cb.BackColorInvalid       = System.Drawing.Color.White;
     this.m_cb.BackColorValid         = System.Drawing.Color.White;
     this.m_cb.CommitValueOnFocusLost = true;
     this.m_cb.DisplayProperty        = null;
     this.m_cb.ForeColorInvalid       = System.Drawing.Color.Gray;
     this.m_cb.ForeColorValid         = System.Drawing.Color.Black;
     this.m_cb.FormattingEnabled      = true;
     this.m_cb.Location = new System.Drawing.Point(12, 65);
     this.m_cb.Name     = "m_cb";
     this.m_cb.PreserveSelectionThruFocusChange = false;
     this.m_cb.Size               = new System.Drawing.Size(121, 21);
     this.m_cb.TabIndex           = 0;
     this.m_cb.UseValidityColours = true;
     this.m_cb.Value              = null;
     //
     // m_abtn_switch
     //
     this.m_abtn_switch.FrameRate  = 5F;
     this.m_abtn_switch.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
     this.m_abtn_switch.ImageIndex = 0;
     this.m_abtn_switch.ImageList  = this.m_abtn_images;
     this.m_abtn_switch.Location   = new System.Drawing.Point(93, 286);
     this.m_abtn_switch.Name       = "m_abtn_switch";
     this.m_abtn_switch.Size       = new System.Drawing.Size(146, 64);
     this.m_abtn_switch.TabIndex   = 10;
     this.m_abtn_switch.UseVisualStyleBackColor = true;
     //
     // m_abtn_images
     //
     this.m_abtn_images.ImageStream      = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("m_abtn_images.ImageStream")));
     this.m_abtn_images.TransparentColor = System.Drawing.Color.Transparent;
     this.m_abtn_images.Images.SetKeyName(0, "slide_switch0.png");
     this.m_abtn_images.Images.SetKeyName(1, "slide_switch1.png");
     this.m_abtn_images.Images.SetKeyName(2, "slide_switch2.png");
     this.m_abtn_images.Images.SetKeyName(3, "slide_switch3.png");
     this.m_abtn_images.Images.SetKeyName(4, "slide_switch4.png");
     //
     // m_pattern_filter
     //
     this.m_pattern_filter.History  = new Rylogic.Common.Pattern[0];
     this.m_pattern_filter.Location = new System.Drawing.Point(12, 356);
     this.m_pattern_filter.Name     = "m_pattern_filter";
     pattern1.Active                = true;
     pattern1.Expr                  = "";
     pattern1.IgnoreCase            = false;
     pattern1.Invert                = false;
     pattern1.PatnType              = Rylogic.Common.EPattern.Substring;
     pattern1.WholeLine             = false;
     this.m_pattern_filter.Pattern  = pattern1;
     this.m_pattern_filter.Size     = new System.Drawing.Size(356, 27);
     this.m_pattern_filter.TabIndex = 11;
     //
     // SubclassedControlsUI
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize          = new System.Drawing.Size(380, 415);
     this.Controls.Add(this.m_pattern_filter);
     this.Controls.Add(this.m_abtn_switch);
     this.Controls.Add(this.m_lbl_vb_value);
     this.Controls.Add(this.m_vb_value);
     this.Controls.Add(this.m_browse_path);
     this.Controls.Add(this.m_pb);
     this.Controls.Add(this.m_btn_test);
     this.Controls.Add(this.m_ts);
     this.Controls.Add(this.m_rtb);
     this.Controls.Add(this.m_lb);
     this.Controls.Add(this.m_dtp);
     this.Controls.Add(this.m_cb);
     this.Name = "SubclassedControlsUI";
     this.Text = "Subclassed Controls";
     this.ResumeLayout(false);
     this.PerformLayout();
 }
Exemplo n.º 6
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="model">数据模型</param>
        /// <param name="extractor">模型解析器</param>
        /// <param name="dataHandlers">数据处理器</param>
        public ModelProcessor(IModel model, IModelExtractor extractor = null, params IDataHandler[] dataHandlers)
        {
            Model = model ?? throw new ArgumentNullException(nameof(model));

            Extractor = extractor ?? new ModelExtractor();

            var patterns = new HashSet <string>();

            foreach (var ps in model.Targets.Select(t => t.Patterns))
            {
                if (ps == null)
                {
                    continue;
                }
                foreach (var p in ps)
                {
                    patterns.Add(p);
                }
            }

            var excludePatterns = new HashSet <string>();

            foreach (var ps in model.Targets.Select(t => t.ExcludePatterns))
            {
                if (ps == null)
                {
                    continue;
                }
                foreach (var p in ps)
                {
                    excludePatterns.Add(p);
                }
            }

            Filter = new PatternFilter(patterns, excludePatterns);

            var xPaths = new HashSet <string>();

            foreach (var xs in model.Targets.Select(t => t.XPaths))
            {
                if (xs == null)
                {
                    continue;
                }
                foreach (var x in xs)
                {
                    xPaths.Add(x);
                }
            }

            RequestExtractor = xPaths.Any(x => x == null || x == ".")
                                ? new XPathRequestExtractor(".")
                                : (xPaths.Count == 0 ? null : new XPathRequestExtractor(xPaths));

            if (dataHandlers == null)
            {
                return;
            }
            foreach (var dataHandler in dataHandlers)
            {
                if (dataHandler != null)
                {
                    _dataHandlers.Add(dataHandler);
                }
            }
        }
Exemplo n.º 7
0
        private void CompleteF2L()
        {
            List <Tuple <Cube, Cube> > unsolvedPairs = GetPairs(this.Rubik).ToList();

            while (unsolvedPairs.Count > 0) // 4 pairs
            {
                Tuple <Cube, Cube> currentPair = unsolvedPairs.First();

                Cube edge   = currentPair.Item1;
                Cube corner = currentPair.Item2;

                CubePosition target = new CubePosition(Rubik.GetTargetFlags(corner));

                if (!corner.Position.HasFlag(CubeFlag.TopLayer) && Rubik.GetTargetFlags(corner) != corner.Position.Flags)
                {
                    CubeFlag rotationLayer = CubeFlagService.FirstNotInvalidFlag(corner.Position.Flags, CubeFlag.BottomLayer);
                    bool     direction     = new TestScenario(Rubik, new LayerMove(rotationLayer)).TestCubePosition(corner, CubeFlag.TopLayer);
                    SolverMove(rotationLayer, direction);
                    SolverMove(CubeFlag.TopLayer, true);
                    SolverMove(rotationLayer, !direction);
                }
                // move edge to top position if necessary
                if (!edge.Position.HasFlag(CubeFlag.TopLayer) && Rubik.GetTargetFlags(edge) != edge.Position.Flags)
                {
                    CubeFlag rotationLayer = CubeFlagService.FirstNotInvalidFlag(edge.Position.Flags, CubeFlag.MiddleLayer);
                    bool     direction     = new TestScenario(Rubik, new LayerMove(rotationLayer)).TestCubePosition(edge, CubeFlag.TopLayer);
                    SolverMove(rotationLayer, direction);
                    while ((corner.Position.HasFlag(rotationLayer) && !corner.Position.HasFlag(CubeFlag.BottomLayer)) || edge.Position.HasFlag(rotationLayer))
                    {
                        SolverMove(CubeFlag.TopLayer, true);
                    }
                    SolverMove(rotationLayer, !direction);
                }

                // detect right and front slice
                CubeFlag rightSlice = CubeFlagService.ToInt(target.X) == CubeFlagService.ToInt(target.Z) ? target.Z : target.X;
                CubeFlag frontSlice = CubeFlagService.FirstNotInvalidFlag(target.Flags, CubeFlag.YFlags | rightSlice);

                while (!corner.Position.HasFlag(target.Flags & ~CubeFlag.BottomLayer))
                {
                    SolverMove(CubeFlag.TopLayer, true);
                }

                PatternFilter filter = new PatternFilter(new Func <Pattern, Pattern, bool>(delegate(Pattern p1, Pattern p2)
                {
                    PatternItem item = new PatternItem(corner.Position, Solvability.GetOrientation(this.Rubik, corner), target.Flags);
                    return(p2.Items.Any(i => i.Equals(item)));
                }), true);

                Algorithm algo = null;
                for (int i = 0; i < 4; i++)
                {
                    F2LPattern pattern = new F2LPattern(Rubik.GetTargetFlags(edge), Rubik.GetTargetFlags(corner), rightSlice, frontSlice);
                    algo = pattern.FindBestMatch(Pattern.FromRubik(Rubik), CubeFlag.None, filter);
                    if (algo != null)
                    {
                        SolverAlgorithm(algo); break;
                    }
                    SolverMove(CubeFlag.TopLayer, true);
                }

                int count = unsolvedPairs.Count;
                unsolvedPairs = GetPairs(this.Rubik).ToList();
                if (unsolvedPairs.Count == count)
                {
                    this.BroadcastOnSolutionError("Complete first two layers", "Wrong algorithm");
                    return;
                }
            }
        }