コード例 #1
0
        public void BookBalanceSQLite()
        {
            var profile  = new Profile.Profile();
            var database = new Fake.Database(profile);

            database.Connect();

            var   bookName   = "Sales";
            float bookAmount = 100.00F;

            database.Add(record1);
            database.Add(record2);

            System.Collections.Generic.List <Balance> entries = Function.SQLiteBookBalance(database, bookName, bookAmount);
            CheckTransaction(database);

            Assert.Greater(entries.Count, 1);
            Assert.IsNotNull(entries[0].Entry);
            Assert.Greater(entries[0].Entry, 0);
            Assert.AreEqual(record1[2], entries[0].Account);
            Assert.AreEqual(record2[2], entries[1].Account);

            Assert.AreEqual(1, database.Connection.OpenCount);
            Assert.Less(database.Connection.CloseCount, 2);
        }
コード例 #2
0
 /// <summary>
 /// SetProfile
 /// </summary>
 /// <param name="profile">profile- user control profile</param>
 public static void SetProfile(Profile.Profile profile)
 {
     profile.Controls["lbl_name"].Text       = GlobalProp.CurrentUser.UserName;
     profile.Controls["lbl_department"].Text = GlobalProp.CurrentUser.DepartmentUser.Department;
     profile.logoutClicked += new Profile.Profile.LogoutClickedHandler(BaseService.LogoutClicked);
     profile.Location       = new Point(sizeForm.Width - profile.Size.Width - 10, 1);
 }
コード例 #3
0
        public async Task <IActionResult> GetProfile()
        {
            var profile = _profileRepository.GetProfile(CurrentUserId);

            if (profile == null)
            {
                profile = new Profile.Profile
                {
                    UserId = CurrentUserId
                };
            }
            var user = await _userManager.FindByIdAsync(CurrentUserId.ToString());

            var logins = await _userManager.GetLoginsAsync(user);

            var hasPassword = await _userManager.HasPasswordAsync(user);

            var result = Mapper.Map <ProfileResponse>(profile);

            var measures = _measurementRepository.GetMeasures(CurrentUserId);

            result.Weight = measures.FirstOrDefault(m => m.Id == Constants.Measurements.WeightId)?.LatestValue;
            result.Height = measures.FirstOrDefault(m => m.Id == Constants.Measurements.HeightId)?.LatestValue;
            result.Rmr    = measures.FirstOrDefault(m => m.Id == Constants.Measurements.RmrId)?.LatestValue;

            result.Logins      = logins.Select(l => l.LoginProvider).ToArray();
            result.HasPassword = hasPassword;
            result.Username    = user.UserName;

            LogClientVersion();

            return(Ok(result));
        }
コード例 #4
0
        public void NotifyProfileChanged(Profile.Profile profile, uint?processId)
        {
            var title = string.Format(SettingsStrings.profile_notification_text, profile.Name);
            var text  = string.Join("\n", profile.Devices.Select(wrapper => wrapper.DeviceInfo.NameClean));

            Configuration.Icon.ShowBalloonTip(1000, title, text, ToolTipIcon.Info);
        }
コード例 #5
0
        public X509Certificate Generate(CspParameters cspParam, Profile.Profile Profile, DateTime NotBefore, DateTime NotAfter)
        {
            SetNotBefore(NotBefore);
            SetNotAfter(NotAfter);
            // Ignore profile - no extensions in V1

            return(Generate(cspParam));
        }
コード例 #6
0
        public void NoResultFromDatabase()
        {
            var profile  = new Profile.Profile();
            var database = new Fake.Database(profile);

            database.Connect();

            Assert.AreEqual("0.0.0-Nil", database.SchemaVersion().ToString());
        }
コード例 #7
0
        /// <summary>
        /// Notify on Profile changed
        /// </summary>
        public void NotifyProfileChanged(Profile.Profile profile, uint?processId)
        {
            if (!profile.NotifyOnActivation)
            {
                return;
            }

            _notification.NotifyProfileChanged(profile, processId);
        }
コード例 #8
0
 public static Data.Profile ToProfile(this Profile.Profile input)
 {
     return new Data.Profile
     {
         Id = input.Id,
         LoginId = input.LogindId,
         About = input.About,
         Name = input.Name,
         Image = input.Image.ToImage() as ProfileImage
     };
 }
