Пример #1
0
        protected override void ProcessRecord()
        {
            //base.ProcessRecord();

            WriteObject($"{Ansi.Color.Foreground.LightCyan}** CLEAR model **{Ansi.Color.Foreground.Default}");
            var pbiConnection = new PbiConnection
            {
                TenantId     = Tenant,
                PrincipalId  = Principal,
                ClientSecret = Secret
            };

            pbiConnection.Open().Wait();

            List <string> ClearedTables = new List <string>();

            var groupId       = new Guid(Group);
            var clearedTables = (!string.IsNullOrWhiteSpace(DatasetId))
                ? pbiConnection.ClearPushDataset(groupId, new Guid(DatasetId), LogClearedTable).Result
                : pbiConnection.ClearPushDataset(groupId, DatasetName, LogClearedTable).Result;

            foreach (var t in ClearedTables)
            {
                WriteObject($"{Ansi.Color.Foreground.LightGreen}  Cleared {t} {Ansi.Color.Foreground.Default}");
            }
            WriteObject($"{Ansi.Color.Foreground.LightCyan}Cleared {clearedTables?.Count} tables.{Ansi.Color.Foreground.Default}");

            void LogClearedTable(string t)
            {
                // Implementation issue - we cannot write output during async calls
                ClearedTables.Add(t);
            }
        }
Пример #2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            WriteObject($"{Ansi.Color.Foreground.LightCyan}** REFRESH model executing {Dax?.Name} script**{Ansi.Color.Foreground.Default}");
            if (!Dax.Exists)
            {
                WriteObject($"{Ansi.Color.Foreground.LightRed}DAX file {Dax?.FullName} not found.{Ansi.Color.Foreground.Default}");
                return;
            }

            var pbiConnection = new PbiConnection
            {
                TenantId     = Tenant,
                PrincipalId  = Principal,
                ClientSecret = Secret,

                ClientId = Client,
                Username = Username,
                Password = Password
            };

            pbiConnection.Open().Wait();

            string daxQueries    = File.ReadAllText(Dax.FullName);
            var    groupId       = new Guid(Group);
            var    refreshTables = (!string.IsNullOrWhiteSpace(DatasetId))
                ? pbiConnection.RefreshWithDax(groupId, new Guid(DatasetId), ReadFromWorkspace, ReadFromDatabase, daxQueries, null).Result
                : pbiConnection.RefreshWithDax(groupId, DatasetName, ReadFromWorkspace, ReadFromDatabase, daxQueries, null).Result;

            WriteObject($"{Ansi.Color.Foreground.LightCyan}Refreshed {refreshTables?.Count} tables.{Ansi.Color.Foreground.Default}");
            foreach (var table in refreshTables)
            {
                WriteObject($"{Ansi.Color.Foreground.Cyan}    {table.Item1} ({table.Item2} rows){Ansi.Color.Foreground.Default}");
            }

            /*
             * Async calls to WriteObject not supported
             * LogRefresh could be used as refreshingTable argument
             * of RefreshWithDax to display refresh progress
             *
             * void LogRefresh(string tableName, int rows)
             * {
             *  if (rows < 0)
             *  {
             *      WriteObject($"{Ansi.Color.Foreground.Green}  Refreshing {tableName}  {Ansi.Color.Foreground.Default}");
             *  }
             *  else
             *  {
             *      WriteObject($"{Ansi.Color.Foreground.LightGreen}  Written {rows} rows to {tableName}  {Ansi.Color.Foreground.Default}");
             *  }
             * }
             */
        }
