Example #1
0
        private static async Task <Result <PendingRebootInfo> > GetPendingFileRenameRebootPending()
        {
            Logging.DefaultLogger.Debug($@"Checking if Pending File Rename Operations has a pending reboot.");
            var category = Profile.GetPolicyCategory(typeof(CheckPendingRebootCommand));
            var pendingFileRenameOperationsSubCategory = category.Match(s => Option <string> .Some(s + "\\PendingFileRenameOperations"), Option <string> .None);
            var pendingFileRenameOperationsExcludePatternsSubCategory = pendingFileRenameOperationsSubCategory.Match(s => Option <string> .Some(s + "\\PendingFileRenameOperations\\ExcludePatterns"), Option <string> .None);

            var excludeRenameTargets = Profile.GetBooleanPolicyValue(Context.Machine, pendingFileRenameOperationsSubCategory, "ExcludeRenameTargets", false);
            var excludeDeleteTargets = Profile.GetBooleanPolicyValue(Context.Machine, pendingFileRenameOperationsSubCategory, "ExcludeDeleteTargets", false);
            var excludePatterns      = Profile.GetBooleanPolicyValue(Context.Machine, pendingFileRenameOperationsSubCategory, "ExcludePatterns", false);
            var excludePatternsArray =
                excludePatterns ?
                Profile.GetPolicyStringValueNames(Context.Machine, pendingFileRenameOperationsExcludePatternsSubCategory).ToRegExPatterns().ToArray() :
                Array.Empty <Regex>();
            var pendingFileRenameOperations =
                PendingFileRenameOperationExtensions.GetPendingFileRenameOperations()
                .Exclude(excludeRenameTargets, excludeDeleteTargets, excludePatternsArray)
                .Select(operation => operation.ToDto())
                .ToArray();

            Logging.DefaultLogger.Debug($"#Pending File Rename Operations: {pendingFileRenameOperations.Length}");
            var rebootIsPending = pendingFileRenameOperations.Length > 0;
            var rebootSource    = rebootIsPending ? new List <RebootSource> {
                RebootSource.PendingFileRenameOperations
            } : new List <RebootSource>();
            var pendingRebootInfo = new PendingRebootInfo {
                RebootIsPending = rebootIsPending, Sources = rebootSource
            };

            pendingRebootInfo.PendingFileRenameOperations.AddRange(pendingFileRenameOperations);
            Logging.DefaultLogger.Info($@"Pending file rename operation pending reboot check result: {pendingRebootInfo.ObjectToString()}");
            return(await Task.FromResult(new Result <PendingRebootInfo>(pendingRebootInfo)).ConfigureAwait(false));
        }
Example #2
0
 public static PendingRebootInfo Update(this PendingRebootInfo org, PendingRebootInfo add)
 {
     if (org == null)
     {
         throw new ArgumentNullException(nameof(org));
     }
     if (add == null)
     {
         throw new ArgumentNullException(nameof(add));
     }
     if (!add.RebootIsPending)
     {
         return new PendingRebootInfo
                {
                    RebootIsPending             = org.RebootIsPending,
                    Sources                     = new List <RebootSource>(org.RebootIsPending? org.Sources : new List <RebootSource>()),
                    PendingFileRenameOperations = new List <PendingFileRenameOperationDto>(org.RebootIsPending ? org.PendingFileRenameOperations : new List <PendingFileRenameOperationDto>())
                }
     }
     ;
     return(new PendingRebootInfo
     {
         RebootIsPending = true,
         Sources = new List <RebootSource>(org.RebootIsPending? org.Sources.Concat(add.Sources): add.Sources),
         PendingFileRenameOperations = new List <PendingFileRenameOperationDto>(org.RebootIsPending ? org.PendingFileRenameOperations.Concat(add.PendingFileRenameOperations) : add.PendingFileRenameOperations)
     });
 }
Example #3
0
        public static PendingRebootInfo RemoveRebootSources(this PendingRebootInfo org, IEnumerable <RebootSource> rebootSources)
        {
            if (rebootSources == null)
            {
                throw new ArgumentNullException(nameof(rebootSources));
            }
            var rebootSourceList       = rebootSources.ToList();
            var firstRebootSource      = rebootSourceList.FirstOrDefault();
            var remainingRebootSources = rebootSourceList.Tail();

            return(firstRebootSource != null?org.RemoveSource(firstRebootSource).RemoveRebootSources(remainingRebootSources) : org);
        }
