Пример #1
0
        /// <summary>
        /// Gets an existing or creates a new app.
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        private async Task <MobileLobApp> GetAppAsync(MobileLobApp app)
        {
            MobileLobApp result;

            if (Guid.TryParse(app.Id, out var _))
            {
                // resolve from id
                result = await msGraphClient.DeviceAppManagement.MobileApps[app.Id].Request().GetAsync() as MobileLobApp ?? throw new ArgumentException($"App {app.Id} should be a {nameof(MobileLobApp)}.", nameof(app));
            }
            else
            {
                // resolve from name
                result = (await msGraphClient.DeviceAppManagement.MobileApps.Request().Filter($"displayName eq '{app.DisplayName}'").GetAsync()).OfType <MobileLobApp>().FirstOrDefault();
            }

            if (result == null)
            {
                SetDefaults(app);
                // create new
                logger.LogInformation($"App {app.DisplayName} does not exist - creating new app.");
                result = (MobileLobApp)await msGraphClient.DeviceAppManagement.MobileApps.Request().AddAsync(app);
            }

            if (app.ODataType.TrimStart('#') != result.ODataType.TrimStart('#'))
            {
                throw new NotSupportedException($"Found existing application {result.DisplayName}, but it of type {result.ODataType.TrimStart('#')} and the app being deployed is of type {app.ODataType.TrimStart('#')} - delete the existing app and try again.");
            }

            logger.LogInformation($"Using app {result.Id} ({result.DisplayName}).");

            return(result);
        }
Пример #2
0
        /// <inheritdoc />
        public async Task PublishAsync(IntuneAppPackage package)
        {
            logger.LogInformation($"Publishing Intune app package for {package.App.DisplayName}.");

            var app = await GetAppAsync(package.App);

            var sw = Stopwatch.StartNew();

            var requestBuilder = new MobileLobAppRequestBuilder(msGraphClient.DeviceAppManagement.MobileApps[app.Id]
                                                                .AppendSegmentToRequestUrl(app.ODataType.TrimStart('#')), msGraphClient);

            MobileAppContent content = null;

            // if content has never been committed, need to use last created content if one exists, otherwise an error is thrown
            if (app.CommittedContentVersion == null)
            {
                content = (await requestBuilder.ContentVersions.Request().OrderBy("id desc").GetAsync()).FirstOrDefault();
            }

            if (content == null)
            {
                content = await requestBuilder.ContentVersions.Request().AddAsync(new MobileAppContent());
            }
            else if ((await requestBuilder.ContentVersions[content.Id].Files.Request().Filter("isCommitted ne true").GetAsync()).Any())
            {
                // partially committed content - delete that content version
                await requestBuilder.ContentVersions[content.Id].Request().DeleteAsync();
            }

            // manifests are only supported if the app is a WindowsMobileMSI (not a Win32 app installing an msi)
            if (!(app is WindowsMobileMSI))
            {
                package.File.Manifest = null;
            }

            await CreateAppContentFileAsync(requestBuilder.ContentVersions[content.Id], package);

            MobileLobApp update = (MobileLobApp)Activator.CreateInstance(package.App.GetType());

            update.CommittedContentVersion = content.Id;
            await msGraphClient.DeviceAppManagement.MobileApps[app.Id].Request().UpdateAsync(update);

            logger.LogInformation($"Published Intune app package for {app.DisplayName} in {sw.ElapsedMilliseconds}ms.");
        }
Пример #3
0
 /// <summary>
 /// Gets a copy of the app with default values for null properties that are required.
 /// </summary>
 /// <param name="app"></param>
 private static void SetDefaults(MobileLobApp app)
 {
     if (app is Win32LobApp win32)
     {
         // set required properties with default values if not already specified - can be changed later in the portal
         win32.InstallExperience ??= new Win32LobAppInstallExperience {
             RunAsAccount = RunAsAccountType.System
         };
         win32.InstallCommandLine ??= win32.MsiInformation == null ? win32.SetupFilePath : $"msiexec /i \"{win32.SetupFilePath}\"";
         win32.UninstallCommandLine ??= win32.MsiInformation == null ? "echo Not Supported" : $"msiexec /x \"{win32.MsiInformation.ProductCode}\"";
         win32.Publisher ??= "-";
         win32.ApplicableArchitectures = WindowsArchitecture.X86 | WindowsArchitecture.X64;
         win32.MinimumSupportedOperatingSystem ??= new WindowsMinimumOperatingSystem {
             V10_1607 = true
         };
         if (win32.DetectionRules == null)
         {
             if (win32.MsiInformation == null)
             {
                 // no way to infer - use empty PS script
                 win32.DetectionRules = new[]
                 {
                     new Win32LobAppPowerShellScriptDetection
                     {
                         ScriptContent = Convert.ToBase64String(new byte[0])
                     }
                 };
             }
             else
             {
                 win32.DetectionRules = new[]
                 {
                     new Win32LobAppProductCodeDetection
                     {
                         ProductCode = win32.MsiInformation.ProductCode
                     }
                 };
             }
         }
     }
 }
Пример #4
0
 public Task <IntuneAppPackage> BuildAsync(MobileLobApp app) => packagingService.BuildPackageAsync(path);