public void SaveFile(string fileName, ChunkProcess cp, Encoding encoding) { using System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName, false, encoding); foreach (var chunk in Chunks) { switch (chunk.State) { case State.Normal: foreach (var line in chunk.Lines) { sw.WriteLine(line); } break; case State.ChunkStart: throw new Exception("chunk is not closed"); case State.ChunkEnd: sw.WriteLine(chunk.StartLine); cp(sw, chunk); sw.WriteLine(chunk.EndLine); break; } } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); DecConfig data = await req.Content.ReadAsAsync <DecConfig>(); Config config = data.GetConfig(); var log2 = new MyTraceLister(log); var chunks = View.GetRelevantChunkKeys(config); float eyeHeight = 5; string cs1 = Environment.GetEnvironmentVariable("ConnectionString", EnvironmentVariableTarget.Process); BlobHelper.SetConnectionString(cs1); float heightOffset = (await View.GetHeightAtPoint(config, chunks.Last(), log2)) + eyeHeight; string cs = Environment.GetEnvironmentVariable("ConnectionString2", EnvironmentVariableTarget.Process); QueueHelper.SetConnectionString(cs); ChunkProcess ret = new ChunkProcess() { SessionId = Guid.NewGuid().ToString(), Count = chunks.Length, }; ChunkMetadata[] chunksToProcess = chunks .Select((p, i) => new ChunkMetadata() { Order = i, SessionId = ret.SessionId, ChunkKey = chunks[i], HeightOffset = heightOffset, Config = data, }) .ToArray(); var json = JsonConvert.SerializeObject(chunksToProcess); QueueHelper.Enqueue(Constants.FanOutQueue, json); return(req.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(ret), "application/json")); }
public void SaveFile(string fileName, ChunkProcess cp) { SaveFile(fileName, cp, Encoding.UTF8); }