コード例 #9
0
 public void Setup()
 {
     log     = new Core.Fake.Log();
     profile = new Profile.Profile()
     {
         Log = log
     };
     database = new Fake.Database(profile);
     database.Connect();
     database.Connection.Open();
 }
コード例 #10
0
ファイル: fipsCA.cs プロジェクト: hugocurran/OSCA2
 /// <summary>
 /// Generates the certificate.
 /// </summary>
 /// <param name="gen">The generator.</param>
 /// <param name="profile">The profile.</param>
 /// <param name="notBefore"></param>
 /// <param name="notAfter"></param>
 /// <returns></returns>
 protected override X509Certificate generate(ICertGen gen, Profile.Profile profile, DateTime notBefore, DateTime notAfter)
 {
     if (gen is SysV1CertGen)
     {
         return(((SysV1CertGen)gen).Generate(cspParam, profile, notBefore, notAfter));
     }
     else
     {
         return(((SysV3CertGen)gen).Generate(cspParam, profile, notBefore, notAfter));
     }
 }
コード例 #11
0
        public void NormalFullResult()
        {
            var profile  = new Profile.Profile();
            var database = new Fake.Database(profile);

            database.Connect();

            database.Add(new string[3] {
                "Business", "1.2.3", "4"
            });

            Assert.AreEqual("Business1.2.3-4", database.SchemaVersion().ToString());
        }
コード例 #12
0
        public async Task <IActionResult> SaveProfile([FromBody] ProfileRequest model)
        {
            var profile = _profileRepository.GetProfile(CurrentUserId);

            if (profile == null)
            {
                profile = new Profile.Profile
                {
                    UserId = CurrentUserId
                };
            }
            profile.DoB    = model.DoB;
            profile.Gender = model.Gender;

            var measures = _measurementRepository.GetMeasures(CurrentUserId);

            if (model.Weight.HasValue && model.Weight != measures.FirstOrDefault(m => m.Id == Constants.Measurements.WeightId)?.LatestValue)
            {
                _measurementRepository.CreateMeasurement(new Measurement
                {
                    MeasureId = Constants.Measurements.WeightId,
                    UserId    = CurrentUserId,
                    Time      = DateTimeOffset.Now,
                    Value     = model.Weight.Value
                });
            }
            if (model.Height.HasValue && model.Height != measures.FirstOrDefault(m => m.Id == Constants.Measurements.HeightId)?.LatestValue)
            {
                _measurementRepository.CreateMeasurement(new Measurement
                {
                    MeasureId = Constants.Measurements.HeightId,
                    UserId    = CurrentUserId,
                    Time      = DateTimeOffset.Now,
                    Value     = model.Height.Value
                });
            }
            if (model.Rmr.HasValue && model.Rmr != measures.FirstOrDefault(m => m.Id == Constants.Measurements.RmrId)?.LatestValue)
            {
                _measurementRepository.CreateMeasurement(new Measurement
                {
                    MeasureId = Constants.Measurements.RmrId,
                    UserId    = CurrentUserId,
                    Time      = DateTimeOffset.Now,
                    Value     = model.Rmr.Value
                });
            }

            _profileRepository.SaveProfile(profile);

            return(await GetProfile());
        }
コード例 #13
0
ファイル: CngV3CertGen.cs プロジェクト: hugocurran/OSCA2
        /// <summary>
        /// Generate an X509Certificate.
        /// </summary>
        /// <param name="cspParam">The CSP parameter.</param>
        /// <param name="Profile">OSCA profile.</param>
        /// <param name="NotBefore">The not before.</param>
        /// <param name="NotAfter">The not after.</param>
        /// <returns>
        /// An X509Certificate.
        /// </returns>
        /// <exception cref="PolicyEnforcementException">CA policy violation</exception>
        /// <exception cref="CertificateEncodingException">Exception encoding TBS cert
        /// or
        /// Exception producing certificate object</exception>
        public X509Certificate Generate(CngKey key, Profile.Profile Profile, DateTime NotBefore, DateTime NotAfter)
        {
            // Set the validity
            tbsGen.SetStartDate(new Time(NotBefore));
            tbsGen.SetEndDate(new Time(NotAfter));

            // Extract extensions from the profile
            foreach (ProfileExtension ext in Profile.Extensions)
            {
                extGenerator.AddExtension(ext.OID, ext.Critical, ext.DerEncoding);
            }

            // Call the generator
            return(Generate(key, extGenerator.Generate()));
        }
