Example #1
0
 private void CheckLicensing()
 {
     foreach (PluginEntry pe in m_plugins)
     {
         try
         {
             // iterate through all loaded plugins
             // get the vendor id
             int        vid = pe.m_plugin.GetInt("VendorID");
             LicenseKey lk  = KeyRing.Instance().Find(vid);
             if (lk != null)
             {
                 pe.m_licensed = true;
             }
             int options = pe.m_plugin.GetInt("Options");
             if (options != -1)
             {
                 if ((options & PluginOptions.OPTION_NOLICENSE) != 0)
                 {
                     pe.m_licensed = true;
                 }
             }
         }
         catch (Exception ex)
         {
             DebugLogger.Instance().LogError(ex);
         }
     }
 }
Example #2
0
    public void Unprotect_KeyNotFound_ThrowsKeyNotFound()
    {
        // Arrange
        Guid notFoundKeyId = new Guid("654057ab-2491-4471-a72a-b3b114afda38");

        byte[] protectedData = BuildProtectedDataFromCiphertext(
            keyId: notFoundKeyId,
            ciphertext: new byte[0]);

        var mockDescriptor       = new Mock <IAuthenticatedEncryptorDescriptor>();
        var mockEncryptorFactory = new Mock <IAuthenticatedEncryptorFactory>();

        mockEncryptorFactory.Setup(o => o.CreateEncryptorInstance(It.IsAny <IKey>())).Returns(new Mock <IAuthenticatedEncryptor>().Object);
        var encryptorFactory = new AuthenticatedEncryptorFactory(NullLoggerFactory.Instance);

        // the keyring has only one key
        Key key                 = new Key(Guid.Empty, DateTimeOffset.Now, DateTimeOffset.Now, DateTimeOffset.Now, mockDescriptor.Object, new[] { mockEncryptorFactory.Object });
        var keyRing             = new KeyRing(key, new[] { key });
        var mockKeyRingProvider = new Mock <IKeyRingProvider>();

        mockKeyRingProvider.Setup(o => o.GetCurrentKeyRing()).Returns(keyRing);

        IDataProtector protector = new KeyRingBasedDataProtector(
            keyRingProvider: mockKeyRingProvider.Object,
            logger: GetLogger(),
            originalPurposes: null,
            newPurpose: "purpose");

        // Act & assert
        var ex = ExceptionAssert2.ThrowsCryptographicException(() => protector.Unprotect(protectedData));

        Assert.Equal(Error.Common_KeyNotFound(notFoundKeyId).Message, ex.Message);
    }
Example #3
0
        public OicqRequestTgtgt(uint uin, string password, uint ssoseq, KeyRing keyring)
        {
            _cmd    = 0x0810;
            _subCmd = 0x09;

            _keyBody = new KeyBody(keyring._randKey, keyring._defaultPublicKey);
            _tlvBody = new TlvBody(_subCmd, uin, password, ssoseq, keyring._tgtgKey);

            // 構建 oicq_request
            PutByte(0x02); // 頭部 0x02

            EnterBarrier(2, Endian.Big, 4);
            {
                PutUshortBE(8001); // 協議版本 1F 41
                PutUshortBE(_cmd);
                PutUshortBE(1);
                PutUintBE(uin);
                PutByte(0x03);
                PutByte(0x87); // 加密方式id
                PutByte(0x00); // 永遠0
                PutUintBE(2);
                PutUintBE(AppInfo.appClientVersion);
                PutUintBE(0);

                PutPacket(_keyBody);
                PutPacketEncrypted(_tlvBody, TeaCryptor.Instance, keyring._shareKey);
            }
            LeaveBarrier();

            PutByte(0x03); // 尾部 0x03
        }
