Ejemplo n.º 1
0
        private ICoreProcessStartInfo CreateStartInfo(DFCCommand command, bool?isX64os)
        {
            var startInfo = this.ProcessFactory.CreateStartInfo();

            startInfo.FileName           = isX64os == true ? DFC_x64_PATH : DFC_x32_PATH;
            startInfo.CreateNoWindow     = true;
            startInfo.WorkingDirectory   = System.IO.Path.GetDirectoryName(DFC_x64_PATH);
            startInfo.WaitForTermination = true;
            startInfo.Arguments          = GetArguments(command);
            return(startInfo);
        }
Ejemplo n.º 2
0
        private async void OnExecuteAction(object param)
        {
            if (param is DFAction action)
            {
                try
                {
                    var service = this.ServiceManager.Current;

                    if (service == null)
                    {
                        return;
                    }

                    if (!service.IsConnected)
                    {
                        return;
                    }

                    if (!service.IsAuthenticated)
                    {
                        return;
                    }

                    var LOC_ATTRIBUTE = action.GetAttributeOfType <Localization.LocalizedAttribute>();
                    var LOC_STRING    = LOC_ATTRIBUTE != null?Loc(LOC_ATTRIBUTE.ResourceKey) : action.ToString();

                    var LOC_BASE_MESSAGE = Loc("ACTION_WARNING");
                    if (await this.MessageService.ShowWarningMessageAsync($"{LOC_BASE_MESSAGE} {LOC_STRING} ?", Manager.ManagerMessageDialogStyle.AffirmativeAndNegative) != Manager.ManagerMessageDialogResult.Affirmative)
                    {
                        return;
                    }

                    //get a list of selected computers
                    var selectedHosts = this.Selector.SelectedItems
                                        .Where(x => x.DispatcherId != null)
                                        .ToList();

                    var TASKS = selectedHosts.Select(async(host) =>
                    {
                        var dispatcherId = host.DispatcherId;
                        if (dispatcherId.HasValue)
                        {
                            if (host is IDynamicPropertyObject dynamic)
                            {
                                dynamic.SetPropertyValue(PROPERTY_IS_WORKING, true);

                                try
                                {
                                    var dispatcher = this.ServiceManager.Current.ProxyDispatcherGet(dispatcherId.Value);

                                    if (dynamic.GetPropertyValue <bool>(PROPERTY_DEEP_FREEZE_INSTALLED))
                                    {
                                        DFCCommand command = DFCCommand.BOOTFROZEN;
                                        switch (action)
                                        {
                                        case DFAction.Freeze:
                                            command = DFCCommand.BOOTFROZEN;
                                            break;

                                        case DFAction.Thaw:
                                            command = DFCCommand.BOOTTHAWED;
                                            break;

                                        case DFAction.ThawLocked:
                                            command = DFCCommand.BOOTTHAWEDNOINPUT;
                                            break;

                                        default:
                                            throw new ArgumentException();
                                        }

                                        var START_INFO = this.CreateStartInfo(command, host.Is64BitOperatingSystem == true);
                                        var PROCESS    = await ProcessFactory.StartAsync(START_INFO, dispatcher);

                                        if (PROCESS?.ExitCode > 1 & PROCESS?.ExitCode < 5)
                                        {
                                            this.LogService.AddError($"Deep freeze command {command} for {host.Name} failed with error : {(DFCCommandResult)PROCESS.ExitCode}");
                                        }

                                        if (PROCESS?.ExitCode >= 5)
                                        {
                                            this.LogService.AddError($"Deep freeze  Internal error executing command {command} for {host.Name} exit code : {PROCESS.ExitCode}");
                                        }
                                    }
                                }
                                catch (ConnectionLostException)
                                {
                                    //connection can be lost while executing command due to a restart
                                }
                                finally
                                {
                                    dynamic.SetPropertyValue(PROPERTY_IS_WORKING, false);
                                }
                            }
                        }
                    }).ToList();

                    await Task.WhenAll(TASKS);
                }
                catch
                {
                }
                finally
                {
                }
            }
        }
Ejemplo n.º 3
0
 private string GetArguments(DFCCommand command)
 {
     return(this.GetArguments(DEEP_FREEZE_PASWORD, command.ToString()));
 }