├── README.md ├── MigrationSample ├── MigrationWinFormSample │ ├── Models │ │ ├── ResourceGroup.cs │ │ ├── WorkspaceCollectionKeys.cs │ │ ├── Subscription.cs │ │ ├── PBIWorkspaceCollection.cs │ │ └── Group.cs │ ├── Program.cs │ ├── Auxilary │ │ ├── UpdateCredentialsSourceManager.cs │ │ ├── CreateGroupSourceManager.cs │ │ ├── ReportsGridSourceManager.cs │ │ ├── ImportSourceManager.cs │ │ ├── ExportSourceManager.cs │ │ ├── ProvisioningTabPage.cs │ │ └── AnalyzeSourceManager.cs │ ├── packages.config │ ├── Properties │ │ ├── Settings.settings │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Settings.Designer.cs │ │ └── Resources.resx │ ├── Dialogs │ │ ├── HelpDialog.cs │ │ ├── RenameForm.cs │ │ ├── HelpDialog.resx │ │ ├── RenameForm.resx │ │ ├── SelectResourceGroup.resx │ │ ├── SelectResourceGroup.cs │ │ ├── HelpDialog.Designer.cs │ │ ├── RenameForm.Designer.cs │ │ └── SelectResourceGroup.Designer.cs │ ├── Core │ │ ├── AnalyzedWorkspaceCollection.cs │ │ ├── PBIProvisioningContext.cs │ │ ├── MigrationPlan.cs │ │ ├── SaaSController.cs │ │ ├── ReportMigrationData.cs │ │ ├── AzureTokenManager.cs │ │ └── PaaSController.cs │ ├── App.config │ ├── SovereignClouds │ │ └── Mooncake.config │ ├── MainForm.resx │ ├── MigrationTabForm.resx │ ├── MigrationSample.csproj │ ├── MainForm.Designer.cs │ └── MainForm.cs └── powerbi-migration-sample.sln ├── LICENSE └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 4 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Models/ResourceGroup.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace MigrationSample 4 | { 5 | public class ResourceGroup 6 | { 7 | [JsonProperty(PropertyName = "name")] 8 | public string Name { get; set; } 9 | } 10 | 11 | public class AzureResourceGroups 12 | { 13 | public ResourceGroup[] Value { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Models/WorkspaceCollectionKeys.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace MigrationSample.Model 4 | { 5 | public class WorkspaceCollectionKeys 6 | { 7 | [JsonProperty(PropertyName = "key1")] 8 | public string Key1 { get; set; } 9 | 10 | [JsonProperty(PropertyName = "key2")] 11 | public string Key2 { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Models/Subscription.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace MigrationSample 5 | { 6 | public class Subscription 7 | { 8 | [JsonProperty(PropertyName = "displayName")] 9 | public string DisplayName { get; set; } 10 | 11 | [JsonProperty(PropertyName = "subscriptionId")] 12 | public Guid Id { get; set; } 13 | } 14 | 15 | public class AzureSubscriptions 16 | { 17 | public Subscription[] Value { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Models/PBIWorkspaceCollection.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | 4 | namespace MigrationSample.Models 5 | { 6 | public class PBIWorkspaceCollection 7 | { 8 | [JsonProperty(PropertyName = "name")] 9 | public string Name { get; set; } 10 | 11 | [JsonProperty(PropertyName = "location")] 12 | public string Location { get; set; } 13 | } 14 | 15 | public class PBIWorkspaceCollections 16 | { 17 | public IList Value { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Models/Group.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MigrationSample.Core 4 | { 5 | public class O365Group 6 | { 7 | public string Id { get; set; } 8 | 9 | public string DisplayName { get; set; } 10 | 11 | public string Description { get; set; } 12 | 13 | public string MailNickname { get; set; } 14 | 15 | public string Visibility { get; set; } 16 | 17 | public bool MailEnabled { get; set; } 18 | 19 | public bool SecurityEnabled { get; set; } 20 | 21 | public List GroupTypes { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace MigrationSample 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new MainForm()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Auxilary/UpdateCredentialsSourceManager.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Forms; 3 | 4 | namespace MigrationSample.Auxilary 5 | { 6 | class UpdateCredentialsSourceManager : ReportsGridSourceManager 7 | { 8 | public UpdateCredentialsSourceManager(DataGridView dataGridView) : base(dataGridView) 9 | { 10 | 11 | } 12 | 13 | public override void UpdateSource() 14 | { 15 | DataSource = FilteredReports.Select(r => new 16 | { 17 | TargetGroupName = r.SaaSTargetGroupName, 18 | TargetReportName = r.SaaSTargetReportName, 19 | DirectQueryConnectionString = r.DirectQueryConnectionString, 20 | }); 21 | 22 | base.UpdateSource(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Auxilary/CreateGroupSourceManager.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Forms; 3 | 4 | namespace MigrationSample.Auxilary 5 | { 6 | class CreateGroupSourceManager : ReportsGridSourceManager 7 | { 8 | public CreateGroupSourceManager(DataGridView dataGridView) : base(dataGridView) 9 | { 10 | 11 | } 12 | 13 | public override void UpdateSource() 14 | { 15 | DataSource = FilteredReports.Select(r => new 16 | { 17 | GroupName = r.SaaSTargetGroupName, 18 | GroupCreationStatus = r.SaaSTargetGroupCreationStatus, 19 | ForReport = r.SaaSTargetReportName, 20 | CreatedGroupId = r.SaaSTargetGroupId, 21 | }); 22 | 23 | base.UpdateSource(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Auxilary/ReportsGridSourceManager.cs: -------------------------------------------------------------------------------- 1 | using MigrationSample.Core; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | 5 | namespace MigrationSample.Auxilary 6 | { 7 | public class ReportsGridSourceManager 8 | { 9 | public BindingSource BindingSource { get; private set; } 10 | 11 | public object DataSource { set { BindingSource.DataSource = value; } } 12 | 13 | public List FilteredReports { get; set; } 14 | 15 | public ReportsGridSourceManager(DataGridView dataGridView) 16 | { 17 | BindingSource = new BindingSource(); 18 | dataGridView.DataSource = BindingSource; 19 | } 20 | 21 | public virtual void UpdateSource() 22 | { 23 | BindingSource.ResetBindings(false); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Auxilary/ImportSourceManager.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Forms; 3 | 4 | namespace MigrationSample.Auxilary 5 | { 6 | class ImportSourceManager : ReportsGridSourceManager 7 | { 8 | public ImportSourceManager(DataGridView dataGridView) : base(dataGridView) 9 | { 10 | } 11 | 12 | public override void UpdateSource() 13 | { 14 | DataSource = FilteredReports.Select(r => new 15 | { 16 | TargetName = r.SaaSTargetReportName, 17 | UploadState = r.SaaSImportState, 18 | UploadError = r.SaaSImportError, 19 | TargetGroupName = r.SaaSTargetGroupName, 20 | TargetGroupCreatedId = r.SaaSTargetGroupId, 21 | UploadedReportId = r.SaaSReportId, 22 | }); 23 | 24 | base.UpdateSource(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 10 | 11 | 12 | 4 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/HelpDialog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Diagnostics; 6 | using System.Drawing; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | 12 | namespace MigrationWinFormSample.Dialogs 13 | { 14 | 15 | public partial class HelpDialog : Form 16 | { 17 | private string HelpUrl { get; set; } 18 | 19 | public HelpDialog(string title, string text, string helpUrl) 20 | { 21 | InitializeComponent(); 22 | 23 | InstractionsLbl.Text = text; 24 | 25 | this.Text = title; 26 | 27 | HelpUrl = helpUrl; 28 | } 29 | 30 | private void HelpBtn_Click(object sender, EventArgs e) 31 | { 32 | Process.Start(HelpUrl); 33 | } 34 | 35 | private void OKbtn_Click(object sender, EventArgs e) 36 | { 37 | Close(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Auxilary/ExportSourceManager.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Windows.Forms; 4 | 5 | namespace MigrationSample.Auxilary 6 | { 7 | public class ExportSourceManager : ReportsGridSourceManager 8 | { 9 | public ExportSourceManager(DataGridView dataGridView) : base(dataGridView) 10 | { 11 | 12 | } 13 | 14 | public override void UpdateSource() 15 | { 16 | DataSource = FilteredReports.Select(r => new 17 | { 18 | PaaSReportName = r.PaaSReportName, 19 | PBIXExists = File.Exists(r.PbixPath) ? "Yes" : "No", 20 | ExportState = r.ExportState, 21 | LastExportStatus = r.LastExportStatus, 22 | PaaSWorkspaceCollectionName = r.PaaSWorkspaceCollectionName, 23 | PaaSWorkspaceId = r.PaaSWorkspaceId, 24 | PaaSReportId = r.PaaSReportId, 25 | PbixPath = r.PbixPath, 26 | }); 27 | 28 | base.UpdateSource(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/RenameForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace MigrationSample.Dialogs 12 | { 13 | public partial class RenameForm : Form 14 | { 15 | public string Result 16 | { 17 | get 18 | { 19 | return this.txtResult.Text; 20 | } 21 | } 22 | 23 | public RenameForm(string prevName) 24 | { 25 | InitializeComponent(); 26 | this.txtResult.Text = prevName; 27 | } 28 | 29 | 30 | private void btnOk_Click(object sender, EventArgs e) 31 | { 32 | this.DialogResult = DialogResult.OK; 33 | this.Close(); 34 | } 35 | 36 | private void btnCancel_Click(object sender, EventArgs e) 37 | { 38 | this.Close(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MigrationSample/powerbi-migration-sample.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MigrationSample", "MigrationWinFormSample\MigrationSample.csproj", "{8B4C0E7C-D19F-4EC9-BD3B-BF5CAA6DCEE1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8B4C0E7C-D19F-4EC9-BD3B-BF5CAA6DCEE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {8B4C0E7C-D19F-4EC9-BD3B-BF5CAA6DCEE1}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {8B4C0E7C-D19F-4EC9-BD3B-BF5CAA6DCEE1}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {8B4C0E7C-D19F-4EC9-BD3B-BF5CAA6DCEE1}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Core/AnalyzedWorkspaceCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace MigrationSample.Core 4 | { 5 | public class AnalyzedWorkspaceCollection 6 | { 7 | public string WorkspaceCollectionName { get; set; } 8 | 9 | public List Workspaces { get; set; } 10 | 11 | public int ExportableReportsCnt { get; set; } 12 | 13 | public int AllReportsCnt { get; set; } 14 | 15 | public AnalyzedWorkspaceCollection(string wcName) 16 | { 17 | WorkspaceCollectionName = wcName; 18 | 19 | Workspaces = new List(); 20 | } 21 | } 22 | 23 | public class AnalyzedWorkspace 24 | { 25 | public string WorkspaceId { get; set; } 26 | 27 | public List Reports { get; set; } 28 | 29 | public int ExportableReportsCnt { get; set; } 30 | 31 | public AnalyzedWorkspace(string workspaceId) 32 | { 33 | WorkspaceId = workspaceId; 34 | 35 | Reports = new List(); 36 | } 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Core/PBIProvisioningContext.cs: -------------------------------------------------------------------------------- 1 | using MigrationSample.Models; 2 | 3 | namespace MigrationSample 4 | { 5 | public enum MigrationEnvironment 6 | { 7 | dxt, 8 | msit, 9 | prod 10 | }; 11 | 12 | public class PBIProvisioningContext 13 | { 14 | public string DisplayName; 15 | 16 | public MigrationEnvironment Environment { get; set; } 17 | 18 | public Subscription Subscription { get; set; } 19 | 20 | public string ResourceGroupName { get; set; } 21 | 22 | public PBIWorkspaceCollection WorkspaceCollection { get; set; } 23 | 24 | public string WorkspaceId { get; set; } 25 | 26 | public PBIProvisioningContext() 27 | { 28 | 29 | } 30 | 31 | public PBIProvisioningContext(PBIProvisioningContext previousContext) 32 | { 33 | DisplayName = previousContext.DisplayName; 34 | Environment = previousContext.Environment; 35 | Subscription = previousContext.Subscription; 36 | ResourceGroupName = previousContext.ResourceGroupName; 37 | WorkspaceCollection = previousContext.WorkspaceCollection; 38 | WorkspaceId = previousContext.WorkspaceId; 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MigrationSample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MigrationSample")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("dceb0208-8184-4d71-8f87-1c9ce79dbadf")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Auxilary/ProvisioningTabPage.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | 3 | namespace MigrationSample.Dialogs 4 | { 5 | public class ResourceGroupTabPage : TabPage 6 | { 7 | private MigrationTabForm migrationTabForm { get; set; } 8 | 9 | public ResourceGroupTabPage(MigrationTabForm form) 10 | { 11 | this.migrationTabForm = form; 12 | this.Controls.Add(form.flowLayoutPanel); 13 | this.Text = form.Text; 14 | } 15 | 16 | public void SetContext(PBIProvisioningContext context) 17 | { 18 | this.Text = context.DisplayName; 19 | } 20 | 21 | public void SetDisplayName(string name) 22 | { 23 | migrationTabForm.MigrationPlan.Context.DisplayName = name; 24 | Text = name; 25 | } 26 | 27 | protected override void Dispose(bool disposing) 28 | { 29 | if (disposing) { migrationTabForm.Dispose(); } 30 | base.Dispose(disposing); 31 | } 32 | 33 | public string GetMigrationPlanFile() 34 | { 35 | return migrationTabForm.GetMigrationPlanFile(); 36 | } 37 | 38 | public void SaveMigrationPlan() 39 | { 40 | migrationTabForm.SaveMigrationPlan(); 41 | } 42 | 43 | public void ResizeItemSize() 44 | { 45 | migrationTabForm.ResizeItemSize(); 46 | } 47 | 48 | public void SaveMigrationPlanAs() 49 | { 50 | migrationTabForm.SaveMigrationPlanAs(); 51 | } 52 | } 53 | 54 | public class ProvisioningFormPage : Form 55 | { 56 | public TableLayoutPanel flowLayoutPanel; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Core/MigrationPlan.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml.Serialization; 3 | 4 | namespace MigrationSample.Core 5 | { 6 | public class MigrationPlan 7 | { 8 | public List ReportsMigrationData { get; set; } 9 | 10 | public PBIProvisioningContext Context { get; set; } 11 | 12 | public string MigrationRootPath { get; set; } 13 | 14 | public MigrationPlan() 15 | { 16 | } 17 | 18 | public MigrationPlan(PBIProvisioningContext context) 19 | { 20 | Context = context; 21 | 22 | ReportsMigrationData = new List(); 23 | } 24 | 25 | /// 26 | /// Saves to an xml file 27 | /// 28 | /// File path of the new xml file 29 | public void Save(string FileName) 30 | { 31 | using (var writer = new System.IO.StreamWriter(FileName)) 32 | { 33 | var serializer = new XmlSerializer(this.GetType()); 34 | serializer.Serialize(writer, this); 35 | writer.Flush(); 36 | } 37 | } 38 | 39 | /// 40 | /// Load an object from an xml file 41 | /// 42 | /// Xml file name 43 | /// The object created from the xml file 44 | public static MigrationPlan Load(string FileName) 45 | { 46 | try 47 | { 48 | using (var stream = System.IO.File.OpenRead(FileName)) 49 | { 50 | var serializer = new XmlSerializer(typeof(MigrationPlan)); 51 | return serializer.Deserialize(stream) as MigrationPlan; 52 | } 53 | } 54 | catch 55 | { 56 | return null; 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Auxilary/AnalyzeSourceManager.cs: -------------------------------------------------------------------------------- 1 | using MigrationSample.Core; 2 | using System.Linq; 3 | using System.Windows.Forms; 4 | 5 | namespace MigrationSample.Auxilary 6 | { 7 | class AnalyzeSourceManager : ReportsGridSourceManager 8 | { 9 | public static class ReportTypeStrings 10 | { 11 | public static string PushDataset = "Pushed Data Set."; 12 | public static string ImportedDirectQuery = "Imported Dataset. Direct Query."; 13 | public static string ImportedCached = "Imported Dataset. Cached Data."; 14 | public static string OldImport = $"Imported Dataset. Created before {ReportMigrationData.MinimalSupportedImportUpdateDate.ToString("MM/dd/yyyy")}."; 15 | } 16 | 17 | public static class DownloadabilityStrings 18 | { 19 | public static string CanBeDownloaded = "Yes. Can be downloaded."; 20 | public static string ShouldBeCreatedFromLocal = "No. Should be created from local pbix."; 21 | public static string ShouldBeCreatedFromJson = "No. Should be recreated from json."; 22 | } 23 | 24 | public AnalyzeSourceManager(DataGridView dataGridView) : base(dataGridView) 25 | { 26 | 27 | } 28 | 29 | public override void UpdateSource() 30 | { 31 | DataSource = FilteredReports.Select(r => new 32 | { 33 | PaaSReportName = r.PaaSReportName, 34 | Type = (r.IsBoundToOldDataset) ? ReportTypeStrings.OldImport : 35 | (r.IsPushDataset) ? ReportTypeStrings.PushDataset : 36 | (!string.IsNullOrWhiteSpace(r.DirectQueryConnectionString)) ? ReportTypeStrings.ImportedDirectQuery : 37 | ReportTypeStrings.ImportedCached, 38 | Downloadable = (r.IsBoundToOldDataset) ? DownloadabilityStrings.ShouldBeCreatedFromLocal : 39 | (r.IsPushDataset) ? DownloadabilityStrings.ShouldBeCreatedFromJson : DownloadabilityStrings.CanBeDownloaded, 40 | }); 41 | 42 | base.UpdateSource(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Core/SaaSController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.PowerBI.Api.V2; 2 | using Microsoft.PowerBI.Api.V2.Models; 3 | using Microsoft.Rest; 4 | using System; 5 | using System.IO; 6 | using System.Threading.Tasks; 7 | using System.Configuration; 8 | 9 | namespace MigrationSample.Core 10 | { 11 | static class SaaSController 12 | { 13 | private static string GraphUrlWithVersion 14 | { 15 | get 16 | { 17 | return $"{ConfigurationManager.AppSettings["graph-apiEndpointUri"]}/{ConfigurationManager.AppSettings["graph-apiEndpointUri-version"]}"; 18 | } 19 | } 20 | 21 | public static ODataResponseListGroup GetGroups() 22 | { 23 | using (var client = CreatePowerBIClient()) 24 | { 25 | return client.Groups.GetGroups(); 26 | } 27 | } 28 | 29 | public static async Task GetImports(string groupId) 30 | { 31 | using (var client = CreatePowerBIClient()) 32 | { 33 | return await client.Imports.GetImportsInGroupAsync(groupId); 34 | } 35 | } 36 | 37 | private static PowerBIClient CreatePowerBIClient() 38 | { 39 | var credentials = new TokenCredentials(AzureTokenManager.GetPowerBISaaSToken()); 40 | return new PowerBIClient(new Uri($"{ConfigurationManager.AppSettings["powerbi-service-apiEndpointUri"]}"), credentials); 41 | } 42 | 43 | public static async Task GetReports(string groupId) 44 | { 45 | using (var client = CreatePowerBIClient()) 46 | { 47 | return await client.Reports.GetReportsInGroupAsync(groupId); 48 | } 49 | } 50 | 51 | public static async Task SendImport(string pbixPath, string groupId, string targetName, string nameConflict) 52 | { 53 | using (var client = CreatePowerBIClient()) 54 | { 55 | using (var file = File.Open(pbixPath, FileMode.Open)) 56 | { 57 | return (await client.Imports.PostImportWithFileAsyncInGroup(groupId, file, targetName, nameConflict)).Id; 58 | } 59 | } 60 | } 61 | 62 | public static async Task CreateGroupAsync(string groupName) 63 | { 64 | using (var client = CreatePowerBIClient()) 65 | { 66 | return await client.Groups.CreateGroupAsync(new GroupCreationRequest(groupName)); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MigrationSample.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MigrationSample.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Core/ReportMigrationData.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.PowerBI.Api.V1.Models; 2 | using System; 3 | 4 | namespace MigrationSample.Core 5 | { 6 | public enum ExportState 7 | { 8 | Failed, 9 | InProgress, 10 | Done 11 | } 12 | 13 | public enum ImportState 14 | { 15 | Failed, 16 | InProgress, 17 | Done, 18 | Publishing 19 | } 20 | 21 | public class ReportMigrationData 22 | { 23 | public static readonly DateTime MinimalSupportedImportUpdateDate = new DateTime(2016, 11, 26); 24 | 25 | public string PaaSWorkspaceCollectionName { get; set; } 26 | 27 | public string PaaSWorkspaceId { get; set; } 28 | 29 | public string PaaSReportId { get; set; } 30 | 31 | public string PaaSReportLastImportTime { get; set; } 32 | 33 | public string PaaSReportName { get; set; } 34 | 35 | public bool IsPushDataset { get; set; } 36 | 37 | public bool IsBoundToOldDataset { get; set; } 38 | 39 | public string PbixPath { get; set; } 40 | 41 | public ExportState? ExportState { get; set; } 42 | 43 | public string LastExportStatus { get; set; } 44 | 45 | public string SaaSTargetGroupName { get; set; } 46 | 47 | public string SaaSTargetGroupId { get; set; } 48 | 49 | public string SaaSTargetGroupCreationStatus { get; set; } 50 | 51 | public string SaaSTargetReportName { get; set; } 52 | 53 | public ImportState? SaaSImportState { get; set; } 54 | 55 | public string SaaSReportId { get; set; } 56 | 57 | public string SaaSImportError { get; set; } 58 | 59 | public string DirectQueryConnectionString { get; set; } 60 | 61 | /// 62 | /// This constructor is required for serialization 63 | /// 64 | public ReportMigrationData() 65 | { 66 | } 67 | 68 | public void ResetImportProgressData() 69 | { 70 | SaaSTargetGroupCreationStatus = null; 71 | SaaSTargetGroupId = null; 72 | SaaSImportError = null; 73 | SaaSImportState = null; 74 | SaaSReportId = null; 75 | } 76 | 77 | public ReportMigrationData(Report report, Import import, Dataset dataset, ODataResponseListDatasource datasources, string workspaceCollectionName, string workspaceId) 78 | { 79 | IsPushDataset = (dataset.AddRowsAPIEnabled.HasValue) ? dataset.AddRowsAPIEnabled.Value : false; 80 | 81 | if (import == null) 82 | { 83 | IsBoundToOldDataset = false; 84 | } 85 | else 86 | { 87 | PaaSReportLastImportTime = import.UpdatedDateTime.ToString(); 88 | 89 | IsBoundToOldDataset = import.UpdatedDateTime < MinimalSupportedImportUpdateDate; 90 | 91 | if (datasources != null) 92 | { 93 | DirectQueryConnectionString = datasources.Value[0].ConnectionString; 94 | } 95 | } 96 | 97 | PaaSReportId = report.Id; 98 | PaaSReportName = report.Name; 99 | PaaSWorkspaceCollectionName = workspaceCollectionName; 100 | PaaSWorkspaceId = workspaceId; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MigrationWinFormSample.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.UserScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("")] 29 | public string Tabs { 30 | get { 31 | return ((string)(this["Tabs"])); 32 | } 33 | set { 34 | this["Tabs"] = value; 35 | } 36 | } 37 | 38 | [global::System.Configuration.UserScopedSettingAttribute()] 39 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 40 | [global::System.Configuration.DefaultSettingValueAttribute("0")] 41 | public int OpenedTab { 42 | get { 43 | return ((int)(this["OpenedTab"])); 44 | } 45 | set { 46 | this["OpenedTab"] = value; 47 | } 48 | } 49 | 50 | [global::System.Configuration.UserScopedSettingAttribute()] 51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 52 | [global::System.Configuration.DefaultSettingValueAttribute("4")] 53 | public int Environment { 54 | get { 55 | return ((int)(this["Environment"])); 56 | } 57 | set { 58 | this["Environment"] = value; 59 | } 60 | } 61 | 62 | [global::System.Configuration.UserScopedSettingAttribute()] 63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 64 | public global::System.DateTime prodAzureTokenExpiration { 65 | get { 66 | return ((global::System.DateTime)(this["prodAzureTokenExpiration"])); 67 | } 68 | set { 69 | this["prodAzureTokenExpiration"] = value; 70 | } 71 | } 72 | 73 | [global::System.Configuration.UserScopedSettingAttribute()] 74 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 75 | [global::System.Configuration.DefaultSettingValueAttribute("")] 76 | public string prodAzureToken { 77 | get { 78 | return ((string)(this["prodAzureToken"])); 79 | } 80 | set { 81 | this["prodAzureToken"] = value; 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Core/AzureTokenManager.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Clients.ActiveDirectory; 2 | using MigrationWinFormSample.Dialogs; 3 | using System; 4 | using System.Configuration; 5 | using System.Windows.Forms; 6 | 7 | namespace MigrationSample.Core 8 | { 9 | static class AzureTokenManager 10 | { 11 | private static readonly string clientId = "ea0616ba-638b-4df5-95b9-636659ae5121"; 12 | private static readonly Uri redirectUri = new Uri("urn:ietf:wg:oauth:2.0:oob"); 13 | 14 | static readonly string resourceUri = ConfigurationManager.AppSettings["AADPowerBIResourceId"]; 15 | static readonly string authorityUri = $"{ConfigurationManager.AppSettings["powerbi-service-loginWindowsUrl"]}/common/oauth2/authorize"; 16 | 17 | static readonly string graphResourceUri = ConfigurationManager.AppSettings["graph-apiEndpointUri"]; 18 | static readonly string graphAuthorityUri = $"{ConfigurationManager.AppSettings["powerbi-service-loginWindowsUrl"]}/common/"; 19 | 20 | private static DateTime ProdAzureTokenExpiration; 21 | private static string ProdAzureToken = null; 22 | 23 | private static AuthenticationResult PBISaaSAuthResult { get; set; } 24 | 25 | private static AuthenticationResult GraphAuthResult { get; set; } 26 | 27 | public static string GetPowerBISaaSToken() 28 | { 29 | if (PBISaaSAuthResult == null || PBISaaSAuthResult.ExpiresOn < DateTime.UtcNow) 30 | { 31 | var dialog = new HelpDialog( 32 | "Master account required", 33 | "In order to create groups and upload content, you need to sign in with your master account.", 34 | "https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-migrate-from-powerbi-embedded/#accounts-within-azure-ad" 35 | ); 36 | 37 | var dialogResult = dialog.ShowDialog(); 38 | 39 | AuthenticationContext authContext = new AuthenticationContext(authorityUri); 40 | PBISaaSAuthResult = authContext.AcquireToken(resourceUri, clientId, redirectUri, PromptBehavior.Always); 41 | } 42 | 43 | return PBISaaSAuthResult.AccessToken; 44 | } 45 | 46 | private static void RefreshGraphAuthResult() 47 | { 48 | if (GraphAuthResult == null || GraphAuthResult.ExpiresOn < DateTime.UtcNow) 49 | { 50 | AuthenticationContext authContext = new AuthenticationContext(graphAuthorityUri); 51 | 52 | GraphAuthResult = authContext.AcquireToken( 53 | graphResourceUri, clientId, 54 | redirectUri, 55 | PromptBehavior.Auto, 56 | new UserIdentifier( 57 | PBISaaSAuthResult.UserInfo.DisplayableId, 58 | UserIdentifierType.RequiredDisplayableId)); 59 | } 60 | } 61 | 62 | public static string GetGraphUserUniqueId() 63 | { 64 | RefreshGraphAuthResult(); 65 | 66 | return PBISaaSAuthResult.UserInfo.UniqueId; 67 | } 68 | 69 | public static string GetGraphToken() 70 | { 71 | RefreshGraphAuthResult(); 72 | 73 | return GraphAuthResult.AccessToken; 74 | } 75 | 76 | public static void LoadAppData() 77 | { 78 | ProdAzureToken = MigrationWinFormSample.Properties.Settings.Default.prodAzureToken; 79 | ProdAzureTokenExpiration = MigrationWinFormSample.Properties.Settings.Default.prodAzureTokenExpiration; 80 | } 81 | 82 | public static void SetAppData() 83 | { 84 | MigrationWinFormSample.Properties.Settings.Default.prodAzureToken = ProdAzureToken; 85 | MigrationWinFormSample.Properties.Settings.Default.prodAzureTokenExpiration = ProdAzureTokenExpiration; 86 | } 87 | 88 | public static string GetAzureToken(MigrationEnvironment env) 89 | { 90 | if (ProdAzureTokenExpiration != null && ProdAzureTokenExpiration > DateTime.UtcNow && ConfigurationManager.AppSettings["ignorePaaSAzureTokenCache"] == null) 91 | { 92 | return ProdAzureToken; 93 | } 94 | 95 | return null; 96 | } 97 | 98 | public static void SetAzureToken(AuthenticationResult authenticationResult, MigrationEnvironment env) 99 | { 100 | ProdAzureTokenExpiration = authenticationResult.ExpiresOn.DateTime; 101 | ProdAzureToken = authenticationResult.AccessToken; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 0 74 | 75 | 76 | 4 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 0 91 | 92 | 93 | 4 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/SovereignClouds/Mooncake.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 0 74 | 75 | 76 | 4 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 0 91 | 92 | 93 | 4 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/HelpDialog.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/RenameForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/SelectResourceGroup.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/SelectResourceGroup.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using MigrationSample.Core; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Configuration; 6 | using System.Data; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace MigrationSample.Dialogs 12 | { 13 | public partial class SelectResourceGroup : Form 14 | { 15 | public ResourceGroupTabPage TargetTabPage { get; set; } 16 | 17 | public SelectResourceGroup() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | private void btnSelect_Click(object sender, EventArgs e) 23 | { 24 | var context = GetContext(); 25 | 26 | if (context.Subscription == null) 27 | { 28 | MessageBox.Show("Select a Subscription"); 29 | return; 30 | } 31 | 32 | if (context.ResourceGroupName == null) 33 | { 34 | MessageBox.Show("Select a resource group"); 35 | return; 36 | } 37 | 38 | this.Close(); 39 | 40 | context.DisplayName = $"{context.Subscription.DisplayName}-{context.ResourceGroupName}"; 41 | 42 | if (TargetTabPage == null) 43 | { 44 | MainForm parent = (MainForm)this.Owner; 45 | TargetTabPage = parent.AddTab(context); 46 | } 47 | else { 48 | TargetTabPage.SetContext(context); 49 | } 50 | } 51 | 52 | private async void comboEnvironment_SelectedIndexChanged(object sender, EventArgs e) 53 | { 54 | MigrationWinFormSample.Properties.Settings.Default.Environment = comboEnvironment.SelectedIndex; 55 | 56 | await BlockUIAndExecuteAsync(LoadSubscriptions); 57 | } 58 | 59 | public async Task LoadSubscriptions() 60 | { 61 | this.SubscriptionsGridView.DataSource = null; 62 | this.comboResourceGroup.DataSource = null; 63 | 64 | PaaSController backend = new PaaSController(GetContext()); 65 | 66 | try 67 | { 68 | string content = await backend.GetSubscriptions(); 69 | AzureSubscriptions subscriptions = JsonConvert.DeserializeObject(content); 70 | if (subscriptions == null || subscriptions.Value == null || subscriptions.Value.Count() == 0) 71 | { 72 | MessageBox.Show("No subscriptions found."); 73 | return; 74 | } 75 | this.SubscriptionsGridView.DataSource = subscriptions.Value; 76 | this.SubscriptionsGridView.CurrentCell = this.SubscriptionsGridView[1, 0]; 77 | } 78 | catch (Exception e) 79 | { 80 | MessageBox.Show($"Failed to get subscriptions: {e.Message}"); 81 | return; 82 | } 83 | 84 | await LoadResourceGroups(); 85 | } 86 | 87 | public PBIProvisioningContext GetContext() 88 | { 89 | MigrationEnvironment env; 90 | if (!Enum.TryParse(this.comboEnvironment.SelectedItem as string, out env)) 91 | { 92 | throw new Exception("Not supported Environement.The app should bail out."); 93 | } 94 | 95 | Subscription subscription = null; 96 | if (SubscriptionsGridView.CurrentCell != null) 97 | { 98 | subscription = SubscriptionsGridView.Rows[SubscriptionsGridView.CurrentCell.RowIndex].DataBoundItem as Subscription; 99 | } 100 | 101 | return new PBIProvisioningContext() 102 | { 103 | Environment = env, 104 | Subscription = subscription, 105 | ResourceGroupName = comboResourceGroup.SelectedItem as string, 106 | }; 107 | } 108 | 109 | private async void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 110 | { 111 | await BlockUIAndExecuteAsync(LoadResourceGroups); 112 | } 113 | 114 | public async Task LoadResourceGroups() 115 | { 116 | PaaSController backend = new PaaSController(GetContext()); 117 | 118 | string content = await backend.GetResourceGroups(); 119 | AzureResourceGroups resourceGroups = JsonConvert.DeserializeObject(content); 120 | if (resourceGroups == null || resourceGroups.Value == null || resourceGroups.Value.Count() == 0) 121 | { 122 | MessageBox.Show("No subscriptions found."); 123 | return; 124 | } 125 | 126 | this.comboResourceGroup.DataSource = resourceGroups.Value.Select(rg => rg.Name).ToList(); 127 | } 128 | 129 | public async Task BlockUIAndExecuteAsync(Func func) 130 | { 131 | this.Enabled = false; 132 | try 133 | { 134 | await func(); 135 | } 136 | finally 137 | { 138 | this.Enabled = true; 139 | } 140 | } 141 | 142 | private async void SubscriptionsGridView_MouseUp(object sender, MouseEventArgs e) 143 | { 144 | await BlockUIAndExecuteAsync(LoadResourceGroups); 145 | } 146 | 147 | private void SelectResourceGroup_Load(object sender, EventArgs e) 148 | { 149 | var defaultEnvironementString = ConfigurationManager.AppSettings["default-environement"]; 150 | MigrationEnvironment defaultEnvironement; 151 | 152 | if (!string.IsNullOrWhiteSpace(defaultEnvironementString) && Enum.TryParse(defaultEnvironementString, out defaultEnvironement)) 153 | { 154 | comboEnvironment.Items.Add(defaultEnvironement.ToString()); 155 | comboEnvironment.SelectedIndex = 0; 156 | comboEnvironment.Enabled = false; 157 | } 158 | else 159 | { 160 | comboEnvironment.Items.Clear(); 161 | foreach (MigrationEnvironment env in Enum.GetValues(typeof(MigrationEnvironment))) 162 | { 163 | comboEnvironment.Items.Add(env.ToString()); 164 | } 165 | } 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/MainForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 25 125 | 126 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/MigrationTabForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 34 125 | 126 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/HelpDialog.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace MigrationWinFormSample.Dialogs 2 | { 3 | partial class HelpDialog 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 32 | this.InstractionsLbl = new System.Windows.Forms.Label(); 33 | this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); 34 | this.HelpBtn = new System.Windows.Forms.Button(); 35 | this.OKbtn = new System.Windows.Forms.Button(); 36 | this.tableLayoutPanel1.SuspendLayout(); 37 | this.flowLayoutPanel1.SuspendLayout(); 38 | this.SuspendLayout(); 39 | // 40 | // tableLayoutPanel1 41 | // 42 | this.tableLayoutPanel1.ColumnCount = 1; 43 | this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); 44 | this.tableLayoutPanel1.Controls.Add(this.InstractionsLbl, 0, 0); 45 | this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 1); 46 | this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; 47 | this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); 48 | this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 49 | this.tableLayoutPanel1.RowCount = 2; 50 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 59.48276F)); 51 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 40.51724F)); 52 | this.tableLayoutPanel1.Size = new System.Drawing.Size(578, 116); 53 | this.tableLayoutPanel1.TabIndex = 0; 54 | // 55 | // InstractionsLbl 56 | // 57 | this.InstractionsLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 58 | | System.Windows.Forms.AnchorStyles.Left) 59 | | System.Windows.Forms.AnchorStyles.Right))); 60 | this.InstractionsLbl.AutoSize = true; 61 | this.InstractionsLbl.BackColor = System.Drawing.SystemColors.Window; 62 | this.InstractionsLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 63 | this.InstractionsLbl.Location = new System.Drawing.Point(3, 0); 64 | this.InstractionsLbl.Name = "InstractionsLbl"; 65 | this.InstractionsLbl.Size = new System.Drawing.Size(572, 69); 66 | this.InstractionsLbl.TabIndex = 0; 67 | this.InstractionsLbl.Text = "label1"; 68 | this.InstractionsLbl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 69 | // 70 | // flowLayoutPanel1 71 | // 72 | this.flowLayoutPanel1.Controls.Add(this.HelpBtn); 73 | this.flowLayoutPanel1.Controls.Add(this.OKbtn); 74 | this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; 75 | this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft; 76 | this.flowLayoutPanel1.Location = new System.Drawing.Point(7, 76); 77 | this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(7); 78 | this.flowLayoutPanel1.Name = "flowLayoutPanel1"; 79 | this.flowLayoutPanel1.Size = new System.Drawing.Size(564, 33); 80 | this.flowLayoutPanel1.TabIndex = 1; 81 | // 82 | // HelpBtn 83 | // 84 | this.HelpBtn.Location = new System.Drawing.Point(465, 3); 85 | this.HelpBtn.Name = "HelpBtn"; 86 | this.HelpBtn.Size = new System.Drawing.Size(96, 26); 87 | this.HelpBtn.TabIndex = 0; 88 | this.HelpBtn.Text = "Learn more"; 89 | this.HelpBtn.UseVisualStyleBackColor = true; 90 | this.HelpBtn.Click += new System.EventHandler(this.HelpBtn_Click); 91 | // 92 | // OKbtn 93 | // 94 | this.OKbtn.Location = new System.Drawing.Point(363, 3); 95 | this.OKbtn.Name = "OKbtn"; 96 | this.OKbtn.Size = new System.Drawing.Size(96, 26); 97 | this.OKbtn.TabIndex = 1; 98 | this.OKbtn.Text = "Sign in"; 99 | this.OKbtn.UseVisualStyleBackColor = true; 100 | this.OKbtn.Click += new System.EventHandler(this.OKbtn_Click); 101 | // 102 | // HelpDialog 103 | // 104 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 105 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 106 | this.ClientSize = new System.Drawing.Size(578, 116); 107 | this.Controls.Add(this.tableLayoutPanel1); 108 | this.Name = "HelpDialog"; 109 | this.Text = "HelpDialog"; 110 | this.tableLayoutPanel1.ResumeLayout(false); 111 | this.tableLayoutPanel1.PerformLayout(); 112 | this.flowLayoutPanel1.ResumeLayout(false); 113 | this.ResumeLayout(false); 114 | 115 | } 116 | 117 | #endregion 118 | 119 | private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; 120 | private System.Windows.Forms.Label InstractionsLbl; 121 | private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; 122 | private System.Windows.Forms.Button HelpBtn; 123 | private System.Windows.Forms.Button OKbtn; 124 | } 125 | } -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/RenameForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace MigrationSample.Dialogs 2 | { 3 | partial class RenameForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 32 | this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel(); 33 | this.btnOk = new System.Windows.Forms.Button(); 34 | this.btnCancel = new System.Windows.Forms.Button(); 35 | this.txtResult = new System.Windows.Forms.TextBox(); 36 | this.enterNameLbl = new System.Windows.Forms.Label(); 37 | this.tableLayoutPanel1.SuspendLayout(); 38 | this.flowLayoutPanel2.SuspendLayout(); 39 | this.SuspendLayout(); 40 | // 41 | // tableLayoutPanel1 42 | // 43 | this.tableLayoutPanel1.ColumnCount = 1; 44 | this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); 45 | this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel2, 0, 2); 46 | this.tableLayoutPanel1.Controls.Add(this.txtResult, 0, 1); 47 | this.tableLayoutPanel1.Controls.Add(this.enterNameLbl, 0, 0); 48 | this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; 49 | this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); 50 | this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(2); 51 | this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 52 | this.tableLayoutPanel1.RowCount = 3; 53 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); 54 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); 55 | this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 38F)); 56 | this.tableLayoutPanel1.Size = new System.Drawing.Size(350, 90); 57 | this.tableLayoutPanel1.TabIndex = 4; 58 | // 59 | // flowLayoutPanel2 60 | // 61 | this.flowLayoutPanel2.Controls.Add(this.btnOk); 62 | this.flowLayoutPanel2.Controls.Add(this.btnCancel); 63 | this.flowLayoutPanel2.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft; 64 | this.flowLayoutPanel2.Location = new System.Drawing.Point(2, 54); 65 | this.flowLayoutPanel2.Margin = new System.Windows.Forms.Padding(2); 66 | this.flowLayoutPanel2.Name = "flowLayoutPanel2"; 67 | this.flowLayoutPanel2.Size = new System.Drawing.Size(346, 34); 68 | this.flowLayoutPanel2.TabIndex = 3; 69 | // 70 | // btnOk 71 | // 72 | this.btnOk.Location = new System.Drawing.Point(268, 3); 73 | this.btnOk.Name = "btnOk"; 74 | this.btnOk.Size = new System.Drawing.Size(75, 23); 75 | this.btnOk.TabIndex = 1; 76 | this.btnOk.Text = "OK"; 77 | this.btnOk.UseVisualStyleBackColor = true; 78 | this.btnOk.Click += new System.EventHandler(this.btnOk_Click); 79 | // 80 | // btnCancel 81 | // 82 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 83 | this.btnCancel.Location = new System.Drawing.Point(187, 3); 84 | this.btnCancel.Name = "btnCancel"; 85 | this.btnCancel.Size = new System.Drawing.Size(75, 23); 86 | this.btnCancel.TabIndex = 0; 87 | this.btnCancel.Text = "Cancel"; 88 | this.btnCancel.UseVisualStyleBackColor = true; 89 | this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); 90 | // 91 | // txtResult 92 | // 93 | this.txtResult.Location = new System.Drawing.Point(3, 29); 94 | this.txtResult.Name = "txtResult"; 95 | this.txtResult.Size = new System.Drawing.Size(344, 20); 96 | this.txtResult.TabIndex = 1; 97 | // 98 | // enterNameLbl 99 | // 100 | this.enterNameLbl.AutoSize = true; 101 | this.enterNameLbl.Dock = System.Windows.Forms.DockStyle.Fill; 102 | this.enterNameLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 103 | this.enterNameLbl.Location = new System.Drawing.Point(2, 0); 104 | this.enterNameLbl.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); 105 | this.enterNameLbl.Name = "enterNameLbl"; 106 | this.enterNameLbl.Size = new System.Drawing.Size(346, 26); 107 | this.enterNameLbl.TabIndex = 4; 108 | this.enterNameLbl.Text = "Enter New Name"; 109 | this.enterNameLbl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 110 | // 111 | // RenameForm 112 | // 113 | this.AcceptButton = this.btnOk; 114 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 115 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 116 | this.CancelButton = this.btnCancel; 117 | this.ClientSize = new System.Drawing.Size(350, 90); 118 | this.Controls.Add(this.tableLayoutPanel1); 119 | this.Name = "RenameForm"; 120 | this.tableLayoutPanel1.ResumeLayout(false); 121 | this.tableLayoutPanel1.PerformLayout(); 122 | this.flowLayoutPanel2.ResumeLayout(false); 123 | this.ResumeLayout(false); 124 | 125 | } 126 | 127 | #endregion 128 | private System.Windows.Forms.TextBox txtResult; 129 | private System.Windows.Forms.Button btnOk; 130 | private System.Windows.Forms.Button btnCancel; 131 | private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; 132 | private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2; 133 | private System.Windows.Forms.Label enterNameLbl; 134 | } 135 | } -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/MigrationSample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8B4C0E7C-D19F-4EC9-BD3B-BF5CAA6DCEE1} 8 | WinExe 9 | Properties 10 | MigrationWinFormSample 11 | MigrationWinFormSample 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll 37 | True 38 | 39 | 40 | ..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll 41 | True 42 | 43 | 44 | ..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll 45 | True 46 | 47 | 48 | ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll 49 | True 50 | 51 | 52 | ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll 53 | True 54 | 55 | 56 | ..\packages\Microsoft.PowerBI.Api.2.0.1\lib\portable45-net45+win8+wpa81\Microsoft.PowerBI.Api.dll 57 | True 58 | 59 | 60 | ..\packages\Microsoft.PowerBI.Core.1.1.10\lib\net45\Microsoft.PowerBI.Core.dll 61 | True 62 | 63 | 64 | ..\packages\Microsoft.Rest.ClientRuntime.2.0.1\lib\net45\Microsoft.Rest.ClientRuntime.dll 65 | True 66 | 67 | 68 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 69 | True 70 | 71 | 72 | 73 | 74 | 75 | 76 | ..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll 77 | True 78 | 79 | 80 | 81 | 82 | 83 | ..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll 84 | True 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | Form 111 | 112 | 113 | HelpDialog.cs 114 | 115 | 116 | Form 117 | 118 | 119 | RenameForm.cs 120 | 121 | 122 | Component 123 | 124 | 125 | Form 126 | 127 | 128 | SelectResourceGroup.cs 129 | 130 | 131 | Form 132 | 133 | 134 | MainForm.cs 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | Form 146 | 147 | 148 | MigrationTabForm.cs 149 | 150 | 151 | HelpDialog.cs 152 | 153 | 154 | RenameForm.cs 155 | 156 | 157 | SelectResourceGroup.cs 158 | 159 | 160 | MainForm.cs 161 | 162 | 163 | ResXFileCodeGenerator 164 | Resources.Designer.cs 165 | Designer 166 | 167 | 168 | True 169 | Resources.resx 170 | 171 | 172 | MigrationTabForm.cs 173 | 174 | 175 | 176 | SettingsSingleFileGenerator 177 | Settings.Designer.cs 178 | 179 | 180 | True 181 | Settings.settings 182 | True 183 | 184 | 185 | 186 | 187 | Designer 188 | 189 | 190 | 191 | 198 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace MigrationSample 2 | { 3 | partial class MainForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.tabControlMain = new System.Windows.Forms.TabControl(); 32 | this.menuStrip1 = new System.Windows.Forms.MenuStrip(); 33 | this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 34 | this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 35 | this.openMigrationPlanToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 36 | this.saveMigrationPlanToFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 37 | this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 38 | this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 39 | this.startToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 40 | this.analyzePlanMigrationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 41 | this.downloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 42 | this.createGroupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 43 | this.uploadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 44 | this.menuStrip1.SuspendLayout(); 45 | this.SuspendLayout(); 46 | // 47 | // tabControlMain 48 | // 49 | this.tabControlMain.Dock = System.Windows.Forms.DockStyle.Fill; 50 | this.tabControlMain.Location = new System.Drawing.Point(0, 24); 51 | this.tabControlMain.Name = "tabControlMain"; 52 | this.tabControlMain.SelectedIndex = 0; 53 | this.tabControlMain.Size = new System.Drawing.Size(932, 699); 54 | this.tabControlMain.TabIndex = 1; 55 | this.tabControlMain.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tabControlMain_MouseUp); 56 | // 57 | // menuStrip1 58 | // 59 | this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); 60 | this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 61 | this.fileToolStripMenuItem, 62 | this.helpToolStripMenuItem}); 63 | this.menuStrip1.Location = new System.Drawing.Point(0, 0); 64 | this.menuStrip1.Name = "menuStrip1"; 65 | this.menuStrip1.Size = new System.Drawing.Size(932, 24); 66 | this.menuStrip1.TabIndex = 2; 67 | this.menuStrip1.Text = "menuStrip1"; 68 | // 69 | // fileToolStripMenuItem 70 | // 71 | this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 72 | this.newToolStripMenuItem, 73 | this.openMigrationPlanToolStripMenuItem, 74 | this.saveMigrationPlanToFileToolStripMenuItem, 75 | this.saveAsToolStripMenuItem}); 76 | this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; 77 | this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); 78 | this.fileToolStripMenuItem.Text = "File"; 79 | this.fileToolStripMenuItem.Click += new System.EventHandler(this.fileToolStripMenuItem_Click); 80 | // 81 | // newToolStripMenuItem 82 | // 83 | this.newToolStripMenuItem.Name = "newToolStripMenuItem"; 84 | this.newToolStripMenuItem.Size = new System.Drawing.Size(227, 22); 85 | this.newToolStripMenuItem.Text = "New Migration Plan"; 86 | this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); 87 | // 88 | // openMigrationPlanToolStripMenuItem 89 | // 90 | this.openMigrationPlanToolStripMenuItem.Name = "openMigrationPlanToolStripMenuItem"; 91 | this.openMigrationPlanToolStripMenuItem.Size = new System.Drawing.Size(227, 22); 92 | this.openMigrationPlanToolStripMenuItem.Text = "Open Existing Migration Plan"; 93 | this.openMigrationPlanToolStripMenuItem.Click += new System.EventHandler(this.openMigrationPlanToolStripMenuItem_Click); 94 | // 95 | // saveMigrationPlanToFileToolStripMenuItem 96 | // 97 | this.saveMigrationPlanToFileToolStripMenuItem.Name = "saveMigrationPlanToFileToolStripMenuItem"; 98 | this.saveMigrationPlanToFileToolStripMenuItem.Size = new System.Drawing.Size(227, 22); 99 | this.saveMigrationPlanToFileToolStripMenuItem.Text = "Save Migration Plan"; 100 | this.saveMigrationPlanToFileToolStripMenuItem.Click += new System.EventHandler(this.saveMigrationPlanToFileToolStripMenuItem_Click); 101 | // 102 | // saveAsToolStripMenuItem 103 | // 104 | this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; 105 | this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(227, 22); 106 | this.saveAsToolStripMenuItem.Text = "Save Migration Plan As"; 107 | this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click); 108 | // 109 | // helpToolStripMenuItem 110 | // 111 | this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 112 | this.startToolStripMenuItem, 113 | this.analyzePlanMigrationToolStripMenuItem, 114 | this.downloadToolStripMenuItem, 115 | this.createGroupToolStripMenuItem, 116 | this.uploadToolStripMenuItem}); 117 | this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; 118 | this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20); 119 | this.helpToolStripMenuItem.Text = "Help"; 120 | // 121 | // startToolStripMenuItem 122 | // 123 | this.startToolStripMenuItem.Name = "startToolStripMenuItem"; 124 | this.startToolStripMenuItem.Size = new System.Drawing.Size(199, 22); 125 | this.startToolStripMenuItem.Text = "Start"; 126 | this.startToolStripMenuItem.Click += new System.EventHandler(this.startToolStripMenuItem_Click); 127 | // 128 | // analyzePlanMigrationToolStripMenuItem 129 | // 130 | this.analyzePlanMigrationToolStripMenuItem.Name = "analyzePlanMigrationToolStripMenuItem"; 131 | this.analyzePlanMigrationToolStripMenuItem.Size = new System.Drawing.Size(199, 22); 132 | this.analyzePlanMigrationToolStripMenuItem.Text = "Analyze & Plan Migration"; 133 | this.analyzePlanMigrationToolStripMenuItem.Click += new System.EventHandler(this.analyzePlanMigrationToolStripMenuItem_Click); 134 | // 135 | // downloadToolStripMenuItem 136 | // 137 | this.downloadToolStripMenuItem.Name = "downloadToolStripMenuItem"; 138 | this.downloadToolStripMenuItem.Size = new System.Drawing.Size(199, 22); 139 | this.downloadToolStripMenuItem.Text = "Download "; 140 | this.downloadToolStripMenuItem.Click += new System.EventHandler(this.downloadToolStripMenuItem_Click); 141 | // 142 | // createGroupToolStripMenuItem 143 | // 144 | this.createGroupToolStripMenuItem.Name = "createGroupToolStripMenuItem"; 145 | this.createGroupToolStripMenuItem.Size = new System.Drawing.Size(199, 22); 146 | this.createGroupToolStripMenuItem.Text = "Create Group"; 147 | this.createGroupToolStripMenuItem.Click += new System.EventHandler(this.createGroupToolStripMenuItem_Click); 148 | // 149 | // uploadToolStripMenuItem 150 | // 151 | this.uploadToolStripMenuItem.Name = "uploadToolStripMenuItem"; 152 | this.uploadToolStripMenuItem.Size = new System.Drawing.Size(199, 22); 153 | this.uploadToolStripMenuItem.Text = "Upload"; 154 | this.uploadToolStripMenuItem.Click += new System.EventHandler(this.uploadToolStripMenuItem_Click); 155 | // 156 | // MainForm 157 | // 158 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 159 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 160 | this.BackColor = System.Drawing.Color.PowderBlue; 161 | this.ClientSize = new System.Drawing.Size(932, 723); 162 | this.Controls.Add(this.tabControlMain); 163 | this.Controls.Add(this.menuStrip1); 164 | this.MainMenuStrip = this.menuStrip1; 165 | this.Name = "MainForm"; 166 | this.Text = "Migration Sample"; 167 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); 168 | this.Resize += new System.EventHandler(this.MainForm_Resize); 169 | this.menuStrip1.ResumeLayout(false); 170 | this.menuStrip1.PerformLayout(); 171 | this.ResumeLayout(false); 172 | this.PerformLayout(); 173 | 174 | } 175 | 176 | #endregion 177 | private System.Windows.Forms.TabControl tabControlMain; 178 | private System.Windows.Forms.MenuStrip menuStrip1; 179 | private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; 180 | private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem; 181 | private System.Windows.Forms.ToolStripMenuItem openMigrationPlanToolStripMenuItem; 182 | private System.Windows.Forms.ToolStripMenuItem saveMigrationPlanToFileToolStripMenuItem; 183 | private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem; 184 | private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem; 185 | private System.Windows.Forms.ToolStripMenuItem analyzePlanMigrationToolStripMenuItem; 186 | private System.Windows.Forms.ToolStripMenuItem downloadToolStripMenuItem; 187 | private System.Windows.Forms.ToolStripMenuItem createGroupToolStripMenuItem; 188 | private System.Windows.Forms.ToolStripMenuItem uploadToolStripMenuItem; 189 | private System.Windows.Forms.ToolStripMenuItem startToolStripMenuItem; 190 | } 191 | } 192 | 193 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Dialogs/SelectResourceGroup.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace MigrationSample.Dialogs 2 | { 3 | partial class SelectResourceGroup 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.lblEnvironement = new System.Windows.Forms.Label(); 32 | this.comboEnvironment = new System.Windows.Forms.ComboBox(); 33 | this.subscriptinsLbl = new System.Windows.Forms.Label(); 34 | this.SubscriptionsGridView = new System.Windows.Forms.DataGridView(); 35 | this.resourceGroupLbl = new System.Windows.Forms.Label(); 36 | this.comboResourceGroup = new System.Windows.Forms.ComboBox(); 37 | this.selectBtn = new System.Windows.Forms.Button(); 38 | this.mainResoureceGroupTlp = new System.Windows.Forms.TableLayoutPanel(); 39 | this.environementFlp = new System.Windows.Forms.FlowLayoutPanel(); 40 | this.resourceGroupFlp = new System.Windows.Forms.FlowLayoutPanel(); 41 | ((System.ComponentModel.ISupportInitialize)(this.SubscriptionsGridView)).BeginInit(); 42 | this.mainResoureceGroupTlp.SuspendLayout(); 43 | this.environementFlp.SuspendLayout(); 44 | this.resourceGroupFlp.SuspendLayout(); 45 | this.SuspendLayout(); 46 | // 47 | // lblEnvironement 48 | // 49 | this.lblEnvironement.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 50 | this.lblEnvironement.Location = new System.Drawing.Point(3, 0); 51 | this.lblEnvironement.Name = "lblEnvironement"; 52 | this.lblEnvironement.Size = new System.Drawing.Size(114, 23); 53 | this.lblEnvironement.TabIndex = 0; 54 | this.lblEnvironement.Text = "Environment:"; 55 | // 56 | // comboEnvironment 57 | // 58 | this.comboEnvironment.Dock = System.Windows.Forms.DockStyle.Right; 59 | this.comboEnvironment.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 60 | this.environementFlp.SetFlowBreak(this.comboEnvironment, true); 61 | this.comboEnvironment.FormattingEnabled = true; 62 | this.comboEnvironment.Location = new System.Drawing.Point(123, 3); 63 | this.comboEnvironment.Name = "comboEnvironment"; 64 | this.comboEnvironment.Size = new System.Drawing.Size(248, 21); 65 | this.comboEnvironment.TabIndex = 1; 66 | this.comboEnvironment.SelectedIndexChanged += new System.EventHandler(this.comboEnvironment_SelectedIndexChanged); 67 | // 68 | // subscriptinsLbl 69 | // 70 | this.subscriptinsLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 71 | this.subscriptinsLbl.Location = new System.Drawing.Point(3, 30); 72 | this.subscriptinsLbl.Name = "subscriptinsLbl"; 73 | this.subscriptinsLbl.Size = new System.Drawing.Size(91, 24); 74 | this.subscriptinsLbl.TabIndex = 2; 75 | this.subscriptinsLbl.Text = "Subscription:"; 76 | // 77 | // SubscriptionsGridView 78 | // 79 | this.SubscriptionsGridView.AllowUserToAddRows = false; 80 | this.SubscriptionsGridView.AllowUserToDeleteRows = false; 81 | this.SubscriptionsGridView.AllowUserToOrderColumns = true; 82 | this.SubscriptionsGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; 83 | this.SubscriptionsGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 84 | this.SubscriptionsGridView.Dock = System.Windows.Forms.DockStyle.Fill; 85 | this.SubscriptionsGridView.Location = new System.Drawing.Point(3, 63); 86 | this.SubscriptionsGridView.Name = "SubscriptionsGridView"; 87 | this.SubscriptionsGridView.ReadOnly = true; 88 | this.SubscriptionsGridView.Size = new System.Drawing.Size(468, 410); 89 | this.SubscriptionsGridView.TabIndex = 7; 90 | this.SubscriptionsGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); 91 | this.SubscriptionsGridView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SubscriptionsGridView_MouseUp); 92 | // 93 | // resourceGroupLbl 94 | // 95 | this.resourceGroupLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 96 | this.resourceGroupLbl.Location = new System.Drawing.Point(3, 0); 97 | this.resourceGroupLbl.Name = "resourceGroupLbl"; 98 | this.resourceGroupLbl.Size = new System.Drawing.Size(125, 24); 99 | this.resourceGroupLbl.TabIndex = 4; 100 | this.resourceGroupLbl.Text = "Resource Group:"; 101 | // 102 | // comboResourceGroup 103 | // 104 | this.comboResourceGroup.Dock = System.Windows.Forms.DockStyle.Right; 105 | this.comboResourceGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 106 | this.resourceGroupFlp.SetFlowBreak(this.comboResourceGroup, true); 107 | this.comboResourceGroup.FormattingEnabled = true; 108 | this.comboResourceGroup.Location = new System.Drawing.Point(134, 3); 109 | this.comboResourceGroup.Name = "comboResourceGroup"; 110 | this.comboResourceGroup.Size = new System.Drawing.Size(325, 21); 111 | this.comboResourceGroup.TabIndex = 5; 112 | // 113 | // selectBtn 114 | // 115 | this.selectBtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 116 | this.selectBtn.Location = new System.Drawing.Point(3, 509); 117 | this.selectBtn.Name = "selectBtn"; 118 | this.selectBtn.Size = new System.Drawing.Size(286, 23); 119 | this.selectBtn.TabIndex = 6; 120 | this.selectBtn.Text = "Select"; 121 | this.selectBtn.UseVisualStyleBackColor = true; 122 | this.selectBtn.Click += new System.EventHandler(this.btnSelect_Click); 123 | // 124 | // mainResoureceGroupTlp 125 | // 126 | this.mainResoureceGroupTlp.ColumnCount = 1; 127 | this.mainResoureceGroupTlp.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); 128 | this.mainResoureceGroupTlp.Controls.Add(this.subscriptinsLbl, 0, 1); 129 | this.mainResoureceGroupTlp.Controls.Add(this.SubscriptionsGridView, 0, 2); 130 | this.mainResoureceGroupTlp.Controls.Add(this.selectBtn, 0, 4); 131 | this.mainResoureceGroupTlp.Controls.Add(this.environementFlp, 0, 0); 132 | this.mainResoureceGroupTlp.Controls.Add(this.resourceGroupFlp, 0, 3); 133 | this.mainResoureceGroupTlp.Dock = System.Windows.Forms.DockStyle.Fill; 134 | this.mainResoureceGroupTlp.Location = new System.Drawing.Point(0, 0); 135 | this.mainResoureceGroupTlp.Name = "mainResoureceGroupTlp"; 136 | this.mainResoureceGroupTlp.RowCount = 5; 137 | this.mainResoureceGroupTlp.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); 138 | this.mainResoureceGroupTlp.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); 139 | this.mainResoureceGroupTlp.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); 140 | this.mainResoureceGroupTlp.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); 141 | this.mainResoureceGroupTlp.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); 142 | this.mainResoureceGroupTlp.Size = new System.Drawing.Size(474, 536); 143 | this.mainResoureceGroupTlp.TabIndex = 1; 144 | // 145 | // environementFlp 146 | // 147 | this.environementFlp.Controls.Add(this.lblEnvironement); 148 | this.environementFlp.Controls.Add(this.comboEnvironment); 149 | this.environementFlp.Dock = System.Windows.Forms.DockStyle.Fill; 150 | this.environementFlp.Location = new System.Drawing.Point(3, 3); 151 | this.environementFlp.Name = "environementFlp"; 152 | this.environementFlp.Size = new System.Drawing.Size(468, 24); 153 | this.environementFlp.TabIndex = 8; 154 | // 155 | // resourceGroupFlp 156 | // 157 | this.resourceGroupFlp.Controls.Add(this.resourceGroupLbl); 158 | this.resourceGroupFlp.Controls.Add(this.comboResourceGroup); 159 | this.resourceGroupFlp.Dock = System.Windows.Forms.DockStyle.Fill; 160 | this.resourceGroupFlp.Location = new System.Drawing.Point(3, 479); 161 | this.resourceGroupFlp.Name = "resourceGroupFlp"; 162 | this.resourceGroupFlp.Size = new System.Drawing.Size(468, 24); 163 | this.resourceGroupFlp.TabIndex = 9; 164 | // 165 | // SelectResourceGroup 166 | // 167 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 168 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 169 | this.ClientSize = new System.Drawing.Size(474, 536); 170 | this.Controls.Add(this.mainResoureceGroupTlp); 171 | this.Name = "SelectResourceGroup"; 172 | this.Text = "Select Power BI Workspace Collections Resource Group"; 173 | this.Load += new System.EventHandler(this.SelectResourceGroup_Load); 174 | ((System.ComponentModel.ISupportInitialize)(this.SubscriptionsGridView)).EndInit(); 175 | this.mainResoureceGroupTlp.ResumeLayout(false); 176 | this.environementFlp.ResumeLayout(false); 177 | this.resourceGroupFlp.ResumeLayout(false); 178 | this.ResumeLayout(false); 179 | 180 | } 181 | 182 | #endregion 183 | private System.Windows.Forms.Label lblEnvironement; 184 | private System.Windows.Forms.ComboBox comboEnvironment; 185 | private System.Windows.Forms.Label subscriptinsLbl; 186 | private System.Windows.Forms.Label resourceGroupLbl; 187 | private System.Windows.Forms.ComboBox comboResourceGroup; 188 | private System.Windows.Forms.Button selectBtn; 189 | private System.Windows.Forms.DataGridView SubscriptionsGridView; 190 | private System.Windows.Forms.FlowLayoutPanel environementFlp; 191 | private System.Windows.Forms.FlowLayoutPanel resourceGroupFlp; 192 | private System.Windows.Forms.TableLayoutPanel mainResoureceGroupTlp; 193 | } 194 | } -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/MainForm.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Configuration; 5 | using System.Diagnostics; 6 | using System.Drawing; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Windows.Forms; 10 | using MigrationSample.Core; 11 | using MigrationSample.Dialogs; 12 | 13 | namespace MigrationSample 14 | { 15 | public partial class MainForm : Form 16 | { 17 | private class MenuItemActions { 18 | public const string DeleteTab = "Delete Tab"; 19 | public const string RenameTab = "Rename Tab"; 20 | } 21 | 22 | public static Form MainControl { get; private set; } 23 | 24 | private SelectResourceGroup SelectResourceGroupDialog { get; set; } 25 | 26 | public MainForm() 27 | { 28 | InitializeComponent(); 29 | 30 | MainControl = this; 31 | 32 | LoadAppData(); 33 | } 34 | 35 | public ResourceGroupTabPage AddTab(MigrationPlan migrationPlan, string migrationPlanFilePath) 36 | { 37 | var tabForm = new MigrationTabForm(migrationPlan, migrationPlanFilePath); 38 | var page = new ResourceGroupTabPage(tabForm); 39 | 40 | AddPage(page, tabForm.DisplayName); 41 | 42 | return page; 43 | } 44 | 45 | public ResourceGroupTabPage AddTab(PBIProvisioningContext context) 46 | { 47 | var page = new ResourceGroupTabPage(new MigrationTabForm(context)); 48 | 49 | AddPage(page, context.DisplayName); 50 | 51 | return page; 52 | } 53 | 54 | private void AddPage(ResourceGroupTabPage page, string displayText) 55 | { 56 | this.tabControlMain.TabPages.Add(page); 57 | page.Text = displayText; 58 | 59 | this.tabControlMain.SelectedIndex = this.tabControlMain.TabCount - 1; 60 | 61 | page.BackColor = Color.PowderBlue; 62 | } 63 | 64 | private void SaveTabsToAppData() 65 | { 66 | var migrationPlanFiles = new List(); 67 | 68 | foreach (var page in this.tabControlMain.TabPages) 69 | { 70 | string path = (page as ResourceGroupTabPage).GetMigrationPlanFile(); 71 | if (path != null) 72 | { 73 | migrationPlanFiles.Add(path); 74 | } 75 | } 76 | 77 | MigrationWinFormSample.Properties.Settings.Default.Tabs = JsonConvert.SerializeObject(migrationPlanFiles); 78 | MigrationWinFormSample.Properties.Settings.Default.OpenedTab = tabControlMain.SelectedIndex; 79 | MigrationWinFormSample.Properties.Settings.Default.Save(); 80 | } 81 | 82 | private void LoadAppData() 83 | { 84 | var settingsPath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; 85 | if (!File.Exists(settingsPath)) 86 | { 87 | return; 88 | } 89 | 90 | AzureTokenManager.LoadAppData(); 91 | 92 | var filePaths = 93 | JsonConvert.DeserializeObject>(MigrationWinFormSample.Properties.Settings.Default.Tabs); 94 | 95 | if (filePaths == null || !filePaths.Any()) 96 | { 97 | return; 98 | } 99 | 100 | foreach (var filePath in filePaths) 101 | { 102 | if (!File.Exists(filePath)) 103 | { 104 | MessageBox.Show($"The file {filePath} does not exist", "Failed to read Migration Plan", MessageBoxButtons.OK, MessageBoxIcon.Error); 105 | } 106 | else 107 | { 108 | TryAddTab(filePath); 109 | } 110 | } 111 | 112 | tabControlMain.SelectedIndex = MigrationWinFormSample.Properties.Settings.Default.OpenedTab; 113 | } 114 | 115 | private void TryAddTab(string filePath) 116 | { 117 | var migrationPlan = MigrationPlan.Load(filePath); 118 | 119 | if (migrationPlan == null) 120 | { 121 | MessageBox.Show($"Failed to read Migration Plan from: {filePath}"); 122 | return; 123 | } 124 | 125 | AddTab(migrationPlan, filePath); 126 | } 127 | 128 | /// 129 | /// When user right clicks one of the tabs in the tabControlMain, show context menu options 130 | /// current options are: Delete Tab and Rename Tab 131 | /// 132 | /// 133 | /// 134 | private void tabControlMain_MouseUp(object sender, MouseEventArgs e) 135 | { 136 | // check if the right mouse button was pressed 137 | if (e.Button == MouseButtons.Right) 138 | { 139 | // iterate through all the tab pages 140 | for (int i = 0; i < tabControlMain.TabCount; i++) 141 | { 142 | // get their rectangle area and check if it contains the mouse cursor 143 | Rectangle r = tabControlMain.GetTabRect(i); 144 | if (r.Contains(e.Location)) 145 | { 146 | ContextMenuStrip contexMenu = new ContextMenuStrip(); 147 | 148 | foreach (var action in new List{ 149 | MenuItemActions.DeleteTab, 150 | MenuItemActions.RenameTab 151 | }) 152 | { 153 | contexMenu.Items.Add(action).Tag = tabControlMain.TabPages[i]; 154 | } 155 | 156 | contexMenu.Show(this, new Point(r.Right + this.tabControlMain.Left, r.Bottom + this.tabControlMain.Top)); 157 | contexMenu.ItemClicked += new ToolStripItemClickedEventHandler(contextMenuStrip1_ItemClicked); 158 | } 159 | } 160 | } 161 | } 162 | 163 | private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) 164 | { 165 | ToolStripItem item = e.ClickedItem; 166 | var page = item.Tag as ResourceGroupTabPage; 167 | 168 | if (string.Equals(item.Text, MenuItemActions.DeleteTab)) 169 | { 170 | tabControlMain.TabPages.Remove(page); 171 | } 172 | else if (string.Equals(item.Text, MenuItemActions.RenameTab)) 173 | { 174 | var renameForm = new RenameForm(page.Text); 175 | renameForm.Text = "Rename Tab Form"; 176 | 177 | var dialogResult = renameForm.ShowDialog(this); 178 | if (dialogResult != DialogResult.OK) 179 | { 180 | return; 181 | } 182 | 183 | var result = renameForm.Result; 184 | 185 | page.SetDisplayName(result); 186 | } 187 | } 188 | 189 | private void newToolStripMenuItem_Click(object sender, EventArgs e) 190 | { 191 | if (SelectResourceGroupDialog == null) 192 | { 193 | SelectResourceGroupDialog = new SelectResourceGroup(); 194 | } 195 | 196 | SelectResourceGroupDialog.TargetTabPage = null; 197 | 198 | SelectResourceGroupDialog.ShowDialog(this); 199 | } 200 | 201 | private void MainForm_FormClosing(object sender, FormClosingEventArgs e) 202 | { 203 | AzureTokenManager.SetAppData(); 204 | 205 | SaveTabsToAppData(); 206 | 207 | MigrationWinFormSample.Properties.Settings.Default.Save(); 208 | } 209 | 210 | private void personalSettingsToolStripMenuItem_Click(object sender, EventArgs e) 211 | { 212 | var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; 213 | 214 | if (!File.Exists(path)) 215 | { 216 | MessageBox.Show($"Configuration Directory {path} has not been created yet. It is created and updated when the Application is closed."); 217 | return; 218 | } 219 | 220 | Process.Start(Path.GetDirectoryName(path)); 221 | } 222 | 223 | private string SelectFileToOpen(string initialDirectory = null) 224 | { 225 | OpenFileDialog chooseFileDialog = new OpenFileDialog(); 226 | chooseFileDialog.Filter = "XML file|*.xml"; 227 | chooseFileDialog.FilterIndex = 1; 228 | chooseFileDialog.Title = "Select Migration Plan File"; 229 | chooseFileDialog.Multiselect = false; 230 | 231 | if (initialDirectory != null) 232 | { 233 | chooseFileDialog.InitialDirectory = initialDirectory; 234 | } 235 | 236 | if (chooseFileDialog.ShowDialog() == DialogResult.OK) 237 | { 238 | return chooseFileDialog.FileName; 239 | } 240 | 241 | return null; 242 | } 243 | 244 | private void openMigrationPlanToolStripMenuItem_Click(object sender, EventArgs e) 245 | { 246 | var filePath = SelectFileToOpen(); 247 | 248 | if (filePath != null) 249 | { 250 | TryAddTab(filePath); 251 | } 252 | } 253 | 254 | public static string SelectFileToSave(string initDirectory, string defaultFileName) 255 | { 256 | SaveFileDialog saveFileDialog = new SaveFileDialog(); 257 | saveFileDialog.Filter = "XML file|*.xml"; 258 | saveFileDialog.Title = "Select Migration Plan File"; 259 | saveFileDialog.DefaultExt = "xml"; 260 | saveFileDialog.InitialDirectory = initDirectory; 261 | saveFileDialog.FileName = defaultFileName; 262 | var result = saveFileDialog.ShowDialog(); 263 | 264 | if (result == DialogResult.OK) 265 | { 266 | return saveFileDialog.FileName; 267 | } 268 | 269 | return null; 270 | } 271 | 272 | private void openMigrationRootFolderToolStripMenuItem_Click(object sender, EventArgs e) 273 | { 274 | string migrationRoot = ConfigurationManager.AppSettings["MigrationRoot"]; 275 | 276 | if (!File.Exists(migrationRoot)) 277 | { 278 | MessageBox.Show($"Migration Root {migrationRoot} has not been created yet."); 279 | } 280 | 281 | Process.Start(ConfigurationManager.AppSettings["MigrationRoot"]); 282 | } 283 | 284 | private void saveMigrationPlanToFileToolStripMenuItem_Click(object sender, EventArgs e) 285 | { 286 | if (this.tabControlMain.SelectedTab == null) 287 | { 288 | MessageBox.Show("There is no Migration Plan to save"); 289 | return; 290 | } 291 | 292 | var page = (ResourceGroupTabPage)this.tabControlMain.SelectedTab; 293 | 294 | page.SaveMigrationPlan(); 295 | } 296 | 297 | private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) 298 | { 299 | if (this.tabControlMain.SelectedTab == null) 300 | { 301 | MessageBox.Show("There is no Migration Plan to save"); 302 | return; 303 | } 304 | 305 | var page = (ResourceGroupTabPage)this.tabControlMain.SelectedTab; 306 | 307 | page.SaveMigrationPlanAs(); 308 | } 309 | 310 | private void fileToolStripMenuItem_Click(object sender, EventArgs e) 311 | { 312 | var fileMenu = (sender as ToolStripMenuItem); 313 | 314 | bool enableSave = tabControlMain.TabPages.Count != 0; 315 | 316 | fileMenu.DropDownItems[2].Enabled = enableSave; 317 | fileMenu.DropDownItems[3].Enabled = enableSave; 318 | } 319 | 320 | private void analyzePlanMigrationToolStripMenuItem_Click(object sender, EventArgs e) 321 | { 322 | Process.Start("https://powerbi.microsoft.com/documentation/powerbi-developer-migrate-tool/#step-1-analyze-amp-plan-migration"); 323 | } 324 | 325 | private void downloadToolStripMenuItem_Click(object sender, EventArgs e) 326 | { 327 | Process.Start("https://powerbi.microsoft.com/documentation/powerbi-developer-migrate-tool/#step-2-download"); 328 | } 329 | 330 | private void createGroupToolStripMenuItem_Click(object sender, EventArgs e) 331 | { 332 | Process.Start("https://powerbi.microsoft.com/documentation/powerbi-developer-migrate-tool/#step-3-create-groups"); 333 | } 334 | 335 | private void uploadToolStripMenuItem_Click(object sender, EventArgs e) 336 | { 337 | Process.Start("https://powerbi.microsoft.com/documentation/powerbi-developer-migrate-tool/#step-4-upload"); 338 | } 339 | 340 | private void startToolStripMenuItem_Click(object sender, EventArgs e) 341 | { 342 | Process.Start("https://powerbi.microsoft.com/documentation/powerbi-developer-migrate-tool"); 343 | } 344 | 345 | private void MainForm_Resize(object sender, EventArgs e) 346 | { 347 | foreach (var page in tabControlMain.TabPages) 348 | { 349 | ((ResourceGroupTabPage)page).ResizeItemSize(); 350 | } 351 | } 352 | } 353 | } 354 | -------------------------------------------------------------------------------- /MigrationSample/MigrationWinFormSample/Core/PaaSController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.IdentityModel.Clients.ActiveDirectory; 2 | using Microsoft.PowerBI.Api.V1; 3 | using Microsoft.PowerBI.Api.V1.Models; 4 | using Microsoft.Rest; 5 | using Microsoft.Rest.Serialization; 6 | using Newtonsoft.Json; 7 | using Newtonsoft.Json.Linq; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Configuration; 11 | using System.Data; 12 | using System.Linq; 13 | using System.Net; 14 | using System.Net.Http; 15 | using System.Net.Http.Headers; 16 | using System.Threading.Tasks; 17 | using MigrationSample.Models; 18 | using System.IO; 19 | using MigrationSample.Model; 20 | 21 | namespace MigrationSample.Core 22 | { 23 | public class PaaSController 24 | { 25 | private static readonly string version = "?api-version=2016-01-29"; 26 | private static readonly string clientId = "ea0616ba-638b-4df5-95b9-636659ae5121"; 27 | private static readonly Uri redirectUri = new Uri("urn:ietf:wg:oauth:2.0:oob"); 28 | 29 | private static Dictionary accessKeysPerWSC = new Dictionary(); 30 | 31 | public PBIProvisioningContext Context { get; set; } 32 | 33 | private string TenantsUrl 34 | { 35 | get 36 | { 37 | return ConfigurationManager.AppSettings["tenantsUrl"]; 38 | } 39 | } 40 | 41 | private string SubscriptionsUrl 42 | { 43 | get 44 | { 45 | return ConfigurationManager.AppSettings["subscriptionsUrl"]; 46 | } 47 | } 48 | 49 | private string ArmResource 50 | { 51 | get 52 | { 53 | return ConfigurationManager.AppSettings["armResource"]; 54 | } 55 | } 56 | 57 | private string ApiEndpointUri { 58 | get 59 | { 60 | return ConfigurationManager.AppSettings[string.Format("{0}-apiEndpointUri", Context.Environment)]; 61 | } 62 | } 63 | 64 | public PaaSController(PBIProvisioningContext context) 65 | { 66 | this.Context = context; 67 | } 68 | 69 | public void SetAzureToken(AuthenticationResult authenticationResult) 70 | { 71 | AzureTokenManager.SetAzureToken(authenticationResult, Context.Environment); 72 | } 73 | 74 | public async Task GetResourceGroups() 75 | { 76 | if (Context.Subscription != null) 77 | { 78 | return await GetFromUrl(string.Format("{0}/subscriptions/{1}/resourcegroups{2}", GetAzureEndpointUrl(), Context.Subscription.Id, "?api-version=2016-09-01")); 79 | } 80 | return null; 81 | } 82 | 83 | public string GetAzureToken() 84 | { 85 | return AzureTokenManager.GetAzureToken(Context.Environment); 86 | } 87 | 88 | public async Task> ExportToFile(string workspaceId, string reportId, string path) 89 | { 90 | using (var client = await CreateAppKeyClient()) 91 | { 92 | var response = await client.Reports.ExportReportWithHttpMessagesAsync(Context.WorkspaceCollection.Name, workspaceId, reportId); 93 | 94 | if (response.Response.StatusCode == HttpStatusCode.OK) 95 | { 96 | var stream = await response.Response.Content.ReadAsStreamAsync(); 97 | 98 | using (FileStream fileStream = File.Create(path)) 99 | { 100 | stream.CopyTo(fileStream); 101 | fileStream.Close(); 102 | } 103 | } 104 | 105 | return response; 106 | } 107 | } 108 | 109 | public async Task> GetRelevantWorkspaceCollections() 110 | { 111 | IList wscs = (await GetWorkspaceCollections()).Value; 112 | 113 | string dxtLocation = ConfigurationManager.AppSettings["dxt-location-friendly"]; 114 | string msitLocation = ConfigurationManager.AppSettings["msit-location-friendly"]; 115 | 116 | if (Context.Environment.Equals(MigrationEnvironment.prod)) 117 | { 118 | return wscs.Where(wsc => (!wsc.Location.Equals(dxtLocation)) && (!wsc.Location.Equals(msitLocation))).ToList(); 119 | } 120 | else if (Context.Environment.Equals(MigrationEnvironment.msit)) 121 | { 122 | return wscs.Where(wsc => wsc.Location.Equals(msitLocation)).ToList(); 123 | } 124 | else if (Context.Environment.Equals(MigrationEnvironment.dxt)) 125 | { 126 | return wscs.Where(wsc => wsc.Location.Equals(dxtLocation)).ToList(); 127 | } 128 | else 129 | { 130 | return wscs; 131 | } 132 | } 133 | 134 | public async Task GetWorkspaceCollections() 135 | { 136 | var responseContent = await GetWorkspaceCollectionsJson(); 137 | if (string.IsNullOrEmpty(responseContent)) 138 | { 139 | return null; 140 | } 141 | 142 | return JsonConvert.DeserializeObject(responseContent); 143 | } 144 | 145 | private async Task GetWorkspaceCollectionsJson() 146 | { 147 | var url = string.Format("{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.PowerBI/workspaceCollections{3}", 148 | GetAzureEndpointUrl(), Context.Subscription.Id, Context.ResourceGroupName, version); 149 | HttpClient client = new HttpClient(); 150 | 151 | using (client) 152 | { 153 | var request = new HttpRequestMessage(HttpMethod.Get, url); 154 | // Set authorization header from you acquired Azure AD token 155 | request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await GetAzureAccessTokenAsync()); 156 | var response = await client.SendAsync(request); 157 | 158 | if (response.StatusCode != HttpStatusCode.OK) 159 | { 160 | var message = await response.Content.ReadAsStringAsync(); 161 | throw new Exception(message); 162 | } 163 | 164 | var json = await response.Content.ReadAsStringAsync(); 165 | return json; 166 | } 167 | } 168 | 169 | public async Task GetSubscriptions() 170 | { 171 | return await GetFromUrl(SubscriptionsUrl); 172 | } 173 | 174 | /// 175 | /// Gets a list of Power BI Workspace Collections workspaces within the specified collection 176 | /// 177 | /// The Power BI workspace collection name 178 | /// 179 | public async Task> GetWorkspaces() 180 | { 181 | using (var client = await CreateAppKeyClient()) 182 | { 183 | var response = await client.Workspaces.GetWorkspacesByCollectionNameAsync(Context.WorkspaceCollection.Name); 184 | return response.Value; 185 | } 186 | } 187 | 188 | public async Task GetDatasources(string datasetId) 189 | { 190 | using (var client = await CreateAppKeyClient()) 191 | { 192 | try 193 | { 194 | return client.Datasets.GetDatasources(Context.WorkspaceCollection.Name, Context.WorkspaceId, datasetId); 195 | } 196 | catch 197 | { 198 | return null; 199 | } 200 | } 201 | } 202 | 203 | public async Task GetImports() 204 | { 205 | using (var client = await CreateAppKeyClient()) 206 | { 207 | return await client.Imports.GetImportsAsync(Context.WorkspaceCollection.Name, Context.WorkspaceId); 208 | } 209 | } 210 | 211 | public async Task> GetDatasets() 212 | { 213 | using (var client = await CreateAppKeyClient()) 214 | { 215 | var response = await client.Datasets.GetDatasetsAsync(Context.WorkspaceCollection.Name, Context.WorkspaceId); 216 | return response.Value; 217 | } 218 | } 219 | 220 | public async Task> GetReports() 221 | { 222 | using (var client = await CreateAppKeyClient()) 223 | { 224 | var response = await client.Reports.GetReportsAsync(Context.WorkspaceCollection.Name, Context.WorkspaceId); 225 | return response.Value; 226 | } 227 | } 228 | 229 | public async Task GetAccessKeys() 230 | { 231 | if (!accessKeysPerWSC.ContainsKey(Context.WorkspaceCollection.Name)) 232 | { 233 | accessKeysPerWSC[Context.WorkspaceCollection.Name] = await ListWorkspaceCollectionKeys(); 234 | } 235 | 236 | return accessKeysPerWSC[Context.WorkspaceCollection.Name]; 237 | } 238 | 239 | private async Task CreateAppKeyClient() 240 | { 241 | // Create a token credentials with "AppKey" type 242 | var credentials = new TokenCredentials((await GetAccessKeys()).Key1, "AppKey"); 243 | 244 | // Instantiate your Power BI client passing in the required credentials 245 | var client = new PowerBIClient(credentials); 246 | 247 | // Override the api endpoint base URL. Default value is https://api.powerbi.com 248 | client.BaseUri = new Uri(ApiEndpointUri); 249 | 250 | return client; 251 | } 252 | 253 | private async Task GetFromUrl(string url) 254 | { 255 | HttpClient client = new HttpClient(); 256 | 257 | using (client) 258 | { 259 | var request = new HttpRequestMessage(HttpMethod.Get, url); 260 | // Set authorization header from you acquired Azure AD token 261 | request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await GetAzureAccessTokenAsync()); 262 | var response = await client.SendAsync(request); 263 | 264 | if (response.StatusCode != HttpStatusCode.OK) 265 | { 266 | var message = await response.Content.ReadAsStringAsync(); 267 | throw new Exception(message); 268 | } 269 | 270 | var json = await response.Content.ReadAsStringAsync(); 271 | return json; 272 | } 273 | } 274 | 275 | private async Task GetAzureAccessTokenAsync() 276 | { 277 | if (!string.IsNullOrWhiteSpace(GetAzureToken())) 278 | { 279 | return GetAzureToken(); 280 | } 281 | 282 | var commonToken = GetCommonAzureAccessToken(); 283 | var tenantId = (await GetTenantIdsAsync(commonToken.AccessToken)).FirstOrDefault(); 284 | 285 | if (string.IsNullOrWhiteSpace(tenantId)) 286 | { 287 | throw new InvalidOperationException("Unable to get tenant id for user account"); 288 | } 289 | 290 | var authority = string.Format("{0}/{1}/oauth2/authorize", GetWindowsLoginUrl(), tenantId); 291 | var authContext = new AuthenticationContext(authority); 292 | var authenticationResult = await authContext.AcquireTokenByRefreshTokenAsync(commonToken.RefreshToken, clientId, ArmResource); 293 | 294 | SetAzureToken(authenticationResult); 295 | 296 | return authenticationResult.AccessToken; 297 | } 298 | 299 | private async Task> GetTenantIdsAsync(string commonToken) 300 | { 301 | using (var httpClient = new HttpClient()) 302 | { 303 | httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + commonToken); 304 | 305 | var response = await httpClient.GetStringAsync(TenantsUrl); 306 | 307 | var tenantsJson = JsonConvert.DeserializeObject(response); 308 | var tenants = tenantsJson["value"] as JArray; 309 | 310 | return tenants.Select(t => t["tenantId"].Value()); 311 | } 312 | } 313 | 314 | private AuthenticationResult GetCommonAzureAccessToken() 315 | { 316 | string urlPattern = "{0}/common/oauth2/authorize"; 317 | 318 | var authContext = new AuthenticationContext(string.Format(urlPattern, GetWindowsLoginUrl())); 319 | 320 | AuthenticationResult result = authContext.AcquireToken( 321 | resource: ArmResource, 322 | clientId: clientId, 323 | redirectUri: redirectUri, 324 | promptBehavior: PaaSAuthPromptBehavior()); 325 | 326 | if (result == null) 327 | { 328 | throw new InvalidOperationException("Failed to obtain the JWT token"); 329 | } 330 | 331 | return result; 332 | } 333 | 334 | private string GetAzureEndpointUrl() 335 | { 336 | return ConfigurationManager.AppSettings[string.Format("{0}-azureApiEndpoint", Context.Environment)]; 337 | } 338 | 339 | private string GetWindowsLoginUrl() 340 | { 341 | return ConfigurationManager.AppSettings["loginWindowsUrl"]; 342 | } 343 | 344 | private PromptBehavior PaaSAuthPromptBehavior() 345 | { 346 | if (ConfigurationManager.AppSettings["PaaSAuthPromptBehavior"] == "Always") 347 | { 348 | return PromptBehavior.Always; 349 | } 350 | return PromptBehavior.Auto; 351 | } 352 | 353 | /// 354 | /// Gets the workspace collection access keys for the specified collection 355 | /// 356 | /// The azure subscription id 357 | /// The azure resource group 358 | /// The Power BI workspace collection name 359 | /// 360 | private async Task ListWorkspaceCollectionKeys() 361 | { 362 | var url = string.Format("{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.PowerBI/workspaceCollections/{3}/listkeys{4}", 363 | GetAzureEndpointUrl(), 364 | Context.Subscription.Id, 365 | Context.ResourceGroupName, 366 | Context.WorkspaceCollection.Name, 367 | version); 368 | 369 | HttpClient client = new HttpClient(); 370 | 371 | using (client) 372 | { 373 | var request = new HttpRequestMessage(HttpMethod.Post, url); 374 | // Set authorization header from you acquired Azure AD token 375 | request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await GetAzureAccessTokenAsync()); 376 | 377 | request.Content = new StringContent(string.Empty); 378 | var response = await client.SendAsync(request); 379 | 380 | if (response.StatusCode != HttpStatusCode.OK) 381 | { 382 | var responseText = await response.Content.ReadAsStringAsync(); 383 | var message = string.Format("Status: {0}, Reason: {1}, Message: {2}", response.StatusCode, response.ReasonPhrase, responseText); 384 | throw new Exception(message); 385 | } 386 | 387 | var json = await response.Content.ReadAsStringAsync(); 388 | return SafeJsonConvert.DeserializeObject(json); 389 | } 390 | } 391 | } 392 | } 393 | --------------------------------------------------------------------------------