Exemple #1
0
 public void TestAdapter()
 {
     var a = new ArrayList { 1, 5, 3, 3, 2, 4, 3 };
     var sortedA = a.Cast<int>().OrderBy(i => i).ToList();
     a.Sort(new ComparisonAdapter<int>(IntComparer));
     CollectionAssert.AreEqual(sortedA, a);
 }
Exemple #2
0
        static void Main(string[] args)
        {
            ArrayList pessoas = new ArrayList();

            pessoas.Add("Agnaldo");
            pessoas.Add("Alexandre");
            pessoas.Add("Vítor");
            pessoas.Add("Sincic");
            pessoas.Add("Laerte");
            pessoas.Add("Thiago");
            pessoas.Add("Roberto");

            //var lista = from p in pessoas
            //            select p;
            //Could not find an implementation of the query pattern for source type 'System.Collections.ArrayList'.  'Select' not found.  Consider explicitly specifying the type of the range variable 'p'.

            var listaCast = from p in pessoas.Cast<String>()
                            select p;

            ObjectDumper.Write(listaCast);

            Console.WriteLine();

            var listaDeclaracaoTipo = from String p in pessoas
                                      select p;

            ObjectDumper.Write(listaDeclaracaoTipo);

            Console.ReadKey();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            List<string> words = new List<string>(); // New string-typed list
            words.Add("melon");
            words.Add("avocado");
            words.AddRange(new[] { "banana", "plum" });
            words.Insert(0, "lemon"); // Insert at start
            words.InsertRange(0, new[] { "peach", "nashi" }); // Insert at start
            words.Remove("melon");
            words.RemoveAt(3); // Remove the 4th element
            words.RemoveRange(0, 2); // Remove first 2 elements
            words.RemoveAll(s => s.StartsWith("n"));// Remove all strings starting in 'n'
            Console.WriteLine(words[0]); // first word
            Console.WriteLine(words[words.Count - 1]); // last word
            foreach (string s in words) Console.WriteLine(s); // all words
            List<string> subset = words.GetRange(1, 2); // 2nd->3rd words
            string[] wordsArray = words.ToArray(); // Creates a new typed array
            string[] existing = new string[1000];// Copy first two elements to the end of an existing array
            words.CopyTo(0, existing, 998, 2);
            List<string> upperCastWords = words.ConvertAll(s => s.ToUpper());
            List<int> lengths = words.ConvertAll(s => s.Length);

            ArrayList al = new ArrayList();
            al.Add("hello");
            string first = (string)al[0];
            string[] strArr = (string[])al.ToArray(typeof(string));
            List<string> list = al.Cast<string>().ToList();
        }
        public override string DoJob()
        {
            StartRun();
            var ppg = new PlayerProjectionGenerator( playerCache: null );
            var gameList = new ArrayList();

             //  do any unplayed games
             Logger.Debug( "   Doing whole season" );
            var s = new NflSeason( TimeKeeper.Season, loadGames: true, loadDivisions: false ); //  long time to load
            foreach ( var game in s.GameList )
                if (! game.Played() )
               gameList.Add( game );

            var nGames = 0;
            foreach ( var game in gameList.Cast<NFLGame>() )
            {
                ppg.Execute( game );
                nGames++;
            }
            //  records will be in the PGMETRIC table

            StopRun();

            var finishedMessage = string.Format( "Generated projections for {0} games", nGames );
            Logger.Info( "  {0}", finishedMessage );
            return finishedMessage;
        }
        static void Main(string[] args)
        {
            var genericList = new List<int>();
            var nonGenericList = new ArrayList();

            for (var i = 0; i < 10000000; i++)
            {
                genericList.Add(1);
                nonGenericList.Add(1);
            }

            var start = DateTime.Now;
            double result = genericList.Sum();
            var end = DateTime.Now;
            var duration = end - start;
            Console.WriteLine("Generic result: {0}\n generic time:{1}", result, duration.Milliseconds);

            result = 0;
            start = DateTime.Now;
            result = nonGenericList.Cast<int>().Sum();
            end = DateTime.Now;
            duration = end - start;
            Console.WriteLine("Generic result: {0}\n nongeneric time:{1}", result, duration.Milliseconds);

            Console.ReadLine();
        }
