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); } }
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); } }
static void Main(string[] args) { try { FPLogger.ConsoleMessage("\nEnter cluster to connect to [" + clusterAddress + "]: "); String answer = Console.ReadLine(); if (answer != "") { clusterAddress = answer; } // The 3.2 SDK introduced dynamic logging features FPLogger log = new FPLogger(); log.LogPath = "c:\\mySDKLog.txt"; log.Start(); // New in 3.1 - applications can be registered FPPool.RegisterApplication("GetClusterInfo", "3.1"); using (FPPool myPool = new FPPool(clusterAddress)) { FPLogger.ConsoleMessage("\nCluster time is " + myPool.ClusterTime); // Display the pool information individually. We could just have used // // FPLogger.ConsoleMessage(myPool); // // as the pool object overrides toString() to print exactly this. FPLogger.ConsoleMessage( "\nPool Information" + "\n================" + "\nCluster ID: " + myPool.ClusterID + "\nCluster Name: " + myPool.ClusterName + "\nCentraStar software version: " + myPool.CentraStarVersion + "\nSDK version: " + FPPool.SDKVersion + "\nCluster Capacity (Bytes): " + myPool.Capacity + "\nCluster Free Space (Bytes): " + myPool.FreeSpace + "\nCluster Replica Address: " + myPool.ReplicaAddress); FPLogger.Stop(); FPLogger.RegisterCallback(myLoggingCB); log.Start(); FPLogger.Log(FPLogLevel.Error, "logged via our callback i.e. the Console"); FPLogger.Stop(); log.DisableCallback = FPBool.True; log.LogPath = "c:\\mySDKLog2.txt"; log.Start(); // Print out the information on the Governors if we have Advanced Retention if (myPool.HoldSupported) { FPLogger.ConsoleMessage( "\nVariable Retention Min " + myPool.VariableRetentionMin + "\nVariable Retention Max " + myPool.VariableRetentionMax + "\nFixed Retention Min " + myPool.FixedRetentionMin + "\nFixed Retention Max " + myPool.FixedRetentionMax + "\nDefault Retention " + myPool.RetentionDefault); } FPLogger.ConsoleMessage("\nRetention classes configured on the cluster:"); foreach (FPRetentionClass rc in myPool.RetentionClasses) { FPLogger.ConsoleMessage("\n\t" + rc); } // Check for a ProfileClip associated with the pool connection. try { String clipID = myPool.ProfileClip; FPLogger.ConsoleMessage("\nProfile Clip id " + clipID + " has metadata: "); using (FPClip clipRef = myPool.ClipOpen(clipID, FPMisc.OPEN_FLAT)) { foreach (FPAttribute attr in clipRef.Attributes) { FPLogger.ConsoleMessage("\n\t" + attr); } } } catch (FPLibraryException e) { ErrorInfo err = e.errorInfo; if (e.errorInfo.error == FPMisc.PROFILECLIPID_NOTFOUND_ERR) { FPLogger.ConsoleMessage("\nNo Profile Clip exists for this application.\n"); } else if (e.errorInfo.error == FPMisc.SERVER_ERR) { FPLogger.ConsoleMessage("\nThe Centera cluster you are attempting to access may not support profile clips.\n"); } else { throw e; } } log.Save("c:\\myLogState.out"); } } catch (FPLibraryException e) { ErrorInfo err = e.errorInfo; FPLogger.ConsoleMessage("\nException thrown in FP Library: " + e); } }