public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Function, "get",
                         Route = "ProcessTabularModel/{databaseName}")] HttpRequestMessage req,
            string databaseName,
            TraceWriter log)
        {
            log.Info("Received request to process the model " + databaseName);
            try
            {
                SqlServerAnalysisServerTabular tabularModel = new SqlServerAnalysisServerTabular()
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings["SsasTabularConnection"].ConnectionString,
                    DatabaseName     = databaseName ?? ConfigurationManager.AppSettings["DatabaseName"]
                };

                tabularModel.ProcessModelFull();
            }
            catch (Exception e)
            {
                log.Error($"Error processing database - {databaseName}: {e.ToString()}", e);
                return(req.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }

            var successMessage = $"Successfully processed database - {databaseName}";

            log.Info(successMessage);
            return(req.CreateResponse(HttpStatusCode.OK, new { result = successMessage }));
        }
        public static void Run([QueueTrigger("%ProcessModelQueue%", Connection = "AzureWebJobsStorage")] string myQueueItem,
                               [Table("%ProcessModelStatusTable%", Connection = "AzureWebJobsStorage")] CloudTable statusTable,
                               TraceWriter log)
        {
            log.Info($"Received queue trigger to process database : {myQueueItem}");

            QueueMessageProcesssTabular queueMessage = null;

            try
            {
                queueMessage = JsonConvert.DeserializeObject <QueueMessageProcesssTabular>(myQueueItem);

                SqlServerAnalysisServerTabular tabularModel = new SqlServerAnalysisServerTabular()
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings["SsasTabularConnection"].ConnectionString,
                    DatabaseName     = queueMessage.Database ?? ConfigurationManager.AppSettings["DatabaseName"]
                };

                queueMessage.Status = "Running";
                queueMessage.ETag   = "*";
                TableOperation updateOperation = TableOperation.InsertOrReplace(queueMessage);
                statusTable.Execute(updateOperation);

                tabularModel.ProcessModelFull();

                queueMessage.Status = "Complete";
                queueMessage.ETag   = "*";
                updateOperation     = TableOperation.InsertOrReplace(queueMessage);
                statusTable.Execute(updateOperation);
            }
            catch (Exception e)
            {
                log.Error($"Error occured processing database - {queueMessage?.Database} : {e.ToString()}", e);
                queueMessage.Status       = "Error Processing";
                queueMessage.ErrorDetails = e.ToString();
                queueMessage.ETag         = "*";
                TableOperation updateOperation = TableOperation.InsertOrReplace(queueMessage);
                statusTable.Execute(updateOperation);
            }

            log.Info($"Successfully completed database processing for  + {queueMessage?.Database}");
        }
        //[FunctionName("ProcessTabular")]
        public static void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"C# Timer trigger function started at: {DateTime.Now}");

            try
            {
                SqlServerAnalysisServerTabular tabularModel = new SqlServerAnalysisServerTabular()
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings["SsasTabularConnection"].ConnectionString,
                    DatabaseName     = ConfigurationManager.AppSettings["DatabaseName"]
                };

                tabularModel.ProcessModelFull();
            }
            catch (Exception e)
            {
                log.Info($"C# Timer trigger function exception: {e.ToString()}");
            }

            log.Info($"C# Timer trigger function finished at: {DateTime.Now}");
        }