Exemple #6
0
        private void PrintForm_Load(object sender, EventArgs e)
        { 
            var inif = new INIFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\eXpressPrint\\config.ini");

            if (!string.IsNullOrEmpty(inif.Read("PRINT_OPT", "AUTO")))
            {
                if (inif.Read("PRINT_OPT", "AUTO").Equals("Y"))
                    PrintAndReturn(_PrintImage);
            }


            if (!string.IsNullOrEmpty(inif.Read("PRINT_SET", "COPIES")))
            {
                var arr = new ArrayList();
               
                arr.AddRange(inif.Read("PRINT_SET", "COPIES").Split(','));

                var sortedList = arr.Cast<string>().OrderBy(item => int.Parse(item));

                foreach (var item in sortedList)
                {
                    comboBoxNumOfCopies.Items.Add(item);
                }

                comboBoxNumOfCopies.Items.Insert(0,"--Select--");
                comboBoxNumOfCopies.SelectedIndex = 0;
            }
            
            formState.Maximize(this);
            txtNumberOfCopies.Focus();
        }
        public void LegacyListTest()
        {
            var names = new ArrayList()
            {
                "Peniel",
                "Tafadzwa",
                "Aime",
                "Kuziva",
                "Majd"
            };

            //Fluent API: first cast the arrayList to IEnumerable List<>
            var nameWithJ = names.Cast<string>().Where(p => p.ToLower().Contains("j"));

            Console.WriteLine("Names with J: ");
            foreach (var j in nameWithJ)
            {
                Console.WriteLine($"\t{j}");
            }

            //Query syntax: first cast the ArrayList to IEnumerabli List<>
            var nameWithI = from string i in names
                where i.ToLower().Contains("i")
                select i;

            Console.WriteLine("\nNames with i: ");
            foreach (var i in nameWithI)
            {
                Console.WriteLine($"\t{i}");
            }

            Assert.AreEqual(nameWithI.Count(), 3);
            Assert.AreEqual(nameWithJ.Count(), 1);
        }
        public SyncResponseMasterDataInfo<OutletDTO> GetOutlet(QueryMasterData myQuery)
        {
            var response = new SyncResponseMasterDataInfo<OutletDTO>();
            response.MasterData = new SyncMasterDataInfo<OutletDTO>();
            response.MasterData.EntityName = MasterDataCollective.Outlet.ToString();
            try
            {
                var costCentre = GetSyncCostCentre(myQuery.ApplicationId);
                var query = _context.tblCostCentre.AsQueryable();
                query = query.Where(n => n.CostCentreType == (int)CostCentreType.Outlet
                    && (n.IM_Status == (int)EntityStatus.Active || n.IM_Status == (int)EntityStatus.Inactive || n.IM_Status == (int)EntityStatus.New));

                var deletedQuery = _context.tblCostCentre.AsQueryable();
                deletedQuery = deletedQuery.Where(n => n.CostCentreType == (int)CostCentreType.Outlet
                    && (n.IM_Status == (int)EntityStatus.Deleted));
                if (costCentre != null)
                {
                    switch (costCentre.CostCentreType)
                    {
                        case CostCentreType.Distributor:
                            query = query.Where(n => n.ParentCostCentreId == costCentre.Id
                                && n.IM_DateLastUpdated > myQuery.From);
                            deletedQuery = deletedQuery.Where(n => n.ParentCostCentreId == costCentre.Id
                                && n.IM_DateLastUpdated > myQuery.From);
                            break;
                        case CostCentreType.DistributorSalesman:
                            var routeIds = GetRouteIds(costCentre, myQuery.From);
                            query = query.Where(n => routeIds.Contains(n.RouteId.Value));
                            deletedQuery = deletedQuery.Where(n => routeIds.Contains(n.RouteId.Value));
                            break;
                    }
                }
                query = query.OrderBy(s => s.IM_DateCreated);
                deletedQuery = deletedQuery.OrderBy(s => s.IM_DateCreated);

                if (myQuery.Skip.HasValue && myQuery.Take.HasValue)
                    query = query.Skip(myQuery.Skip.Value).Take(myQuery.Take.Value);

                if (myQuery.Skip.HasValue && myQuery.Skip.Value == 0)
                {
                    response.DeletedItems = deletedQuery.Select(s => s.Id).ToList();
                }

                var list = new ArrayList();
                foreach (var item in query.ToArray())
                {
                    list.Add(Map(item));
                }
                response.MasterData.MasterDataItems = list.Cast<OutletDTO>().ToArray();
               // response.MasterData.MasterDataItems = query.ToList().Select(n => Map(n)).ToArray();
                response.ErrorInfo = "Success";
            }
            catch (Exception ex)
            {
                response.ErrorInfo = ex.Message;
            }
            response.MasterData.LastSyncTimeStamp = DateTime.Now;
            return response;
        }
 public IEnumerable<Socket> Select(ICollection<Socket> handles)
 {
     Console.Write("Waiting for pending connections...");
     var pending = new ArrayList(handles.ToArray());
     Socket.Select(pending, null, null, 10000);
     Console.WriteLine("done");
     return pending.Cast<Socket>();
 }
Exemple #10
0
    public static IEnumerable <string> FolderNames(string xml, char startingLetter)
    {
        IEnumerable <string> temp;
        XmlDocument          xmldooc = new XmlDocument();

        xmldooc.LoadXml(xml);
        XmlNode rootnode = xmldooc.DocumentElement;

        GetNodesAttr(rootnode, startingLetter);
        temp = result.Cast <string>();
        DisplayNodes(rootnode);
        return(temp);
    }
Exemple #11
0
        static void Untyped()
        {
            var list = new System.Collections.ArrayList(Formula1.GetChampions() as System.Collections.ICollection);

            var query = from r in list.Cast <Racer>()
                        where r.Country == "USA"
                        orderby r.Wins descending
                        select r;

            foreach (var racer in query)
            {
                WriteLine($"{racer:A}");
            }
        }
        public SyncResponseMasterDataInfo<ProductPricingDTO> GetPricing(QueryMasterData q)
        {
            var response = new SyncResponseMasterDataInfo<ProductPricingDTO>();
            response.MasterData = new SyncMasterDataInfo<ProductPricingDTO>();;
            response.MasterData.EntityName = MasterDataCollective.Pricing.ToString();
            try
            {
                var query = _context.tblPricing.AsQueryable();
                query = query.Where(n => 
                    n.IM_Status == (int)EntityStatus.Active || n.IM_Status == (int)EntityStatus.Inactive);

                var deletedQuery = _context.tblPricing.AsQueryable();
                deletedQuery = deletedQuery.Where(n =>
                    n.IM_Status == (int)EntityStatus.Deleted);

                var syncostcentre = GetSyncCostCentre(q.ApplicationId);
                if (syncostcentre != null)
                {
                    var pricingTiers = GetApplicablePricingTiers(syncostcentre);

                    query = query.Where(s => s.IM_DateLastUpdated > q.From && pricingTiers.Contains(s.Tier));
                    deletedQuery = deletedQuery.Where(s => s.IM_DateLastUpdated > q.From && pricingTiers.Contains(s.Tier));
                }
                query = query.OrderBy(s => s.IM_DateCreated);
                deletedQuery = deletedQuery.OrderBy(s => s.IM_DateCreated);

                if (q.Skip.HasValue && q.Take.HasValue)
                    query = query.Skip(q.Skip.Value).Take(q.Take.Value);

                if (q.Skip.HasValue && q.Skip.Value == 0)
                {
                    response.DeletedItems = deletedQuery.Select(s => s.id).ToList();
                }

                var list = new ArrayList();
                foreach (var item in query.ToArray())
                {
                    list.Add(Map(item));
                }
                response.MasterData.MasterDataItems = list.Cast<ProductPricingDTO>().ToArray();
                
                response.ErrorInfo = "Success";
            }
            catch (Exception ex)
            {
                response.ErrorInfo = ex.Message;
            }
            response.MasterData.LastSyncTimeStamp = DateTime.Now;
            return response;
        }
