Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My last three posts have clearly specified that I am looking for a way to add the values from my text file ("Master MD5 SIG.txt") to raptordb and then to have the ability to call upon that database to read the values ("Master MD5 SIG.txt") so that my program will compare the values in the database with my current filesystem. The code Supplied to me is still confusing as I have not a clue where to place what?

the code is:

C#
RaptorDB.RaptorDB rap = RaptorDB.RaptorDB.Open("strings", 30, false, INDEXTYPE.HASH);
rap.IndexingTimerSeconds = 1;
rap.InMemoryIndex = true;
string key = "some very long string";
 
for (int i = 0; i < count; i++)
{
	string ss = key + i.ToString("000000");
	rap.Set(ss, ss);
}
 
rap.SaveIndex(true);
int j = 0;
for (int i = 0; i < count; i++)
{
	string ss = key + i.ToString("000000");
	byte[] bb = null;
	if (rap.Get(ss, out bb) == false)
		j++;// Console.WriteLine("error");
}




What is meant by "String"? and "Some Very Long String"? and also ("000000")? Even after converting this code to VB.NET there is errors with the syntax "Count" and it looks as if your telling me in the code to enter strings where "Strings" and "Some Very Long String" is stated when the code that I need is to add the text file.


Thank you anyone who can help me to learn how to use this. I have come to some what of a stand still as the OP does not respond or give clear instructions which forces me to ask more questions.
Posted
Updated 9-Sep-11 3:54am
v2
Comments
Mehdi Gholam 9-Sep-11 10:03am    
Have you read the original article?
Mehdi Gholam 9-Sep-11 10:06am    
Do you know what a hashtable or dictionary is?
Dale 2012 9-Sep-11 18:02pm    
It would only take less than five minutes I am sure to clarify what your code does and to do 4 things with the raptor database.

1. add the text file into the database
2. Sort the values by hash
3. Save the values from the text file to the database
4. read the values from the database to the program

are these functions not part of your program? if not what can I use in its place?.

Dale 2012 9-Sep-11 17:54pm    
Would I be asking questions to answers I already know?

1 solution

Some basics :

1) A dictionary or hashtable is a structure for storing information referenced by a key.
C#
Dictionary<string,string> dic = new Dictionary<string,string>();
dic.Add("somestringkey","value associated with key"); // to set the value
dic["someotherkey"] = "another value for that key"; // another way to set a value

// to read
string val = dic["somestringkey"]; // will show "value associated with key"


2) To create a keyvalue store in RaptorDB of type hash for storing strings up to 255 chars in a file named storage (with various extensions for indexes etc.).
C#
RaptorDB.RaptorDB rap = RaptorDB.RaptorDB.Open("storage", 255, false, INDEXTYPE.HASH);

rap.Set("somestringkey","value associated with key"); // to set like a dictionary

string val = "";
if(rap.Get("somestringkey", out val))
{
   // val now contains what was read 
}


3) From your description of your requirements you want to save MD5 hash codes for filenames
C#
dic.Add("c:\\path\\filename.ext","123123134123123"); // MD5 hash for the filename.ext
 
Share this answer
 
v2
Comments
Dale 2012 12-Sep-11 6:30am    
Your example is just what i needed and now it makes perfect sense as to whats going on. Thank you once again your example for number one works perfect as I have tested it but in your second example where it says
Dim val As String = rap.Get("somestringkey") ' to read like a dictionary, I get an error which reads. overload resolution failed because no accessible 'Get' accepts this number of arguments? any clue as to why I may be getting this error?
Dale 2012 12-Sep-11 7:39am    
This is the code I have so far with one error.

Imports RaptorDB
Public Class Form1
Dim rap As RaptorDB.RaptorDB = RaptorDB.RaptorDB.Open("storage", 255, False, INDEXTYPE.HASH)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rap.Set("A1", My.Resources.Master_MD5_SIG) ' to set like a dictionary
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim val As String = rap.Get("A1") ' will show "value associated with key"
TextBox1.Text = val
End Sub
End Class
Mehdi Gholam 12-Sep-11 7:53am    
My apologies! the format for "Get" which I showed was from my vNext version, sorry.
I have updated the sample.
Dale 2012 13-Sep-11 22:22pm    
Ok I have tried the code and at first it seems error free until I try to debug it. Maybe you can see where I have went wrong?

Imports RaptorDB
Public Class Form1
Dim rap As RaptorDB.RaptorDB = RaptorDB.RaptorDB.Open("storage", 255, False, INDEXTYPE.HASH)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rap.Set("A1", "123456789") ' to set like a dictionary
Dim val As String = ""
If rap.Get("A1", val) Then
TextBox1.Text = val
End If
End Sub
End Class


The error message I get is:

System.InvalidOperationException was unhandled
Message=An error occurred creating the form. See Exception.InnerException for details. The error is: Path cannot be the empty string or all whitespace.
Source=RaptorDatabase Test
StackTrace:
at RaptorDatabase_Test.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at RaptorDatabase_Test.My.MyProject.MyForms.get_Form1()
at RaptorDatabase_Test.My.MyApplication.OnCreateMainForm() in C:\Users\Admin\AppData\Local\Temporary Projects\RaptorDatabase Test\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at RaptorDatabase_Test.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.ArgumentException
Message=Path cannot be the empty string or all whitespace.
Source=mscorlib
StackTrace:
at System.IO.Directory.CreateDirectory(String path)
at RaptorDB.RaptorDB.Initialize(String filename, Byte maxkeysize, Boolean AllowDuplicateKeys, INDEXTYPE idxtype) in C:\Users\Admin\Desktop\Raptor Database\RaptorDB\RaptorDB.cs:line 234
at RaptorDB.RaptorDB..ctor(String Filename, Byte MaxKeysize, Boolean AllowDuplicateKeys, INDEXTYPE idxtype) in C:\Users\Admin\Desktop\Raptor Database\RaptorDB\RaptorDB.cs:line 20
at RaptorDB.RaptorDB.Open(String Filename, Byte MaxKeysize, Boolean AllowDuplicateKeys, INDEXTYPE idxtype) in C:\Users\Admin\Desktop\Raptor Database\RaptorDB\RaptorDB.cs:line 53
at RaptorDatabase_Test.Form1..ctor() in C:\Users\Admin\AppData\Local\Temporary Projects\RaptorDatabase Test\Form1.vb:line 3
InnerException:




An error occurred creating the form. See Exception.InnerException for details. The error is: Path cannot be the empty string or all whitespace.
Dale 2012 13-Sep-11 9:44am    
Your a good man thank you!! I will try the corrected code you have supplied but one thing is still a bit off in your assumption for number 3. You give code for saving MD5 hash codes for file names when in fact my question was how to quickly add the contents of the text file into the database. My text document contains way to many MD5 hash codes to enter them one by one. Any ideas? thank you for everything you have taught me!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900