protected override void OnStart(string[] args) { try { Program.Log.WriteEntry("PowerQueryNet.Service Start", EventLogEntryType.Information); PowerQueryService.Start(); } catch (Exception ex) { Program.Log.WriteEntry(ex.ToString(), EventLogEntryType.Error); this.Stop(); } }
static void Main(string[] args) { if (args == null || args.Length == 0) { ServiceBase.Run(new WindowsService()); } else if (args.FirstOrDefault(x => x == "-ipc") != null) { try { PowerQueryService.Start(); var taskHandle = new ManualResetEvent(false); taskHandle.WaitOne(); } catch (Exception ex) { Log.WriteEntry(ex.ToString(), EventLogEntryType.Error); } } }
static void Main(string[] args) { Log = new EventLog { Source = "PowerQueryNet" }; if (args == null || args.Length == 0) { ServiceBase.Run(new WindowsService()); } else if (args.FirstOrDefault(x => x == "-ipc") != null) { try { PowerQueryService.Start(); var taskHandle = new ManualResetEvent(false); taskHandle.WaitOne(); } catch (Exception ex) { Log.WriteEntry(ex.ToString(), EventLogEntryType.Error); } } else if (args.Length == 1) { string filePath = args[0]; string fileExtension = Path.GetExtension(filePath); ExecuteResponse executeResponse = null; AllocConsole(); try { var powerQueryService = new PowerQueryService(); if (fileExtension == ".pq") { string powerQueryFolder = Path.GetDirectoryName(filePath); string powerQueryFile = Path.GetFileNameWithoutExtension(filePath); var queries = Queries.LoadFromFolder(powerQueryFolder); var credentials = Credentials.LoadFromFile(Path.Combine(powerQueryFolder, "#credentials.xml")); var executeRequest = new ExecuteRequest { QueryName = powerQueryFile, Queries = queries, Credentials = credentials, }; executeResponse = powerQueryService.Execute(executeRequest); OutputResponse(executeResponse); //string connectionString = @"Data Source=P16019\SQL2016; Integrated Security=true; Initial Catalog=TEST"; //string response = powerQueryService.ExecuteToSQL(connectionString, powerQueryFile, queries, credentials); } if (fileExtension == ".xlsx" || fileExtension == ".xlsm" || fileExtension == ".pbix" || fileExtension == ".pbit" ) { string mashup = powerQueryService.MashupFromFile(filePath); Console.WriteLine(mashup); //Queries queries = powerQueryService.MashupToQueries(filePath); } Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("ex = {0}", ex.ToString()); } } else { AllocConsole(); Console.WriteLine(" Usage: -ipc"); Console.WriteLine(" Usage: [Power Query File Path]"); Console.WriteLine(" Usage: [Excel or Power BI File Path]"); Console.WriteLine(""); Console.WriteLine(" -ipc\t\t\t\tOpen named pipes service for interprocess communication"); Console.WriteLine(" [Power Query File Path]\tRun Power Query formula (*.pq)"); Console.WriteLine(" [Excel or Power BI File Path]\tGet Mashup from Excel or Power BI (*.xlsx;*.xlsm;*.pbix;*.pbit)"); Console.ReadLine(); } }