Exemple #13
0
        static void Main()
        {
            ArrayList list = new ArrayList { "First", "Second", "Third"};
            var strings = list.Cast<string>();
            foreach (string item in strings)
            {
                Console.WriteLine(item);
            }

            list = new ArrayList { 1, "not an int", 2, 3};
            var ints = list.OfType<int>();
            foreach (int item in ints)
            {
                Console.WriteLine(item);
            }
        }
Exemple #14
0
        public static FileMontageImageExpressionResult JobAttachmentsImageMontage(ArrayList JobAttachments, DiscoDataContext Database)
        {
            if (JobAttachments == null)
                throw new ArgumentNullException("JobAttachments");

            var attachments = JobAttachments.Cast<JobAttachment>().Where(a => a.MimeType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)).ToList();

            if (attachments.Count > 0)
            {
                var attachmentFilepaths = attachments.Select(a => a.RepositoryFilename(Database)).ToList();

                return new FileMontageImageExpressionResult(attachmentFilepaths);
            }
            else
                return null;
        }
Exemple #15
0
        private void AddimaginaryConsumer()
        {
            _consumers.Add(new Consumer(_stock - _requirement));

            foreach (Supplier supplier in _suppliers)
            {
                ArrayList ratesList = new ArrayList();

                foreach (int rate in supplier.GetRates())
                {
                    ratesList.Add(rate);
                }

                ratesList.Add(0);
                supplier.SetRates(ratesList.Cast<int>().ToArray());
            }
        }
Exemple #16
0
        public void GenericsPerformanceGains() //Generics perform so much better than normal collections
        {
            const int iterations = 10000000;

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var list = new ArrayList();

            for (var currentIteration = 0; currentIteration <= iterations; currentIteration++)
            {
                list.Add(currentIteration);
            }

            foreach (var value in list.Cast<int>())  //We need to perform a cast in every member of the list
            {
            }

            stopwatch.Stop();

            var arrayListMilliseconds = stopwatch.ElapsedMilliseconds;

            stopwatch.Reset();
            stopwatch.Start();

            var intList = new List<int>();

            for (var currentIteration = 0; currentIteration <= iterations; currentIteration++)
            {
                intList.Add(currentIteration); //No cast is required
            }

            foreach (var integer in intList)
            {
                var value = integer;
            }

            stopwatch.Stop();

            var listMilliseconds = stopwatch.ElapsedMilliseconds;

            //List<T> will always outperform ArrayList, CLR performs internal optimizations as well
            Assert.IsTrue(arrayListMilliseconds > listMilliseconds);
        }
        public void MultipleIterationsYieldSameResults()
        {
            var accumulator = new ArrayList();

            using (var process = MockRepository.GenerateStub<EtlProcess>())
            {
                process.Stub(x => x.TranslateRows(null)).IgnoreArguments()
                    .WhenCalled(x => x.ReturnValue = x.Arguments[0]);

                process.PipelineExecuter = new SingleThreadedPipelineExecuter();

                process.Register(new GenericEnumerableOperation(new[] {Row.FromObject(new {Prop = "Hello"})}));
                process.Register(new OutputSpyOperation(2, r => accumulator.Add(r["Prop"])));

                process.Execute();
            }

            Assert.Equal(accumulator.Cast<string>().ToArray(), Enumerable.Repeat("Hello", 2).ToArray());
        }
        public void LegacyListTest()
        {
            var names = new ArrayList()
            {
                "Jeremy",
                "Casey",
                "Jimbo",
                "Bill"
            };

            var namesWithJ = names.Cast<string>()
                .Where(s => s.StartsWith("J"));

            var namesWithJ2 = from string s in names
                              where s.StartsWith("J")
                              select s;

            Assert.AreEqual(namesWithJ.Count(), 2);
            Assert.AreEqual(namesWithJ2.Count(), 2);
        }
		public void InitalizeControl(ArrayList visibleServices, string machineName, string searchPattern )
		{

			
			if ( visibleServices != null )
			{
                this.visibleServicesList = visibleServices.Cast<string>().ToList();

			}

            this.MachineName = machineName;
            this.SearchPattern = searchPattern;
       
            
			this.pipeline = new Pipeline( (ISimpleKexplorerGUI) this.serviceGUI );

			this.pipeline.AddJob( this );

			this.pipeline.StartWork();

			this.InitalizeScriptManager();

		}
Exemple #20
0
        private void ClickTomeValidate(object sender, EventArgs e)
        {
            if (_elc == null)
                return;

            var properties = new ArrayList();

            for (var n = 0; n < _elc.Lists[112].elementValues.Length; n++)
            {
                for (var f = 4; f < 14; f++)
                {
                    var attribute = _elc.GetValue(112, n, f);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Tome: " + _elc.GetValue(112, n, 0) + ")");
                }
            }

            if (properties.Count == 0)
                MessageBox.Show("OK, no invalid tome properties found!");
            else
            {
                string message = properties.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

            // ReSharper disable ObjectCreationAsStatement
                new Debug("Invalid Tome Properties", message);
            // ReSharper restore ObjectCreationAsStatement
            }
        }
Exemple #21
0
        private void ClickSkillValidate(object sender, EventArgs e)
        {
            if (_elc == null) return;

            var mobSkills = new ArrayList();

            // check all monster skills (list 38 fields 119, 121, 123, 125, 127, 129)
            for (var n = 0; n < _elc.Lists[38].elementValues.Length; n++)
            {
                for (var f = 119; f < 130; f += 2)
                {
                    var skill = _elc.GetValue(38, n, f);

                    if (Convert.ToInt32(skill) > 846)
                        mobSkills.Add("Invalid Skill: " + skill + " (Monster: " + _elc.GetValue(38, n, 0) + ")");
                }
            }

            if (mobSkills.Count == 0)
                MessageBox.Show("OK, no invalid skills found!");
            else
            {
                var message = mobSkills.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

            // ReSharper disable ObjectCreationAsStatement
                new Debug("Invalid Skills", message);
            // ReSharper restore ObjectCreationAsStatement
            }
        }
