Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            IntPtr userData = new IntPtr(0);

            try
            {
                FPPool myPool = new FPPool("128.221.200.56?c:\\pea\\emea1.pea");
                FPTag  myTag;

                FPLogger log = new FPLogger();
                log.LogPath = "C:\\GenStreamsLog.txt";
                log.Start();

                // First we'll write a test clip to the Centera
                string   fileName = "c:\\discovery.xml";
                FileInfo info     = new FileInfo(fileName);

                FPClip myClip = myPool.ClipCreate("GenericStreamWrite_testClip");
                myTag = myClip.AddTag("testTag");

                FPGenericStream myStream = new FPGenericStream(File.OpenRead(fileName), userData);
                myStream.StreamLen = info.Length;
                myTag.BlobWrite(myStream);
                myTag.Close();
                myStream.Close();
                string clipID = myClip.Write();
                myClip.Close();
                FPLogger.ConsoleMessage("\nGenericStreamWrite test succeeded");

                // Now we will test reading it back from the Centera			{
                myClip = myPool.ClipOpen(clipID, FPMisc.OPEN_ASTREE);
                myTag  = myClip.NextTag;


                myStream           = new FPGenericStream(File.OpenWrite("c:\\test.out"), userData);
                myStream.StreamLen = myTag.BlobSize;

                myTag.BlobRead(myStream);
                myStream.Close();
                FPLogger.ConsoleMessage("\nGenericStreamRead test succeeded for FileStream");


                // We could use a Memory stream. As it is a bi-directional stream we
                // need to use a ctor that specifies the direction we want to use.
                // We'll set up the space first.

                MemoryStream s = new MemoryStream((int)myTag.BlobSize);
                myStream = new FPGenericStream(s, FPStream.StreamDirection.OutputFromCentera, userData);

                myStream.StreamLen = myTag.BlobSize;

                myTag.BlobRead(myStream, FPMisc.OPTION_DEFAULT_OPTIONS);
                myStream.Close();
                FPLogger.ConsoleMessage("\nGenericStreamRead test succeeded for MemoryStream");
                myTag.Close();
                myClip.Close();


                myPool.Close();
            }
            catch (FPLibraryException e)
            {
                ErrorInfo err = e.errorInfo;
                FPLogger.ConsoleMessage("\nException thrown in FP Library: Error " + err.error + " " + err.message);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IntPtr       userData = new IntPtr(0);
            string       clipID;
            BinaryReader myReader;
            BinaryWriter myWriter;
            BlobStream   myStream;

            // For thsi test we are using a file as the input. *Any* stream could be used.
            // This would be your test PDF - in a file or memory stream.
            FileStream inputStream = new FileStream("e:\\testfile", FileMode.Open);

            FPLogger.ConsoleMessage("\nInput file length " + inputStream.Length);

            try
            {
                FPLogger log = new FPLogger();
                log.LogPath = "C:\\GenStreamsLog.txt";
                log.Start();

                // Create a test clip demonstrating how to write a blob using a stream
                FPPool myPool = new FPPool("cse1.centera.lab.emc.com");
                FPClip myClip = myPool.ClipCreate("GenericStreamWrite_testClip");
                FPTag  myTag  = myClip.AddTag("testTag");

                // Simple test of the BlobWriteStream - write contents of a local file
                // to Centera using a StreamReader and StreamWriter
                // We are using a temporary MemoryStream for our staging area
                myStream = new BlobWriteStream(myTag);
                myReader = new BinaryReader(inputStream);
                myWriter = new BinaryWriter(myStream);

                long writeTime1 = DateTime.Now.Ticks;

                myWriter.Write(myReader.ReadBytes((int)inputStream.Length));
                myWriter.Flush();
                ((BlobWriteStream)myStream).Close(); // If we don't do this it will stay open forever with keep alives!

                writeTime1 = DateTime.Now.Ticks - writeTime1;

                // If we assign values to existing FP objects we must explicitly close
                // them first to avoid potential "Object In Use" errors on future closure
                myTag.Close();

                myTag = myClip.AddTag("SlicedBlob");

                inputStream.Seek(0, SeekOrigin.Begin);
                long writeTime = DateTime.Now.Ticks;

                SlicedBlobWriter.Instance(inputStream, myTag, 8);

                writeTime = DateTime.Now.Ticks - writeTime;
                myTag.Close();

                clipID = myClip.Write();
                myClip.Close();

                FPLogger.ConsoleMessage("\nGenericStreamWrite test succeeded " + clipID);

                // Now we will test reading it back from the Centera			{
                myClip = myPool.ClipOpen(clipID, FPMisc.OPEN_ASTREE);
                myTag  = myClip.NextTag;

                // Here we create a stream to read back the blob
                long readTime1 = DateTime.Now.Ticks;
                myStream = new BlobReadStream(myTag);

                // This is only to test to verify when we read the content back it is the same as the
                // input file i.e. we are going to store it on the file system and then use file system tools
                // to compare the files
                myReader = new BinaryReader(myStream);
                myWriter = new BinaryWriter(new FileStream("c:\\testfile2.out", FileMode.Create));

                ((BlobReadStream)myStream).Join();
                myWriter.Write(myReader.ReadBytes((int)myTag.BlobSize));

                myWriter.Flush();

                myStream.Close();
                readTime1 = DateTime.Now.Ticks - readTime1;

                myTag.Close();

                // This shows how to read content back using multiple threads
                myTag = myClip.NextTag;
                long readTime = DateTime.Now.Ticks;
                SlicedBlobReader.Instance(new FileStream("c:\\testfile2.out.sliced", FileMode.Create), myTag, 8);
                readTime = DateTime.Now.Ticks - readTime;

                myTag.Close();
                myClip.Close();
                myPool.Close();

                FPLogger.ConsoleMessage("\nSerial tests - Write time: " + TimeSpan.FromTicks(writeTime1) + " Read time " + TimeSpan.FromTicks(readTime1));
                FPLogger.ConsoleMessage("\nMulti threaded tests - Write time: " + TimeSpan.FromTicks(writeTime) + " Read time " + TimeSpan.FromTicks(readTime));
            }
            catch (FPLibraryException e)
            {
                ErrorInfo err = e.errorInfo;
                FPLogger.ConsoleMessage("\nException thrown in FP Library: Error " + err.error + " " + err.message);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                FPLogger.ConsoleMessage("\nCluster to connect to [" + defaultCluster + "] : ");
                String clusterAddress = System.Console.ReadLine();
                if ("" == clusterAddress)
                {
                    clusterAddress = defaultCluster;
                }

                UTF8Encoding converter2 = new UTF8Encoding();

                // We are going to create a filename containing Chinese characters

                byte[] inputFileName = { 0xE6, 0x98, 0x8E, 0xE5, 0xA4, 0xA9, 0x2E, 0x74, 0x78, 0x74 };
                string fileName      = System.Text.Encoding.UTF8.GetString(inputFileName);
                File.WriteAllText(fileName, "Test file with wide characters in the file name\n");

                FPLogger.ConsoleMessage("\nEnter the threshold to use for Embedded Blobs: ");
                String blobString = System.Console.ReadLine();

                if (blobString == "")
                {
                    blobString = "0";
                }
                int blobThreshold = Int32.Parse(blobString);

                if (blobThreshold > 0)
                {
                    FPLogger.ConsoleMessage("\nContent less than " + blobString + " bytes will be embedded in the CDF.");
                }
                else
                {
                    FPLogger.ConsoleMessage("\nContent will never be embedded in the CDF.");
                }

                FPPool.EmbeddedBlobThreshold = blobThreshold;
                FPPool thePool = new FPPool(clusterAddress);

                // Create the clip
                FPClip clipRef = new FPClip(thePool, "UTF8_Example");
                clipRef.SetAttribute("OriginalFilename", fileName);

                FPTag fileTag = clipRef.AddTag("WideFilenameTag");
                fileTag.SetAttribute("filename", fileName);

                // Write the content of the file to the Centera
                FPStream streamRef = new FPWideFilenameStream(fileName);
                fileTag.BlobWrite(streamRef, FPMisc.OPTION_CLIENT_CALCID);
                streamRef.Close();

                long blobSize = fileTag.BlobSize;

                if (blobThreshold > 0 && blobSize < blobThreshold)
                {
                    FPLogger.ConsoleMessage("\nContent was embedded in the CDF as size "
                                            + blobSize
                                            + " is less than the threshold.");
                }

                fileTag.Close();
                fileTag = clipRef.AddTag("TestTag");

                fileTag.SetAttribute("fileCabinetGuid", "52d9cf57-7261-472a-b6d9-a8cdd30d1d27");
                fileTag.SetAttribute("attr2", "a second attribute");
                fileTag.SetAttribute("anotherattr", "the third attribute");

                /* Or you can write from a memory buffer holding the data
                 * The exampe uses a byte array containing a string
                 */
                UTF8Encoding converter = new UTF8Encoding();
                byte[]       rawBuffer = converter.GetBytes("This is a test string to illustrate how to interface to Centera using a buffer stream");
                IntPtr       source    = Marshal.AllocHGlobal(rawBuffer.Length);
                Marshal.Copy(rawBuffer, 0, source, rawBuffer.Length);
                streamRef = new FPStream(source, rawBuffer.Length, FPStream.StreamDirection.InputToCentera);
                fileTag.BlobWrite(streamRef, FPMisc.OPTION_CLIENT_CALCID);

                streamRef.Close();
                Marshal.FreeHGlobal(source);
                fileTag.Close();

                fileTag = clipRef.AddTag("TestTag2");
                fileTag.SetAttribute("filename", fileName);

                // We will only store a fragment of the file - "length" characters from position "offset"
                long offset = 5;
                long length = 30;

                streamRef = new FPWideFilenameStream(fileName, offset, length);
                fileTag.BlobWrite(streamRef, FPMisc.OPTION_CLIENT_CALCID);
                streamRef.Close();

                // And this is how we read back at most "length" characters into a file at position "offset"
                // We can also specify that we don't want the created file to be larger than "maxFileSize"
                long maxFileSize = 20;
                streamRef = new FPWideFilenameStream(fileName + ".partial", FileMode.OpenOrCreate, offset, length, maxFileSize);
                fileTag.BlobRead(streamRef);
                streamRef.Close();

                String clipID = clipRef.Write();

                /* Write the Clip ID to the output file, "inputFileName.clipID" */
                FPLogger.ConsoleMessage("\nThe C-Clip ID of the content is " + clipID);
                FileStream   outFile   = new FileStream(fileName + ".clipID", FileMode.Create);
                BinaryWriter outWriter = new BinaryWriter(outFile);
                outWriter.Write(clipID.ToString() + "\n");

                outWriter.Close();
                outFile.Close();
                fileTag.Close();
                clipRef.Close();
                thePool.Close();
            }
            catch (FPLibraryException e)
            {
                ErrorInfo err = e.errorInfo;
                FPLogger.ConsoleMessage("\nException thrown in FP Library: Error " + err.error + " " + err.message);
            }
        }