コード例 #14
0
        /// <summary>
        /// Issue a certificate based on a PKCS#10 certificate request and OSCA profile
        /// </summary>
        /// <param name="Request">DER encoded PKCS#10 certificate request</param>
        /// <param name="Profile">OSCA Profile</param>
        /// <returns>
        /// Requested certificate
        /// </returns>
        /// <exception cref="System.Exception">Certificate issue failed</exception>
        public X509Certificate IssueCertificate(byte[] Request, Profile.Profile Profile)
        {
            Pkcs10CertificationRequest p10;

            try
            {
                p10 = new Pkcs10CertificationRequest(Request);
            }
            catch (Exception ex)
            {
                logEvent(LogEvent.EventType.Error, "Certificate issue fail: " + ex.Message);
                throw new Exception("Certificate issue failed", ex);
            }
            return(IssueCertificate(p10, Profile));
        }
コード例 #15
0
ファイル: BcV3CertGen.cs プロジェクト: hugocurran/OSCA2
        /// <summary>
        /// Generate an X509Certificate.
        /// </summary>
        /// <param name="privateKey">The private key of the issuer that is signing this certificate.</param>
        /// <param name="Profile">OSCA profile.</param>
        /// <param name="Start">Start date</param>
        /// <returns>
        /// An X509Certificate.
        /// </returns>
        /// <exception cref="PolicyEnforcementException">CA policy violation</exception>
        /// <exception cref="CertificateEncodingException">Exception encoding TBS cert
        /// or
        /// Exception producing certificate object</exception>
        public virtual X509Certificate Generate(AsymmetricKeyParameter privateKey, Profile.Profile Profile, DateTime NotBefore, DateTime NotAfter)
        {
            // Set the validity according to the profile
            tbsGen.SetStartDate(new Time(NotBefore));
            tbsGen.SetEndDate(new Time(NotAfter));

            // Extract extensions from the profile
            foreach (ProfileExtension ext in Profile.Extensions)
            {
                extGenerator.AddExtension(ext.OID, ext.Critical, ext.DerEncoding);
            }

            // Call the generator
            return(Generate(privateKey, extGenerator.Generate()));
        }
コード例 #16
0
        /// <summary>
        /// Issue a certificate based on a PKCS#10 certificate request object and OSCA profile
        /// </summary>
        /// <param name="Request">PKCS#10 certificate request</param>
        /// <param name="Profile">The profile.</param>
        /// <returns>
        /// Requested certificate
        /// </returns>
        /// <exception cref="System.Exception">Certificate issue failed</exception>
        public X509Certificate IssueCertificate(Pkcs10CertificationRequest Request, Profile.Profile Profile)
        {
            X509Certificate cert = null;

            try
            {
                cert = issueCertificate(Request, Profile, DateTime.Now.ToUniversalTime(), Profile.CertificateLifetime.NotAfter(DateTime.Now).ToUniversalTime());
                logEvent(LogEvent.EventType.IssueCert, "Certificate issued. Serial: " + cert.SerialNumber.ToString());
            }
            catch (Exception ex)
            {
                logEvent(LogEvent.EventType.Error, "Certificate issue fail: " + ex.Message);
                throw new Exception("Certificate issue failed: " + ex.Message, ex);
            }

            return(cert);
        }