Exemple #22
0
        public void Execute()
        {
            var persons = new List<Person>
            {
                new Person {Id = 1, Name = "gsf_zero1"},
                new Person {Id = 2, Name = "gsf_zero2"},
                new Customer {Id = 3, Name = "gsf_zero3", Orders = Enumerable.Empty<Order>()},
                new Customer
                {
                    Id = 4,
                    Name = "gsf_zero4",
                    Orders = new List<Order>
                    {
                        new Order {Id = 1, Quantity = 10},
                        new Order {Id = 2, Quantity = 2}
                    }
                },
                new Person {Id = 5, Name = "gsf_zero5"}
            };

            //
            // Castメソッドを利用することにより、特定の型のみのシーケンスに変換することができる。
            // OfTypeメソッドと違い、Castメソッドは単純にキャスト処理を行う為、キャスト出来ない型が
            // 含まれている場合は例外が発生する。
            // (OfTypeメソッドの場合、除外される。)
            //
            //
            // 尚、Castメソッドは他の変換演算子とは違い、ソースシーケンスのスナップショットを作成しない。
            // つまり、通常のクエリと同じく、Castで取得したシーケンスが列挙される度に評価される。
            // 変換演算子の中で、このような動作を行うのはAsEnumerableとOfTypeとCastである。
            //
            Output.WriteLine("========== Cast<Person>の結果 ==========");
            foreach (var data in persons.Cast<Person>())
            {
                Output.WriteLine(data);
            }

            //////////////////////////////////////////////////////////
            //
            // 以下のpersons.Cast<Customer>()はPersonオブジェクトをCustomerオブジェクトに
            // キャスト出来ない為、例外が発生する。
            //
            Output.WriteLine("========== Cast<Customer>の結果 ==========");
            try
            {
                foreach (var data in persons.Cast<Customer>())
                {
                    Output.WriteLine(data);
                }
            }
            catch (InvalidCastException ex)
            {
                Output.WriteLine(ex.Message);
            }

            /*
              IEnumerable<Person> p = persons.Cast<Person>();
              persons.Add(new Person());

              Output.WriteLine("aaa");
              foreach (var a in p)
              {
                Output.WriteLine(a);
              }
            */

            //
            // 元々GenericではないリストをIEnumerable<T>に変換する場合にも利用出来る.
            // 当然、Castメソッドを利用する場合は、コレクション内部のデータが全てキャスト可能で
            // ないといけない。
            //
            var arrayList = new ArrayList();
            arrayList.Add(10);
            arrayList.Add(20);
            arrayList.Add(30);
            arrayList.Add(40);

            Output.WriteLine("========== Genericではないコレクションを変換 ==========");
            var intList = arrayList.Cast<int>();
            foreach (var data in intList)
            {
                Output.WriteLine(data);
            }
        }
        private static void LinqTests()
        {
            string[]             names         = { "Tom", "Dick", "Harry" };
            IEnumerable <string> filteredNames = System.Linq.Enumerable.Where(names, n => n.Length >= 4);

            foreach (string n in filteredNames)
            {
                Console.Write(n + "|");
            }
            IEnumerable <string> filteredNames2 = names.Where(n => n.Length >= 4);
            // Projecting
            IEnumerable <string> blee = names.Select(n => n.ToUpper());
            var query = names.Select(n => new
            {
                Name   = n,
                Length = n.Length
            });

            // Take and Skip
            int[]             numbers    = { 10, 9, 8, 7, 6 };
            IEnumerable <int> firstThree = numbers.Take(3);      // firstThree is { 10, 9 , 8 }
            IEnumerable <int> lastTwo    = numbers.Skip(3);
            // Element operators
            int firstNumber    = numbers.First();                     // 10
            int lastNumber     = numbers.Last();                      // 6
            int secondNumber   = numbers.ElementAt(2);                // 8
            int firstOddNumber = numbers.First(n => n % 2 == 1);      // 9
            // Aggregation operators
            int    count    = numbers.Count();                        // 5
            int    min      = numbers.Min();                          // 6
            int    max      = numbers.Max();                          // 10
            double avg      = numbers.Average();                      // 8
            int    evenNums = numbers.Count(n => n % 2 == 0);         // 3
            int    maxRemainderAfterDivBy5 = numbers.Max(n => n % 5); // 4
            // Quantitfiers
            bool hasTheNumberNine        = numbers.Contains(9);       // true
            bool hasMoreThanZeroElements = numbers.Any();             // true
            bool hasOddNum = numbers.Any(n => n % 2 == 1);            // true
            bool allOddNum = numbers.All(n => n % 2 == 1);            // false

            // Set operators
            int[]             seq1        = { 1, 2, 3 }, seq2 = { 3, 4, 5 };
            IEnumerable <int> concat      = seq1.Concat(seq2);      // { 1, 2, 3, 3, 4, 5 }
            IEnumerable <int> union       = seq1.Union(seq2);       // { 1, 2, 3, 4, 5 }
            IEnumerable <int> commonality = seq1.Intersect(seq2);   // { 3 }
            IEnumerable <int> difference1 = seq1.Except(seq2);      // { 1, 2 }
            IEnumerable <int> difference2 = seq2.Except(seq1);      // { 4, 5 }
            // Deferred Execution
            var numbers2 = new System.Collections.Generic.List <int> {
                1
            };
            IEnumerable <int> query2 = numbers.Select(n => n * 10);

            numbers2.Add(2);                                        // Sneak in an extra element
            // Deferred / Lazy (evaluation)
            foreach (int n in query2)
            {
                Console.Write(n + "|");
            }
            // Cache/freeze - avoid reexecution
            var numbers3 = new System.Collections.Generic.List <int>()
            {
                1, 2
            };

            System.Collections.Generic.List <int> timesTen = numbers.Select(n => n * 10).ToList(); // Executes immediately into a List<int>
            numbers3.Clear();
            Console.WriteLine(timesTen.Count);                                                     // Still 2
            names.Where(n => n.Length == names.Min(n2 => n2.Length));

            // Chaining Query Operators
            string[]             names3 = { "Tom", "Dick", "Harry", "Mary", "Jay" };
            IEnumerable <string> query3 = names3
                                          .Where(n => n.Contains("a"))
                                          .OrderBy(n => n.Length)
                                          .Select(n => n.ToUpper());

            foreach (string name in query3)
            {
                Console.Write(name + "|");                                              // Result: JAY|MARY|HARRY
            }
            // Query Expressions
            IEnumerable <string> query4 = from n in names3
                                          where n.Contains("a")
                                          orderby n.Length
                                          select n.ToUpper();

            IEnumerable <string> query5 = from n in names3
                                          where n.Length == names3.Min(n2 => n2.Length)
                                          select n;

            // The Let keyword
            IEnumerable <string> query6 = from n in names3
                                          let vowelless = Regex.Replace(n, "[aeiou]", "")
                                                          where vowelless.Length > 2
                                                          orderby vowelless
                                                          select n + " - " + vowelless;
            // Translates to
            IEnumerable <string> query6a = names3
                                           .Select(n => new
            {
                n         = n,
                vowelless = Regex.Replace(n, "[aeiou]", "")
            })
                                           .Where(temp0 => (temp0.vowelless.Length > 2))
                                           .OrderBy(temp0 => temp0.vowelless)
                                           .Select(temp0 => ((temp0.n + " - ") + temp0.vowelless));

            // Query Continuations
            IEnumerable <string> query7 = from c in "The quick brown tiger".Split()
                                          select c.ToUpper() into upper
                                              where upper.StartsWith("T")
                                          select upper;                                 // Result: "THE", "TIGER"

            // Translates to
            IEnumerable <string> query7a = "The quick brown tiger".Split()
                                           .Select(c => c.ToUpper())
                                           .Where(upper => upper.StartsWith("T"));

            // Multiple Generators
            int[]                numbersA = { 1, 2, 3 };
            string[]             lettersA = { "a", "b" };
            IEnumerable <string> query8   = from n in numbersA
                                            from l in lettersA
                                            select n.ToString() + l;

            IEnumerable <string> query8a = numbers.SelectMany(
                n => lettersA,
                (n, l) => (n.ToString() + l));

            string[]             players = { "Tom", "Jay", "Mary" };
            IEnumerable <string> query9  = from name1 in players
                                           from name2 in players
                                           where name1.CompareTo(name2) < 0
                                           orderby name1, name2
            select name1 + " vs " + name2;                                              // Result: { "Jay vs Mary", "Jay vs Tom", "Mary vs Tom" }

            string[]             fullNames = { "Anne Williams", "John Fred Smith", "Sue Green" };
            IEnumerable <string> query10   = from fullName in fullNames
                                             from name in fullName.Split()
                                             select name + " come from " + fullName;

            // Joining
            var customers = new[]
            {
                new { ID = 1, Name = "Tom" },
                new { ID = 2, Name = "Dick" },
                new { ID = 3, Name = "Harry" },
            };
            var purchases = new[]
            {
                new { CustomerID = 1, Product = "House" },
                new { CustomerID = 2, Product = "Boat" },
                new { CustomerID = 3, Product = "Car" },
                new { CustomerID = 4, Product = "Holiday" },
            };
            IEnumerable <string> query11 = from c in customers
                                           join p in purchases on c.ID equals p.CustomerID
                                           select c.Name + " bought a " + p.Product;
            // Translates to
            IEnumerable <string> query11a = customers
                                            .Join(purchases, c => c.ID, p => p.CustomerID, (c, p) => c.Name + " bought a " + p.Product);

            // GroupJoin
            Purchase[] purchases2 = new Purchase[]
            {
                new Purchase(1, "House"),
                new Purchase(2, "Boat"),
                new Purchase(3, "Car"),
                new Purchase(4, "Holiday")
            };

            IEnumerable <IEnumerable <Purchase> > query12 = from c in customers
                                                            join p in purchases2 on c.ID equals p.CustomerID into custPurchases
                                                            select custPurchases;         // custPurchases is a sequence

            foreach (IEnumerable <Purchase> purchaseSequence in query12)
            {
                foreach (Purchase p in purchaseSequence)
                {
                    Console.WriteLine(p.Description);
                }
            }
            var query13 = from c in customers
                          join p in purchases2 on c.ID equals p.CustomerID into custPurchases
                          select new { CustName = c.Name, custPurchases };
            var query14 = from c in customers
                          select new
            {
                CustName      = c.Name,
                custPurchases = purchases2.Where(p => c.ID == p.CustomerID)
            };

            // Zip
            int[]                numbersZip = { 3, 5, 7 };
            string[]             words      = { "three", "five", "seven", "ignored" };
            IEnumerable <string> zip        =
                numbersZip.Zip(words, (n, w) => n + "=" + w);

            // Ordering
            IEnumerable <string> query15 = from n in names
                                           orderby n.Length, n
            select n;
            // Translates to
            IEnumerable <string> query15a = names.OrderBy(n => n.Length).ThenBy(n => n);

            IEnumerable <string> query16 = from n in names
                                           orderby n.Length descending, n
            select n;
            // Translates to
            IEnumerable <string> query16a = names.OrderByDescending(n => n.Length).ThenBy(n => n);

            // Grouping
            var query17 = from name in names
                          group name by name.Length;
            // Translates to
            IEnumerable <IGrouping <int, string> > query17a = names.GroupBy(name => names.Length);

            foreach (IGrouping <int, string> grouping in query17)
            {
                Console.WriteLine("\r\n Length=" + grouping.Key + ":");
                foreach (string name in grouping)
                {
                    Console.WriteLine(" " + name);
                }
            }
            var query18 = from name in names group name.ToUpper() by name.Length;

            // Translates to
            var query18a = names.GroupBy(
                name => name.Length,
                name => name.ToUpper());

            var query19 = from name in names
                          group name.ToUpper() by name.Length into grouping
                          orderby grouping.Key
                          select grouping;

            var query19b = from name in names
                           group name.ToUpper() by name.Length into grouping
                               where grouping.Count() == 2
                           select grouping;

            // OfType and Cast
            var classicList = new System.Collections.ArrayList();

            classicList.AddRange(new int[] { 3, 4, 5 });
            IEnumerable <int> sequence1 = classicList.Cast <int>();
            var aaa = from int x in classicList select x;
            // Translates to
            var bbb = from x in classicList.Cast <int>() select x;
        }
