private void SavePbit(string fileName) { if (SourceType != ModelSourceType.Pbit) { Status = "Save failed!"; throw new InvalidOperationException("Tabular Editor cannot currently convert an Analysis Services Tabular model to a Power BI Template. Please choose a different save format."); } var fi = new FileInfo(fileName); if (!fi.Exists) { Status = "Save failed!"; throw new InvalidOperationException("Tabular Editor cannot save a model as a new .pbit file. Please choose an existing .pbit file or save the model as a .bim file."); } var dbcontent = Serializer.SerializeDB(SerializeOptions.PowerBi); // Save to .pbit file: PowerBIHelper.SaveDatabaseToPbitFile(fileName, dbcontent); Status = "File saved."; if (!IsConnected) { UndoManager.SetCheckpoint(); } }
public void PopulateLocalInstances() { comboBox1.Items.Clear(); comboBox1.DisplayMember = "Name"; PowerBIHelper.Refresh(); comboBox1.Items.AddRange(PowerBIHelper.Instances.OrderBy(i => i.Name).ToArray()); PowerBIInstancesLoaded = true; }
public async Task <IActionResult> Debug(string debugString) { await PowerBIHelper.Push(debugString, _powerOptions.Value.PowerBiUrl); Console.WriteLine($"From Device Debug: {debugString}"); return(Ok("Good")); }
public async Task <IActionResult> BootTest() { Console.WriteLine($"Options: DB - ${_powerOptions.Value.DBConnectionString}, PowerBi - {_powerOptions.Value.PowerBiUrl}"); await PowerBIHelper.Push("Booted", _powerOptions.Value.PowerBiUrl); Console.WriteLine("Booted"); return(Ok("Good")); }
public BaseController() { this.workspaceCollection = ConfigurationManager.AppSettings["powerbiWorkspaceCollection"]; this.accessKey = ConfigurationManager.AppSettings["powerbiAccessKey"]; this.apiUrl = ConfigurationManager.AppSettings["powerbiApiUrl"]; //System.Web.HttpContext.Current.Application["WorkspaceID"] = ConfigurationManager.AppSettings["powerbiWorkspaceId"]; if (System.Web.HttpContext.Current.Application["WorkspaceID"] == null) { PowerBIHelper.UploadReports(); } this.workspaceId = System.Web.HttpContext.Current.Application["WorkspaceID"].ToString(); }
private void RefreshPowerBIInstances() { _powerBIInstances = new List <PowerBIInstance>() { _pbiLoadingInstance }; SelectedPowerBIInstance = _pbiLoadingInstance; Task.Run(() => { // display the "loading..." message _powerBIInstances.Clear(); _powerBIInstances.Add(_pbiLoadingInstance); NotifyOfPropertyChange(() => PowerBIDesignerInstances); NotifyOfPropertyChange(() => PowerBIInstanceDetected); // look for local workspace instances _powerBIInstances = PowerBIHelper.GetLocalInstances(false); if (_powerBIInstances.Count == 0) { // Add the none found 'fake' instance _powerBIInstances.Add(_pbiNoneInstance); } if (PowerBIInstanceDetected) { if (SelectedPowerBIInstance == null || SelectedPowerBIInstance?.Port == -1) { SelectedPowerBIInstance = _powerBIInstances[0]; } } else { if (PowerBIModeSelected) { ServerModeSelected = true; } SelectedPowerBIInstance = _pbiNoneInstance; } // update bound properties NotifyOfPropertyChange(() => PowerBIInstanceDetected); NotifyOfPropertyChange(() => PowerBIDesignerInstances); NotifyOfPropertyChange(() => SelectedPowerBIInstance); }).ContinueWith(t => { // we should only come here if we got an exception Log.Error(t.Exception, "Error getting PowerBI/SSDT instances: {message}", t.Exception.Message); _eventAggregator.PublishOnUIThread(new OutputMessage(MessageType.Error, $"Error getting PowerBI/SSDT instances: {t.Exception.Message}")); }, TaskContinuationOptions.OnlyOnFaulted); }
public async Task <IActionResult> Index(double kwh) { var result = kwh; var resultDay = result * 24; if (resultDay < 0) { resultDay = 0; } decimal resultDollars = ((decimal)resultDay * 28.52M) / 100M; var rString = string.Format("{0:0.00}", result); var rStringDay = string.Format("{0:0.00}", resultDay); var rDollars = resultDollars.ToString("C0"); Console.WriteLine($"{rString}kwh -> {rStringDay} kwh per day -> {rDollars} per day @ {DateTime.Now.ToString()}"); await _context.PowerReadings.AddAsync(new PowerReading { KilowattHours = result, DailyKilowattHours = result * 24, MeasureTime = DateTime.Now }); await _context.SaveChangesAsync(); var averageSoFarYesterday = await _databaseService.AverageSoFarYesterday(); var averageSoFarToday = await _databaseService.AverageSoFarToday(); var averageLast24Hours = await _databaseService.AverageLast24Hours(); var averageYesterday = await _databaseService.AverageYesterday(); await PowerBIHelper.Push(result, averageSoFarToday, averageSoFarYesterday, averageLast24Hours, averageYesterday, resultDollars, _powerOptions.Value.PowerBiUrl); return(Ok(result)); }
private void RefreshPowerBIInstances() { PowerBIHelper.Refresh(); PowerBIDesignerDetected = PowerBIHelper.Instances.Count > 0; if (PowerBIHelper.Instances.Count > 0) { if (SelectedPowerBIInstance == null) { SelectedPowerBIInstance = PowerBIHelper.Instances[0]; } } else { if (PowerBIModeSelected) { ServerModeSelected = true; } SelectedPowerBIInstance = null; } // update bound properties NotifyOfPropertyChange(() => PowerBIDesignerDetected); NotifyOfPropertyChange(() => PowerBIDesignerInstances); NotifyOfPropertyChange(() => SelectedPowerBIInstance); }
private void Connections_Load(object sender, EventArgs e) { //Settings.Default.SourceServerAutoCompleteEntries = "localhost|"; //Settings.Default.TargetServerAutoCompleteEntries = "localhost|"; //Settings.Default.SourceCatalog = ""; //Settings.Default.TargetCatalog = ""; //Settings.Default.Save(); //this.Width = Convert.ToInt32(this.Width * 1.3); this.Height = Convert.ToInt32(grpSource.Height * 2.6); if (_dpiScaleFactor > 1) { //DPI float dpiScaleFactorFudged = _dpiScaleFactor * Utils.PrimaryFudgeFactor; float fudgeFactorWidth = 0.95f; this.Scale(new SizeF(dpiScaleFactorFudged * (_dpiScaleFactor > 1.7 ? 1 : Utils.SecondaryFudgeFactor), dpiScaleFactorFudged * Utils.SecondaryFudgeFactor)); this.Width = Convert.ToInt32(this.Width * dpiScaleFactorFudged * fudgeFactorWidth); foreach (Control control in Utils.GetChildInControl(this)) //.OfType<Button>()) { if (control is GroupBox || control is Button) { control.Font = new Font(control.Font.FontFamily, control.Font.Size * dpiScaleFactorFudged * Utils.SecondaryFudgeFactor, control.Font.Style); } if (control is GroupBox || control.Name == "btnSwitch") { control.Width = Convert.ToInt32(control.Width * dpiScaleFactorFudged * fudgeFactorWidth); } if (control is ComboBox) { control.Width = Convert.ToInt32(control.Width * fudgeFactorWidth); } if (control is Panel) { control.Left = Convert.ToInt32(control.Left * dpiScaleFactorFudged); } } this.btnSwitch.Left = grpSource.Right + Convert.ToInt32(12 * dpiScaleFactorFudged); this.grpTarget.Left = btnSwitch.Right + Convert.ToInt32(12 * dpiScaleFactorFudged); } cboSourceServer.DataSource = ComparisonControl.ReverseArray <string>(Settings.Default.SourceServerAutoCompleteEntries.Substring(0, Settings.Default.SourceServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray())); cboTargetServer.DataSource = ComparisonControl.ReverseArray <string>(Settings.Default.TargetServerAutoCompleteEntries.Substring(0, Settings.Default.TargetServerAutoCompleteEntries.Length - 1).Split("|".ToCharArray())); cboSourceDatabase.Text = Settings.Default.SourceCatalog; cboTargetDatabase.Text = Settings.Default.TargetCatalog; #region Prep Desktop/SSDT instances cboSourceDesktop.Items.Clear(); cboTargetDesktop.Items.Clear(); BindingSource desktopBindingSource = new BindingSource(); BindingSource desktopBindingTarget = new BindingSource(); _powerBIInstances.Clear(); try { _powerBIInstances = PowerBIHelper.GetLocalInstances(); } catch { } if (_powerBIInstances.Count > 0) { rdoSourceDesktop.Enabled = true; rdoTargetDesktop.Enabled = true; desktopBindingSource.DataSource = _powerBIInstances; desktopBindingTarget.DataSource = _powerBIInstances; cboSourceDesktop.DataSource = desktopBindingSource; cboSourceDesktop.ValueMember = "Port"; cboSourceDesktop.DisplayMember = "Name"; cboTargetDesktop.DataSource = desktopBindingTarget; cboTargetDesktop.ValueMember = "Port"; cboTargetDesktop.DisplayMember = "Name"; } else { rdoSourceDesktop.Enabled = false; rdoTargetDesktop.Enabled = false; } #endregion BindSourceConnectionInfo(); BindTargetConnectionInfo(); }
/// <summary> /// Loads an Analysis Services tabular database (Compatibility Level 1200 or newer) from a file /// or folder. /// </summary> /// <param name="path"></param> public TabularModelHandler(string path, TabularModelHandlerSettings settings = null) { Settings = settings ?? TabularModelHandlerSettings.Default; Singleton = this; server = null; var fi = new FileInfo(path); string data; if (fi.Exists && fi.Extension == ".pbit") { data = PowerBIHelper.LoadDatabaseFromPbitFile(path); SourceType = ModelSourceType.Pbit; Source = path; } else if (!fi.Exists || fi.Name == "database.json") { if (fi.Name == "database.json") { path = fi.DirectoryName; } if (Directory.Exists(path)) { data = CombineFolderJson(path); } else { throw new FileNotFoundException(); } SourceType = ModelSourceType.Folder; Source = path; } else { data = File.ReadAllText(path); SourceType = ModelSourceType.File; Source = path; } database = TOM.JsonSerializer.DeserializeDatabase(data); CompatibilityLevel = database.CompatibilityLevel; Status = "File loaded succesfully."; Init(); var serializeOptionsAnnotation = Model.GetAnnotation("TabularEditor_SerializeOptions"); if (serializeOptionsAnnotation != null) { SerializeOptions = JsonConvert.DeserializeObject <SerializeOptions>(serializeOptionsAnnotation); } // Check if translations / perspectives are stored locally in the model: if (SourceType == ModelSourceType.Folder && (SerializeOptions.LocalTranslations || SerializeOptions.LocalPerspectives)) { UndoManager.Enabled = false; BeginUpdate("Apply translations and perspectives from annotations"); var translationsJson = Model.GetAnnotation("TabularEditor_Cultures"); if (SerializeOptions.LocalTranslations && translationsJson != null) { Model.Cultures.FromJson(translationsJson); foreach (var item in AllTranslatableObjects) { item.LoadTranslations(); } } var perspectivesJson = Model.GetAnnotation("TabularEditor_Perspectives"); if (SerializeOptions.LocalPerspectives && perspectivesJson != null) { Model.Perspectives.FromJson(perspectivesJson); foreach (var item in AllPerspectiveObjects) { item.LoadPerspectives(); } } EndUpdate(); UndoManager.Enabled = true; } }