Пример #3
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            WriteObject($"{Ansi.Color.Foreground.LightCyan}** SIMULATE real-time updates using {Configuration?.Name} configuration**{Ansi.Color.Foreground.Default}");

            if (!Configuration.Exists)
            {
                WriteObject($"{Ansi.Color.Foreground.LightRed}Configuration file {Configuration?.FullName} not found.{Ansi.Color.Foreground.Default}");
                return;
            }

            Simulator simulator = Simulator.ReadParameters(Configuration.FullName);

            var pbiConnection = new PbiConnection
            {
                TenantId     = Tenant,
                PrincipalId  = Principal,
                ClientSecret = Secret
            };

            pbiConnection.Open().Wait();
            var groupId = new Guid(Group);

            bool loopSimulation = true;

            do
            {
                var pushedTables = (!string.IsNullOrWhiteSpace(DatasetId))
                    ? pbiConnection.PushSimulation(groupId, new Guid(DatasetId), simulator).Result
                    : pbiConnection.PushSimulation(groupId, DatasetName, simulator).Result;

                WriteObject($"{Ansi.Color.Foreground.LightCyan}Pushed data in {pushedTables?.Count} tables.{Ansi.Color.Foreground.Default}");
                foreach (var table in pushedTables)
                {
                    WriteObject($"{Ansi.Color.Foreground.Cyan}    {table.Item1} ({table.Item2} rows){Ansi.Color.Foreground.Default}");
                }

                WriteObject($"Waiting {simulator.Parameters.BatchInterval} seconds - press X to stop.");
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                while (sw.ElapsedMilliseconds < simulator.Parameters.BatchInterval * 1000)
                {
                    if (Stopping || Console.KeyAvailable && (Console.ReadKey(true).Key == ConsoleKey.X))
                    {
                        loopSimulation = false;
                        break;
                    }
                    System.Threading.Thread.Sleep(250);
                }
            }while (loopSimulation);

            WriteObject($"{Ansi.Color.Foreground.White}Simulation stopped.{Ansi.Color.Foreground.Default}");
        }
Пример #4
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            WriteObject($"{Ansi.Color.Foreground.LightCyan}** ALTER model **{Ansi.Color.Foreground.Default}");
            if (!Model.Exists)
            {
                WriteObject($"{Ansi.Color.Foreground.LightRed}Model file {Model?.FullName} not found.{Ansi.Color.Foreground.Default}");
                return;
            }

            var pbiConnection = new PbiConnection
            {
                TenantId     = Tenant,
                PrincipalId  = Principal,
                ClientSecret = Secret
            };

            var unsupportedMeasures      = new List <TabModel.Measure>();
            var unsupportedRelationships = new List <TabModel.Relationship>();
            var groupId       = new Guid(Group);
            var alteredTables = pbiConnection.AlterPushDataset(Model, groupId, DatasetName, DumpUnsupportedMeasure, DumpUnsupportedRelationship).Result;

            foreach (var unsupportedMeasure in unsupportedMeasures)
            {
                WriteObject($"{Ansi.Color.Foreground.LightYellow}Unsupported measure: {Ansi.Color.Foreground.Yellow}{ unsupportedMeasure.Name} {Ansi.Color.Foreground.Default}");
            }

            foreach (var unsupportedRelationship in unsupportedRelationships)
            {
                WriteObject($"{Ansi.Color.Foreground.LightYellow}Unsupported relationship: {Ansi.Color.Foreground.Yellow}");
                WriteObject(
                    (unsupportedRelationship is TabModel.SingleColumnRelationship sr)
                        ? $"'{sr.FromTable.Name}'[{sr.FromColumn.Name}]{sr.CardinalityText()}'{sr.ToTable.Name}'[{sr.ToColumn.Name}] ({sr.CrossFilteringBehavior})"
                        : unsupportedRelationship.ToString()
                    );
                WriteObject($"{Ansi.Color.Foreground.Default}");
            }

            foreach (var table in alteredTables)
            {
                WriteObject($"{Ansi.Color.Foreground.LightCyan}Altered table {table}{Ansi.Color.Foreground.Default}");
            }

            void DumpUnsupportedMeasure(TabModel.Measure unsupportedMeasure)
            {
                unsupportedMeasures.Add(unsupportedMeasure);
            }

            void DumpUnsupportedRelationship(TabModel.Relationship unsupportedRelationship)
            {
                unsupportedRelationships.Add(unsupportedRelationship);
            }
        }
Пример #5
0
        static void Publish(FileInfo model, string principal, string secret, string tenant, string group, string datasetName, string datasetId)
        {
            Console.WriteLine($"{Ansi.Color.Foreground.LightCyan}** PUBLISH model **{Ansi.Color.Foreground.Default}");
            if (!model.Exists)
            {
                Console.WriteLine($"{Ansi.Color.Foreground.LightRed}Model file {model?.FullName} not found.{Ansi.Color.Foreground.Default}");
                return;
            }

            var pbiConnection = new PbiConnection
            {
                TenantId     = tenant,
                PrincipalId  = principal,
                ClientSecret = secret
            };

            var    groupId      = new Guid(group);
            string newDatasetId = pbiConnection.CreatePushDataset(model, groupId, datasetName, false, false, DumpUnsupportedMeasure, DumpUnsupportedRelationship).Result;

            Console.WriteLine($"{Ansi.Color.Foreground.LightCyan}Created dataset id={newDatasetId}{Ansi.Color.Foreground.Default}");