Unsolved
This post is more than 5 years old
5 Posts
0
2499
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!
gstuartemc
417 Posts
0
April 18th, 2011 08:00
You seem to be calling clipRef.close twice - this could be causing an error and an incorrect error message might be getting returned.
Also - does closing the BinaryWriter maybe close the underlying Stream object as well?
zhenyazh
5 Posts
0
April 18th, 2011 08:00
i just tried to call the closing function earlier.
there was actually one calling, the one at the end, which gave the error,
sorry for confusing
mmraz
8 Posts
0
April 19th, 2011 04:00
It looks like the fileTag.close() call is within the block of code that is commented out, so you still have a tag open, so the clip is still in use.
gstuartemc
417 Posts
0
April 26th, 2011 09:00
Good spot Mark - it does, indeed, look like it is still commented out. I didn't spot it because you have mixed and matched your comment style making it very hard to read!
And if this is another example of "it's not actually like that" then please post the actual code that is causing you a problem, with commented out sections (or "old" code) removed!!