Example #4
0
    public void GetAuthenticatedEncryptorByKeyId_DefersInstantiation_AndReturnsRevocationInfo()
    {
        // Arrange
        var expectedEncryptorInstance1 = new Mock <IAuthenticatedEncryptor>().Object;
        var expectedEncryptorInstance2 = new Mock <IAuthenticatedEncryptor>().Object;

        var key1 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance1, isRevoked: true);
        var key2 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance2);


        // Act
        var keyRing = new KeyRing(key2, new[] { key1, key2 });

        // Assert
        Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled);
        Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out var isRevoked));
        Assert.True(isRevoked);
        Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled);
        Assert.Same(expectedEncryptorInstance1, keyRing.GetAuthenticatedEncryptorByKeyId(key1.KeyId, out isRevoked));
        Assert.True(isRevoked);
        Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled);
        Assert.Equal(0, key2.NumTimesCreateEncryptorInstanceCalled);
        Assert.Same(expectedEncryptorInstance2, keyRing.GetAuthenticatedEncryptorByKeyId(key2.KeyId, out isRevoked));
        Assert.False(isRevoked);
        Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled);
        Assert.Same(expectedEncryptorInstance2, keyRing.GetAuthenticatedEncryptorByKeyId(key2.KeyId, out isRevoked));
        Assert.False(isRevoked);
        Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled);
        Assert.Same(expectedEncryptorInstance2, keyRing.DefaultAuthenticatedEncryptor);
        Assert.Equal(1, key2.NumTimesCreateEncryptorInstanceCalled);
    }
Example #5
0
        public static void FindKeys_OnCommand(CommandEventArgs e)
        {
            uint keyval = 0;

            try { keyval = uint.Parse(e.ArgString); }
            catch { e.Mobile.SendMessage("Error"); }

            if (keyval <= 0)
            {
                e.Mobile.SendMessage("Invalid keyval.");
                return;
            }

            foreach (Item i in World.Items.Values)
            {
                if ((i is KeyRing) && (( KeyRing )i).Keys != null && (( KeyRing )i).Keys.Count > 0)
                {
                    KeyRing ring = ( KeyRing )i;

                    foreach (KeyInfo info in ring.Keys)
                    {
                        if (info.KeyValue == keyval)
                        {
                            e.Mobile.SendMessage("Key Found On: {0}", ring.Serial);
                        }
                    }
                }
            }
        }
Example #6
0
        public static Item DupeItem(Mobile from, object item, bool RecurseContainers)
        {
            Type   t = item.GetType();
            object o = Construct(t);

            if (o == null)
            {
                if (from != null)
                {
                    from.SendMessage("Unable to dupe {0}. Item must have a 0 parameter constructor.", t.Name);
                }

                return(null);
            }

            if (o is Item)
            {
                Item newItem = (Item)o;
                Item srcItem = (Item)item;
                CopyProperties(o, item, t, "Parent");

                if ((o is Container) && RecurseContainers)
                {
                    Container srcContainer = (Container)item;
                    Container newContainer = (Container)o;

                    newContainer.Items.Clear(); // if container object type adds items in its constructor, we need to remove them.
                    for (int i = 0; i < srcContainer.Items.Count; i++)
                    {
                        Item a = DupeItem(from, srcContainer.Items[i], true);

                        if (a != null)
                        {
                            newContainer.AddItem(a);
                            newContainer.UpdateTotals();
                        }
                    }
                }

                if ((o is KeyRing) && RecurseContainers)
                {
                    KeyRing srcRing = (KeyRing)item;
                    KeyRing newRing = new KeyRing();

                    int count = srcRing.Keys.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Key newkey = new Key(srcRing.Keys[i].KeyValue);
                        newRing.Add(newkey);
                    }
                    return(newRing);
                }

                newItem.UpdateTotals();
                return(newItem);
            }

            return(null);
        }
 //Megadjaegy questnek a rewardját questId alapján
 public void GiveQuestReward(int questId)
 {
     PlayerStats.Money = _inMemoryContextHelper.LoadDataType <Quest>()[questId].Reward;
     if (_inMemoryContextHelper.LoadDataType <Quest>()[questId].KeyReward != null)
     {
         KeyRing.AddKey(_inMemoryContextHelper.LoadDataType <Quest>()[questId].KeyReward);
     }
 }
 /// <summary>
 /// Checks if a lock can be opened.
 /// </summary>
 /// <param name="lockName"> The name of the lock.</param>
 /// <returns>True if it can be opened, False if not.</returns>
 public bool CheckEntryPointLock(String lockName)
 {
     if (KeyRing.CheckKey(lockName))
     {
         return(true);
     }
     return(false);
 }
