Esempio n. 1
0
 public static Safeguard Clone(Safeguard other)
 {
     return(new Safeguard(
                moveID: other.moveID,
                turnsLeft: other.turnsLeft
                ));
 }
        public MinimizeWindowCommand(Window window)
        {
            Safeguard.EnsureNotNull("window", window);

            this.window = window;
            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
        public ButtonPopupCommand(MainWindowViewModel mainWindowViewModel)
        {
            Safeguard.EnsureNotNull("mainWindowViewModel", mainWindowViewModel);

            this.mainWindowViewModel = mainWindowViewModel;
            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
        public LoadImageCommand(CapturePictureViewModel viewModel)
        {
            Safeguard.EnsureNotNull("viewModel", viewModel);

            this.viewModel = viewModel;
            this.viewModel.PropertyChanged += OnViewModelPropertyChanged;
        }
Esempio n. 5
0
        public WindowCloseCommand(Window window)
        {
            Safeguard.EnsureNotNull("selectColorView", window);

            this.window = window;
            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
Esempio n. 6
0
        private static void Execute(ToolOptions opts)
        {
            try
            {
                var config = new LoggerConfiguration();
                config.WriteTo.ColoredConsole(outputTemplate: "{Message:lj}{NewLine}{Exception}");

                if (opts.Verbose)
                {
                    config.MinimumLevel.Debug();
                }
                else
                {
                    config.MinimumLevel.Information();
                }

                Log.Logger = config.CreateLogger();

                ISafeguardConnection connection;
                if (!string.IsNullOrEmpty(opts.Username))
                {
                    var password = HandlePassword(opts.ReadPassword);
                    connection = Safeguard.Connect(opts.Appliance, opts.IdentityProvider, opts.Username, password,
                                                   opts.ApiVersion, opts.Insecure);
                }
                else if (!string.IsNullOrEmpty(opts.CertificateFile))
                {
                    var password = HandlePassword(opts.ReadPassword);
                    connection = Safeguard.Connect(opts.Appliance, opts.CertificateFile, password, opts.ApiVersion,
                                                   opts.Insecure);
                }
                else if (!string.IsNullOrEmpty(opts.Thumbprint))
                {
                    connection = Safeguard.Connect(opts.Appliance, opts.Thumbprint, opts.ApiVersion, opts.Insecure);
                }
                else if (opts.Anonymous)
                {
                    connection = Safeguard.Connect(opts.Appliance, opts.ApiVersion, opts.Insecure);
                }
                else
                {
                    throw new Exception("Must specify Anonymous, Username, CertificateFile, or Thumbprint");
                }

                Log.Debug($"Access Token Lifetime Remaining: {connection.GetAccessTokenLifetimeRemaining()}");

                var responseBody = opts.Csv
                    ? connection.InvokeMethodCsv(opts.Service, opts.Method, opts.RelativeUrl, opts.Body)
                    : connection.InvokeMethod(opts.Service, opts.Method, opts.RelativeUrl, opts.Body);
                //Log.Information(responseBody); // if JSON is nested too deep Serilog swallows a '}' -- need to file issue with them
                Console.WriteLine(responseBody);

                connection.LogOut();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Fatal exception occurred");
                Environment.Exit(1);
            }
        }
        private ISafeguardConnection GetSgConnection()
        {
            var sppAddress      = _configDb.SafeguardAddress;
            var userCertificate = _configDb.UserCertificateBase64Data;
            var passPhrase      = _configDb.UserCertificatePassphrase?.ToSecureString();
            var apiVersion      = _configDb.ApiVersion ?? WellKnownData.DefaultApiVersion;
            var ignoreSsl       = _configDb.IgnoreSsl ?? true;

            if (sppAddress != null && userCertificate != null)
            {
                try
                {
                    _logger.Debug("Connecting to Safeguard: {address}", sppAddress);
                    var connection = ignoreSsl
                        ? Safeguard.Connect(sppAddress, Convert.FromBase64String(userCertificate), passPhrase, apiVersion, true)
                        : Safeguard.Connect(sppAddress, Convert.FromBase64String(userCertificate), passPhrase, CertificateValidationCallback, apiVersion);

                    return(connection);
                }
                catch (SafeguardDotNetException ex)
                {
                    _logger.Error(ex, $"Failed to connect to Safeguard at '{sppAddress}': {ex.Message}");
                }
            }

            return(null);
        }
        public CopyToClipboardCommand(Func <BitmapSource> functionToRetrieveImage)
        {
            Safeguard.EnsureNotNull("functionToRetrieveText", functionToRetrieveImage);

            this.functionToRetrieveImage = functionToRetrieveImage;
            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
        public LoadDocumentCommand(MainWindowViewModel mainWindow)
        {
            Safeguard.EnsureNotNull("mainWindow", mainWindow);

            this.mainWindow = mainWindow;
            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
Esempio n. 10
0
        public IEnumerable <RetrievableAccount> GetRetrievableAccounts()
        {
            var configuration = _configurationRepository.GetConfiguration();

            if (configuration == null)
            {
                _logger.Error("No configuration was found.  DevOps service must be configured first");
                return(null);
            }

            ISafeguardConnection connection = null;

            try
            {
                connection = Safeguard.Connect(configuration.SppAddress, configuration.CertificateUserThumbPrint,
                                               _safeguardApiVersion, _safeguardIgnoreSsl);
                var rawJson = connection.InvokeMethod(Service.Core, Method.Get,
                                                      $"A2ARegistrations/{configuration.A2ARegistrationId}/RetrievableAccounts");
                var retrievableAccounts = JsonHelper.DeserializeObject <IEnumerable <RetrievableAccount> >(rawJson);

                return(retrievableAccounts.ToList());
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed to get the retrievable accounts from SPP: {ex.Message}.");
            }
            finally
            {
                connection?.Dispose();
            }

            return(null);
        }
Esempio n. 11
0
        public static void Fade(this FrameworkElement element, double startOpacity, double toOpacity, TimeSpan timeSpan, EventHandler completedEvent)
        {
            Safeguard.EnsureNotNull("element", element);

            DoubleAnimation fadeAnimation = new DoubleAnimation()
            {
                From     = startOpacity,
                To       = toOpacity,
                Duration = timeSpan
            };

            Storyboard.SetTarget(fadeAnimation, element);
            Storyboard.SetTargetProperty(fadeAnimation, new PropertyPath(UIElement.OpacityProperty));

            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(fadeAnimation);

            if (completedEvent != null)
            {
                storyboard.Completed += completedEvent;
            }

            storyboard.Begin();
        }
        public SaveDocumentCommand(InkWriterDocument document)
        {
            Safeguard.EnsureNotNull("document", document);

            this.document = document;
            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
Esempio n. 13
0
        private IEnumerable <AccountMapping> GetAccountMappings(Configuration configuration)
        {
            ISafeguardConnection connection = null;

            try
            {
                connection = Safeguard.Connect(configuration.SppAddress, configuration.CertificateUserThumbPrint,
                                               _safeguardApiVersion, _safeguardIgnoreSsl);
                var rawJson = connection.InvokeMethod(Service.Core, Method.Get,
                                                      $"A2ARegistrations/{configuration.A2ARegistrationId}/RetrievableAccounts");

                var retrievableAccounts = JsonHelper.DeserializeObject <IEnumerable <RetrievableAccount> >(rawJson);

                var accountMappings = new List <AccountMapping>();
                foreach (var account in retrievableAccounts)
                {
                    accountMappings.Add(new AccountMapping()
                    {
                        AccountName = account.AccountName,
                        ApiKey      = account.ApiKey,
                        VaultName   = ""
                    });
                }

                return(accountMappings);
            }
            finally
            {
                connection?.Dispose();
            }
        }
Esempio n. 14
0
        private static ISafeguardConnection CreateConnection(ToolOptions opts)
        {
            ISafeguardConnection connection;

            if (!string.IsNullOrEmpty(opts.Username))
            {
                var password = HandlePassword(opts.ReadPassword);
                connection = Safeguard.Connect(opts.Appliance, opts.IdentityProvider, opts.Username, password,
                                               opts.ApiVersion, opts.Insecure);
            }
            else if (!string.IsNullOrEmpty(opts.CertificateFile))
            {
                var password = HandlePassword(opts.ReadPassword);
                connection = Safeguard.Connect(opts.Appliance, opts.CertificateFile, password, opts.ApiVersion,
                                               opts.Insecure);
            }
            else if (!string.IsNullOrEmpty(opts.Thumbprint))
            {
                connection = Safeguard.Connect(opts.Appliance, opts.Thumbprint, opts.ApiVersion, opts.Insecure);
            }
            else
            {
                throw new Exception("Must specify Username, CertificateFile, or Thumbprint");
            }
            return(connection);
        }
Esempio n. 15
0
        public static ISafeguardConnection Connect(string appliance)
        {
            Log.Debug("Calling RSTS for primary authentication");
            var authorizationCode = ShowRstsWindowPrimary(appliance);

            using (var rstsAccessToken = PostAuthorizationCodeFlow(appliance, authorizationCode))
            {
                Log.Debug("Posting RSTS access token to login response service");
                var responseObject = PostLoginResponse(appliance, rstsAccessToken);
                var statusValue    = responseObject.GetValue("Status").ToString();
                if (statusValue.Equals("Needs2FA"))
                {
                    Log.Debug("Authentication requires 2FA, continuing with RSTS for secondary authentication");
                    authorizationCode = ShowRstsWindowSecondary(
                        responseObject.GetValue("PrimaryProviderId").ToString(),
                        responseObject.GetValue("SecondaryProviderId").ToString());
                    using (var secondRstsAccessToken = PostAuthorizationCodeFlow(appliance, authorizationCode))
                    {
                        Log.Debug("Posting second RSTS access token to login response service");
                        responseObject = PostLoginResponse(appliance, secondRstsAccessToken);
                        statusValue    = responseObject.GetValue("Status").ToString();
                    }
                }
                if (!statusValue.Equals("Success"))
                {
                    throw new SafeguardDotNetException($"Error response status {statusValue} from login response service");
                }
                using (var accessToken = responseObject.GetValue("UserToken").ToString().ToSecureString())
                    return(Safeguard.Connect(appliance, accessToken, DefaultApiVersion, true));
            }
        }
Esempio n. 16
0
        public ToggleCaptureCommand(CapturePictureViewModel viewModel)
        {
            Safeguard.EnsureNotNull("viewModel", viewModel);

            this.viewModel = viewModel;
            /// TODO: Must get IDisopsable.
            this.viewModel.PropertyChanged += OnViewModelPropertyChanged;
        }
        public void ResetDocument(InkWriterDocument newDocument)
        {
            Safeguard.EnsureNotNull("newDocument", newDocument);

            this.document.PageChanged -= this.OnDocumentPageChanged;
            this.document              = newDocument;
            this.document.PageChanged += this.OnDocumentPageChanged;
        }
Esempio n. 18
0
        public NewPageCommand(MainWindowViewModel mainWindow, InkWriterDocument document)
        {
            Safeguard.EnsureNotNull("mainWindow", mainWindow);
            Safeguard.EnsureNotNull("document", document);

            this.mainWindow = mainWindow;
            this.document   = document;
            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
        public DeletePageCommand(MainWindowViewModel mainWindow, InkWriterDocument document)
        {
            Safeguard.EnsureNotNull("mainWindow", mainWindow);
            Safeguard.EnsureNotNull("document", document);

            this.mainWindow            = mainWindow;
            this.document              = document;
            this.document.PageChanged += this.OnDocumentPageChanged;
        }
        public PageNavigationCommand(MainWindowViewModel mainWindow, InkWriterDocument document, NavigationRequestType navigationRequestType)
        {
            Safeguard.EnsureNotNull("mainWindow", mainWindow);
            Safeguard.EnsureNotNull("document", document);

            this.document              = document;
            this.mainWindow            = mainWindow;
            this.document.PageChanged += this.OnDocumentPageChanged;
            this.navigationRequestType = navigationRequestType;
        }
        public EmbeddPictureCommand(CapturePictureViewModel capturePictureView, MainWindowViewModel mainWindow)
        {
            Safeguard.EnsureNotNull("capturePictureView", capturePictureView);
            Safeguard.EnsureNotNull("mainWindow", mainWindow);

            this.capturePictureView  = capturePictureView;
            this.mainWindowViewModel = mainWindow;

            this.capturePictureView.PropertyChanged += this.OnViewModelPropertyChanged;
        }
        public SelectWidthViewModel(InkCanvas inkCanvas, List <double> selectableWidths, Window window)
        {
            Safeguard.EnsureNotNull("window", window);
            Safeguard.EnsureNotNull("inkCanvas", inkCanvas);
            Safeguard.EnsureNotNull("selectableWidths", selectableWidths);

            this.window           = window;
            this.inkCanvas        = inkCanvas;
            this.SelectableWidths = selectableWidths;

            this.CloseCommand = new CommonCommands.WindowCloseCommand(window);
        }
Esempio n. 23
0
        public SelectColorViewModel(InkCanvas inkCanvas, List <Color> selectableColors, Window window)
        {
            Safeguard.EnsureNotNull("window", window);
            Safeguard.EnsureNotNull("inkCanvas", inkCanvas);
            Safeguard.EnsureNotNull("selectableColors", selectableColors);

            this.window           = window;
            this.inkCanvas        = inkCanvas;
            this.SelectableColors = selectableColors;

            this.CloseCommand = new CommonCommands.WindowCloseCommand(window);
        }
        public CloseApplicationCommand(MainWindowViewModel mainWindow, InkWriterDocument document, InkWriterSettings settings)
        {
            Safeguard.EnsureNotNull("mainWindow", mainWindow);
            Safeguard.EnsureNotNull("document", document);
            Safeguard.EnsureNotNull("settings", settings);

            this.document   = document;
            this.settings   = settings;
            this.mainWindow = mainWindow;

            this.CanExecuteChanged?.Invoke(this, new EventArgs());
        }
Esempio n. 25
0
        public ZoomImageCommand(ZoomType zoomType, VideoCaptureDevice videoCaptureDevice)
        {
            Safeguard.EnsureNotNull("videoCaptureDevice", videoCaptureDevice);

            this.zoomType           = zoomType;
            this.videoCaptureDevice = videoCaptureDevice;

            if (!Initialized)
            {
                this.videoCaptureDevice.GetCameraPropertyRange(CameraControlProperty.Zoom, out MinZoom, out MaxZoom, out StepSize, out DefaultValue, out ControlFlags);
                Initialized = true;
            }
        }
Esempio n. 26
0
        private static void Execute(TestOptions opts)
        {
            try
            {
                var config = new LoggerConfiguration();
                config.WriteTo.ColoredConsole(outputTemplate: "{Message:lj}{NewLine}{Exception}");

                if (opts.Verbose)
                {
                    config.MinimumLevel.Debug();
                }
                else
                {
                    config.MinimumLevel.Information();
                }

                Log.Logger = config.CreateLogger();

                TestConnectExceptions(opts.Appliance);

                ISafeguardConnection connection;
                if (!string.IsNullOrEmpty(opts.Username))
                {
                    var password = HandlePassword(opts.ReadPassword);
                    connection = Safeguard.Connect(opts.Appliance, opts.IdentityProvider, opts.Username, password,
                                                   opts.ApiVersion, opts.Insecure);
                }
                else if (opts.Anonymous)
                {
                    connection = Safeguard.Connect(opts.Appliance, opts.ApiVersion, opts.Insecure);
                }
                else
                {
                    throw new Exception("Must specify Anonymous or Username");
                }

                Log.Debug($"Access Token Lifetime Remaining: {connection.GetAccessTokenLifetimeRemaining()}");

                TestApiExceptions(connection);

                connection.LogOut();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Fatal exception occurred");
                Environment.Exit(1);
            }
        }
Esempio n. 27
0
        public static void InvokeOnGui(this DispatcherObject application, DispatcherPriority priority, Action action)
        {
            Safeguard.EnsureNotNull("application", application);
            Safeguard.EnsureNotNull("action", action);

            Dispatcher dispatcher = application.Dispatcher;

            if (dispatcher == null || dispatcher.CheckAccess())
            {
                action();
            }
            else
            {
                dispatcher.Invoke(priority, action);
            }
        }
        public void Start()
        {
            _eventListener = Safeguard.Event.GetPersistentEventListener(_safeguardAddress,
                                                                        _safeguardClientCertificateThumbprint, _safeguardApiVersion, _safeguardIgnoreSsl);
            _connection = Safeguard.Connect(_safeguardAddress, _safeguardClientCertificateThumbprint,
                                            _safeguardApiVersion, _safeguardIgnoreSsl);
            using (var a2AContext = Safeguard.A2A.GetContext(_safeguardAddress, _safeguardClientCertificateThumbprint,
                                                             _safeguardApiVersion, _safeguardIgnoreSsl))
            {
                _serviceNowPassword = a2AContext.RetrievePassword(_safeguardA2AApiKeyForServiceNowPassword);
            }

            _validator = new ServiceNowTicketValidator(_serviceNowDnsName, _serviceNowClientSecret, _serviceNowUserName,
                                                       _serviceNowPassword);
            _eventListener.RegisterEventHandler("AccessRequestPendingApproval", HandlePendingApprovalNotification);

            _eventListener.Start();
        }
        public void Execute(object parameter)
        {
            Safeguard.EnsureNotNull("mainWindowViewModel.InkCanvas", mainWindowViewModel.InkCanvas);

            Bitmap      bitmap      = (Bitmap)BitmapToBitmapSourceConverter.ConvertBack(this.capturePictureView.Image, typeof(Bitmap), null, CultureInfo.CurrentUICulture);
            Bitmap      copy        = ImageManipulation.Copy(bitmap);
            ImageSource imageSource = (ImageSource)BitmapToBitmapSourceConverter.Convert(copy, typeof(ImageSource), null, CultureInfo.CurrentUICulture);

            this.mainWindowViewModel.InkCanvas.Children.Add(new System.Windows.Controls.Image
            {
                Source = imageSource
            });

            this.capturePictureView.PropertyChanged -= this.OnViewModelPropertyChanged;
            this.capturePictureView.CloseCommand.Execute(null);

            this.mainWindowViewModel.UpdatePage();
        }
Esempio n. 30
0
        public Configuration UpdateConnectionConfiguration(ConnectionConfiguration connectionConfig)
        {
            if (connectionConfig == null)
            {
                throw new Exception("The initial configuration cannot be null.");
            }
            if (connectionConfig.CertificateUserThumbprint == null)
            {
                throw new Exception("The user certificate thumbprint cannot be null.");
            }
            if (connectionConfig.SppAddress == null)
            {
                throw new Exception("The SPS network address cannot be null.");
            }

            var configuration = _configurationRepository.GetConfiguration();

            if (configuration == null)
            {
                _logger.Error("No configuration was found.  DevOps service must be configured first");
                return(null);
            }

            configuration.CertificateUserThumbPrint = connectionConfig.CertificateUserThumbprint;
            configuration.SppAddress = connectionConfig.SppAddress;

            //Validate the connection information
            var connection = Safeguard.Connect(connectionConfig.SppAddress,
                                               connectionConfig.CertificateUserThumbprint, _safeguardApiVersion, _safeguardIgnoreSsl);

            if (connection == null)
            {
                _logger.Error("SPP connection configuration failed.");
            }

            connection?.LogOut();

            _configurationRepository.SaveConfiguration(configuration);

            return(configuration);
        }