コード例 #17
0
        /// <summary>
        /// Issue a certificate based on a PKCS#10 certificate request object, OSCA profile and notBefore/notAfter dates
        /// </summary>
        /// <param name="Request">PKCS#10 certificate request</param>
        /// <param name="Profile">The profile.</param>
        /// <param name="NotBefore">The not before.</param>
        /// <param name="NotAfter">The not after.</param>
        /// <returns>
        /// Requested certificate
        /// </returns>
        /// <exception cref="System.Exception">Certificate issue failed</exception>
        /// <remarks>
        /// This method is intended to support rekey.
        /// </remarks>
        public X509Certificate IssueCertificate(Pkcs10CertificationRequest Request, Profile.Profile Profile, DateTime NotBefore, DateTime NotAfter)
        {
            X509Certificate cert = null;

            try
            {
                cert = issueCertificate(Request, Profile, NotBefore, NotAfter);
                logEvent(LogEvent.EventType.IssueCert, "Certificate issued. Serial: " + cert.SerialNumber.ToString());
            }
            catch (Exception ex)
            {
                logEvent(LogEvent.EventType.Error, "Certificate issue fail: " + ex.Message);
                throw new Exception("Certificate issue failed", ex);
            }

            return(cert);
        }
コード例 #18
0
        public void NotifyProfileChanged(Profile.Profile profile, uint?processId)
        {
            if (profile.Playback == null)
            {
                return;
            }

            using var enumerator = new MMDeviceEnumerator();
            try
            {
                var device = enumerator.GetDevice(profile.Playback.Id);
                NotifyDefaultChanged(device);
            }
            catch (Exception)
            {
                //Ignored
            }
        }
コード例 #19
0
        public void GetSingle()
        {
            var profile  = new Profile.Profile();
            var database = new Fake.Database(profile);

            database.Connect();

            database.Add(new string[2] {
                "Stephen Arthur Jazdzewski", "Steve"
            });

            var individual = new Individual(database, 3);

            Assert.AreEqual(3, individual.Id);
            Assert.AreEqual(true, individual.Person);
            Assert.AreEqual("Steve", individual.GoesBy);
            Assert.AreEqual("Stephen Arthur Jazdzewski", individual.FullName);
        }
コード例 #20
0
        public void AuthenticationFailure()
        {
            var log     = new Core.Fake.Log();
            var profile = new Profile.Profile()
            {
                Log = log
            };

            Database = new Fake.Database(profile)
            {
                // Driver specific Exception
                DatabaseException = new System.Exception("Authentication failed")
            };

            Assert.Throws(typeof(System.Exception), new TestDelegate(HostConnectOpenException));

            Assert.That(log.Output, Contains.Substring(Log.Level.Fatal.ToString()));
            Assert.That(log.Output, Contains.Substring("Authentication failed"));
        }
コード例 #21
0
        public void ConnectionRefused()
        {
            var log     = new Core.Fake.Log();
            var profile = new Profile.Profile()
            {
                Log = log
            };

            Database = new Fake.Database(profile)
            {
                // Could not resolve host 'hostname'
                // https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
                ConnectionException = new System.Net.Sockets.SocketException(10061)
            };

            Assert.Throws(typeof(System.Net.Sockets.SocketException), new TestDelegate(HostConnectOpenException));

            Assert.That(log.Output, Contains.Substring(Log.Level.Fatal.ToString()));
            Assert.That(log.Output, Contains.Substring("refused"));
        }
コード例 #22
0
        public void CantFindTable()
        {
            var log     = new Core.Fake.Log();
            var profile = new Profile.Profile()
            {
                Log = log
            };

            // Driver specific Exception
            Database = new Fake.Database(profile)
            {
                CommandException = new System.Exception("can't find table \"VERSIONS\"")
            };
            Database.Connect();
            Database.Connection.Open();

            Assert.Throws(typeof(System.Exception), new TestDelegate(ExecuteReaderException));

            Assert.That(log.Output, Contains.Substring(Log.Level.Fatal.ToString()));
            Assert.That(log.Output, Contains.Substring("VERSIONS"));
        }
コード例 #23
0
        public void Book()
        {
            var profile  = new Profile.Profile();
            var database = new Fake.Database(profile);

            database.Connect();

            var   bookName   = "Sales";
            float bookAmount = 111.11F;
            int?  entryId    = 1;

            database.SetValue(entryId);

            var entry = database.Book(bookName, bookAmount);

            CheckTransaction(database);

            Assert.IsNotNull(entry);
            Assert.Greater(entry, 0);
            Assert.AreEqual(entryId, entry);
        }