Exemple #24
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    public bool ClearLearnedCommand(object command)
    {
      bool result = false;

      // no point iterating through the hash table if it doesn't contain this ActionType
      if (!_commandsLearned.ContainsValue(command))
      {
        return false;
      }

      // Can't remove items while enumerating a Hashtable so we do it this way...
      var commandsArr = new ArrayList(_commandsLearned);
      commandsArr.Sort(this);

      foreach (var entry in commandsArr.Cast<DictionaryEntry>().Where(entry => (int)entry.Value == (int)command))
      {
        _commandsLearned.Remove(entry.Key);
        result = true;
      }

      if (result)
      {
        SaveInternalValues();
      }

      return result;
    }
Exemple #25
0
        //public void PrivateMessageFormLoad(string chatMessage, string username, string ChannelName)
        //{
        //    var now = DateTime.UtcNow;
        //    ObjectPusherRequest request = new ObjectPusherRequest(
        //       ChannelName,
        //        "message_received",
        //        new
        //        {
        //            message = chatMessage,
        //            user = username,
        //            timestamp = now.ToShortDateString() + " " + now.ToShortTimeString()
        //        });
        //    // var socketID =HttpContext.Request["socket_id"].ToString();
        //    //  Provider.Authenticate("presence-channel",request.SocketId.ToString());
        //    Provider.Trigger(request);
        //}
        public ActionResult _CreatePrivateChatModal(string fromUser, string toUser)
        {
            ArrayList list = new ArrayList { fromUser,toUser};

            IEnumerable<string> sortedArray = list.Cast<string>().OrderBy(str => str);
            ViewBag.ChannelName = "private-"+sortedArray.ToArray()[0] + sortedArray.ToArray()[1] + "pChannel";
            ViewBag.MemberID = toUser;
            ViewBag.Me = fromUser;

            return PartialView();
        }
