Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileSearchEngine"/> class.
        /// </summary>
        /// <param name="dir">
        /// The dir represents the starting point for the search started by <see cref="Search"/> method.
        /// </param>
        /// <param name="extension"> </param>
        /// <exception cref="Fbb.Exceptions.General.InvalidArgumentException">
        /// </exception>
        public FileSearchEngine(IDirectoryDefinition dir, string extension)
        {
            if (dir == null)
              {
            throw new InvalidArgumentException("The argument 'dir' can not be null!");
              }

              if (string.IsNullOrEmpty(dir.Path))
              {
            throw new InvalidArgumentException("The argument 'dir.Path' can not be null or empty!");
              }

              if (string.IsNullOrEmpty(extension))
              {
            throw new InvalidArgumentException("The argument 'extension' can not be null or empty!");
              }

              DirCount               = 0;
              FileCount              = 0;
              Dir                    = dir;
              Extension              = extension;
              FileFoundDuringSearch  = new List<string>();
              ExcludeDirs            = new List<IDirectoryDefinition>();
              IncludeSubDirsInSearch = true;
              Log                    = Out.ZoneFactory(Ids.REGION_SEARCH, GetType().Name);
        }
Exemple #2
0
        public ProjectDefinition()
        {
            Directories         = new List<IDirectoryDefinition>();
              ExcludedDirectories = new List<IDirectoryDefinition>();
              InvalidDirectories  = new List<IDirectoryDefinition>();

              Files               = new List<IFileDefinition>();
              ExcludedFiles       = new List<IFileDefinition>();
              InvalidFiles        = new List<IFileDefinition>();

              Categories          = new Dictionary<int, ICategoryDefinition>();
        }
Exemple #3
0
        public override void Initialize()
        {
            Proxies = null;
            SplitMeasurements = new List<Split>();

            SplitMeasurements.Add(new Split { Time = Environment.TickCount, Text = @"... first split before anything else" });

            InitializeLogSystem();

            SplitMeasurements.Add(new Split { Time = Environment.TickCount, Text = @"... log system initialized" });

              Initializer = new ApplicationInitializer();
        }
Exemple #4
0
        public ProjectDefinition()
        {
            UnderConstruction   = true;

            RootDirectory       = new DirectoryDefinition();
              Directories         = new List<IDirectoryDefinition>();
              ExcludedDirectories = new List<IDirectoryDefinition>();
              InvalidDirectories  = new List<IDirectoryDefinition>();

              Files               = new List<IFileDefinition>();
              ExcludedFiles       = new List<IFileDefinition>();
              InvalidFiles        = new List<IFileDefinition>();

              Categories          = new Dictionary<int, ICategoryDefinition>();

            UnderConstruction   = false;
        }