Example #9
0
        public void GetAuthenticatedEncryptorByKeyId_should_return_encryptor()
        {
            var sut = new KeyRing(new Mock <IKey>().Object, new[] { new Mock <IKey>().Object }, new RsaEncryptorConfiguration());

            var result = sut.GetAuthenticatedEncryptorByKeyId(Guid.NewGuid(), out bool _);

            Assert.Null(result);
        }
Example #10
0
        public void DefaultAuthenticatedEncryptor_should_return_encryptor()
        {
            var sut = new KeyRing(new Mock <IKey>().Object, new[] { new Mock <IKey>().Object }, new RsaEncryptorConfiguration());

            var result = sut.DefaultAuthenticatedEncryptor;

            Assert.Null(result);
        }
        // [END kms_create_keyring]

        // [START kms_get_keyring]
        public static void GetKeyRing(string projectId, string locationId, string keyRingId)
        {
            KeyManagementServiceClient client = KeyManagementServiceClient.Create();
            KeyRingName keyRingName           = new KeyRingName(projectId, locationId, keyRingId);

            KeyRing result = client.GetKeyRing(keyRingName);

            Console.WriteLine($"Found KeyRing: {result.Name}");
            Console.WriteLine($"  Created on: {result.CreateTime}");
        }
Example #12
0
        /// <summary>
        /// Loading 'lite' plugins from zip file .plg files
        /// </summary>
        public void ScanForPluginsLite()
        {
            // load the list of plugin states
            string picn = m_apppath + m_pathsep + "pluginconfig.cfg"; // plugin configuration name

            m_pluginstates.Load(picn);

            // get a list of dll's in this current directory
            // try to register them as a plug-in
            string[] filePaths = Directory.GetFiles(m_apppath, "*.plg");
            foreach (String pluginname in filePaths)
            {
                try
                {
                    // create an instance of the plugin
                    PluginLite pll = new PluginLite();
                    pll.m_filename = pluginname;
                    pll.LoadManifest();
                    IPlugin plug = (IPlugin)pll;
                    string  args = Path.GetFileNameWithoutExtension(pluginname);

                    // create an entry for the plugin
                    PluginEntry pe = new PluginEntry(plug, args);
                    //add the entry to the list of plugins
                    m_plugins.Add(pe);
                    //mark the plugin as enabled by default
                    pe.m_enabled = true;
                    if (m_pluginstates.InList(args))
                    {
                        // this plugin is listed in the disabled list.
                        DebugLogger.Instance().LogInfo("Plugin " + args + " marked disabled");
                        pe.m_enabled = false;
                    }
                    //get the vendor id of the newly loaded plugin
                    int vid = plug.GetInt("VendorID");
                    //look for the license key for this plugin
                    LicenseKey lk = KeyRing.Instance().Find(vid);
                    // if we found it, mark it as licensed
                    if (lk != null)
                    {
                        //initialize the plugin by setting the host.
                        if (pe.m_enabled)
                        {
                            plug.Host = this; // this will initialize the plugin - the plugin's init function will be called
                            DebugLogger.Instance().LogInfo("Loaded licensed plugin " + args);
                        }
                    }
                    DebugLogger.Instance().LogInfo("Loaded plugin " + args);
                }
                catch (Exception ex)
                {
                    DebugLogger.Instance().LogError(ex.Message);
                }
            }
        }
 private string FindLicenseKey(int vendorID)
 {
     foreach (LicenseKey lk in KeyRing.Instance().m_keys)
     {
         if (vendorID == lk.VendorID)
         {
             return(lk.m_key);
         }
     }
     return("no key");
 }
 public void ScanForPlugins()
 {
     // get a list of dll's in this current directory
     // try to register them as a plug-in
     //string[] filePaths = Directory.GetFiles(m_apppath + m_pathsep + "Plugins", "*.dll");
     string[] filePaths = Directory.GetFiles(m_apppath, "*.dll");
     foreach (String pluginname in filePaths)
     {
         string args = Path.GetFileNameWithoutExtension(pluginname);
         if (args.ToLower().StartsWith("pl"))
         {
             // located a dll that is a potential plugin
             Type ObjType = null;
             try
             {
                 // load it
                 Assembly ass = null;
                 //string args = Path.GetFileNameWithoutExtension(pluginname);
                 ass = Assembly.Load(args);
                 if (ass != null)
                 {
                     ObjType = ass.GetType(args + ".PlugIn"); // look for the plugin interface
                     // OK Lets create the object as we have the Report Type
                     if (ObjType != null)
                     {
                         // create an instance of the plugin
                         IPlugin plug = (IPlugin)Activator.CreateInstance(ObjType);
                         // create an entry for the plugin
                         PluginEntry pe = new PluginEntry(plug);
                         //add the entry to the list of plugins
                         m_plugins.Add(pe);
                         //get the vendor id of the newly loaded plugin
                         int vid = plug.GetInt("VendorID");
                         //look for the license key for this plugin
                         LicenseKey lk = KeyRing.Instance().Find(vid);
                         // if we found it, mark it as licensed
                         if (lk != null)
                         {
                             pe.m_licensed = true;
                             //initialize the plugin by setting the host.
                             plug.Host = this; // this will initialize the plugin - the plugin's init function will be called
                             DebugLogger.Instance().LogInfo("Loaded licensed plugin " + args);
                         }
                         DebugLogger.Instance().LogInfo("Loaded plugin " + args);
                     }
                 }
             }
             catch (Exception ex)
             {
                 DebugLogger.Instance().LogError(ex.Message);
             }
         }
     }
 }
