Exemple #1
0
        private async Task <JArray> Search(string graphUrl)
        {
            var url    = graphUrl;
            var result = new List <JObject>();
            var i      = 0;

            do
            {
                i++;

                // Print page number
                Log.Info($"Getting page #{i}");

                // Query Graph
                var json = await _graph.SendGraphRequest(HttpMethod.Get, url, null);

                result.AddRange((JObject.Parse(json)["value"] as JArray).Cast <JObject>());

                // Get next link url
                var root = GraphRootElementModel.Parse(json);

                if (root == null || string.IsNullOrEmpty(root.odata_nextLink))
                {
                    url = null;
                }
                else
                {
                    url = graphUrl + "&$" + root.odata_nextLink;
                }
            } while (string.IsNullOrEmpty(url) == false);

            return(JArray.FromObject(result));
        }
Exemple #2
0
        private async Task <JArray> QueryUsers(UserFilter filter)
        {
            var url    = _graph.BuildUrl(ApiPath, filter.Filter);
            var result = new List <JObject>();
            var i      = 0;

            do
            {
                i++;

                // Print page number
                Log.Info($"Getting page #{i}");

                // Query Graph
                var json = await _graph.SendGraphRequest(HttpMethod.Get, url, null);

                var jt = Json.TryParse(json);

                if (jt is JObject jo && jo["value"] is JArray ja)
                {
                    result.AddRange(ja.Cast <JObject>());
                }
                else
                {
                    if (jt != null)
                    {
                        Log.Error($"Invalid response {jt.ToString(Formatting.Indented)}");
                    }
                    else
                    {
                        Log.Error($"Invalid response {json}");
                    }

                    return(null);
                }

                // Get next link url
                var root = GraphRootElementModel.Parse(json);

                if (root == null || string.IsNullOrEmpty(root.odata_nextLink))
                {
                    url = null;
                }
                else
                {
                    url = url + "&$" + root.odata_nextLink;
                }
            } while (string.IsNullOrEmpty(url) == false);
Exemple #3
0
        public override async Task Run()
        {
            // Create an output folder
            var outputFolder = Settings.OutputFolder.Subdirectory(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));

            outputFolder.Create();

            // Set the report URL
            string graphUrl = _graph.BuildUrl("/activities/audit",
                                              $"$filter=category eq 'B2C'&$top={Settings.PageSize}");

            string url = graphUrl;

            int i = 0;

            do
            {
                i++;

                // Print page number
                Log.Info($"Getting page #{i}");

                // Query Graph
                var json = await _graph.SendGraphRequest(HttpMethod.Get, url, null);

                // Get next link url
                GraphRootElementModel root = GraphRootElementModel.Parse(json);
                if (root == null || string.IsNullOrEmpty(root.odata_nextLink))
                {
                    url = null;
                }
                else
                {
                    url = graphUrl + "&$" + root.odata_nextLink;
                }

                // Save the data
                var file = outputFolder.File($"Audit_{i.ToString("0000")}.txt");

                File.WriteAllText(file.FullName, json);
            } while (string.IsNullOrEmpty(url) == false);
        }
Exemple #4
0
        public async Task Run()
        {
            // Create an output folder
            string outputFolder = Path.Combine(this.AppSettings.OutputFolder, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));

            Directory.CreateDirectory(outputFolder);

            // Set the report URL
            string graphUrl = this.AzureADGraphClient.BuildUrl("/activities/audit",
                                                               $"$filter=category eq 'B2C'&$top={AppSettings.PageSize}");

            string url = graphUrl;

            int i = 0;

            do
            {
                i++;

                // Print page number
                Console.WriteLine($"Getting page #{i}");

                // Query Graph
                var json = await this.AzureADGraphClient.SendGraphRequest(HttpMethod.Get, url, null);

                // Get next link url
                GraphRootElementModel root = GraphRootElementModel.Parse(json);
                if (root == null || string.IsNullOrEmpty(root.odata_nextLink))
                {
                    url = null;
                }
                else
                {
                    url = graphUrl + "&$" + root.odata_nextLink;
                }

                // Save the data
                string filePath = Path.Combine(outputFolder, $"Audit_{i.ToString("0000")}.txt");
                File.WriteAllText(filePath, json);
            } while (string.IsNullOrEmpty(url) == false);
        }
Exemple #5
0
        private async Task Export(string graphUrl, string outputFolder, string fileName)
        {
            string url = graphUrl;

            int i = 0;

            do
            {
                i++;

                // Print page number
                Log.Info($"Getting page #{i}");

                // Query Graph
                var json = await this._graph.SendGraphRequest(HttpMethod.Get, url, null);

                // Get next link url
                GraphRootElementModel root = GraphRootElementModel.Parse(json);
                if (root == null || string.IsNullOrEmpty(root.odata_nextLink))
                {
                    url = null;
                }
                else
                {
                    url = graphUrl + "&$" + root.odata_nextLink;
                }

                // Save the data
                string pageNumber = string.Empty;
                if (i > 1)
                {
                    pageNumber = "_" + i.ToString();
                }

                string filePath = Path.Combine(outputFolder, $"{fileName}{pageNumber}.txt");
                File.WriteAllText(filePath, json);
            } while (string.IsNullOrEmpty(url) == false);
        }
Exemple #6
0
        private async Task Search(string graphUrl)
        {
            // Create an output folder
            string outputFolder = Path.Combine(this.AppSettings.OutputFolder, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
            string url          = graphUrl;

            Directory.CreateDirectory(outputFolder);

            int i = 0;

            do
            {
                i++;

                // Print page number
                Console.WriteLine($"Getting page #{i}");

                // Query Graph
                var json = await this.AzureADGraphClient.SendGraphRequest(HttpMethod.Get, url, null);

                // Get next link url
                GraphRootElementModel root = GraphRootElementModel.Parse(json);
                if (root == null || string.IsNullOrEmpty(root.odata_nextLink))
                {
                    url = null;
                }
                else
                {
                    url = graphUrl + "&$" + root.odata_nextLink;
                }

                // Save the data
                string filePath = Path.Combine(outputFolder, $"Users_{i.ToString("0000")}.txt");
                File.WriteAllText(filePath, json);
            } while (string.IsNullOrEmpty(url) == false);
        }