コード例 #24
0
        public void ReaderGet()
        {
            var log     = new Core.Fake.Log();
            var profile = new Profile.Profile()
            {
                Log = log
            };

            // Driver specific Exception
            Database = new Fake.Database(profile)
            {
                ReaderGetException = new System.Exception("Before start of result set")
            };
            Database.Connect();
            Database.Connection.Open();
            Database.Command.CommandText = "";
            Reader = (Fake.Reader)Database.Command.ExecuteReader();
            Reader.Read();

            Assert.Throws(typeof(System.Exception), new TestDelegate(ReadGetException));

            Assert.That(log.Output, Contains.Substring(Log.Level.Error.ToString()));
            Assert.That(log.Output, Contains.Substring("Before start"));
        }
コード例 #25
0
        public void DataReadError()
        {
            var log     = new Core.Fake.Log();
            var profile = new Profile.Profile()
            {
                Log = log
            };
            var database = new Fake.Database(profile)
            {
                // Driver specific Exception
                ReaderGetException = new System.Exception("Before start of result set")
            };

            database.Connect();

            database.Add(new string[3] {
                "Business", "1.2.3", "4"
            });

            Assert.AreEqual("0.0.0-Nil", database.SchemaVersion().ToString());
            Assert.That(log.Output, Contains.Substring(Log.Level.Error.ToString()));
            Assert.That(log.Output, Contains.Substring("Before start"));
            Assert.That(log.Output, Contains.Substring("Version"));
        }
コード例 #26
0
ファイル: Database.cs プロジェクト: macromatt/Business
 public Database(Profile.Profile profile)
 {
     Profile = profile;
 }
コード例 #27
0
 public void NotifyProfileChanged(Profile.Profile profile, uint?processId)
 {
 }
コード例 #28
0
 /// <summary>
 /// Generates the certificate.
 /// </summary>
 /// <param name="gen">The generator.</param>
 /// <param name="profile">The profile.</param>
 /// <param name="notBefore">The not before.</param>
 /// <param name="notAfter">The not after.</param>
 /// <returns></returns>
 protected virtual X509Certificate generate(ICertGen gen, Profile.Profile profile, DateTime notBefore, DateTime notAfter)
 {
     return(((IbcCertGen)gen).Generate(privateKey, profile, notBefore, notAfter));
 }
コード例 #29
0
        /// <summary>
        /// Migrate configuration to a new schema
        /// </summary>
        public bool Migrate()
        {
            var migrated = false;

            if (SelectedPlaybackDeviceListId.Count > 0)
            {
                SelectedDevices.UnionWith(
                    SelectedPlaybackDeviceListId.Select((s => new DeviceInfo("", s, DataFlow.Render))));
                SelectedPlaybackDeviceListId.Clear();
                migrated = true;
            }

            if (SelectedRecordingDeviceListId.Count > 0)
            {
                SelectedDevices.UnionWith(
                    SelectedRecordingDeviceListId.Select((s => new DeviceInfo("", s, DataFlow.Capture))));
                SelectedRecordingDeviceListId.Clear();
                migrated = true;
            }

            if (NotificationSettings == NotificationTypeEnum.ToastNotification)
            {
                NotificationSettings = NotificationTypeEnum.BannerNotification;
            }

#pragma warning disable 612
            if (!MigratedFields.Contains(nameof(KeepSystrayIcon)))
            {
                SwitchIcon = KeepSystrayIcon ? IconChangerFactory.ActionEnum.Never : IconChangerFactory.ActionEnum.Always;
                MigratedFields.Add(nameof(KeepSystrayIcon));
                migrated = true;
            }

            if (!MigratedFields.Contains(nameof(ProfileSettings) + "_final"))
            {
                Profiles = ProfileSettings
                           .Select(setting =>
                {
                    var profile = new Profile.Profile
                    {
                        AlsoSwitchDefaultDevice = setting.AlsoSwitchDefaultDevice,
                        Communication           = null,
                        Playback  = setting.Playback,
                        Name      = setting.ProfileName,
                        Recording = setting.Recording
                    };
                    if (setting.HotKey != null)
                    {
                        profile.Triggers.Add(new Trigger(TriggerFactory.Enum.HotKey)
                        {
                            HotKey = setting.HotKey
                        });
                    }

                    if (!string.IsNullOrEmpty(setting.ApplicationPath))
                    {
                        profile.Triggers.Add(new Trigger(TriggerFactory.Enum.Process)
                        {
                            ApplicationPath = setting.ApplicationPath
                        });
                    }

                    return(profile);
                }).ToHashSet();
                MigratedFields.Add(nameof(ProfileSettings) + "_final");
                migrated = true;
            }

            if (!MigratedFields.Contains(nameof(LastDonationNagTime)))
            {
                LastDonationNagTime = DateTime.UtcNow - TimeSpan.FromDays(10);
                MigratedFields.Add(nameof(LastDonationNagTime));
                migrated = true;
            }

            return(migrated);

#pragma warning restore 612
        }