Example #15
0
        public Core(uint uin, string password)
        {
            _uin      = uin;
            _password = password;

            _lastError    = 0;
            _lastErrorStr = "";

            _ssoMan  = new SsoMan(this);
            _keyRing = new KeyRing();
        }
Example #16
0
        public void EncryptionOfALookupFieldIsDeterministic()
        {
            const string input = "*****@*****.**";

            var keyRing         = new KeyRing();
            var lookupProtector = new AspNetCoreIdentityEncryption.LookupProtector(keyRing);

            string output1 = lookupProtector.Protect(keyRing.CurrentKeyId, input);
            string output2 = lookupProtector.Protect(keyRing.CurrentKeyId, input);

            Assert.Equal(output1, output2);
        }
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")  // Player triggered collision with key
        {
            KeyRing keyRing = other.GetComponent <KeyRing>();

            if (keyRing.Pickupkey(colour) == true) // key has been picked up by player
            {
                gameObject.SetActive(false);       // remove object from Unity scene as picked up
            }
        }
    }
Example #18
0
    public void DefaultKeyId_Prop()
    {
        // Arrange
        var key1 = new MyKey();
        var key2 = new MyKey();

        // Act
        var keyRing = new KeyRing(key2, new[] { key1, key2 });

        // Assert
        Assert.Equal(key2.KeyId, keyRing.DefaultKeyId);
    }
        public void EncryptionOfALookupFieldIsNotDeterministic()
        {
            const string input = "*****@*****.**";

            var keyRing = new KeyRing();
            var personalDataProtector = new AspNetCoreIdentityEncryption.PersonalDataProtector(keyRing);

            string output1 = personalDataProtector.Protect(input);
            string output2 = personalDataProtector.Protect(input);

            Assert.NotEqual(output1, output2);
        }
