예제 #1
0
        static void Main(string[] args)
        {
            var collection = new SecretCollection();

            collection.AddItem("Ala ma kota", false);
            collection.AddItem("Ola ma pytona ale to tajemnica!", true);
            collection.AddItem("Piotrek ma psa", false);
            collection.AddItem("Piotrek ma też kota", false);
            collection.AddItem("Aga ma kanarka ale to też tajemnica", true);
            collection.AddItem("Jacek ma psa", false);

            foreach (var element in collection)
            {
                Console.WriteLine(element);
            }

            Console.WriteLine();
            Console.WriteLine("Reverse iteration:");
            Console.WriteLine();

            collection.ReverseOrder();

            foreach (var element in collection)
            {
                Console.WriteLine(element.ToString());
            }

            Console.Read();
        }
예제 #2
0
        private SecretCollection AttemptDecryptXecretsSessionElement(EncryptionKeyCollection keyCollection, XmlElement xecretsSessionElement)
        {
            foreach (EncryptionKey key in keyCollection)
            {
                DateTime lastUpdateUtc = DateTime.Parse(xecretsSessionElement.Attributes["LastUpdateUtc"].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
                if (lastUpdateUtc > LastUpdateUtc)
                {
                    LastUpdateUtc = lastUpdateUtc;
                }

                XmlDocument decryptedXml = DecryptEncryptedData(new InternalEncryptionKey(key), xecretsSessionElement);
                if (decryptedXml == null)
                {
                    continue;
                }

                SecretCollection decryptedSecrets = GetSessionSecrets(decryptedXml.SelectNodes("Secrets/Secret"), key);

                // Set the last updated for each and every secret - we don't actually store this per secret, only per
                // session, but that's not a fact we expose externally.
                foreach (Secret secret in decryptedSecrets)
                {
                    InternalSecret internalSecret = secret as InternalSecret;
                    internalSecret.LastUpdateUtc = lastUpdateUtc;
                }

                keyCollection.Remove(key);
                return(decryptedSecrets);
            }
            return(new SecretCollection());
        }
예제 #3
0
        public SecretCollection FindSecrets(IEnumerable <EncryptionKey> keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            // Get a copy of the collection so we can remove keys as we use them.
            EncryptionKeyCollection unusedKeys = new EncryptionKeyCollection("");

            unusedKeys.AddRange(keys);

            // Accumulate decrypted secrets here.
            SecretCollection secrets = new SecretCollection();

            XmlNodeList nodeList = GetXecretsSession(XecretsDocument).SelectNodes("XecretsSession");

            foreach (XmlNode node in nodeList)
            {
                SecretCollection decryptedSessionSecrets = AttemptDecryptXecretsSessionElement(unusedKeys, (XmlElement)node);
                secrets.AddRange(decryptedSessionSecrets);
            }

            secrets.OriginalCount = secrets.Count;
            return(secrets);
        }
        public OmitSecretIterator(SecretCollection collection, bool reverse = false)
        {
            this.collection = collection;
            this.reverse    = reverse;

            if (reverse)
            {
                position = collection.GetAllNotForbiden().Count;
            }
        }
예제 #5
0
 internal Map(List <Texture2D> textures, Texture2D background, int[,] map, List <GameObject> objects, string ambientAudio, DoorCollection <Door> doors, ActorCollection <Actor> actors, SecretCollection <Secret> secrets, Vector2 spawnPoint)
 {
     Textures            = textures;
     Background          = background;
     this.ObjectDatabase = objects;
     WorldMap            = map;
     AmbientAudio        = ambientAudio;
     Doors      = doors;
     SpawnPoint = spawnPoint;
     Actors     = actors;
     Secrets    = secrets;
     CreatePathFinder(map);
     Bullets = new BulletCollection <Bullet>();
 }
예제 #6
0
        private static SecretCollection GetSessionSecrets(XmlNodeList nodeList, EncryptionKey key)
        {
            SecretCollection secrets = new SecretCollection();

            foreach (XmlNode node in nodeList)
            {
                XmlElement secretElement = (XmlElement)node;

                Guid   id          = new Guid(secretElement.Attributes["Id"].Value);
                string title       = String.Empty;
                string description = String.Empty;
                string theSecret   = String.Empty;
                foreach (XmlNode textElement in secretElement.ChildNodes)
                {
                    switch (textElement.Name)
                    {
                    case "Title":
                        title = WebUtility.HtmlDecode(textElement.InnerText);
                        break;

                    case "Description":
                        description = WebUtility.HtmlDecode(textElement.InnerText);
                        break;

                    case "TheSecret":
                        theSecret = WebUtility.HtmlDecode(textElement.InnerText);
                        break;

                    default:
                        if (New <ILogging>().IsWarningEnabled)
                        {
                            New <ILogging>().LogWarning($"Unrecognized element: {textElement.Name}");
                        }
                        break;
                    }
                }

                secrets.Add(new InternalSecret(new Secret(id, title, description, theSecret, key)));
            }

            return(secrets);
        }
예제 #7
0
        private void secretsChecklist_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (pass)
            {
                pass = false;
                return;
            }

            if (secretsChecklistCheckedIndex.HasValue && secretsChecklist.GetItemChecked(secretsChecklistCheckedIndex.Value))
            {
                pass = true;
                secretsChecklist.SetItemCheckState(secretsChecklistCheckedIndex.Value, CheckState.Unchecked);
            }

            activeCollection = secretCollections[e.Index];

            buttonDecryptSecret.Visible  = e.CurrentValue == CheckState.Unchecked;
            groupBox4.Visible            = e.CurrentValue == CheckState.Unchecked;
            secretsChecklistCheckedIndex = e.Index;
        }