Exemple #5
0
        public static void ColorBorder(string title, string Data, ConsoleColor color)
        {
            title = String.Concat("[ ", title, " ]");

            string UpBorder = "\n ╔════════════════════════════════════════════════════════════════════════════╗  ╠════════════════════════════════════════════════════════════════════════════╣ ";
            string DownBorder = " ╚════════════════════════════════════════════════════════════════════════════╝";
            string SideBorder = " ║                                                                            ║ ";

            string curentborder = String.Concat(SideBorder, SideBorder, SideBorder);

            List<string> DataList = new List<string>();

            for (; Data.Length > 76;)
            {
                curentborder = String.Concat(curentborder, SideBorder);
                DataList.Add(Data.Substring(0, 74));
                Data = Data.Remove(0, 74);
            }
            DataList.Add(Data);

            lock (LockObj)
            {
                Console.Write(string.Concat(UpBorder, curentborder, DownBorder));

                Console.ForegroundColor = ConsoleColor.Green;
                Console.SetCursorPosition(4, Console.CursorTop - DataList.Count - 3);
                Console.Write(title);

                Console.SetCursorPosition(3, Console.CursorTop + 1);

                Console.ForegroundColor = color;
                for (int x = 0; x < DataList.Count; x++)
                {
                    Console.SetCursorPosition(3, Console.CursorTop + 1);
                    Console.Write(DataList[x]);
                }
                Console.ResetColor();
                Console.SetCursorPosition(0, Console.CursorTop + 3);
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("中介者模式:用一个中介对象来封装一系列的对象交互,中介者使各对象不需要显示地相互引用,从而使其耦合松散,从而可以独立地改变他们之间的交互。中介者模式又称为调停者模式,它是一种对象行为型模式。");

            ConcreteMediator mediator = new ConcreteMediator();
            Button bt = new Button();
            List lt = new List();
            TextBox tb = new TextBox();

            bt.setMediator(mediator);
            lt.setMediator(mediator);
            tb.setMediator(mediator);

            mediator.button = bt;
            mediator.list = lt;
            mediator.textBox = tb;

            bt.changed();
            lt.changed();

            Console.ReadKey();
        }
Exemple #7
0
        private List<MatchMappedToExcel> ConvertMatchesToExcelFormat(List<IMatch> matches)
        {
            List<MatchMappedToExcel> list = new List<MatchMappedToExcel>();

            foreach (IMatch m in matches)
            {
                list.Add(new MatchMappedToExcel()
                {
                    BatchId             = m.Batch.Id.ToString(),
                    Timestamp           = m.Batch.TimeStamp,
                    ProjectName         = m.ProjectDefinitionRef.Name,
                    MatchId             = m.Id.ToString(),
                    Language            = m.LanguageDeclarationRef.Name,
                    Severity            = $"{RuleSeverityMapper.Int2RuleSeverity((int)m.Severity)}",
                    Category            = m.CategoryDeclarationRef.Name,
                    CategoryDescription = m.CategoryDeclarationRef.Description,
                    Rule                = m.RuleDeclarationRef.Name,
                    RuleDescription     = m.RuleDeclarationRef.Description,
                    RuleExpression      = m.RuleDeclarationRef.Expression,
                    Filename            = m.Filename,
                    MatchOnLine         = m.LineNumber.ToString(),
                    CodeExtract         = m.CodeExtract
                });
            }
            return list;
        }
Exemple #8
0
 public LinkFile2Language()
 {
     Filenames = new List<string>();
 }
Exemple #9
0
        static void Main(string[] args)
        {
            #region 工厂方法
            double total = 0.0d;
            CashContext cc = new CashContext(new CashNormal());
            total = cc.GetResult(100.04);
            cc = new CashContext(new CashRebate("0.8"));
            total = cc.GetResult(100.04);
            Console.WriteLine(total);
            #endregion

            #region 装饰器方法
            Decorator.Component person = new Decorator.Component("xiaocai");

            Tshirt tshirt = new Tshirt();
            BigTrouser bt = new BigTrouser();

            bt.Decorator(person);
            tshirt.Decorator(bt);
            tshirt.show();

            Console.WriteLine("*****************************");
            #endregion

            #region 代理方法
            SchoolGirl sg = new SchoolGirl();
            sg.Name = "李娇骄";
            Proxy.Proxy daili = new Proxy.Proxy(sg);
            daili.GiveDolls();
            daili.GiveFlowers();
            #endregion

            #region 原型模式
            ConcretePrototype1 p1 = new ConcretePrototype1("123");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned :"+c1.Id);

            Resume a = new Resume("Andy");
            a.setInfo("Man", "24");
            a.setWorkExperience("1998-2005","IBM ");
            Resume b = (Resume)a.Clone();
            b.setWorkExperience("2002-2005", "Dell");
            a.display();
            b.display();
            #endregion

            #region 模板模式
            Console.WriteLine("Student A testPaper:");
            TestPaperA testA = new TestPaperA();
            testA.Test1();
            testA.Test2();
            Console.WriteLine("Student B testPaper:");
            TestPaperB testB = new TestPaperB();
            testB.Test1();
            testB.Test2();
            #endregion

            #region 抽象工厂方法
            User user = new User();

            IFactory factory = new SqlServerFactory();
            IUser iu = factory.CreateUser();
            //IUser riu = (IUser)Assembly.Load("AbstractFactory").CreateInstance("SqlserverUser");
            //反射
            //Assembly.Load("程序集名称").CreateInstance("程序集名称.类名称");
            iu.Insert(user);
            iu.GetUser(1);
            #endregion

            #region Facade 外观模式
            Fund jijin = new Fund();
            jijin.BuyFund();
            jijin.sellFund();
            #endregion

            #region 建造者模式
            Director director = new Director();
            abstractBuilder builder1 = new Builder1();
            abstractBuilder builder2 = new BuilderB();
            director.Construct(builder1);
            Builder.Builder b1 = builder1.getBuilder();
            b1.show();

            director.Construct(builder2);
            Builder.Builder b2 = builder2.getBuilder();
            b2.show();
            #endregion
            #region 观察者模式
            Observer.ConcreteSubject s = new Observer.ConcreteSubject();
            s.Attach(new Observer.ConcreteObserver(s, "x"));
            s.Attach(new Observer.ConcreteObserver(s, "y"));
            s.SubjectState = "ABC";
            s.Notify();
            ///下面是使用委托
            ///委托就是一种引用方法的类型。一旦为委托分配了方法,委托将于该方法具有完全相同的行为。
            ///委托方法的使用可以像其他的方法一样具有参数和返回值。委托可以看作是对函数的抽象,是函数的”类“,委托的实例将代表一个具体的函数
            ///一个委托可以搭载多个方法,所有方法被依次唤起,委托搭载的方法不需要属于同一个类,只需要具有相同的原型和形式,也就是拥有相同的参数列表和返回类型。
            ///在使用带参数的委托时,只需要在声明事件的地方将参数传递给事件。在绑定时将调用的方法绑定给事件。
            Bosscs boss = new Bosscs();
            StockObserver tongshi1 = new StockObserver("tongshi1",boss);
            NBAObserver tongshiNBA = new NBAObserver("tongshiNBA", boss);
            boss.Update += new EventHandler1(tongshi1.CloseStockMarket);
            boss.Update += new EventHandler1(tongshiNBA.CloseStockMarket);
            boss.update2 += new EventHandler2(tongshiNBA.print);
            boss.SubjectState = " I am back ";
            boss.Notify();
            #endregion

            #region 状态模式
            State.Context c = new State.Context(new CreateStateA());
            c.Request();
            c.Request();
            c.Request();
            c.Request();

            #endregion

            #region 备忘录模式
            Originator o = new Originator();
            o.State = "On";
            o.Show();
            Caretaker care = new Caretaker();
            care.Memento = o.CreateMemento();
            o.State = "Off";
            o.Show();

            o.SetMemento(care.Memento);
            o.Show();

            GameRole gameRole = new GameRole();
            gameRole.GetInitState();
            gameRole.StateDisplay();

            RoleStateManager stateManager = new RoleStateManager();
            stateManager.Memento = gameRole.SaveState();

            gameRole.Fight();
            gameRole.StateDisplay();

            gameRole.RecoveryState(stateManager.Memento);
            gameRole.StateDisplay();
            #endregion

            #region 组合模式
            Composite.Composite root = new Composite.Component("root");
            root.Add(new Leaf("Leaf A"));
            root.Add(new Leaf("Leaf B"));

            Composite.Composite comp = new Composite.Component("comp X");
            comp.Add(new Leaf("Leaf XA"));
            comp.Add(new Leaf("Leaf XB"));
            root.Add(comp);

            Composite.Composite comp2 = new Composite.Component("Comp X2");
            comp2.Add(new Leaf("Leaf X2A"));
            comp2.Add(new Leaf("Leaf X2B"));
            comp.Add(comp2);

            root.Add(new Leaf("Leaf C"));
            Leaf leaf = new Leaf("Leaf D");

            root.Add(leaf);
            root.Display(1);
            root.Remove(leaf);
            root.Display(1);
            #endregion

            #region 迭代器模式
            ConCreteAggregate aggregate = new ConCreteAggregate();
            aggregate[0] = "大鸟";
            aggregate[1] = "小菜";
            aggregate[2]="行李";
            aggregate[3] = "老外";
            aggregate[4] = "小偷";
            Iterator.Iterator myIterator = new ConCreteIterator(aggregate);
            object item = myIterator.First();
            while (!myIterator.IsDone())
            {
                Console.WriteLine(myIterator.CurrentItem() + "请买车票");
                myIterator.Next();
            }
            #endregion

            #region 单例模式
             //所有类都有构造方法,不编码则默认生成空的构造方法,若有显示定义的构造方法,默认的构造方法就会失效。只要将构造方法改写为私有的,外部的程序就不能通过new 来初始化它。
            //通过一个共有的方法来返回类的实例。
            Singleton.Singleton s1 = Singleton.Singleton.GetInstance();
            Singleton.Singleton s2 = Singleton.Singleton.GetInstance();

            if (s1 == s2)
            {
                Console.WriteLine("两个对象是相同的实例。");
            }

            #endregion

            #region 命令模式
            Receiver r = new Receiver();
            Command.Command command = new Command.ConcreteCommand(r);
            Invoker invoker = new Invoker();
            invoker.SetCommand(command);
            invoker.ExecuteCommand();
            #endregion

            #region 职责链模式
            Handler h1 = new ConcreteHandler1();
            Handler h2 = new ConcreteHandler2();
            h1.SetSuccessor(h2);
            int[] requests = { 2, 3, 4, 5, 6, 12, 34, 11, 15 };
            foreach (int request in requests)
            {
                h1.HandlerRequest(request);
            }
            #endregion

            #region 中介者模式
            ConcreteMediator mediator = new ConcreteMediator();
            ConcreteColleague1 colleague1 = new ConcreteColleague1(mediator);
            ConcreteColleague2 colleague2 = new ConcreteColleague2(mediator);
            mediator.Colleague1 = colleague1;
            mediator.Colleague2 = colleague2;
            colleague1.Send("吃饭了吗?");
            colleague2.Send("还没有呢");
            #endregion

            #region 享元模式
            int extri = 22;
            FlyweightFactory f = new FlyweightFactory();
            Flyweight.Flyweight fx = f.GetFlyweight("X");
            fx.Operation(--extri);

            Flyweight.Flyweight fy = f.GetFlyweight("Y");
            fy.Operation(--extri);

            Flyweight.Flyweight fz = f.GetFlyweight("Z");
            fz.Operation(--extri);

            #endregion

            #region 解释器模式
            <<<<<<< HEAD
            Interpreter.Context context = new Interpreter.Context();
            IList<Interpreter.AbstractExpression> list = new List<Interpreter.AbstractExpression>();
            list.Add(new Interpreter.TerminalExpression());
            list.Add(new Interpreter.NormalExpression());
            foreach (Interpreter.AbstractExpression exp in list)
                exp.Interpret(context);
            =======
            Interpreter.Context context1 = new Interpreter.Context();
            IList<AbstractExpression> list = new List<AbstractExpression>();
            list.Add(new TerminalExpression());
            list.Add(new NonTerminalExpression());
            foreach (AbstractExpression exp in list)
            {
                exp.Interpreter(context1);
            }
            #endregion

            #region 访问者模式
            ObjectStructure os = new ObjectStructure();
            os.Add(new Man());
            os.Add(new Woman());
            Success v1 = new Success();
            os.Display(v1);
            Failing f1 = new Failing();
            os.Display(f1);

            Amativeness a1 = new Amativeness();
            os.Display(a1);
            >>>>>>> 77e342ef6e96917a8dc01e72e41626dcffd4ba13
            #endregion
            Console.Read();
        }
Exemple #10
0
 /// <summary>
 /// </summary>
 /// <param name="home"></param>
 public WebOutput()
     : base()
 {
     ContainerOfRuleNodes  = new List<XmlNode>();
       ContainerOfMatchNodes = new List<XmlNode>();
 }
 public ControlCenter()
 {
     this.fieldCoodinates = new bool[5, 5];
     InitField();
     planes = new List<AirCraftMachine>();
 }
Exemple #12
0
 public override void Initialize()
 {
     InternalMatches = new List<IMatch>();
 }
Exemple #13
0
        protected override void Dispose(bool disposing)
        {
            // If you need thread safety, use a lock around these
            // operations, as well as in your methods that use the resource.
            if (Disposed)
                return;

            // If disposing equals true, dispose all managed
            // and unmanaged resources.
            if (disposing)
            {
                //// Dispose managed resources.
                //if (Home != null)
                //{
                //  Home.Dispose();
                //}

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.
            }

            // Indicate that the instance has been disposed.
            InternalMatches = null;
            Disposed        = true;
        }
Exemple #14
0
        public List<int> RetrieveLanguageIdsFromRules()
        {
            List<int> list = new List<int>();
              foreach (KeyValuePair<int, ICategoryDefinition> categoryDefinition in Categories)
              {
            if (!categoryDefinition.Value.Enabled)
              continue;

            foreach (KeyValuePair<int, IRuleDefinition> ruleDefinition in categoryDefinition.Value.Rules)
            {
              if (!ruleDefinition.Value.Enabled)
            continue;

              IConfigurationProxy  configProxy = ProxyHome.Instance.RetrieveConfigurationProxy(ConfigKeyKeeper.Instance.AccessKey);
              IRuleDeclaration ruleDeclaration = configProxy.RuleDeclarationFromCategoryIdAndRuleId(categoryDefinition.Value.CategoryDeclarationReferenceId, ruleDefinition.Value.RuleDeclarationReferenceId);

              foreach (KeyValuePair<int, ILanguageDeclaration> pair in ruleDeclaration.Languages)
              {
            ILanguageDeclaration languageReference = pair.Value;
            if (!list.Contains(languageReference.Id))
              list.Add(languageReference.Id);
              }
            }
              }
              return list;
        }
Exemple #15
0
        private void LoadProjectDefinitions(XDocument doc)
        {
            lock (_lockConfigurationFile)
              {
            // Validate input...
            if (doc == null)
              throw new ArgumentNullException("doc");

            List<IProjectDefinition> projectDefinitions = new List<IProjectDefinition>();

            foreach (XElement projDefinition in doc.Descendants(PROJECT_DEFINITION))
            {
              ProjectDefinition projectDefinition = new ProjectDefinition();

              // Load the attributes: "Enabled" and "Name"...
              projectDefinition.Id = int.Parse(projDefinition.Attribute(XName.Get(ID)).Value);
              projectDefinition.Enabled = bool.Parse(projDefinition.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...
              projectDefinition.Name = projDefinition.Attribute(XName.Get(NAME)).Value;

              // Load the directories to "Include" and the directories to "Exclude"...
              XElement includeDirs = projDefinition.Descendants(PROJECT_DIRECTORIES).Descendants(PROJECT_INCLUDE).First();
              XElement excludeDirs = projDefinition.Descendants(PROJECT_DIRECTORIES).Descendants(PROJECT_EXCLUDE).First();
              projectDefinition.Directories.AddRange(LoadDirectoryDefinitions(includeDirs));
              projectDefinition.ExcludedDirectories.AddRange(LoadDirectoryDefinitions(excludeDirs));

              // Load the directories to "Include" and the directories to "Exclude"...
              XElement includeFiles = projDefinition.Descendants(PROJECT_FILES).Descendants(PROJECT_INCLUDE).First();
              XElement excludeFiles = projDefinition.Descendants(PROJECT_FILES).Descendants(PROJECT_EXCLUDE).First();
              projectDefinition.Files.AddRange(LoadFileDefinitions(includeFiles));
              projectDefinition.ExcludedFiles.AddRange(LoadFileDefinitions(excludeFiles));

              // Load the category definitions...
              foreach (XElement category in projDefinition.Descendants(PROJECT_CATEGORY))
              {
            CategoryDefinition categoryDefinition = LoadCategoryDefinition(category);
            categoryDefinition.ParentDefinition = projectDefinition;
            projectDefinition.Categories.Add(categoryDefinition.CategoryDeclarationReferenceId, categoryDefinition);

            // Update 'Category Definition' statistics counters...
            ProxyHome.Instance.RetrieveStatisticsProxy(ConfigKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.TotalCategoryDefinitions);
            if (categoryDefinition.Enabled)
              ProxyHome.Instance.RetrieveStatisticsProxy(ConfigKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.ActiveCategoryDefinitions);
              }

              Manager.Definitions.Projects.Add(projectDefinition.Id, projectDefinition);

              // Update 'Project Definition' statistics counters...
              ProxyHome.Instance.RetrieveStatisticsProxy(ConfigKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.TotalProjectDefinitions);
              if (projectDefinition.Enabled)
            ProxyHome.Instance.RetrieveStatisticsProxy(ConfigKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.ActiveProjectDefinitions);
            }
              }
        }
Exemple #16
0
        private List<FileDefinition> LoadFileDefinitions(XElement includeElement)
        {
            List<FileDefinition> list = new List<FileDefinition>();

              foreach (XElement file in includeElement.Descendants(PROJECT_FILE))
              {
            FileDefinition fileDefinition = new FileDefinition();

            fileDefinition.Enabled = bool.Parse(file.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...
            fileDefinition.Path = file.Attribute(XName.Get(PROJECT_PATH)).Value;

            list.Add(fileDefinition);
              }
              return list;
        }
Exemple #17
0
        private List<DirectoryDefinition> LoadDirectoryDefinitions(XElement includeElement)
        {
            List<DirectoryDefinition> list = new List<DirectoryDefinition>();

              foreach (XElement dir in includeElement.Descendants(PROJECT_DIRECTORY))
              {
            DirectoryDefinition directoryDefinition = new DirectoryDefinition();

            directoryDefinition.Enabled = bool.Parse(dir.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...
            directoryDefinition.Path = dir.Attribute(XName.Get(PROJECT_PATH)).Value;

            list.Add(directoryDefinition);
              }
              return list;
        }
Exemple #18
0
        private List<FileDefinition> LoadFileDefinitions(ProjectDefinition projectDefinition, XElement includeElement)
        {
            List<FileDefinition> list = new List<FileDefinition>();

              foreach (XElement file in includeElement.Descendants(PROJECT_FILE))
              {
            FileDefinition fileDefinition = new FileDefinition();

            fileDefinition.Enabled = bool.Parse(file.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...

                string tmpPath = file.Attribute(XName.Get(PROJECT_PATH)).Value;
                if (string.IsNullOrEmpty(tmpPath))
                {
                    Log.Warning("Empty file defined in project '" + projectDefinition.Name + "'.");
                    continue;
                }

                string path = null;
                if (tmpPath.StartsWith("*"))
                {
                    tmpPath = tmpPath.TrimStart('*');
                    path = string.IsNullOrEmpty(tmpPath) ? projectDefinition.RootDirectory.Path : Path.GetFullPath(projectDefinition.RootDirectory.Path + tmpPath);

                    if (!File.Exists(path))
              {
                  Log.Warning("Unable to find file '" + path + "' in project '" + projectDefinition.Name + "'.");
                  continue;
              }
              }
              fileDefinition.Path = path;
                list.Add(fileDefinition);
              }
              return list;
        }