public void Process(string fullPath, SegmentOp operation, ODataModel model, string contentType = "application/atom+xml", string accept = "application/atom+xml", Stream inputStream = null) { _body = new StringBuilder(); var segments = SegmentParser.parse(fullPath, String.Empty, model); _response = new ResponseParameters(null, Encoding.UTF8, new StringWriter(_body), 200); var callbacks = new ProcessorCallbacks( (rt, item) => { _accessSingle.Add(new Tuple <ResourceType, object>(rt, item)); return(true); }, (rt, items) => { _accessMany.Add(new Tuple <ResourceType, IEnumerable>(rt, items)); return(true); }, (rt, item) => { _created.Add(new Tuple <ResourceType, object>(rt, item)); return(true); }, (rt, item) => { _updated.Add(new Tuple <ResourceType, object>(rt, item)); return(true); }, (rt, item) => { _removed.Add(new Tuple <ResourceType, object>(rt, item)); return(true); } ); SegmentProcessor.Process(operation, segments, callbacks, new RequestParameters( model, model as IDataServiceMetadataProvider, new DataServiceMetadataProviderWrapper(model), contentType, Encoding.UTF8, inputStream, new Uri("http://localhost/base/"), new [] { accept } ), _response ); }
public void IsSegmentStreamCreationSupportFail() { var processor = new SegmentProcessor(); ResponseBase result = processor.ProcessSegment(resourceDetail, _protocolFailureMock.Object, _segment); Assert.IsTrue(result.Denied); Assert.AreEqual(_segment.CurrentTry, 1); Assert.AreEqual(_segment.StartPosition, 0); }
public void IsStartedPositionMoved() { var processor = new SegmentProcessor(); _segmentCheckPosition.OutputStream = new MemoryStream(); var result = processor.ProcessSegment(resourceDetail, _protocolDownloadSuccessMock.Object, _segmentCheckPosition); Assert.IsFalse(result.Denied); Assert.IsNotNull(_segmentCheckPosition.OutputStream); Assert.AreEqual(_segmentCheckPosition.OutputStream.Position, _testStreamLength); _segmentCheckPosition.OutputStream.Close(); }
public void IsSegmentStreamWritingSupportFail() { var processor = new SegmentProcessor(); _segment.OutputStream = null; _segment = new Segment(); ResponseBase result = processor.ProcessSegment(resourceDetail, _protocolDownloadSuccessMock.Object, _segment); Assert.IsTrue(result.Denied); Assert.AreEqual(_segment.CurrentTry, 1); Assert.AreEqual(_segment.StartPosition, 0); }
public void IsSegmentWritten() { var processor = new SegmentProcessor(); var result = processor.ProcessSegment(resourceDetail, _protocolDownloadSuccessMock.Object, _segment); Assert.IsFalse(result.Denied); Assert.IsNotNull(_segment.OutputStream); Assert.AreEqual(_segment.StartPosition, _segment.EndPosition); string valueWritten; _segment.OutputStream.Position = 0; using (StreamReader reader = new StreamReader(_segment.OutputStream)) { valueWritten = reader.ReadToEnd(); } Assert.AreEqual(valueWritten, "a test string for the stream"); _segment.OutputStream.Close(); }
public void IsFileSplitInferiorToMiSize() { var processor = new SegmentProcessor(); int numberOfSegments = 10; remoteFileInfo.FileSize = 230000; var listSegmentResponse = processor.GetSegments(numberOfSegments, 200000, remoteFileInfo, "FileName"); Assert.IsFalse(listSegmentResponse.Denied); Assert.IsNotNull(listSegmentResponse.ReturnedValue); var listSegment = listSegmentResponse.ReturnedValue; Assert.AreEqual(listSegment.Count, 1); long startPosition = 0; long endPosition = 230000; Assert.AreEqual(listSegment[0].StartPosition, startPosition); Assert.AreEqual(listSegment[0].EndPosition, endPosition); }
public void IsFileSplitToSegments() { var processor = new SegmentProcessor(); int numberOfSegments = 10; remoteFileInfo.FileSize = 2500000; var listSegmentResponse = processor.GetSegments(numberOfSegments, 200000, remoteFileInfo, "FileName"); Assert.IsFalse(listSegmentResponse.Denied); Assert.IsNotNull(listSegmentResponse.ReturnedValue); var listSegment = listSegmentResponse.ReturnedValue; Assert.AreEqual(listSegment.Count, 10); long startPosition = 0; long endPosition = 250000; foreach (Segment t in listSegment) { Assert.AreEqual(t.StartPosition, startPosition); Assert.AreEqual(t.EndPosition, endPosition); startPosition = endPosition; endPosition = endPosition + remoteFileInfo.FileSize / 10; } }
static async Task Main(string[] args) { Console.WriteLine(Environment.CurrentDirectory); if (IsApiTest) { var apiRequest = SetTestData(); try { var publicIpAddress = await NetworkHelper.GetPublicIpAddress(); Console.WriteLine($"Public IP request {publicIpAddress}"); await RestClientService.SendRequest(apiRequest); Console.WriteLine("API request success"); } catch (HttpRequestException ex) { Console.WriteLine($"Could not connect to service on { RestClientService.ServiceUrl }"); Console.WriteLine("Original exception:\n\n" + ex); } catch (ApiException ex) { Console.WriteLine("API request failed"); if (!new System.Net.HttpStatusCode[] { System.Net.HttpStatusCode.NotFound, System.Net.HttpStatusCode.Unauthorized }.Contains(ex.StatusCode)) { // Extract the details of the error var errors = await ex.GetContentAsAsync <Dictionary <string, string> >(); // Combine the errors into a string var message = string.Join("; ", errors.Values); // Throw a normal exception //throw new Exception(message); Console.WriteLine("Message:\n" + message); } Console.WriteLine("Original exception:\n" + ex); } } else { var lines = FileHelper.GetLinesFromFile(FileName); var segmentList = FileProcessor.BuildFileSegments(lines); var MIRSegments = SegmentProcessor.GenerateAllSegments(segmentList); var clipboard = new StringBuilder(); if (SegmentTypeTest.HasValue) { MIRSegments = MIRSegments .Where(_ => _ != null && _.Type == SegmentTypeTest) .ToList(); } foreach (var segment in MIRSegments) { clipboard.AppendLine(segment.ToString()); Console.Write(segment.ToString()); } ClipboardService.SetText(clipboard.ToString()); } Console.ReadLine(); }