Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        public static async Task Run([QueueTrigger(Constants.ChunkQueueName, Connection = "ConnectionString2")] string myQueueItem, TraceWriter log)
        {
            log.Info($"ProcessQueueChunk processed: {myQueueItem}");

            string computerName = Environment.GetEnvironmentVariable("ComputerName", EnvironmentVariableTarget.Process);

            log.Info($"Computer name: {computerName}");

            var chunkMetadata = JsonConvert.DeserializeObject <ChunkMetadata>(myQueueItem);
            var config        = chunkMetadata.Config.GetConfig();

            string cs = Environment.GetEnvironmentVariable("ConnectionString", EnvironmentVariableTarget.Process);

            BlobHelper.SetConnectionString(cs);
            var log2 = new MyTraceLister(log);

            var imageFile = chunkMetadata.SessionId + "." + chunkMetadata.ChunkKey + ".png";

            int numParts = (int)((config.ElevationViewMax.Radians - config.ElevationViewMin.Radians) / config.AngularResolution.Radians);

            MyColor[][]          resultImage = null;
            View.ColorHeight[][] view        = null;
            if (chunkMetadata.ChunkKey == 0)
            {
                resultImage = View.ProcessImageBackdrop(config.NumTheta, numParts);
            }
            else
            {
                var chunkView = await View.GetPolarData(config, chunkMetadata.ChunkKey, chunkMetadata.HeightOffset, log2);

                if (chunkView.Count() == 0)
                {
                    log.Error($"ERROR: No pixels from GetPolarData");
                }

                view = new View.ColorHeight[config.NumTheta][];
                for (int i = 0; i < view.Length; i++)
                {
                    view[i] = new View.ColorHeight[numParts];
                }

                foreach (var pixel in chunkView)
                {
                    view[pixel.iTheta][pixel.iViewElev] = pixel.ToColorHeight();
                }

                resultImage = await View.ProcessImage(view, log2);

                if (resultImage.SelectMany(p => p).Count(p => p.R != 0 || p.G != 0 || p.B != 0) == 0)
                {
                    log.Error($"ERROR: Only black pixels in result image");
                }
            }

            Utils.WriteImageFile(resultImage, Path.Combine(Path.GetTempPath(), imageFile), a => a, OutputType.PNG);
            string location = await BlobHelper.WriteStream("share", imageFile, Path.Combine(Path.GetTempPath(), imageFile), log2);

            string maptxt = "";
            ////    id = 0;
            //    if (id == 0)
            //    {
            //        maptxt = View.ProcessImageMapBackdrop(location);
            //    }
            //    else
            //    {
            //        maptxt = View.ProcessImageMap(view3, location);
            //    }

            string cs2 = Environment.GetEnvironmentVariable("ConnectionString2", EnvironmentVariableTarget.Process);

            TableHelper.SetConnectionString(cs2);
            try
            {
                TableHelper.Insert(chunkMetadata.SessionId, chunkMetadata.Order, location, maptxt);
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }

            // return req.CreateResponse(HttpStatusCode.OK, maptxt);
        }