Example #20
0
        public void EncryptionTwoDifferentPlainTextsDoesNotProduceTheSameResult()
        {
            const string input1 = "*****@*****.**";
            const string input2 = "*****@*****.**";

            var keyRing         = new KeyRing();
            var lookupProtector = new AspNetCoreIdentityEncryption.LookupProtector(keyRing);

            string output1 = lookupProtector.Protect(keyRing.CurrentKeyId, input1);
            string output2 = lookupProtector.Protect(keyRing.CurrentKeyId, input2);

            Assert.NotEqual(output1, output2);
        }
Example #21
0
        public void EncryptThenDecryptProducesPlainText()
        {
            const string input = "*****@*****.**";

            var keyRing         = new KeyRing();
            var keyId           = keyRing.CurrentKeyId;
            var lookupProtector = new AspNetCoreIdentityEncryption.LookupProtector(keyRing);

            var cipherText = lookupProtector.Protect(keyId, input);
            var plainText  = lookupProtector.Unprotect(keyId, cipherText);

            Assert.Equal(input, plainText);
        }
        public GameCoreServices(GamePage gamePage, GamePageViewModel gamePageViewModel, PlayerStats playerStats, LogHelper logHelper, InMemoryContextHelper inMemoryContextHelper)
        {
            LogHelper  = logHelper;
            KeyRing    = new KeyRing();
            GameCanvas = gamePage.MainCanvas;
            StackPanel = gamePage._InventoryStackPanel;

            GamePageViewModel           = gamePageViewModel;
            PlayerStats                 = playerStats;
            PlayerStats.CurrentLocation = inMemoryContextHelper.LoadDataType <Location>()[0];

            _inMemoryContextHelper = inMemoryContextHelper;
        }
        // [END kms_list_cryptokeys]

        // [START kms_create_keyring]
        public static void CreateKeyRing(string projectId, string locationId, string keyRingId)
        {
            KeyManagementServiceClient client = KeyManagementServiceClient.Create();

            // The location in which to create the key ring.
            LocationName locationName = new LocationName(projectId, locationId);

            // Initial values for the KeyRing (currently unused).
            KeyRing keyRing = new KeyRing();

            KeyRing result = client.CreateKeyRing(locationName, keyRingId, keyRing);

            Console.Write($"Created Key Ring: {result.Name}");
        }
Example #24
0
    public void DefaultKeyIdAndEncryptor_IfDefaultKeyNotPresentInAllKeys()
    {
        // Arrange
        var key1 = new MyKey();
        var key2 = new MyKey();
        var key3 = new MyKey(expectedEncryptorInstance: new Mock <IAuthenticatedEncryptor>().Object);

        // Act
        var keyRing = new KeyRing(key3, new[] { key1, key2 });

        // Assert
        Assert.Equal(key3.KeyId, keyRing.DefaultKeyId);
        Assert.Equal(key3.CreateEncryptor(), keyRing.GetAuthenticatedEncryptorByKeyId(key3.KeyId, out var _));
    }
Example #25
0
        public void RoatingTheKeyRingDoesNotBreakDecryption()
        {
            const string input = "*****@*****.**";

            var keyRing         = new KeyRing();
            var keyId           = keyRing.CurrentKeyId;
            var lookupProtector = new AspNetCoreIdentityEncryption.LookupProtector(keyRing);

            var cipherText = lookupProtector.Protect(keyId, input);

            keyRing.CreateAndActivateNewKey();
            var plainText = lookupProtector.Unprotect(keyId, cipherText);

            Assert.Equal(input, plainText);
        }
