UNSOLVED

zhenyazh

updated

15 years ago

Z

zhenyazh

5 Posts

0

2645

April 18th, 2011 01:00

fpclip still in use

Hi,

I am writing a simple program that inserts a small txt file into centera and then deletes it.

when i store the file and try to close the clipref i get the error..

This is the code i am using (it was taken from sourceforge, and passed few adjustments and simplifications):

static void store()

        {

            try

            {

                FPLogger.ConsoleMessage("\nCluster to connect to [" + defaultCluster + "] : ");

                String clusterAddress = defaultCluster;

                String fileName = "c:\\1.txt";

                int blobThreshold = 22;

                FPPool.EmbeddedBlobThreshold = blobThreshold;

                pool = new FPPool(clusterAddress);

                // Create the clip

                FPClip clipRef = new FPClip(pool, fileName);

                clipRef.RetentionExpiry = new DateTime(2012, 1, 1);

                // Or you could set this using a TimeSpan

                //clipRef.RetentionPeriod = new TimeSpan(500, 12, 20, 30);

                clipRef.SetAttribute("OriginalFilename", fileName);

                FPTag fileTag = clipRef.AddTag("StoreContentObject");

                fileTag.SetAttribute("filename", fileName);

                // Write the content of the file to the Centera

                FPStream streamRef = new FPStream(fileName, 16 * 1024);

                fileTag.BlobWrite(streamRef, FPMisc.OPTION_CLIENT_CALCID);

                streamRef.Close();

                long blobSize = fileTag.BlobSize;

                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);

                // With SDK version 3.2 we can also create a stream

                // to represent a partial section of a file e.g. 10 bytes from position 5

                long offset = 5;

                long length = 10;

                streamRef = new FPStream(fileName, 16 * 1024, offset, length);

                fileTag.BlobWrite(streamRef, FPMisc.OPTION_CLIENT_CALCID);

                streamRef.Close();

                fileTag.Close();

*/

             id = clipRef.Write();

             clipRef.Close();

                /* Write the Clip ID to the output file, "inputFileName.clipID" */

                String outFileName = fileName + ".clipID";

                FileStream outFile = new FileStream(outFileName, FileMode.Create);

                BinaryWriter outWriter = new BinaryWriter(outFile);

                outWriter.Write(id.ToString());

                outWriter.Close();

                outFile.Close();

             clipRef.Close();

                pool.Close();

            }

            catch (FPLibraryException e)

            {

                ErrorInfo err = e.errorInfo;

                FPLogger.ConsoleMessage("\nException thrown in FP Library: Error " + err.error + " " + err.message);

            }

        }

thanks!