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

        foreach (var document in documents)
        {
            if (document.Name == name)
            {
                documentFound = true;

                IEncryptable encryptableDocument = document as IEncryptable;
                if (encryptableDocument != null)
                {
                    encryptableDocument.Encrypt();
                    Console.WriteLine("Document encrypted: " + name);
                }
                else
                {
                    Console.WriteLine("Document does not support encryption: " + name);
                }
            }
        }
        if (!documentFound)
        {
            Console.WriteLine("Document not found: " + name);
        }
    }
        private static void EncryptDocument(string name)
        {
            //
            bool found = false;

            foreach (var item in documents)
            {
                if (item.Name == name)
                {
                    found = true;
                    IEncryptable obj = item as IEncryptable;
                    if (obj != null)
                    {
                        obj.Encrypt();
                        Console.WriteLine("Document encrypted: {0}", name);
                    }
                    else
                    {
                        Console.WriteLine("Document does not support encryption: {0}", name);
                    }
                }
            }
            if (found == false)
            {
                Console.WriteLine("Document not found: {0}", name);
            }
        }
Exemple #3
0
    private static void EncryptAllDocuments()
    {
        bool documentEncrypted = false;

        foreach (var document in documents)
        {
            IEncryptable encryptableDocument = document as IEncryptable;
            if (encryptableDocument != null)
            {
                documentEncrypted = true;
                encryptableDocument.Encrypt();
            }
        }

        if (documentEncrypted)
        {
            Console.WriteLine("All documents encrypted");
        }
        else
        {
            Console.WriteLine("No encryptable documents found");
        }
    }
        private static void EncryptAllDocuments()
        {
            //
            bool found = false;

            foreach (var item in documents)
            {
                IEncryptable obj = item as IEncryptable;
                if (obj != null)
                {
                    found = true;
                    obj.Encrypt();
                }
            }
            if (found == true)
            {
                Console.WriteLine("All documents encrypted");
            }
            else
            {
                Console.WriteLine("No encryptable documents found");
            }
        }
Exemple #5
0
        static void Main()
        {
            //pravi objekat dokumenta
            Document doc = new Document("Test document");

            //pretvara dokument za razlicita sucelja
            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not supported");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("Compressible not supported");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedBytes();
                ilcDoc.Compress();
                //ilcDoc.Read(); //ne moze pozvati metodu read
            }
            else
            {
                Console.WriteLine("LoggedCompressible not supported");
            }

            IStorableCompressible isc = doc as IStorableCompressible;

            if (isc != null)
            {
                isc.LogOriginalSize();  //IStorableCompressible
                isc.LogSavedBytes();    //ILoggedCompressible
                isc.Compress();         //ICompressible
                isc.Read();             //IStorable
            }
            else
            {
                Console.WriteLine("StorableCompressible not supported");
            }

            IEncryptable ie = doc as IEncryptable;

            if (ie != null)
            {
                ie.Encrypt();
            }
            else
            {
                Console.WriteLine("Encrytable not supported");
            }
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            // create a document object
            Document doc = new Document("Test Document");

            // cast the document to the various interfaces
            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not supported");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("Compressible not supported");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedBytes();
                ilcDoc.Compress();
                // ilcDoc.Read();
            }
            else
            {
                Console.WriteLine("LoggedCompressible not supported");
            }

            IStorableCompressible isc = doc as IStorableCompressible;

            if (isc != null)
            {
                isc.LogOriginalSize();  // IStorableCompressible
                isc.LogSavedBytes();    // ILoggedCompressible
                isc.Compress();         // ICompressible
                isc.Read();             // IStorable
            }
            else
            {
                Console.WriteLine("StorableCompressible not supported");
            }

            IEncryptable ie = doc as IEncryptable;

            if (ie != null)
            {
                ie.Encrypt();
            }
            else
            {
                Console.WriteLine("Encryptable not supported");
            }

            IStorable isDocument = (IStorable)doc;

            isDocument.Status = 0;
            isDocument.Read();

            // error!
//            IStorable doc1 = new IStorable ();

            // OK!
            IStorable doc2 = new Document("Test2 document");

            if (doc2)
            {
                doc2.Read();
            }
        }
        static void Main(string[] args)
        {
            Document doc = new Document("Hello! This is Document");

            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not support");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("ICompressible not support");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedByte();
                ilcDoc.Compress();
            }
            else
            {
                Console.WriteLine("ILoggedCompressible not support");
            }
            IStorableCompressible iscDoc = doc as IStorableCompressible;

            if (iscDoc != null)
            {
                iscDoc.LogSavedByte();
                iscDoc.LogOriginalSize();
                iscDoc.Compress();
                iscDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorableCompressible not support");
            }

            IEncryptable ieDoc = doc as IEncryptable;

            if (ieDoc != null)
            {
                ieDoc.Encrypt();
            }
            else
            {
                Console.WriteLine("Encrypt not support");
            }
            Console.ReadLine();
        }
Exemple #8
0
 public byte[] GetBytes(string XML)
 {
     return(encryptor.Encrypt(XML));
 }
        static void Main()
        {
            // create a document object
            Document doc = new Document("Test Document");

            // cast the document to the various interfaces
            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable not supported");
            }

            ICompressible icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("Compressible not supported");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedBytes();
                ilcDoc.Compress();
                // ilcDoc.Read();
            }
            else
            {
                Console.WriteLine("LoggedCompressible not supported");
            }

            IStorableCompressible isc = doc as IStorableCompressible;

            if (isc != null)
            {
                isc.LogOriginalSize(); // IStorableCompressible
                isc.LogSavedBytes();   // ILoggedCompressible
                isc.Compress();        // ICompressible
                isc.Read();            // IStorable
            }
            else
            {
                Console.WriteLine("StorableCompressible not supported");
            }

            IEncryptable ie = doc as IEncryptable;

            if (ie != null)
            {
                ie.Encrypt();
            }
            else
            {
                Console.WriteLine("Encryptable not supported");
            }
        }
Exemple #10
0
        static void Main()
        {
            // 创建Document对象
            Document doc = new Document("Test Document");

            // 将Document转换为各种接口
            IStorable isDoc = doc as IStorable;

            if (isDoc != null)
            {
                isDoc.Read();
            }
            else
            {
                Console.WriteLine("IStorable noe supported");
            }

            IComparable icDoc = doc as ICompressible;

            if (icDoc != null)
            {
                icDoc.Compress();
            }
            else
            {
                Console.WriteLine("Compressible not supported");
            }

            ILoggedCompressible ilcDoc = doc as ILoggedCompressible;

            if (ilcDoc != null)
            {
                ilcDoc.LogSavedBytes();
                ilcDoc.Compress();
            }
            else
            {
                Console.WriteLine("LoggedCompressible not supported");
            }

            IStorableCompressible isc = doc as IStorableCompressible;

            if (isc != null)
            {
                isc.LogOriginalSize();
                isc.LogSavedBytes();
                isc.Compress();
                isc.Read();
            }
            else
            {
                Console.WriteLine("StorableCompressible not supported");
            }

            IEncryptable ie = doc as IEncryptable;

            if (ie != null)
            {
                ie.Encrypt();
            }
            else
            {
                Console.WriteLine("Encryptable not supported");
            }
        }
Exemple #11
0
 public static object Encrypt(object key, object source)
 {
     return(_imageEncryptor.Encrypt(key, source));
 }
 private void Provide(string xml)
 {
     sender.Send(encryptable.Encrypt(xml));
 }