Example #26
0
        // [END kms_list_cryptokeys]

        // [START kms_create_keyring]
        public static object CreateKeyRing(string projectId, string location, string keyRing)
        {
            var cloudKms = CreateAuthorizedClient();
            // Generate the full path of the parent to use for creating key rings.
            var     parent          = $"projects/{projectId}/locations/{location}";
            KeyRing keyRingToCreate = new KeyRing();
            var     request         = new ProjectsResource.LocationsResource.KeyRingsResource.CreateRequest(
                cloudKms, keyRingToCreate, parent);

            request.KeyRingId = keyRing;
            var result = request.Execute();

            Console.Write($"Created Key Ring: {result.Name}");
            return(0);
        }
        public KeysetDialog(KeyRing rng = null)
        {
            InitializeComponent();
            ring = rng;

            if (ring != null)
            {
                textBoxName.Text = ring.Name;
            }
            else
            {
                Text = "New Key Ring";
                ring = new KeyRing(-1, "");
            }
            buttonSave.Enabled = false;
        }
Example #28
0
        public void RoatingTheKeyRingProducesDifferentResultsFromEncryption()
        {
            const string input = "*****@*****.**";

            var keyRing         = new KeyRing();
            var lookupProtector = new AspNetCoreIdentityEncryption.LookupProtector(keyRing);

            var keyId   = keyRing.CurrentKeyId;
            var result1 = lookupProtector.Protect(keyId, input);

            keyRing.CreateAndActivateNewKey();
            var newKeyId = keyRing.CurrentKeyId;
            var result2  = lookupProtector.Protect(newKeyId, input);

            Assert.NotEqual(result1, result2);
        }
Example #29
0
    public void DefaultAuthenticatedEncryptor_Prop_InstantiationIsDeferred()
    {
        // Arrange
        var expectedEncryptorInstance = new Mock <IAuthenticatedEncryptor>().Object;

        var key1 = new MyKey(expectedEncryptorInstance: expectedEncryptorInstance);
        var key2 = new MyKey();

        // Act
        var keyRing = new KeyRing(key1, new[] { key1, key2 });

        // Assert
        Assert.Equal(0, key1.NumTimesCreateEncryptorInstanceCalled);
        Assert.Same(expectedEncryptorInstance, keyRing.DefaultAuthenticatedEncryptor);
        Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled);
        Assert.Same(expectedEncryptorInstance, keyRing.DefaultAuthenticatedEncryptor);
        Assert.Equal(1, key1.NumTimesCreateEncryptorInstanceCalled); // should've been cached
    }
Example #30
0
        private async Task <List <string> > GetOutOfSyncAddressesAsync()
        {
            var qbitResult = await _qBitNinjaWalletClient.GetAddresses();

            var qbitAddresses = qbitResult.Select(x => x.Address.ToString()).ToList();
            var safeAddresses = new HashSet <string>();

            for (var i = 0; i < AddressCount; i++)
            {
                safeAddresses.Add(KeyRing.GetAddress(i));
            }

            if (qbitAddresses.Any(qbitAddress => !safeAddresses.Contains(qbitAddress)))
            {
                throw new Exception("QBitNinja wallet and HTTPKeyRingMonitor is out of sync.");
            }

            return(safeAddresses.Where(safeAddress => !qbitAddresses.Contains(safeAddress)).ToList());
        }
Example #31
0
 private void LoadLicenseKeys()
 {
     try
     {
         string licensefile = m_apppath + m_pathsep + "licenses.key";
         if (File.Exists(licensefile))
         {
             KeyRing.Instance().Load(licensefile);
         }
         else
         {
             DebugLogger.Instance().LogInfo("No Key Ring found");
         }
     }
     catch (Exception)
     {
         DebugLogger.Instance().LogInfo("No License File");
     }
 }
 private void loadKeyrings(SQLiteConnection conn)
 {
     SQLiteCommand command = new SQLiteCommand("SELECT ID, Name, owner FROM keyring", conn);
     SQLiteDataReader reader = command.ExecuteReader();
     KeyRing ring;
     while (reader.Read())
     {
         ring = new KeyRing(reader.GetInt16(0), reader.GetString(1));
         if (!reader.IsDBNull(2))
         {
             ring.owner = GetPersonnelById(reader.GetInt16(2));
         }
         keyrings.Add(ring);
     }
 }
