public void ViaSocketWriter() { var ranges = new RangeCollection(); var fileStream = new FileStream(@"C:\Users\jgauffin\Downloads\AspNetMVC3ToolsUpdateSetup.exe", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); ranges.Parse("bytes=0-50000", (int)fileStream.Length); var stream = new ByteRangeStream(ranges, fileStream); var job = new StreamSocketWriterJob(stream); var buffer = new byte[65535]; var args = Substitute.For<SocketAsyncEventArgs>(); args.UserToken.Returns(buffer); job.Write(args); while (true) { if (job.WriteCompleted(5000)) { job.Dispose(); break; } job.Write(args); } }
public void ViaSocketWriter() { var ranges = new RangeCollection(); var fileStream = new FileStream(@"C:\Users\jgauffin\Downloads\AspNetMVC3ToolsUpdateSetup.exe", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); ranges.Parse("bytes=0-50000", (int)fileStream.Length); var stream = new ByteRangeStream(ranges, fileStream); var job = new StreamSocketWriterJob(stream); var buffer = new byte[65535]; var args = Substitute.For <SocketAsyncEventArgs>(); args.UserToken.Returns(buffer); job.Write(args); while (true) { if (job.WriteCompleted(5000)) { job.Dispose(); break; } job.Write(args); } }
private static void SubmitQueue(int taskPerJobCount, string caseName, RangeCollection nullIndexRangeCollection, ICluster cluster, string id, string password, Queue <ITask> taskQueue) { while (taskQueue.Count != 0) { IJob job = cluster.CreateJob(); string firstPieceIndex = null, lastPieceIndex = null; for (int iTaskPerJob = 0; iTaskPerJob < taskPerJobCount; ++iTaskPerJob) { ITask task = taskQueue.Dequeue(); string taskPieceIndex = task.Name.Split(' ')[1]; if (iTaskPerJob == 0) { firstPieceIndex = taskPieceIndex.ToString(); } lastPieceIndex = taskPieceIndex; job.AddTask(task); job.Runtime = task.Runtime; if (taskQueue.Count == 0) { break; } } string jobName = SpecialFunctions.CreateTabString(caseName, firstPieceIndex + "-" + lastPieceIndex, nullIndexRangeCollection).Replace("\t", " "); //!!!create a nicer way to make a space delimited list job.Name = jobName.Substring(0, Math.Min(jobName.Length, 70)); Console.WriteLine(job.Name); job.IsExclusive = false; cluster.AddJob(job); cluster.SubmitJob(job.Id, id, password, true, 0); } }
public void AddTest2() { RangeCollection c = new RangeCollection(); List <AddressRange> ranges = c.Ranges; c.Add(new AddressRange(0, 100)); c.Add(new AddressRange(101, 200)); Assert.AreEqual(1, ranges.Count, "#1"); Assert.AreEqual(new AddressRange(0, 200), ranges[0], "#1b"); c.Add(new AddressRange(300, 400)); c.Add(new AddressRange(500, 600)); Assert.AreEqual(3, ranges.Count, "#2"); c.Add(new AddressRange(50, 205)); Assert.AreEqual(3, ranges.Count, "#3"); Assert.AreEqual(new AddressRange(0, 205), ranges[0], "#3b"); c.Add(new AddressRange(-100, -1)); Assert.AreEqual(3, ranges.Count, "#4"); Assert.AreEqual(new AddressRange(-100, 205), ranges[0], "#4b"); c.Add(new AddressRange(206, 299)); Assert.AreEqual(2, ranges.Count, "#5"); Assert.AreEqual(new AddressRange(-100, 400), ranges[0], "#5b"); c.Add(new AddressRange(0, 600)); Assert.AreEqual(1, ranges.Count, "#6"); Assert.AreEqual(new AddressRange(-100, 600), ranges[0], "#6b"); }
//public ObservableCollection<ImageItem> Source = new ObservableCollection<ImageItem>(); public async Task Init() { var queryOptions = new QueryOptions(CommonFileQuery.OrderByDate, new string[] { ".jpg", ".png", ".jpeg", ".bmp" }) { FolderDepth = FolderDepth.Deep, IndexerOption = IndexerOption.OnlyUseIndexer, UserSearchFilter = "System.Kind:=System.Kind#Picture" }; queryOptions.SetThumbnailPrefetch(ThumbnailMode.SingleItem, 256, ThumbnailOptions.UseCurrentScale); var _fileQueryResult = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions); var files = await _fileQueryResult.GetFilesAsync(); Debug.WriteLine("Count " + files.Count); var list = new List<ImageItem>(); foreach (var f in files) { list.Add(new ImageItem() { LocalPath = f.Path }); } Source = new RangeCollection(list); Source.Init(); }
public override void RunTasks(RangeCollection tasksToRun, long taskCount) { var allTheWorkQuery = InputFile.ReadEachLine(); var myWorkAndAnIndex = SpecialFunctions.DivideWork(allTheWorkQuery, tasksToRun, taskCount, 1, new RangeCollection()); double myTotal = double.NaN; bool isFirst = true; foreach (var numberAndIndex in myWorkAndAnIndex) { double number = double.Parse(numberAndIndex.Key); Thread.Sleep(SleepMilliseconds); //make the work take longer if (isFirst) { myTotal = number; isFirst = false; } else { myTotal = Operator.Aggregate(myTotal, number); } } if (!isFirst) // make sure we actually did something. { //var myUniqueResultFileName = GetFileTaskFileName(tasksToRun.ToString()); //ResultFile = new FileInfo(myUniqueResultFileName); using (TextWriter writer = File.CreateText(ResultFile.FullName)) { writer.WriteLine(myTotal); } } }
public void IndexerForPositiveBadIndex() { RangeCollection range = new RangeCollection(); range.Add(1); Assert.AreEqual(0, range[1]); }
public void IndexOf() { var range = new RangeCollection { 0, 2, 3, 5, 6, 7, 8, 11, 12, 13 }; Assert.AreEqual(0, range.IndexOf(0)); Assert.AreEqual(1, range.IndexOf(2)); Assert.AreEqual(2, range.IndexOf(3)); Assert.AreEqual(3, range.IndexOf(5)); Assert.AreEqual(4, range.IndexOf(6)); Assert.AreEqual(5, range.IndexOf(7)); Assert.AreEqual(6, range.IndexOf(8)); Assert.AreEqual(7, range.IndexOf(11)); Assert.AreEqual(8, range.IndexOf(12)); Assert.AreEqual(9, range.IndexOf(13)); Assert.AreEqual(-1, range.IndexOf(99)); }
public void IndexesCacheGeneration() { RangeCollection range = new RangeCollection(); int [] index_cache = range.Indexes; Assert.AreSame(index_cache, range.Indexes); range.Add(0); range.Add(5); if (index_cache == range.Indexes) { Assert.Fail("Indexes Cache not regenerated after change"); } index_cache = range.Indexes; range.Remove(0); range.Add(3); if (index_cache == range.Indexes) { Assert.Fail("Indexes Cache not regenerated after change"); } }
public void NegativeIndices() { RangeCollection c = new RangeCollection(); c.Add(-10); c.Add(-5); c.Add(5); c.Add(-8); c.Add(10); c.Add(-9); c.Add(-11); Assert.IsTrue(c.Contains(-10), "#1"); Assert.IsTrue(c.Contains(-5), "#2"); Assert.IsTrue(c.Contains(5), "#3"); Assert.IsTrue(c.Contains(-8), "#4"); Assert.AreEqual(4, c.RangeCount, "#5"); Assert.AreEqual(new RangeCollection.Range(-11, -8), c.Ranges[0], "#6"); Assert.AreEqual(new RangeCollection.Range(-5, -5), c.Ranges[1], "#7"); Assert.AreEqual(new RangeCollection.Range(5, 5), c.Ranges[2], "#8"); Assert.AreEqual(new RangeCollection.Range(10, 10), c.Ranges[3], "#9"); Assert.AreEqual(0, c.FindRangeIndexForValue(-9), "#10"); Assert.IsTrue(c.FindRangeIndexForValue(-7) < 0, "#11"); }
private static void _TestRanges(RangeCollection range, int [] indexes) { foreach (int index in indexes) { range.Add(index); } Assert.AreEqual(indexes.Length, range.Count); Array.Sort(indexes); int i = 0; foreach (int index in range) { Assert.AreEqual(indexes[i++], index); } #pragma warning disable 0618 i = 0; foreach (int index in range.Indexes) { Assert.AreEqual(indexes[i++], index); } for (i = 0; i < range.Indexes.Length; i++) { Assert.AreEqual(indexes[i], range.Indexes[i]); } #pragma warning restore 0618 }
static HlaAssignMain CreateProgramFromArguments(string[] args) { ArgCollection argCollection = ArgCollection.GetInstance(args); if (argCollection.ExtractOptionalFlag("help")) { Console.WriteLine(); Console.WriteLine(UsageMessage); Console.WriteLine(HelpMessage); return(null); } bool bExcel = argCollection.ExtractOptionalFlag("EXCEL"); argCollection.CheckNoMoreOptions(); double?leakProbabilityOrNull = argCollection.ExtractNext <double?>("leakProbabilityOrNull"); double pValue = argCollection.ExtractNext <double>("pValue"); string directoryName = argCollection.ExtractNext <string>("directory"); string caseName = argCollection.ExtractNext <string>("caseName"); string hlaFactoryName = argCollection.ExtractNext <string>("hlaFactory"); RangeCollection pieceIndexRange = argCollection.ExtractNext <RangeCollection>("pieceIndexRange"); int pieceCount = argCollection.ExtractNext <int>("pieceCount"); SpecialFunctions.CheckCondition(0 <= pieceIndexRange.FirstElement && pieceIndexRange.LastElement < pieceCount, "The pieceIndexRange must be a subrange of " + RangeCollection.GetInstance(0, pieceCount - 1).ToString()); RangeCollection nullIndexRange = argCollection.ExtractNext <RangeCollection>("nullIndexRange"); argCollection.CheckThatEmpty(); return(new HlaAssignMain(bExcel, leakProbabilityOrNull, pValue, directoryName, caseName, hlaFactoryName, pieceIndexRange, pieceCount, nullIndexRange)); }
public void MergedRanges () { RangeCollection range = new RangeCollection (); int [] indexes = new int [] { 0, 7, 5, 9, 1, 6, 8, 2, 10, 12 }; _TestRanges (range, indexes); Assert.AreEqual (3, range.RangeCount); int i= 0; foreach (RangeCollection.Range r in range.Ranges) { switch (i++) { case 0: Assert.AreEqual (0, r.Start); Assert.AreEqual (2, r.End); break; case 1: Assert.AreEqual (5, r.Start); Assert.AreEqual (10, r.End); break; case 2: Assert.AreEqual (12, r.Start); Assert.AreEqual (12, r.End); break; default: Assert.Fail ("This should not be reached!"); break; } } }
public static RangeCollection Union(this RangeCollection rangeCollection1, RangeCollection rangeCollection2) { RangeCollection result = new RangeCollection(rangeCollection1); result.AddRangeCollection(rangeCollection2); return(result); }
public void IndexOf() { RangeCollection range = new RangeCollection(); range.Add(0); range.Add(2); range.Add(3); range.Add(5); range.Add(6); range.Add(7); range.Add(8); range.Add(11); range.Add(12); range.Add(13); Assert.AreEqual(0, range.IndexOf(0)); Assert.AreEqual(1, range.IndexOf(2)); Assert.AreEqual(2, range.IndexOf(3)); Assert.AreEqual(3, range.IndexOf(5)); Assert.AreEqual(4, range.IndexOf(6)); Assert.AreEqual(5, range.IndexOf(7)); Assert.AreEqual(6, range.IndexOf(8)); Assert.AreEqual(7, range.IndexOf(11)); Assert.AreEqual(8, range.IndexOf(12)); Assert.AreEqual(9, range.IndexOf(13)); Assert.AreEqual(-1, range.IndexOf(99)); }
public void Tabulate(string directory, string caseName, List <KeyValuePair <int, int> > firstNullAndLastNullList) { List <Dictionary <string, string> > realRowCollectionToSort = new List <Dictionary <string, string> >(); List <double> nullDiffCollectionToBeSorted = new List <double>(); //!!!move VirusCount.PhyloTree.RangeCollection to a more general place RangeCollection rangeCollection = RangeCollection.GetInstance(); int minFirstNull = int.MaxValue; int maxLastNull = int.MinValue; foreach (KeyValuePair <int, int> firstNullAndLastNull in firstNullAndLastNullList) { int firstNull = firstNullAndLastNull.Key; minFirstNull = Math.Min(minFirstNull, firstNull); int lastNull = firstNullAndLastNull.Value; maxLastNull = Math.Max(maxLastNull, lastNull); //!!!string repeated elsewere //!!!what "new" or not? string inputFileName = string.Format(@"{0}\{1}.{2}.{3}-{4}.pValues.new.txt", directory, SelectionName, CaseName, firstNull, lastNull); //!!!const int maxNullSeen = int.MinValue; //foreach (Dictionary<string, string> row in SpecialFunctions.TabFileTable(inputFileName, true)) foreach (Dictionary <string, string> row in SpecialFunctions.TabFileTable(inputFileName, PValueDetails.Header, true)) { int nullIndex = int.Parse(row["NullIndex"]); rangeCollection.TryAdd(nullIndex); if (nullIndex == -1) { realRowCollectionToSort.Add(row); } else { double value = AccessPValueFromRow(row); nullDiffCollectionToBeSorted.Add(value); maxNullSeen = Math.Max(maxNullSeen, nullIndex); } } } SpecialFunctions.CheckCondition(realRowCollectionToSort.Count != 0); SpecialFunctions.CheckCondition(rangeCollection.IsComplete(minFirstNull, maxLastNull)); int nullCount = maxLastNull - Math.Max(0, minFirstNull) + 1; Dictionary <Dictionary <string, string>, double> qValueList = SpecialFunctions.ComputeQValues(ref realRowCollectionToSort, AccessPValueFromRow, ref nullDiffCollectionToBeSorted, nullCount); string outputFile = string.Format(@"{0}\{1}.{2}.{3}.qValues.new.txt", directory, SelectionName, CaseName, nullCount); //!!!const using (StreamWriter outputStream = File.CreateText(outputFile)) { outputStream.WriteLine(SpecialFunctions.CreateTabString(PValueDetails.Header, "qValue")); foreach (Dictionary <string, string> row in realRowCollectionToSort) { double qValue = qValueList[row]; outputStream.WriteLine(SpecialFunctions.CreateTabString(row[""], qValue)); } } }
public RangeCollection Typical_Overlap() { var ret = new RangeCollection(); ret.Add(new RangeInt64(3, 7)); ret.Add(new RangeInt64(5, 10)); return(ret); }
internal ItemContainerGenerator (ItemsControl owner) { Cache = new Queue <DependencyObject> (); ContainerIndexMap = new DoubleKeyedDictionary <DependencyObject, int> (); ContainerItemMap = new Dictionary <DependencyObject, object> (); Owner = owner; RealizedElements = new RangeCollection (); }
public void MultipleNumbers() { var range = new RangeCollection(1, 50); range.AddRangeSpecifier("5,7,9,5"); RangeCollectionTests.AssertContains(new[] { 5, 7, 9 }, range, "range"); }
public void SingleNumber() { var range = new RangeCollection(1, 50); range.AddRangeSpecifier("5"); RangeCollectionTests.AssertContains(new[] { 5 }, range, "range"); }
/// <summary> /// Represents a <see cref="Model"/> that executes the appropriate selection logic requested by different commands. /// </summary> public SelectionModel() : base(NAME) { this.items = new List<object>(0); this.SelectedItems = new SelectedItemsCollection(); this.selectionMode = SelectionMode.Extended; this.ranges = new RangeCollection(); }
internal ItemContainerGenerator(ItemsControl owner) { Cache = new Queue <DependencyObject> (); ContainerIndexMap = new DoubleKeyedDictionary <DependencyObject, int> (); ContainerItemMap = new Dictionary <DependencyObject, object> (); Owner = owner; RealizedElements = new RangeCollection(); }
public void AddSimple() { var coll = new RangeCollection(); Assert.AreEqual(new Range[0], coll); coll.Add(0..1); coll.Add(6..9); Assert.AreEqual(new[] { 0..1, 6..9 }, coll);
public RangeCollection Typical_Sparse() { var ret = new RangeCollection(); ret.Add(new RangeInt64(-13, -7)); ret.Add(new RangeInt64(-3, 3)); ret.Add(new RangeInt64(7, 13)); return(ret); }
public void Range() { var range = new RangeCollection(1, 50); range.AddRangeSpecifier("10-20"); RangeCollectionTests.AssertContains( new[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }, range, "range"); }
public void RangeWithStep() { var range = new RangeCollection(1, 50); range.AddRangeSpecifier("10-20/3"); RangeCollectionTests.AssertContains( new[] { 10, 13, 16, 19 }, range, "range"); }
public void All() { var range = new RangeCollection(1, 10); range.AddRangeSpecifier("*"); RangeCollectionTests.AssertContains( new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, range, "range"); }
private static RangeCollection _SetupTestRemoveMerges() { RangeCollection range = new RangeCollection(); int [] indexes = new int [] { 0, 2, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19 }; foreach (int index in indexes) { range.Add(index); } int i = 0; foreach (RangeCollection.Range r in range.Ranges) { switch (i++) { case 0: Assert.AreEqual(0, r.Start); Assert.AreEqual(0, r.End); break; case 1: Assert.AreEqual(2, r.Start); Assert.AreEqual(5, r.End); break; case 2: Assert.AreEqual(7, r.Start); Assert.AreEqual(11, r.End); break; case 3: Assert.AreEqual(14, r.Start); Assert.AreEqual(15, r.End); break; case 4: Assert.AreEqual(17, r.Start); Assert.AreEqual(19, r.End); break; default: Assert.Fail("Should never reach here"); break; } } return(range); }
private void AddCommentsFromXml() { var lst = new List<IRangeID>(); foreach (XmlElement node in CommentXml.SelectNodes("//d:commentList/d:comment", NameSpaceManager)) { var comment = new ExcelComment(NameSpaceManager, node, new ExcelRangeBase(Worksheet, node.GetAttribute("ref"))); lst.Add(comment); } _comments = new RangeCollection(lst); }
public void ContainsTest() { var c = new RangeCollection(); c.Add(new AddressRange(1, 100)); c.Add(new AddressRange(-10, -1)); for (var i = -15; i < 120; i++) { var shouldContain = (i >= -10 && i <= -1) || (i >= 1 && i <= 100); Assert.Equal(shouldContain, c.Contains(new AddressRange(i, i))); } }
public void Run(RangeCollection pieceIndexRange, int pieceCount, RangeCollection nullIndexRange, TextWriter writer) { writer.WriteLine(PValueDetails.Header); foreach (int nullIndex in nullIndexRange.Elements) { Dictionary <string, Set <Hla> > pidToHlaSet = PidToHlaSetForThisNullIndex(nullIndex); CreatePeptideToHlaToPValueDetails(pieceIndexRange, pieceCount, nullIndex, pidToHlaSet, writer); } }
public void ExplicitInterface() { ICollection <int> range = new RangeCollection { 1, 2, 5, 6 }; Assert.AreEqual(4, range.Count); }
private void AddRange(RangeCollection collection, string specifier, string name) { try { collection.AddRangeSpecifier(specifier); } catch (Exception ex) { throw new ArgumentException("Unable to process " + name + " specifier: " + ex.Message, ex); } }
public void ExplicitInterface() { ICollection <int> range = new RangeCollection(); range.Add(1); range.Add(2); range.Add(5); range.Add(6); Assert.AreEqual(4, range.Count); }
public void Add(RangeCollection rowCollection) { lock (_lockObj) { _rangePendingCheckin.AddRangeCollection(rowCollection); if (_rangePendingCheckin.Count() >= _bufferSize) { NonBlockingFlush(); } } }
public void ContainsTest() { RangeCollection c = new RangeCollection(); c.Add(new AddressRange(1, 100)); c.Add(new AddressRange(-10, -1)); for (int i = -15; i < 120; i++) { bool shouldContain = (i >= -10 && i <= -1) || (i >= 1 && i <= 100); Assert.AreEqual(shouldContain, c.Contains(new AddressRange(i, i)), "#1." + i); } }
public void ValidateDivideWork() { RangeCollection rangeColl = new RangeCollection(1, 500); long[] arr1 = rangeColl.ToArray(); long pieceCount = 2; long batchCount = 2; RangeCollection skipListOrNull = new RangeCollection(1, 3); IEnumerable <KeyValuePair <long, long> > keyValuePair = SpecialFunctions.DivideWork <long>(arr1, rangeColl, pieceCount, batchCount, skipListOrNull); Assert.AreEqual(248, keyValuePair.Count()); }
internal void SetUp(Matrix <TRowKey, TColKey, TValue> parentMatrix, IEnumerable <int> colIndexSequence) { ParentMatrix = parentMatrix; //Check that not missing any column indexes or have extra IndexOfParentCol = colIndexSequence.ToList(); Helper.CheckCondition(IndexOfParentCol.Count == ParentMatrix.ColCount, "Every column must be mentioned in the permutation."); RangeCollection rangeCollection = new RangeCollection(colIndexSequence); Helper.CheckCondition(rangeCollection.IsComplete(0, ParentMatrix.ColCount - 1), "Every column must be mentioned exactly once"); }
/// <summary> /// Initializes a new instance of the <see cref="ByteRangeStream" /> class. /// </summary> /// <param name="ranges">The HTTP range header contents.</param> /// <param name="innerStream">The inner stream which we should transfer a range from. The stream is owned by this class.</param> public ByteRangeStream(RangeCollection ranges, Stream innerStream) { if (innerStream == null) throw new ArgumentNullException("innerStream"); if (innerStream.Position != 0) throw new ArgumentException("The stream must be at position 0 for this range class to work", "innerStream"); if (!innerStream.CanSeek) throw new ArgumentException("Stream must be seekable.", "innerStream"); if (!innerStream.CanRead) throw new ArgumentException("Stream must be readablle", "innerStream"); _ranges = ranges; _innerStream = innerStream; }
internal void SetUp(Matrix <TRowKey, TColKey, TValue> parentMatrix, IEnumerable <int> colIndexSequence) { ParentMatrix = parentMatrix; //Check that there are not any missing or extra column indexes IndexOfParentCol = colIndexSequence.ToList(); Helper.CheckCondition(IndexOfParentCol.Count == ParentMatrix.ColCount, Properties.Resource.ExpectedEveryColumnToBeAMemberOfThePermutation); RangeCollection rangeCollection = new RangeCollection(colIndexSequence); Helper.CheckCondition(rangeCollection.IsComplete(0, ParentMatrix.ColCount - 1), Properties.Resource.ExpectedEveryColumnToBeUsedOnceInThePermuation); }
public void Refresh() { int index = current_track == null ? Count : TrackModel.IndexOf(current_track); // If the current track is not playing refresh it too. if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying(current_track)) { index--; } if (index + 1 < Count) { // Get the ViewOrder of the current_track long current_view_order = CurrentTrackViewOrder; // Get the list of generated tracks. var generated = new HashSet <long> (); foreach (long trackID in ServiceManager.DbConnection.QueryEnumerable <long> (@" SELECT TrackID FROM CorePlaylistEntries WHERE PlaylistID = ? AND Generated = 1 AND ViewOrder >= ?", DbId, current_view_order)) { generated.Add(trackID); } // Collect the indices of all generated tracks. var ranges = new RangeCollection(); for (int i = index + 1; i < Count; i++) { if (generated.Contains(((DatabaseTrackInfo)TrackModel[i]).TrackId)) { ranges.Add(i); } } bool removed = false; foreach (var range in ranges.Ranges) { RemoveTrackRange(DatabaseTrackModel, range); removed = true; } if (removed) { OnTracksRemoved(); } } else if (Count == 0 || current_track == null) { UpdatePlayQueue(); } }
public RangeCollection GetTypicalRangeCollection() { var rangeColl = new RangeCollection(); rangeColl.Add( new RangeInt64( 4, 12)); rangeColl.Add( new RangeInt64( 50, 60)); return(rangeColl); }
public void ReadOneRangePartially() { var stream = CreateTextStream(); var ranges = new RangeCollection(); ranges.Parse("bytes=0-99", (int)stream.Length); byte[] target = new byte[100]; var stream2 = new ByteRangeStream(ranges, stream); stream2.Read(target, 0, 50); stream2.Read(target, 50, 50); Assert.Equal(GetString().Substring(0,100), Encoding.ASCII.GetString(target, 0, 100)); }
private TraditionalJob(Action jobDelegate) { if (jobDelegate == null) throw new ArgumentNullException("jobDelegate"); this.jobDelegate = jobDelegate; MinuteRange = new RangeCollection(0, 59); HourRange = new RangeCollection(0, 23); DateRange = new RangeCollection(1, 31); MonthRange = new RangeCollection(1, 12); DayOfWeekRange = new RangeCollection(0, 6); }
internal ExcelVmlDrawingCommentCollection(ExcelPackage pck, ExcelWorksheet ws, Uri uri) : base(pck, ws,uri) { if (uri == null) { VmlDrawingXml.LoadXml(CreateVmlDrawings()); _drawings = new RangeCollection(new List<IRangeID>()); } else { AddDrawingsFromXml(ws); } }
public void LargeSequentialContains () { RangeCollection range = new RangeCollection (); int i, n = 1000000; for (i = 0; i < n; i++) { range.Add (i); } for (i = 0; i < n; i++) { Assert.AreEqual (true, range.Contains (i)); } }
internal ExcelVmlDrawingCommentCollection(ExcelPackage pck, ExcelWorksheet ws, Uri uri) : base(pck, ws, uri) { if (uri == null) { VmlDrawingXml.LoadXml(CreateVmlDrawings()); _drawings = new RangeCollection(new List <IRangeID>()); } else { AddDrawingsFromXml(ws); } }
public static void AddRangeSpecifier(this RangeCollection self, string specifier) { if (self == null) throw new ArgumentNullException("self"); if (specifier == null) throw new ArgumentNullException("specifier"); string[] list = specifier.Split(','); RangeCollection staging = new RangeCollection(self.Minimum, self.Maximum); foreach (string i in list) { Match match = rangeRegex.Match(i); if (!match.Success) ThrowBadRangeSpecifier(specifier); if (match.Groups["single"].Success) { staging.Add(int.Parse(match.Groups["single"].Value)); } else { int start = self.Minimum; int end = self.Maximum; int step = 1; if (match.Groups["step"].Success) step = int.Parse(match.Groups["step"].Value); if (match.Groups["start"].Success) { start = int.Parse(match.Groups["start"].Value); end = int.Parse(match.Groups["end"].Value); } if (end < start) ThrowBadRangeSpecifier(specifier); for (int j = start; j <= end; j += step) staging.Add(j); } } foreach (int i in staging) self.Add(i); }
/// <summary> /// Run Tasks. /// </summary> /// <param name="tasksToRun">Tasks to Run.</param> /// <param name="taskCount">Task Count.</param> public override void RunTasks(RangeCollection tasksToRun, long taskCount) { #if !SILVERLIGHT using (Process proc = new Process()) { proc.StartInfo.FileName = ExeName; proc.StartInfo.Arguments = CommandArgs; proc.StartInfo.UseShellExecute = false; proc.Start(); proc.WaitForExit(); if (proc.ExitCode > 0) throw new Exception("Unable to execute " + ExeName + " " + CommandArgs); } #endif }
public void ValidateRunTasks() { CommandApp commandApp = new CommandApp(); RangeCollection rangeColl = new RangeCollection(1, 500); try { commandApp.RunTasks(rangeColl, 10); ApplicationLog.WriteLine("CommandApp BVT: CommandApp RunTasks Validated successfully"); } catch (Exception ex) { ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "CommandApp BVT: CommandApp RunTasks Validated successfully: {0}", ex.Message)); Assert.Fail("CommandApp BVT: CommandApp RunTasks Not validated successfully"); } }
public void AddTest3() { RangeCollection c = new RangeCollection(); List<AddressRange> ranges = c.Ranges; c.Add(new AddressRange(0, 100)); c.Add(new AddressRange(200, 300)); c.Add(new AddressRange(150, 600)); Assert.AreEqual(2, ranges.Count, "#1"); Assert.AreEqual(new AddressRange(0, 100), ranges[0], "#1b"); Assert.AreEqual(new AddressRange(150, 600), ranges[1], "#1c"); c.Add(new AddressRange(102, 500)); Assert.AreEqual(2, ranges.Count, "#2"); Assert.AreEqual(new AddressRange(102, 600), ranges[1], "#2b"); c.Add(new AddressRange(400, 700)); Assert.AreEqual(2, ranges.Count, "#3"); Assert.AreEqual(new AddressRange(102, 700), ranges[1], "#3b"); }
public void AddTest3() { var c = new RangeCollection(); var ranges = c.Ranges; c.Add(new AddressRange(0, 100)); c.Add(new AddressRange(200, 300)); c.Add(new AddressRange(150, 600)); Assert.Equal(2, ranges.Count); Assert.Equal(new AddressRange(0, 100), ranges[0]); Assert.Equal(new AddressRange(150, 600), ranges[1]); c.Add(new AddressRange(102, 500)); Assert.Equal(2, ranges.Count); Assert.Equal(new AddressRange(102, 600), ranges[1]); c.Add(new AddressRange(400, 700)); Assert.Equal(2, ranges.Count); Assert.Equal(new AddressRange(102, 700), ranges[1]); }
/// <summary> /// Runs the tasks /// </summary> /// <param name="tasksToRun">number of tasks to be ran in a range collection</param> /// <param name="taskCount">task count</param> public override void RunTasks(RangeCollection tasksToRun, long taskCount) { ISequenceParser parser = SequenceParsers.FindParserByFileName(InputFile.FullName); var allTheWorkQuery = parser.Parse(InputFile.FullName); var myWorkAndAnIndex = SpecialFunctions.DivideWork(allTheWorkQuery, tasksToRun, taskCount, 1, new RangeCollection()); var myUniqueResultFileName = GetFileTaskFileName(tasksToRun.ToString()); float gcCount = 0; long seqLength = 0; using (TextWriter writer = File.CreateText(myUniqueResultFileName)) { // loop all sequences in current task foreach (var numberAndIndex in myWorkAndAnIndex) { writer.WriteLine(">" + numberAndIndex.Key.ID); foreach (byte val in numberAndIndex.Key) { seqLength++; switch (val) { case (byte)'G': case (byte)'g': case (byte)'C': case (byte)'c': gcCount++; break; } } if (gcCount > 0) writer.Write(((gcCount / (float)seqLength) * 100) + "%"); else writer.Write(gcCount + "%"); seqLength = 0; gcCount = 0; writer.WriteLine(); } } }
private void HandleRangeRequest(IRequest request) { var rangeHeader = request.Headers["Range"]; var response = request.CreateResponse(HttpStatusCode.PartialContent, "Welcome"); response.ContentType = "application/octet-stream"; response.AddHeader("Accept-Ranges", "bytes"); response.AddHeader("Content-Disposition", @"attachment;filename=""ReallyBigFile.Txt"""); //var fileStream = new FileStream(Environment.CurrentDirectory + @"\Ranges\ReallyBigFile.Txt", FileMode.Open, // FileAccess.Read, FileShare.ReadWrite); var fileStream = new FileStream(@"C:\Users\jgauffin\Downloads\AspNetMVC3ToolsUpdateSetup.exe", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var ranges = new RangeCollection(); ranges.Parse(rangeHeader.Value, (int)fileStream.Length); response.AddHeader("Content-Range", ranges.ToHtmlHeaderValue((int)fileStream.Length)); response.Body = new ByteRangeStream(ranges, fileStream); Send(response); }
public void AddTest() { RangeCollection c = new RangeCollection(); c.Add(new AddressRange(50, 50)); c.Add(new AddressRange(50, 50)); Assert.AreEqual(1, c.Ranges.Count, "#1"); c.Add(new AddressRange(50, 51)); Assert.AreEqual(1, c.Ranges.Count, "#2"); c.Add(new AddressRange(51, 51)); Assert.AreEqual(new AddressRange(50, 51), c.Ranges[0], "#2b"); c.Add(new AddressRange(50, 50)); c.Add(new AddressRange(49, 50)); Assert.AreEqual(1, c.Ranges.Count, "#3"); Assert.AreEqual(new AddressRange(49, 51), c.Ranges[0], "#3b"); c.Add(new AddressRange(45, 47)); Assert.AreEqual(2, c.Ranges.Count, "#4"); Assert.AreEqual(new AddressRange(49, 51), c.Ranges[1], "#4b"); c.Add(new AddressRange(47, 49)); Assert.AreEqual(1, c.Ranges.Count, "#5"); Assert.AreEqual(new AddressRange(45, 51), c.Ranges[0], "#4b"); }
public void AddTest() { var c = new RangeCollection(); c.Add(new AddressRange(50, 50)); c.Add(new AddressRange(50, 50)); Assert.Equal(1, c.Ranges.Count); c.Add(new AddressRange(50, 51)); Assert.Equal(1, c.Ranges.Count); c.Add(new AddressRange(51, 51)); Assert.Equal(new AddressRange(50, 51), c.Ranges[0]); c.Add(new AddressRange(50, 50)); c.Add(new AddressRange(49, 50)); Assert.Equal(1, c.Ranges.Count); Assert.Equal(new AddressRange(49, 51), c.Ranges[0]); c.Add(new AddressRange(45, 47)); Assert.Equal(2, c.Ranges.Count); Assert.Equal(new AddressRange(49, 51), c.Ranges[1]); c.Add(new AddressRange(47, 49)); Assert.Equal(1, c.Ranges.Count); Assert.Equal(new AddressRange(45, 51), c.Ranges[0]); }
protected void AddDrawingsFromXml(ExcelWorksheet ws) { var nodes = VmlDrawingXml.SelectNodes("//v:shape", NameSpaceManager); var list = new List<IRangeID>(); foreach (XmlNode node in nodes) { var rowNode = node.SelectSingleNode("x:ClientData/x:Row", NameSpaceManager); var colNode = node.SelectSingleNode("x:ClientData/x:Column", NameSpaceManager); if (rowNode != null && colNode != null) { var row = int.Parse(rowNode.InnerText) + 1; var col = int.Parse(colNode.InnerText) + 1; list.Add(new ExcelVmlDrawingComment(node, ws.Cells[row, col], NameSpaceManager)); } else { list.Add(new ExcelVmlDrawingComment(node, ws.Cells[1, 1], NameSpaceManager)); } } list.Sort(new Comparison<IRangeID>((r1, r2) => (r1.RangeID < r2.RangeID ? -1 : r1.RangeID > r2.RangeID ? 1 : 0))); //Vml drawings are not sorted. Sort to avoid missmatches. _drawings = new RangeCollection(list); }
public void TestRemovingRanges() { RangeCollection ranges = new RangeCollection(); ranges.AddRange(0, 4); ranges.RemoveRange(1, 2); Assert.AreEqual(2, ranges.Count); Assert.AreEqual(new Range(0, 0), ranges[0]); Assert.AreEqual(new Range(3, 4), ranges[1]); ranges.Clear(); ranges.AddRange(0, 4); ranges.RemoveRange(0, 1); Assert.AreEqual(1, ranges.Count); Assert.AreEqual(new Range(2, 4), ranges[0]); ranges.Clear(); ranges.AddRange(0, 4); ranges.RemoveRange(4, 4); Assert.AreEqual(1, ranges.Count); Assert.AreEqual(new Range(0, 3), ranges[0]); }
public void AddTest2() { RangeCollection c = new RangeCollection(); List<AddressRange> ranges = c.Ranges; c.Add(new AddressRange(0, 100)); c.Add(new AddressRange(101, 200)); Assert.AreEqual(1, ranges.Count, "#1"); Assert.AreEqual(new AddressRange(0, 200), ranges[0], "#1b"); c.Add(new AddressRange(300, 400)); c.Add(new AddressRange(500, 600)); Assert.AreEqual(3, ranges.Count, "#2"); c.Add(new AddressRange(50, 205)); Assert.AreEqual(3, ranges.Count, "#3"); Assert.AreEqual(new AddressRange(0, 205), ranges[0], "#3b"); c.Add(new AddressRange(-100, -1)); Assert.AreEqual(3, ranges.Count, "#4"); Assert.AreEqual(new AddressRange(-100, 205), ranges[0], "#4b"); c.Add(new AddressRange(206, 299)); Assert.AreEqual(2, ranges.Count, "#5"); Assert.AreEqual(new AddressRange(-100, 400), ranges[0], "#5b"); c.Add(new AddressRange(0, 600)); Assert.AreEqual(1, ranges.Count, "#6"); Assert.AreEqual(new AddressRange(-100, 600), ranges[0], "#6b"); }