This class does the actual sorting for SortEntireFile. It is pulled out in this way for testing.
Пример #1
0
		public void EmptyList()
		{
			var output = new List<byte[]>();
			var sorter = new BigDataSorter();
			sorter.WriteResults(val => output.Add(val));
			Assert.That(output, Has.Count.EqualTo(0));
		}
Пример #2
0
        internal static void SortEntireFile(Dictionary <string, Dictionary <string, HashSet <string> > > sortableProperties, XmlWriter writer, string pathname)
        {
            var readerSettings = new XmlReaderSettings {
                IgnoreWhitespace = true
            };

            // Step 2: Sort and rewrite file.
            using (var fastSplitter = new FastXmlElementSplitter(pathname))
            {
                var  sorter = new BigDataSorter();
                bool foundOptionalFirstElement;
                foreach (var record in fastSplitter.GetSecondLevelElementStrings(OptionalFirstElementTag, StartTag, out foundOptionalFirstElement))
                {
                    if (foundOptionalFirstElement)
                    {
                        // Step 2A: Write out custom property declaration(s).
                        WriteElement(writer, SortCustomPropertiesRecord(record));
                        foundOptionalFirstElement = false;
                    }
                    else
                    {
                        // Step 2B: Sort main CmObject record.
                        var sortedMainObject = SortMainElement(sortableProperties, record);
                        sorter.Add(sortedMainObject.Attribute("guid").Value, Utf8.GetBytes(sortedMainObject.ToString()));
                    }
                }
                sorter.WriteResults(val => WriteElement(writer, readerSettings, val));
            }
        }
Пример #3
0
		internal static void SortEntireFile(Dictionary<string, Dictionary<string, HashSet<string>>> sortableProperties, XmlWriter writer, string pathname)
		{
			var readerSettings = new XmlReaderSettings { IgnoreWhitespace = true };

			// Step 2: Sort and rewrite file.
			using (var fastSplitter = new FastXmlElementSplitter(pathname))
			{
				var sorter = new BigDataSorter();
				bool foundOptionalFirstElement;
				foreach (var record in fastSplitter.GetSecondLevelElementStrings(OptionalFirstElementTag, StartTag, out foundOptionalFirstElement))
				{
					if (foundOptionalFirstElement)
					{
						// Step 2A: Write out custom property declaration(s).
						WriteElement(writer, SortCustomPropertiesRecord(record));
						foundOptionalFirstElement = false;
					}
					else
					{
						// Step 2B: Sort main CmObject record.
						var sortedMainObject = SortMainElement(sortableProperties, record);
						sorter.Add(sortedMainObject.Attribute("guid").Value, Utf8.GetBytes(sortedMainObject.ToString()));
					}
				}
				sorter.WriteResults(val => WriteElement(writer, readerSettings, val));
			}
		}
Пример #4
0
		public void TenItems()
		{
			var output = new List<byte[]>();
			var sorter = new BigDataSorter();
			var input = MakeInput(10);
			ShuffleInputs(sorter, input);
			sorter.WriteResults(val => output.Add(val));
			VerifyOutput(output, input);
		}
Пример #5
0
		public void OneItem()
		{
			var output = new List<byte[]>();
			var sorter = new BigDataSorter();
			sorter.Add("a", new byte[] {1});
			sorter.WriteResults(val => output.Add(val));
			Assert.That(output, Has.Count.EqualTo(1));
			VerifyByteArray(output[0], new byte[] {1});
		}
Пример #6
0
		public void MultiFileSort()
		{
			var output = new List<byte[]>();
			var sorter = new BigDataSorter();
			var input = MakeInput(100);
			var totalLength = input.Sum(kvp => kvp.Value.Length);
			sorter.MaxBytes = totalLength / 5; // force it to use about 5 files.
			ShuffleInputs(sorter, input);
			sorter.WriteResults(val => output.Add(val));
			VerifyOutput(output, input);
		}
Пример #7
0
		/// <summary>
		/// Insert the items in the input into the sorter in a mixed-up order.
		/// </summary>
		/// <param name="sorter"></param>
		/// <param name="input"></param>
		private void ShuffleInputs(BigDataSorter sorter, SortedDictionary<string, byte[]> input)
		{
			// Insert all the even items in oder.
			for (int i = 0; i < input.Count/2; i++)
			{
				sorter.Add(input.ElementAt(i * 2).Key, input.ElementAt(i * 2).Value);
			}
			// And all the odd items in reverse order.
			for (int i =  input.Count - 1; i > 0; i--)
			{
				if (i%2 == 1)
					sorter.Add(input.ElementAt(i).Key, input.ElementAt(i).Value);
			}
		}