Example #33
0
        private void buttonCheckoutAddKeyRing_Click(object sender, EventArgs e)
        {

            //Create objects to hold selected checkout and selected keyring
            Checkout selectedCheckout = new Checkout();
            KeyRing selectedKeyRing = new KeyRing();

            //Assign selected checkout
            if (listBoxCheckoutCheckouts.SelectedIndex != -1)
            {
                foreach (Checkout checkout in objects.checkouts)
                {
                    if (checkout.Id == (int)listBoxCheckoutCheckouts.SelectedItem)
                    {
                        selectedCheckout = checkout;
                    }
                }
            }

            ////If a value is selected from the combo box, check it against the current items in the list. If it doesn't exist, add it. 
            //if (comboBoxCheckoutAddKeyRing.SelectedIndex != -1)
            //{
            //    //if (listBoxCheckoutKeyRing.FindString(comboBoxCheckoutAddKeyRing.SelectedItem.ToString(), -1) == -1)
            //    //{
            //        listBoxCheckoutKeyRing.Items.Add(comboBoxCheckoutAddKeyRing.SelectedItem);
            //    //}
            //    //else
            //    //{
            //    //    MessageBox.Show("Selected keyring already in checkout", "Selection Error");
            //    //}

            //}

            else
            {
                MessageBox.Show("Must select Key Ring to add", "Select Key Ring");
            }   

            //If there is already an existing keyring in this checkout, inform the user. Otherwise, assign the selected personnel to the checkout. 
            if (comboBoxCheckoutAddKeyRing.SelectedIndex != -1)
            {
                if (listBoxCheckoutKeyRing.Items.Count != 0)
                {
                    MessageBox.Show("Only one keyring can be assigned to a checkout");
                }

                else 
                { 
                     //listBoxCheckoutKeyRing.Items.Add(selectedKeyRing.FirstName + " " + selectedPerson.LastName);
                    foreach (KeyRing keyRing in objects.keyrings)
                    {
                        if (keyRing.Name == (string)comboBoxCheckoutAddKeyRing.SelectedItem)
                        {
                            selectedKeyRing = keyRing;
                            selectedCheckout.KeyRing = selectedKeyRing;
                            selectedCheckout.Save();
                            listBoxCheckoutKeyRing.Items.Clear();
                            listBoxCheckoutKeyRing.Items.Add(selectedKeyRing.Name);
                        }
                    }
                }
            }

            else
            {
                MessageBox.Show("Must select KeyRing to add", "Select KeyRing");
            }
              
        }
Example #34
0
        /// <summary>
        /// Removes selected keyring from selected checkout. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCheckoutRemoveKeyRing_Click(object sender, EventArgs e)
        {
            Checkout selectedCheckout = new Checkout();
            KeyRing selectedKeyRing = new KeyRing();

            if (listBoxCheckoutCheckouts.SelectedIndex != -1)
            {
                foreach (Checkout checkout in objects.checkouts)
                {
                    if (checkout.Id == (int)listBoxCheckoutCheckouts.SelectedItem)
                    {
                        selectedCheckout = checkout;
                    }
                }
            }

            foreach (KeyRing keyRing in objects.keyrings)
            {
                if (keyRing.Name == (string)listBoxCheckoutKeyRing.SelectedItem)
                {
                    selectedKeyRing = keyRing;
                }
            }

            listBoxCheckoutKeyRing.Items.Clear();
            selectedCheckout.KeyRing = null;
            selectedCheckout.Save(); 
        }