示例#1
0
        static void Main()
        {
            // A collection of Documents
            Document[] docArray = new Document[2];

            // First entry is a Document
            docArray[0] = new Document("Test Document");

            // Second entry is a CompressibleDocument (ok because
            // CompressibleDocument is a Document)
            docArray[1] = new CompressibleDocument("Test compressibleDocument");


            // don't know what we'll pull out of this hat
            foreach (Document doc in docArray)
            {
                // report your name
                Console.WriteLine("Got: {0}", doc);

                // Both pass this test
                IStorable isDoc = doc as IStorable;
                if (isDoc != null)
                {
                    isDoc.Read();
                }

                // fails for Document
                // passes for CompressibleDocument
                ICompressible icDoc = doc as ICompressible;
                if (icDoc != null)
                {
                    icDoc.Compress();
                }
            }
        }
示例#2
0
        static void Main()
        {
            //kolekcija Docmunets
            Document[] docArray = new Document[2];

            //prvi unos je Document
            docArray[0] = new Document("Test document");

            //drugi unos je CompressibleDocument
            //uredu je jer je CompressibleDocument Document
            docArray[1] = new CompressibleDocument("Test compressible document");

            //ne znamo sta cemo izvuci iz sesira
            foreach (Document doc in docArray)
            {
                //ispisuje ime
                Console.WriteLine("Got: {0}", doc);

                //obje prolaze test
                //sa operatorom is
                if (doc is IStorable)
                {
                    IStorable isDoc = (IStorable)doc;
                    isDoc.Read();
                }

                //sa operatorom as
                IStorable isDoc2 = doc as IStorable;
                if (isDoc2 != null)
                {
                    isDoc2.Read();
                }

                //ne uspjeva za Documnet
                //prolazi za CompressibleDocument
                if (doc is ICompressible)
                {
                    ICompressible icDoc = (ICompressible)doc;
                    icDoc.Compress();
                }
            }
        }
示例#3
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");
            }
        }
示例#4
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();
            }
        }
示例#5
0
        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();
        }
        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");
            }
        }
示例#7
0
        public void Run()
        {
            string testString = "String ";

            Note[] myNoteArray = new Note[3];

            for (int i = 0; i < 3; i++)
            {
                string docText = testString + i.ToString();
                if (i % 2 == 0)
                {
                    Document myDocument = new Document(docText, (i + 5) * 10);
                    myNoteArray[i] = myDocument;
                }
                else
                {
                    Note myNote = new Note(docText);
                    myNoteArray[i] = myNote;
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with IS", theNote);

                theNote.Read();     // all notes can do this
                if (theNote is ICompressible)
                {
                    ICompressible myCompressible = theNote as ICompressible;
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }

                if (theNote is Document)
                {
                    Document myDoc = theNote as Document;

                    // clean cast
                    myDoc = theNote as Document;
                    Console.WriteLine("my documentID is {0}", myDoc.ID);
                }
            }

            foreach (Note theNote in myNoteArray)
            {
                Console.WriteLine("\nTesting {0} with AS", theNote);
                ICompressible myCompressible = theNote as ICompressible;
                if (myCompressible != null)
                {
                    myCompressible.Compress();
                }
                else
                {
                    Console.WriteLine("This storable object is not compressible.");
                }    // end else

                Document theDoc = theNote as Document;
                if (theDoc != null)
                {
                    Console.WriteLine("My documentID is {0}", ((Document)theNote).ID);
                }
                else
                {
                    Console.WriteLine("Not a document.");
                }
            }
        }
示例#8
0
 public static object Compress(object source)
 {
     return(_imageComprosser.Compress(source));
 }