Example #4
0
        public static PendingRebootInfo RemoveSource(this PendingRebootInfo org, RebootSource rebootSource)
        {
            if (org == null)
            {
                throw new ArgumentNullException(nameof(org));
            }
            var sources = org.Sources.Where(source => source.Value != rebootSource.Value).ToList();

            return(new PendingRebootInfo {
                RebootIsPending = sources.Count > 0, Sources = sources
            });
        }
Example #5
0
        private static async Task <Result <PendingRebootInfo> > GetCbsRebootPending()
        {
            var rebootPendingRegistryKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending";

            Logging.DefaultLogger.Debug($@"Checking if Component Based Servicing has a pending reboot (Check if key exists: '{rebootPendingRegistryKeyPath}').");
            var rebootIsPending = RegistryOperations.RegistryKeyExists(Registry.LocalMachine, rebootPendingRegistryKeyPath);
            var rebootSource    = rebootIsPending ? new List <RebootSource> {
                RebootSource.Cbs
            } : new List <RebootSource>();
            var pendingRebootInfo = new PendingRebootInfo {
                RebootIsPending = rebootIsPending, Sources = rebootSource
            };

            Logging.DefaultLogger.Info($@"Component Based Servicing (CBS) pending reboot check result: {pendingRebootInfo.ObjectToString()}");
            return(await Task.FromResult(new Result <PendingRebootInfo>(pendingRebootInfo)).ConfigureAwait(false));
        }
Example #6
0
 private static Try <PendingRebootInfo> TryGetSccmClientRebootStatus() => () =>
 {
     dynamic rebootStatus =
         F.RunPowerShell(new Some <Func <PowerShell, Collection <PSObject> > >(powerShell =>
                                                                               powerShell
                                                                               .AddCommand("Invoke-WmiMethod")
                                                                               .AddParameter("NameSpace", @"root\ccm\ClientSDK")
                                                                               .AddParameter("Class", "CCM_ClientUtilities")
                                                                               .AddParameter("Name", "DetermineIfRebootPending")
                                                                               .Invoke())
                         ).FirstOrDefault();
     var rebootIsPending = rebootStatus?.RebootPending || rebootStatus?.IsHardRebootPending;
     var rebootSource    = rebootIsPending ? new List <RebootSource> {
         RebootSource.SccmClient
     } : new List <RebootSource>();
     var pendingRebootInfo = new PendingRebootInfo {
         RebootIsPending = rebootIsPending, Sources = rebootSource
     };
     Logging.DefaultLogger.Info($@"Sccm Client pending reboot check result: {pendingRebootInfo.ObjectToString()}");
     return(new Result <PendingRebootInfo>(pendingRebootInfo));
 };
Example #7
0
        private static ActionDismissToastContentInfo GetCheckPendingRebootToastContentInfo(Some <NotificationProfile> notificationProfile, PendingRebootInfo info, string groupName)
        {
            var             title                = strings.PendingRebootNotification_Title;
            var             content              = strings.PendingRebootNotification_Content1;
            var             content2             = strings.PendingRebootNotification_Content2;
            var             action               = ToastActions.Restart;
            var             actionActivationType = ToastActivationType.Foreground;
            var             greeting             = F.GetGreeting(notificationProfile);
            Option <string> content3             = string.Format(CultureInfo.InvariantCulture, strings.PendingRebootNotification_Source_F0, info.ToSourceDescription());

            return(new ActionDismissToastContentInfo(greeting, title, content, content2, action, actionActivationType, strings.PendingRebootNotification_ActionButtonContent, strings.NotNowActionButtonContent, ToastActions.Dismiss, groupName, content3, notificationProfile.Value.CompanyName));
        }
Example #8
0
 public static async Task <Result <ToastNotificationVisibility> > ShowPendingRebootToastNotification(Some <NotificationProfile> notificationProfile, PendingRebootInfo info, string tag, string groupName)
 {
     return(await ToastHelper.ShowToastNotification(async() =>
     {
         var toastContentInfo = GetCheckPendingRebootToastContentInfo(notificationProfile, info, groupName);
         var toastContent = await ActionDismissToastContent.CreateToastContent(toastContentInfo).ConfigureAwait(true);
         return toastContent;
     }, tag, groupName).ConfigureAwait(false));
 }