Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/ModulesMapping.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"Identity.Partner": "^tenantRelationships.delegatedAdminRelationship$|^tenantRelationships.delegatedAdminCustomer$",
"Mail": "^users.inferenceClassification$|^users.mailFolder$|^users.message$",
"ManagedTenants": "^tenantRelationships.managedTenant$",
"Migrations": "^solutions.migrations",
"Migrations": "^solutions.migrationsRoot",
"NetworkAccess": "^networkAccess\\.",
"Notes": "^users.onenote$|^groups.onenote$|^sites.onenote$",
"People": "^users.person$|^users.profile$|^users.officeGraphInsights$|^users.userAnalytics$",
Expand Down
41 changes: 41 additions & 0 deletions src/Migrations/Migrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Migrations

This directory contains common [AutoREST.PowerShell](https://github.com/Azure/autorest.powershell) configurations for Migrations v1.0 and/or beta modules.

## AutoRest Configuration

> see <https://aka.ms/autorest>

``` yaml
require:
- $(this-folder)/../readme.graph.md
```

### Directives

> see https://github.com/Azure/autorest/blob/master/docs/powershell/directives.md

``` yaml
# Directives go here!

# Rename commands with 'SolutionMigrationCrossTenantMigrationJob<x>' to 'CrossTenantMigrationJob<x>'
directive:
- where:
subject: (^SolutionMigrationCrossTenantMigrationJob)(.*)
set:
subject: CrossTenantMigrationJob$2
# Remove all the 'DisplayName','SolutionMigration', and 'Count' commands, they are redundant/unsupported
- where:
subject: (DisplayName$|SolutionMigration$|Count$)
remove: true
# Remove extra 'Remove' commands, only jobs can be removed
- where:
verb: Remove
subject: CrossTenantMigrationJob.+$
remove: true
# Remove New/Update-CrossTenantMigrationJobUser, they are not supported operations
- where:
verb: (New|Update)
subject: CrossTenantMigrationJobUser$
remove: true
```
1 change: 1 addition & 0 deletions src/Migrations/beta/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
16 changes: 16 additions & 0 deletions src/Migrations/beta/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bin
obj
.vs
generated
internal
exports
tools
custom/*.psm1
custom/autogen-model-cmdlets
test/*-TestResults.xml
/*.ps1
/*.ps1xml
/*.psm1
/*.snk
/*.csproj
/*.nuspec
38 changes: 38 additions & 0 deletions src/Migrations/beta/custom/EventExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

namespace Microsoft.Graph.Beta.PowerShell
{
using System;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Graph.Beta.PowerShell.Runtime;

public static class EventExtensions
{
/// <summary>
/// Print event details to the provided stream
/// </summary>
/// <param name="getEventData">The event data to print</param>
/// <param name="signal">The delegate for signaling events to the runtime</param>
/// <param name="token">The cancellation token for the request</param>
/// <param name="streamName">The name of the stream to print data to</param>
/// <param name="eventName">The name of the event to be printed</param>
public static async void Print(this Func<EventArgs> getEventData, Func<string, CancellationToken, Func<EventArgs>, Task> signal, CancellationToken token, string streamName, string eventName)
{
var eventDisplayName = EventFactory.SplitPascalCase(eventName).ToUpperInvariant();
var data = EventDataConverter.ConvertFrom(getEventData()); // also, we manually use our TypeConverter to return an appropriate type
if (data.Id != Events.Verbose && data.Id != Events.Warning && data.Id != Events.Debug && data.Id != Events.Information && data.Id != Events.Error)
{
await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} The contents are '{data?.Id}' and '{data?.Message}'"));
if (data != null)
{
await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} Parameter: '{data.Parameter}'\n{eventDisplayName} RequestMessage '{data.RequestMessage}'\n{eventDisplayName} Response: '{data.ResponseMessage}'\n{eventDisplayName} Value: '{data.Value}'"));
await signal(streamName, token, () => EventFactory.CreateLogEvent($"{eventDisplayName} ExtendedData Type: '{data.ExtendedData?.GetType()}'\n{eventDisplayName} ExtendedData '{data.ExtendedData}'"));
}
}
}
}
}
72 changes: 72 additions & 0 deletions src/Migrations/beta/custom/EventFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Graph.Beta.PowerShell.Runtime;

namespace Microsoft.Graph.Beta.PowerShell
{
public static class EventFactory
{
/// <summary>
/// Create a tracing event containing a string message
/// </summary>
/// <param name="message">The string message to include in event data</param>
/// <returns>Valid EventData containing the message</returns>
public static EventData CreateLogEvent(Task<string> message)
{
return new EventData
{
Id = Guid.NewGuid().ToString(),
Message = message.Result
};
}

/// <summary>
/// Create a new debug message event
/// </summary>
/// <param name="message">The message</param>
/// <returns>An event containing the debug message</returns>
public static EventData CreateDebugEvent(string message)
{
return new EventData
{
Id = Events.Debug,
Message = message
};
}

/// <summary>
/// Create a new debug message event
/// </summary>
/// <param name="message">The message</param>
/// <returns>An event containing the debug message</returns>
public static EventData CreateWarningEvent(string message)
{
return new EventData
{
Id = Events.Warning,
Message = message
};
}
public static string SplitPascalCase(string word)
{
var regex = new Regex("([a-z]+)([A-Z])");
var output = regex.Replace(word, "$1 $2");
regex = new Regex("([A-Z])([A-Z][a-z])");
return regex.Replace(output, "$1 $2");
}

public static EventArgs CreateLogEvent(string message)
{
return new EventData
{
Id = Guid.NewGuid().ToString(),
Message = message
};
}
}
}
44 changes: 44 additions & 0 deletions src/Migrations/beta/custom/FileUploadCmdlet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
namespace Microsoft.Graph.Beta.PowerShell.Cmdlets.Custom
{
using Microsoft.Graph.PowerShell.Authentication.Common;
using System.IO;
using System.Management.Automation;

public partial class FileUploadCmdlet : PSCmdlet
{
/// <summary>Backing field for <see cref="InFile" /> property.</summary>
private string _inFile;

/// <summary>The path to the file to upload. This SHOULD include the file name and extension.</summary>
[Parameter(Mandatory = true, HelpMessage = "The path to the file to upload. This should include a path and file name. If you omit the path, the current location will be used.")]
[Runtime.Info(
Required = true,
ReadOnly = false,
Description = @"The path to the file to upload. This should include a path and file name. If you omit the path, the current location will be used.",
PossibleTypes = new[] { typeof(string) })]
[ValidateNotNullOrEmpty()]
[Category(ParameterCategory.Runtime)]
public string InFile { get => this._inFile; set => this._inFile = value; }

/// <summary>
/// Creates a file stream from the provided input file.
/// </summary>
/// <returns>A file stream.</returns>
internal Stream GetFileAsStream()
{
if (MyInvocation.BoundParameters.ContainsKey(nameof(InFile)))
{
string resolvedFilePath = this.GetProviderPath(InFile, true);
var fileProvider = ProtectedFileProvider.CreateFileProvider(resolvedFilePath, FileProtection.SharedRead, new DiskDataStore());
return fileProvider.Stream;
}
else
{
return null;
}
}
}
}
Loading
Loading