Example #1
0
    private static void EncryptDocument(string name)
    {
        bool isAnySuchDoc = false;

        foreach (var doc in documents)
        {
            if (doc.Name == name)
            {
                isAnySuchDoc = true;
                EncryptableDocument encryptableDoc = doc as EncryptableDocument;
                if (encryptableDoc != null)
                {
                    encryptableDoc.Encrypt();
                    Console.WriteLine("Document encrypted: {0}", encryptableDoc.Name);
                }
                else
                {
                    Console.WriteLine("Document does not support encryption: {0}", doc.Name);
                }
            }
        }
        if (!isAnySuchDoc)
        {
            Console.WriteLine("Document not found: {0}", name);
        }
    }
Example #2
0
    private static void EncryptAllDocuments()
    {
        bool isAnyEncriptableDoc = false;

        foreach (var doc in documents)
        {
            EncryptableDocument encryptableDoc = doc as EncryptableDocument;
            if (encryptableDoc != null)
            {
                encryptableDoc.Encrypt();
                isAnyEncriptableDoc = true;
            }
        }
        if (isAnyEncriptableDoc)
        {
            Console.WriteLine("All documents encrypted");
        }
        else
        {
            Console.WriteLine("No encryptable documents found");
        }
    }