Exemple #26
0
        private void ClickProbabilityValidate(object sender, EventArgs e)
        {
            if (_elc == null)
                return;

            var probabilities = new ArrayList();
            double attribute;

            // weapons (list 3)
            for (int n = 0; n < _elc.Lists[3].elementValues.Length; n++)
            {
                // weapon drop sockets count(fields 32-34, +=1)

                attribute = 0;

                for (int f = 32; f < 35; f++)
                {
                    attribute += Convert.ToDouble(_elc.GetValue(3, n, f));
                }

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Drop Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Weapon: " + _elc.GetValue(3, n, 0) + ")");

                // weapon craft sockets count(fields 35-37, +=1)

                attribute = 0;

                for (var f = 35; f < 38; f++)
                    attribute += Convert.ToDouble(_elc.GetValue(3, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Craft Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Weapon: " + _elc.GetValue(3, n, 0) + ")");

                // weapon addons count(fields 38-41, +=1)

                attribute = 0;

                for (var f = 38; f < 42; f++)
                    attribute += Convert.ToDouble(_elc.GetValue(3, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Addon Count Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Weapon: " + _elc.GetValue(3, n, 0) + ")");

                // weapon drop (fields 44-106, +=2)

                attribute = 0;

                for (int f = 44; f < 107; f += 2)
                    attribute += Convert.ToDouble(_elc.GetValue(3, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Drop Attriutes Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Weapon: " + _elc.GetValue(3, n, 0) + ")");

                // weapon craft (fields 108-170, +=2)

                attribute = 0;

                for (var f = 108; f < 171; f += 2)
                    attribute += Convert.ToDouble(_elc.GetValue(3, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Craft Attributes Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) + " (Weapon: " +
                                      _elc.GetValue(3, n, 0) + ")");

                // weapons unique (fields 172-202, +=2)

                attribute = 0;

                for (var f = 172; f < 203; f += 2)
                    attribute += Convert.ToDouble(_elc.GetValue(3, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Unique Attributes Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) + " (Weapon: " +
                                      _elc.GetValue(3, n, 0) + ")");
            }

            // armors (list 6)
            for (var n = 0; n < _elc.Lists[6].elementValues.Length; n++)
            {
                // armor drop sockets count(fields 41-45, +=1)

                attribute = 0;

                for (var f = 41; f < 46; f++)
                    attribute += Convert.ToDouble(_elc.GetValue(6, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Drop Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) + " (Armor: " +
                                      _elc.GetValue(6, n, 0) + ")");

                // armor craft sockets count(fields 46-50, +=1)

                attribute = 0;

                for (var f = 46; f < 51; f++)
                    attribute += Convert.ToDouble(_elc.GetValue(6, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Craft Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) + " (Armor: " +
                                      _elc.GetValue(6, n, 0) + ")");

                // armor addons count(fields 51-54, +=1)

                attribute = 0;

                for (var f = 51; f < 55; f++)
                    attribute += Convert.ToDouble(_elc.GetValue(6, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Addon Count Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Armor: " + _elc.GetValue(6, n, 0) + ")");

                // armor drop (fields 56-118, +=2)

                attribute = 0;

                for (var f = 56; f < 119; f += 2)
                    attribute += Convert.ToDouble(_elc.GetValue(6, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Drop Attriutes Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Armor: " + _elc.GetValue(6, n, 0) + ")");

                // armor craft (fields 120-180, +=2)

                attribute = 0;

                for (var f = 120; f < 181; f += 2)
                    attribute += Convert.ToDouble(_elc.GetValue(6, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Craft Attributes Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Armor: " + _elc.GetValue(6, n, 0) + ")");
            }

            // ornaments (list 9)
            for (var n = 0; n < _elc.Lists[9].elementValues.Length; n++)
            {
                // ornament addons count(fields 40-43, +=1)

                attribute = 0;

                for (var f = 40; f < 44; f++)
                    attribute += Convert.ToDouble(_elc.GetValue(9, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Addon Count Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Ornament: " + _elc.GetValue(9, n, 0) + ")");

                // ornament drop (fields 45-107, +=2)

                attribute = 0;

                for (var f = 45; f < 108; f += 2)
                    attribute += Convert.ToDouble(_elc.GetValue(9, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Drop Attriutes Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Ornament: " + _elc.GetValue(9, n, 0) + ")");

                // ornament craft (fields 109-161, +=2)

                attribute = 0;

                for (var f = 109; f < 162; f += 2)
                    attribute += Convert.ToDouble(_elc.GetValue(9, n, f));

            // ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
            // ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Craft Attributes Probability (sum != 1.0): " +
                                      attribute.ToString(CultureInfo.InvariantCulture) +
                                      " (Ornament: " + _elc.GetValue(9, n, 0) + ")");
            }

            if (probabilities.Count == 0)
                MessageBox.Show("OK, no invalid probabilities found!");
            else
            {
                var message = probabilities.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

            // ReSharper disable ObjectCreationAsStatement
                new Debug("Invalid Probabilities", message);
            // ReSharper restore ObjectCreationAsStatement
            }
        }
 public void DeleteAllModules(int moduleId, int tabId, ArrayList fromTabs, bool includeCurrent, bool deleteBaseModule)
 {
     var listTabs = fromTabs.Cast<TabInfo>().ToList();
     DeleteAllModules(moduleId, tabId, listTabs, true, includeCurrent, deleteBaseModule);
 }
Exemple #28
0
        private void ClickPropertyValidate(object sender, EventArgs e)
        {
            if (_elc == null) return;

            var properties = new ArrayList();

            string attribute;

            // weapons (list 3, fields 43-201, +=2)
            for (var n = 0; n < _elc.Lists[3].elementValues.Length; n++)
            {
                for (var f = 43; f < 202; f += 2)
                {
                    attribute = _elc.GetValue(3, n, f);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Weapon: " + _elc.GetValue(3, n, 0) + ")");
                }
            }

            // armors (list 6, fields 55-179, +=2)
            for (var n = 0; n < _elc.Lists[6].elementValues.Length; n++)
            {
                for (var f = 55; f < 180; f += 2)
                {
                    attribute = _elc.GetValue(6, n, f);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Armor: " + _elc.GetValue(6, n, 0) + ")");
                }
            }

            // ornaments (list 9, fields 44-160, +=2)
            for (var n = 0; n < _elc.Lists[9].elementValues.Length; n++)
            {
                for (var f = 44; f < 161; f += 2)
                {
                    attribute = _elc.GetValue(9, n, f);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Ornament: " + _elc.GetValue(9, n, 0) + ")");
                }
            }

            // soulgems (list 35, fields 11-12, +=1)
            for (var n = 0; n < _elc.Lists[35].elementValues.Length; n++)
            {
                for (var f = 11; f < 13; f++)
                {
                    attribute = _elc.GetValue(35, n, f);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Soulgem: " + _elc.GetValue(35, n, 0) + ")");
                }
            }

            // complect boni (list 90, fields 15-19, +=1)
            for (var n = 0; n < _elc.Lists[90].elementValues.Length; n++)
            {
                for (var f = 15; f < 20; f++)
                {
                    attribute = _elc.GetValue(90, n, f);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute +
                            " (Complect Bonus: " + _elc.GetValue(90, n, 0) + ")");
                }
            }

            if (properties.Count == 0)
                MessageBox.Show("OK, no invalid properties found!");
            else
            {
                var message = properties.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

            // ReSharper disable ObjectCreationAsStatement
                new Debug("Invalid Properties", message);
            // ReSharper restore ObjectCreationAsStatement
            }
        }
Exemple #29
0
 public void CollectionGetEnumeratorFor() {
     var testCollection = new ArrayList {"element1", "element2"};
     var testCollectionFacet = new DotNetCollectionFacet(facetHolder);
     INakedObject testAdaptedCollection = testSystem.AdapterFor(testCollection);
     ValidateCollection(testCollectionFacet, testAdaptedCollection, testCollection.Cast<object>());
 }
Exemple #30
0
        public static void TakeListSlice()
        {
            var list = new ArrayList(Enumerable.Range(0, 10).ToList());
            var reversed = list.Cast<object>().Reverse().ToList();

            Assert.AreEqual(list, List.Slice(list));

            Assert.AreEqual(new ArrayList { 0, 1, 2, 3, 4 }, List.Slice(list, end: 5));
            Assert.AreEqual(new ArrayList { 1, 2, 3, 4 }, List.Slice(list, 1, 5));
            Assert.AreEqual(new ArrayList { 0, 2, 4, 6, 8 }, List.Slice(list, step: 2));
            Assert.AreEqual(reversed, List.Slice(list, step: -1));
            Assert.AreEqual(new ArrayList { 0, 1, 2, 3, 4 }, List.Slice(list, -11, -5));
            Assert.AreEqual(reversed, List.Slice(list, -1, -11, -1));
        }
Exemple #31
0
 public void CollectionInitToEmpty() {
     var testCollection = new ArrayList {"element1", "element2"};
     var testCollection1 = new string[] {};
     var testCollectionFacet = new DotNetCollectionFacet(facetHolder);
     INakedObject testAdaptedCollection = testSystem.AdapterFor(testCollection);
     Init(testCollectionFacet, testAdaptedCollection, testCollection.Cast<object>(), testCollection1);
 }
 /// <summary>
 /// 轉型
 /// </summary>
 /// <returns></returns>
 public ActionResult ProcessA()
 {
     string returnValue = "";
     GetEvents getEvents = new GetEvents();
     CalendarEvent[] events = getEvents.CalenderEvent;
     //
     var eventsByDay = from ev in events
                       group ev by ev.StartTime.Date into dayGroup
                       select dayGroup.ToArray();
     //
     ArrayList fruits = new ArrayList();
     fruits.Add("mango");
     fruits.Add("apple");
     fruits.Add("lemon");
     IEnumerable<string> query =
         fruits.Cast<string>().Select(fruit => fruit);
     foreach (string fruit in query)
     {
         if (fruit != "") { returnValue += "<br>"; }
         returnValue += fruit;
     }
     //
     return Content(returnValue);
 }
        public ArrayList searchResults(string search_query)
        {
            bool flag_AND = false;
            bool flag_OR = false;
            bool flag_NOT = false;

            string and_pattern = @"(?<before>\w+) AND (?<after>\w+)";
            string or_pattern = @"(?<before>\w+) OR (?<after>\w+)";
            string not_pattern = @"(?<before>\w+) NOT (?<after>\w+)";

            string and_pattern_after = @"AND (?<after>\w+)";
            string or_pattern_after = @"OR (?<after>\w+)";
            string not_pattern_after = @"NOT (?<after>\w+)";

            string and_pattern_before = @"(?<before>\w+) AND";
            string or_pattern_before = @"(?<before>\w+) OR";
            string not_pattern_before = @"(?<before>\w+) NOT";

            string produced_search_query = search_query;

            ArrayList and_arraylist = new ArrayList();
            ArrayList or_arraylist = new ArrayList();
            ArrayList not_arraylist = new ArrayList();
            ArrayList bracket_arraylist = new ArrayList();

            MatchCollection brackets_pattern = Regex.Matches(produced_search_query, @"\(([^)]*)\)");

            if (brackets_pattern.Count > 0)
            {
                for (int i = 0; i < brackets_pattern.Count; i++)
                {
                    produced_search_query = produced_search_query.Replace(brackets_pattern[i].ToString(), "");

                    MatchCollection and_matches_brackets = Regex.Matches(brackets_pattern[i].Groups[1].ToString(), and_pattern);
                    MatchCollection or_matches_brackets = Regex.Matches(brackets_pattern[i].Groups[1].ToString(), or_pattern);
                    MatchCollection not_matches_brackets = Regex.Matches(brackets_pattern[i].Groups[1].ToString(), not_pattern);

                    for (int y = 0; y < brackets_pattern.Count; y++)
                    {
                        if (and_matches_brackets.Count > 0)
                        {
                            foreach (string index in searchQueryAND(and_matches_brackets[i].ToString().Replace("AND", "")))
                                if (!bracket_arraylist.Contains(index)) bracket_arraylist.Add(index);
                        }

                        if (or_matches_brackets.Count > 0)
                        {
                            foreach (string index in searchQueryOR(or_matches_brackets[i].ToString().Replace("OR", "")))
                                if (!bracket_arraylist.Contains(index)) bracket_arraylist.Add(index);
                        }

                        if (not_matches_brackets.Count > 0)
                        {
                            foreach (string index in searchQueryNOT(not_matches_brackets[i].ToString().Replace("NOT", ""),
                                                          not_matches_brackets))
                                if (!bracket_arraylist.Contains(index)) bracket_arraylist.Add(index);
                        }


                    }
                }
                //MessageBox.Show(produced_search_query);
                MatchCollection and_matches_after = Regex.Matches(produced_search_query, and_pattern_before);
                MatchCollection or_matches_after = Regex.Matches(produced_search_query, or_pattern_before);
                MatchCollection not_matches_after = Regex.Matches(produced_search_query, not_pattern_before);

                if (and_matches_after.Count > 0)
                {
                    ArrayList and_array_after_brackets = new ArrayList();
                    ArrayList intersection = new ArrayList();

                    produced_search_query = produced_search_query.Replace("AND", "");
                    and_array_after_brackets = searchQueryAND(produced_search_query);

                    foreach (string i in and_array_after_brackets.Cast<string>().Intersect(bracket_arraylist.Cast<string>()))
                    {
                        intersection.Add(i);
                    }

                    return intersection;
                }

                if (or_matches_after.Count > 0)
                {
                    ArrayList or_array_after_brackets = new ArrayList();

                    produced_search_query = produced_search_query.Replace("OR", "");
                    or_array_after_brackets = searchQueryOR(produced_search_query);

                    foreach (string index in bracket_arraylist)
                    {
                        if (!or_array_after_brackets.Contains(index)) or_array_after_brackets.Add(index);
                    }

                    return or_array_after_brackets;
                }

                if(not_matches_after.Count > 0)
                {
                    ArrayList not_array_after_brackets = new ArrayList();
                    produced_search_query = produced_search_query.Replace("NOT", "");
                    not_array_after_brackets = searchQueryOR(produced_search_query);

                    foreach (string index in bracket_arraylist)
                    {
                        if (not_array_after_brackets.Contains(index)) not_array_after_brackets.Remove(index);
                    }

                    return not_array_after_brackets;
                }

                return bracket_arraylist;
            }
            else
            {
                MatchCollection and_matches = Regex.Matches(search_query, and_pattern);
                MatchCollection or_matches = Regex.Matches(search_query, or_pattern);
                MatchCollection not_matches = Regex.Matches(search_query, not_pattern);

                if (and_matches.Count > 0)
                {
                    flag_AND = true;
                    produced_search_query = produced_search_query.Replace("AND", "");             
                }

                if (or_matches.Count > 0)
                {
                    flag_OR = true;
                    produced_search_query = produced_search_query.Replace("OR", "");    
                }

                if (not_matches.Count > 0)
                {
                    flag_NOT = true;
                    produced_search_query = produced_search_query.Replace("NOT", ""); 
                }

                if (flag_AND) return searchQueryAND(produced_search_query);

                if (flag_NOT) return searchQueryNOT(produced_search_query, not_matches);

                if (flag_OR) return searchQueryOR(produced_search_query);
            
            }

            return searchQueryAND(produced_search_query);

            //MatchCollection and_matches = Regex.Matches(search_query, and_pattern);
            //MatchCollection or_matches = Regex.Matches(search_query, or_pattern);
            //MatchCollection not_matches = Regex.Matches(search_query, not_pattern);


            //for (int i = 0; i < and_matches.Count; i++)
            //{
            //    MessageBox.Show("And before " + and_matches[i].Groups["before"].ToString());
            //    MessageBox.Show("And after " + and_matches[i].Groups["after"].ToString());
            //}

            //for (int i = 0; i < or_matches.Count; i++)
            //{
            //    MessageBox.Show("or before " + or_matches[i].Groups["before"].ToString());
            //    MessageBox.Show("or after " + or_matches[i].Groups["after"].ToString());
            //}

            //for (int i = 0; i < not_matches.Count; i++)
            //{
            //    MessageBox.Show("not before " + not_matches[i].Groups["before"].ToString());
            //    MessageBox.Show("not after " + not_matches[i].Groups["after"].ToString());
            //}


            //if (and_matches.Count > 0)
            //{
            //    flag_AND = true;
            //    produced_search_query = produced_search_query.Replace("AND", "");             
            //}

            //if (or_matches.Count > 0)
            //{
            //    flag_OR = true;
            //    produced_search_query = produced_search_query.Replace("OR", "");    
            //}

            //if (not_matches.Count > 0)
            //{
            //    flag_NOT = true;
            //    produced_search_query = produced_search_query.Replace("NOT", ""); 
            //}
        }