コード例 #30
0
        /// <summary>
        /// Issues the certificate.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="profile">The profile</param>
        /// <param name="notBefore">The not before.</param>
        /// <param name="notAfter">The not after.</param>
        /// <returns>
        /// Certificate
        /// </returns>
        /// <exception cref="System.ArgumentException">Invalid signature algorithm in request</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Invalid lifetime units in ValidityPeriod</exception>
        private X509Certificate issueCertificate(Pkcs10CertificationRequest request, Profile.Profile profile, DateTime notBefore, DateTime notAfter)
        {
            X509Certificate newCert;
            string          profileName = "";

            // Parse the request
            Pkcs10Parser p10 = new Pkcs10Parser(request);

            // Check that correct sig algorithm has been used
            DerObjectIdentifier sigAlgOid = X509Utilities.GetAlgorithmOid(signatureAlgorithm);

            if (!p10.SignatureAlgorithm.Equals(sigAlgOid))
            {
                logEvent(LogEvent.EventType.Error, "Invalid signature algorithm in request: " + p10.SignatureAlgorithm.ToString());
                throw new ArgumentException("Invalid signature algorithm in request", p10.SignatureAlgorithm.ToString());
            }

            // Create a Cert Generator according to the FIPS 140 policy and CA Type
            ICertGen certGen;

            if ((fips140) && (type == CA_Type.dhTA.ToString()))
            {
                certGen = new SysV1CertGen();
            }
            else if ((fips140) && (type != CA_Type.dhTA.ToString()))
            {
                certGen = new SysV3CertGen(policyEnforcement);
            }
            else
            {
                certGen = new BcV3CertGen(policyEnforcement);
            }

            // Setup the certificate
            certGen.SetSerialNumber(nextCertSerial());
            certGen.SetIssuerDN(caCertificate.SubjectDN);
            certGen.SetSubjectDN(p10.Subject);
            certGen.SetPublicKey(p10.PublicKey);
            certGen.SetSignatureAlgorithm(signatureAlgorithm);
            if (certGen.GetVersion() == X509ver.V3)
            {
                ((V3CertGen)certGen).AddExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(caCertificate.GetPublicKey()));
                ((V3CertGen)certGen).AddExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(p10.PublicKey));
            }

            // Add further extensions either from profile or request attributes
            // If a profile is specified ignore all attributes apart from SubjAltName
            if (profile != null)
            {
                // Add in SubjAltName if there is one
                if ((p10.SubjectAltNames != null) && (certGen.GetVersion() == X509ver.V3))
                {
                    bool critical = p10.IsCritical(X509Extensions.SubjectAlternativeName);
                    ((V3CertGen)certGen).AddExtension(X509Extensions.SubjectAlternativeName, critical, p10.SubjectAltNames);
                }

                // Capture the profile name for database
                profileName = profile.Name;

                // cut the cert
                newCert = generate(certGen, profile, notBefore, notAfter);
            }
            else    // No profile
            {
                // Set the validity period
                certGen.SetNotBefore(notBefore.ToUniversalTime());
                certGen.SetNotAfter(notAfter.ToUniversalTime());

                // Do what it says in the request
                newCert = generate(certGen, p10.Extensions);
            }

            // Add certificate to the CA DB
            Database.AddCertificate(newCert, request.GetDerEncoded(), profileName, dbFileLocation, caCertificate, cspParam);
            logEvent(LogEvent.EventType.DBAddCert, "DB: Certificate added: " + newCert.SerialNumber.ToString());

            return(newCert);
        }