void Start() { //put here your License Key SiaqodbConfigurator.SetLicense(@"QB89ZFVPOc4vXeNEBR5mLxnR0NlnEZfmLDNj3a+Wa6A="); //if ANDROID: //SiaqodbExamples.SiaqodbFactoryExample.SetDBFolder(Application.persistentDataPath); //if Windows or MAC string siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"databaseEx"; SiaqodbExamples.SiaqodbFactoryExample.SetDBFolder(siaoqodbPath); //if iOS (iPhone /iPad) //SiaqodbExamples.SiaqodbFactoryExample.SetDBFolder(Application.dataPath); IList <SiaqodbExamples.IExample> examples = SiaqodbExamples.ExamplesBuilder.GetExamples(this.WriteToConsole); foreach (SiaqodbExamples.IExample example in examples) { this.WriteToConsole("Start example:" + example.GetType().Name + "..."); example.Run(); this.WriteToConsole("End example:" + example.GetType().Name + "..."); this.WriteToConsole("----------------------------------------------"); } this.WriteToConsole("Examples run finished!!!"); SiaqodbExamples.SiaqodbFactoryExample.CloseDatabase(); }
internal async Task <bool> SaveFieldValueAsync(int oid, string field, SqoTypeInfo ti, object value, RawdataSerializer rawSerializer) { long position = MetaHelper.GetSeekPosition(ti, oid); int recordLength = ti.Header.lengthOfRecord; FieldSqoInfo ai = FindField(ti.Fields, field); if (ai == null) { throw new SiaqodbException("Field:" + field + " not exists in the Type Definition, if you use a Property you have to use UseVariable Attribute"); } else if (value != null && ai.AttributeType != value.GetType()) { try { object valConvert = Convertor.ChangeType(value, ai.AttributeType); value = valConvert; } catch { string msg = "Type of value should be:" + ai.AttributeType.ToString(); SiaqodbConfigurator.LogMessage(msg, VerboseLevel.Error); throw new SiaqodbException(msg); } } byte[] by = null; IByteTransformer byteTransformer = ByteTransformerFactory.GetByteTransformer(this, rawSerializer, ai, ti, oid); by = await byteTransformer.GetBytesAsync(value).ConfigureAwait(false); await file.WriteAsync((long)(position + (long)ai.Header.PositionInRecord), by).ConfigureAwait(false); return(true); }
static void Main(string[] args) { Sqo.SiaqodbConfigurator.SetLicense(@"your license key"); SiaqodbConfigurator.SetDocumentSerializer(new MyJsonSerializer()); string siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"siaqodb"; if (!Directory.Exists(siaoqodbPath)) { Directory.CreateDirectory(siaoqodbPath); } using (Siaqodb siaqodb = new Siaqodb(siaoqodbPath)) { CRUD_Document(siaqodb); Console.WriteLine("CRUD with Documents operations executed."); CRUD_POCO(siaqodb); Console.WriteLine("CRUD with POCO operations executed."); SimpleQuery(siaqodb); Console.WriteLine("SimpleQuery executed."); ComplexQuery(siaqodb); Console.WriteLine("ComplexQuery executed."); } Console.ReadLine(); }
public async Task <bool> LoadOidsByIndexAsync(SqoTypeInfo ti, string fieldName, Where where, List <int> oids) { if (cacheIndexes != null) { IBTree index = cacheIndexes.GetIndex(ti, fieldName); if (index != null && where.OperationType != OperationType.Contains && where.OperationType != OperationType.NotEqual && where.OperationType != OperationType.EndWith) { bool error = false; try { await this.LoadOidsByIndexAsync(index, where, oids).ConfigureAwait(false); } catch (IndexCorruptedException ex) { error = true; } if (error) { SiaqodbConfigurator.LogMessage("Index has corrupted, will be rebuild", VerboseLevel.Info); index = await this.RenewIndexAsync(ti, fieldName); await this.LoadOidsByIndexAsync(index, where, oids).ConfigureAwait(false); } return(true); } } return(false); }
public void TestStorePartialOnIndexed() { SiaqodbConfigurator.AddIndex("cId", typeof(C)); Siaqodb s_db = new Siaqodb(objPath); s_db.DropType <A>(); s_db.DropType <B>(); s_db.DropType <C>(); for (int i = 0; i < 10; i++) { A a = new A(); a.aId = i; a.BVar = new B(); a.BVar.bId = 11; a.BVar.Ci = new C(); a.BVar.Ci.ACircular = a; a.BVar.Ci.cId = i % 2; s_db.StoreObject(a); } IList <A> lsA = s_db.LoadAll <A>(); lsA[0].BVar.Ci.cId = 3; s_db.StoreObjectPartially(lsA[0].BVar, "Ci"); var q = (from C c in s_db where c.cId == 3 select c).ToList(); Assert.AreEqual(1, q.Count); }
public static Siaqodb GetInstance() { if (instance == null) { //put here your License Key SiaqodbConfigurator.SetLicense(@"QB89ZFVPOc4vXeNEBR5mLxnR0NlnEZfmLDNj3a+Wa6A="); //if ANDROID: if (Application.platform == RuntimePlatform.Android) { siaoqodbPath = Application.persistentDataPath; } //if Windows or MAC else if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor) { siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"database"; } //if iOS (iPhone /iPad) else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.IPhonePlayer) { siaoqodbPath = Application.dataPath; } if (!Directory.Exists(siaoqodbPath)) { Directory.CreateDirectory(siaoqodbPath); } instance = new Siaqodb(siaoqodbPath); } return(instance); }
private void SetupSiaqodb() { string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder SiaqodbConfigurator.SetLicense(@"put your license key"); db = new Siaqodb(documentsPath); TaskMgr = new TaskManager(db); }
public void TestInclude() { SiaqodbConfigurator.LoadRelatedObjects <A>(false); SiaqodbConfigurator.LoadRelatedObjects <B>(false); try { Siaqodb s_db = new Siaqodb(objPath); s_db.DropType <A>(); s_db.DropType <B>(); s_db.DropType <C>(); for (int i = 0; i < 10; i++) { A a = new A(); a.aId = i; a.BVar = new B(); a.BVar.bId = 11; a.BVar.Ci = new C(); a.BVar.Ci.ACircular = a; a.BVar.Ci.cId = i; s_db.StoreObject(a); } IList <A> allA = s_db.LoadAll <A>(); IList <B> allB = s_db.LoadAll <B>(); for (int i = 0; i < 10; i++) { Assert.IsNull(allA[i].BVar); Assert.IsNull(allB[i].Ci); } var q = (s_db.Cast <A>().Where(a => a.OID > 5).Include("BVar")).ToList(); foreach (A a in q) { Assert.IsNotNull(a.BVar); Assert.IsNull(a.BVar.Ci); } var q1 = (s_db.Cast <A>().Where(a => a.OID > 5).Include("BVar").Include("BVar.Ci")).ToList(); foreach (A a in q1) { Assert.IsNotNull(a.BVar); Assert.IsNotNull(a.BVar.Ci); } var q2 = (from A a in s_db.Query <A>().Include("BVar") select a).ToList(); foreach (A a in q2) { Assert.IsNotNull(a.BVar); Assert.IsNull(a.BVar.Ci); } } finally { SiaqodbConfigurator.LoadRelatedObjects <A>(true); SiaqodbConfigurator.LoadRelatedObjects <B>(true); } }
private void SetupSiaqodb() { string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder string dbpath = Path.Combine(documentsPath, "../Library/siaqodb"); // Library folder if (!System.IO.Directory.Exists(dbpath)) { System.IO.Directory.CreateDirectory(dbpath); } SiaqodbConfigurator.SetLicense(@"put your license key"); db = new Siaqodb(dbpath); TaskMgr = new TaskManager(db); }
public static void SetEncryptionSettings() { SiaqodbConfigurator.EncryptedDatabase = IsEncryptedChecked; if (SiaqodbConfigurator.EncryptedDatabase) { SiaqodbConfigurator.SetEncryptor(Algorithm == "AES" ? BuildInAlgorithm.AES : BuildInAlgorithm.XTEA); if (!string.IsNullOrEmpty(Pwd)) { SiaqodbConfigurator.SetEncryptionPassword(Pwd); } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { SiaqodbConfigurator.ApplyConfigurator(PortableDataLayer.DatabaseManager.GetDefaultConfig()); using (Siaqodb siaqodb = new Siaqodb()) { siaqodb.Open(ApplicationData.Current.LocalFolder.Path); PortableDataLayer.DatabaseManager dbmanager = new PortableDataLayer.DatabaseManager(siaqodb); dbmanager.Run(); } base.OnNavigatedTo(e); }
static void Main(string[] args) { Random rnd = new Random(); SiaqodbConfigurator.SetDocumentSerializer(new MyJsonSerializer()); SiaqodbConfigurator.SetSyncableBucket("invoices", true); Sqo.SiaqodbConfigurator.SetLicense(@"put your license"); try { using (Siaqodb siaqodb = new Siaqodb(@"c:\DATA\")) { IBucket bucket = siaqodb.Documents["invoices"]; Invoice inv = new Invoice { CustomerName = "My Company", InvoiceDate = DateTime.Now, Total = 2390 }; Document document = new Document(); document.Key = "InVoice-" + rnd.Next(); document.SetContent <Invoice>(inv); bucket.Store(document); using (SiaqodbSync syncContext = new SiaqodbSync("http://localhost:11735/v0/", "97c7835153fd66617fad7b43f4000647", "4362kljh63k4599hhgm")) { //pull(which will trigger also push) will upload and than download changes to/from cloud/server PullResult syncResult = syncContext.Pull(bucket); if (syncResult.Error != null) { Console.WriteLine("Error downloading changes:" + syncResult.Error.Message); } else { Console.WriteLine("Sync finished!"); Console.WriteLine("Uploaded:" + syncResult.PushResult.SyncStatistics.TotalUploads + " documents!"); Console.WriteLine("Downloaded:" + syncResult.SyncStatistics.TotalDownloads + " documents!"); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
private static void ComplexQuery(Siaqodb siaqodb) { IBucket bucket = siaqodb.Documents["invoices"]; Invoice invoice = BuildInvoice(); //insert invoice with tags with Document way Document doc = new Document(); doc.Key = invoice.Id; doc.SetContent <Invoice>(invoice); doc.SetTag <int>("year", invoice.InvoiceDate.Year); //this tag will be automatically indexed doc.SetTag <string>("customer", invoice.CustomerCode); //this tag will be automatically indexed bucket.Store(doc); //register key convention, so we can work directly with POCO SiaqodbConfigurator.RegisterKeyConvention <Invoice>(a => a.Id); Invoice invoice2 = BuildInvoice(); //insert invoice with tags in POCO way - invoice is tagged with 2 tags: year and customer bucket.Store(invoice2, new { year = invoice2.InvoiceDate.Year, customer = invoice2.CustomerCode }); //query with Fluent API Query query = new Query(); query.WhereGreaterThanOrEqual("year", invoice.InvoiceDate.Year).WhereEqual("customer", invoice.CustomerCode); //execute query var docs = bucket.Find(query); foreach (Document d in docs) { Invoice inv = d.GetContent <Invoice>(); Console.WriteLine("Invoice with Id:" + d.Key + " loaded by complex query."); } //run same query using LINQ: var docsLINQ = from Document d in bucket where d.GetTag <int>("year") >= invoice.InvoiceDate.Year && d.GetTag <string>("customer") == invoice.CustomerCode select d; foreach (Document d in docsLINQ) { Invoice inv = d.GetContent <Invoice>(); Console.WriteLine("Invoice with Id:" + d.Key + " loaded by LINQ complex query"); } }
public void Run() { Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance(); siaqodb.DropType <POCOSimple>(); //define an Index in POCO way (not by an attribute) SiaqodbConfigurator.AddIndex("ID", typeof(POCOSimple)); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); for (int i = 0; i < 100; i++) { POCOSimple ps = new POCOSimple(); if (i % 2 == 0) { ps.ID = id1; } else { ps.ID = id2; } siaqodb.StoreObject(ps); } DateTime start = DateTime.Now; var q = from POCOSimple ps in siaqodb where ps.ID == id1 select ps; int k = 0; foreach (POCOSimple pocoSimple in q) { //do something with object k++; } string timeElapsed = (DateTime.Now - start).ToString(); Log("Time elapsed to get:" + k.ToString() + " objects by index filtered, is:" + timeElapsed); }
private void btnOK_Click(object sender, EventArgs e) { try { SiaqodbConfigurator.SetTrialLicense(this.textBox1.Text); Sqo.Siaqodb siaqodbConfig = new Sqo.Siaqodb(Application.StartupPath); siaqodbConfig.Close(); TrialLicense.LicenseKey = textBox1.Text; this.licenseKey = textBox1.Text; this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { SiaqodbConfigurator.ApplyConfigurator(PortableDataLayer.DatabaseManager.GetDefaultConfig()); string siaoqodbPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"siaqodb"; if (!Directory.Exists(siaoqodbPath)) { Directory.CreateDirectory(siaoqodbPath); } using (Siaqodb siaqodb = new Siaqodb(siaoqodbPath)) { PortableDataLayer.DatabaseManager dbmanager = new PortableDataLayer.DatabaseManager(siaqodb); dbmanager.Run(); } Console.WriteLine("Done, press enter..."); Console.ReadLine(); }
private void btnOK_Click(object sender, RoutedEventArgs e) { try { SiaqodbConfigurator.SetLicense(this.textBox1.Text); Sqo.Siaqodb siaqodbConfig = new Sqo.Siaqodb(AppDomain.CurrentDomain.BaseDirectory); siaqodbConfig.Close(); TrialLicense.LicenseKey = textBox1.Text; this.licenseKey = textBox1.Text; this.DialogResult = true; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void CreateDatabase2() { try { SiaqodbConfigurator.SetLicense(@"triallicensecode"); SiaqodbConfigurator.EncryptedDatabase = true; SiaqodbConfigurator.SetEncryptor(BuildInAlgorithm.AES); SiaqodbConfigurator.SetEncryptionPassword("supersecret"); string path = System.IO.Path.Combine(BasePath, "SiaqoTest"); Directory.CreateDirectory(path); instance = new Siaqodb(path); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private static void CRUD_POCO(Siaqodb siaqodb) { //register key convention, so we can work directly with POCO SiaqodbConfigurator.RegisterKeyConvention <Invoice>(a => a.Id); IBucket bucket = siaqodb.Documents["invoices"]; Invoice invoice = BuildInvoice(); //insert bucket.Store(invoice); Invoice invoiceLoaded = bucket.Load <Invoice>(invoice.Id); invoiceLoaded.InvoiceDate = invoiceLoaded.InvoiceDate.AddDays(-1); //update bucket.Store(invoiceLoaded); //delete bucket.Delete(invoiceLoaded.Id); }
public bool LoadOidsByIndex(SqoTypeInfo ti, string fieldName, Where where, List <int> oids) { if (cacheIndexes != null) { IBTree index = cacheIndexes.GetIndex(ti, fieldName); if (index != null && where.OperationType != OperationType.Contains && where.OperationType != OperationType.NotEqual && where.OperationType != OperationType.EndWith) { try { this.LoadOidsByIndex(index, where, oids); } catch (IndexCorruptedException ex) { SiaqodbConfigurator.LogMessage("Index has corrupted, will be rebuild", VerboseLevel.Info); index = this.RenewIndex(ti, fieldName); this.LoadOidsByIndex(index, where, oids); } return(true); } } return(false); }
public void LoadOrdersWithonlySomeRelatedObjects() { Siaqodb siaqodb = SiaqodbFactoryExample.GetInstance(); SiaqodbConfigurator.LoadRelatedObjects <Order>(false); SiaqodbConfigurator.LoadRelatedObjects <Customer>(false); IList <Order> orders = siaqodb.LoadAll <Order>(); Log("All orders loaded has complex properties(Customer,OrderDetails)= null, means was not loaded from DB"); var query1 = siaqodb.Query <Order>().Where(o => o.OrderNumber > 2).Include("OrderCustomer"); Log("All orders will have property OrderCustomer loaded(since Customer has LoadRelatedObjects=false, Address will not be loaded)"); foreach (Order order in query1) { Log("Order with nr:" + order.OrderNumber + " is of Customer:" + order.OrderCustomer.Name); } var query2 = siaqodb.Query <Order>().Where(o => o.OrderNumber > 2).Include("OrderCustomer") .Include("OrderCustomer.Address"); Log("All orders will have property OrderCustomer and also property OrderCustomer.Address loaded"); foreach (Order order in query2) { Log("Order with nr:" + order.OrderNumber + " is of Customer:" + order.OrderCustomer.Name + " from City:" + order.OrderCustomer.Address.City); } var query3 = (from Order o in siaqodb where o.OrderNumber > 2 select o).Include("OrderCustomer").Include("OrderCustomer.Address"); foreach (Order order in query3) { Log("Order with nr:" + order.OrderNumber + " is of Customer:" + order.OrderCustomer.Name + " from City:" + order.OrderCustomer.Address.City); } }
public void EncryptUsingXTEA_And_CustomPassword() { SiaqodbConfigurator.SetEncryptor(BuildInAlgorithm.XTEA); SiaqodbConfigurator.SetEncryptionPassword("secret_pwd"); //now database files will be encrypted with XTEA encryption algorithm and can be opened only with the paswword set //because previously, in method EncryptSimple, we used database from path SiaqodbFactoryExample.siaoqodbPath with another Encryption algorithm, //we cannot open now same database with another encryption settings(algorithm+pwd) so open another new DB string siaoqodbPathForEncrypt = SiaqodbFactoryExample.siaoqodbPath + Path.DirectorySeparatorChar + @"siaqodbEncrypted"; if (!Directory.Exists(siaoqodbPathForEncrypt)) { Directory.CreateDirectory(siaoqodbPathForEncrypt); } Siaqodb siaqodb = new Siaqodb(siaoqodbPathForEncrypt); Company comp = CreateCompany("MyCompany"); //data of this object will be encrypted in DB siaqodb.StoreObject(comp); siaqodb.Close(); }
/// <summary> /// Gets the database instance or creates one /// </summary> /// <returns>The instance.</returns> /// <param name="database">Database.</param> public ISiaqodb GetInstance(string database) { try { //Does it exist in the dictionary... Siaqodb db; if (SiaqoDatabases != null) { if (SiaqoDatabases.TryGetValue(database, out db)) { return(db); } } //Did not find it so add it... var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), database); var config = new Configurator(); // Siaqodb Starter version allows you to store 100 objects per type // To obtain a trial or full license please visit https://www.siaqodb.com // If you are using a trial or fully licensed version of Siaqodb, uncomment this line and enter your key //Sqo.SiaqodbConfigurator.SetLicense("[Paste your provided license key here...]"); SiaqodbConfigurator.ApplyConfigurator(config); db = new Siaqodb(dbpath); //Add the instance to the list SiaqoDatabases?.Add(database, db); return(db); } catch (Exception ex) { if (Debugger.IsAttached) { Debug.WriteLine(ex.Message); } return(null); } }
public async Task TestStorePartialOnIndexed() { SiaqodbConfigurator.AddIndex("cId", typeof(C)); Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder); await s_db.DropTypeAsync <A>(); await s_db.DropTypeAsync <B>(); await s_db.DropTypeAsync <C>(); for (int i = 0; i < 10; i++) { A a = new A(); a.aId = i; a.BVar = new B(); a.BVar.bId = 11; a.BVar.Ci = new C(); a.BVar.Ci.ACircular = a; a.BVar.Ci.cId = i % 2; await s_db.StoreObjectAsync(a); } await s_db.FlushAsync(); IList <A> lsA = await s_db.LoadAllAsync <A>(); lsA[0].BVar.Ci.cId = 3; await s_db.StoreObjectPartiallyAsync(lsA[0].BVar, "Ci"); var q = await(from C c in s_db where c.cId == 3 select c).ToListAsync(); Assert.AreEqual(1, q.Count); }
public void Run() { //siaqodb store one file on disk for each Type and names of db files are composed by AssmeblyName+fullNameSpace of Type to be sure about uniqueness //but sometimes name of file can be too long, so would be better if you can customize it, Siaqodb allow that by: SiaqodbConfigurator.SetDatabaseFileName <DummyType>("mydummy"); //1.you have to call it before open any database that has stored/will store objects of DummyType type //2.as you see is not necessary to add extension to fileName, engine put by default .sqo extension //3.only one call to the method above is required(static stored) //open another DB since SiaqodbFactoryExample.GetInstance() return an opened DB string siaoqodbPathNew = Environment.CurrentDirectory + Path.DirectorySeparatorChar + @"siaqodbWithCustomFileNames"; if (!Directory.Exists(siaoqodbPathNew)) { Directory.CreateDirectory(siaoqodbPathNew); } Siaqodb siaqodb = new Siaqodb(siaoqodbPathNew); siaqodb.StoreObject(new DummyType()); Log("In database:" + siaoqodbPathNew + ", fileName for DummyType is mydummy.sqo"); siaqodb.Close(); }
public async Task <IBTree> GetIndexAsync(FieldSqoInfo finfo, SqoTypeInfo tinfo) { Type t = typeof(BTree <>).MakeGenericType(finfo.AttributeType); ConstructorInfo ctor = t.GetConstructor(new Type[] { typeof(Siaqodb) }); IBTree index = (IBTree)ctor.Invoke(new object[] { this.siaqodb }); IndexInfo2 indexInfo = null; string indexName = finfo.Name + tinfo.TypeName; try { IList <IndexInfo2> stIndexes = await this.GetStoredIndexesAsync().ConfigureAwait(false); foreach (IndexInfo2 ii in stIndexes) { if (ii.IndexName == indexName) { indexInfo = ii; break; } } } catch (Exception ex) { SiaqodbConfigurator.LogMessage("IndexInfo cannot be loaded, index will be rebuild", VerboseLevel.Info); } bool indexExists = false; if (indexInfo == null) { indexInfo = await this.BuildIndexAsync(finfo, tinfo, index).ConfigureAwait(false); } else { indexExists = true; } index.SetIndexInfo(indexInfo); Type nodeType = typeof(BTreeNode <>).MakeGenericType(finfo.AttributeType); if (indexInfo.RootOID > 0 && indexExists) { object rootP = null; bool error = false; try { rootP = await siaqodb.LoadObjectByOIDAsync(nodeType, indexInfo.RootOID).ConfigureAwait(false); } catch (IndexCorruptedException ex) { error = true; } if (error) { if (storedIndexes != null && storedIndexes.Contains(indexInfo)) { storedIndexes.Remove(indexInfo); } await siaqodb.DeleteAsync(indexInfo); indexInfo = await this.BuildIndexAsync(finfo, tinfo, index); index.SetIndexInfo(indexInfo); index.Persist(); } if (rootP != null) { index.SetRoot(rootP); } } return(index); }
static void Main(string[] args) { Random rnd = new Random(); Sqo.SiaqodbConfigurator.SetLicense(@"your license"); SiaqodbConfigurator.SetDocumentSerializer(new MyJsonSerializer()); SiaqodbConfigurator.SetSyncableBucket("invoices_encrypted", true); //IQrypt settings IQryptSiaqodbConfigurator.SetEncryptionChiper(IQrypt.Cipher.AES256, "myencryption_key"); IQryptSiaqodbConfigurator.EncryptDocumentContent("invoices_encrypted"); IQryptSiaqodbConfigurator.EncryptTag("customer_code", IQrypt.EncryptionType.DET, typeof(string)); try { using (Siaqodb siaqodb = new Siaqodb(@"c:\DATA\")) { IBucket bucket = siaqodb.Documents["invoices_encrypted"]; Invoice inv = new Invoice { CustomerName = "My Company", InvoiceDate = DateTime.Now, Total = 2390 }; IQryptDocument document = new IQryptDocument(); document.Key = "InVoice-" + rnd.Next(); document.SetContent <Invoice>(inv); string tagVal = "CU2323" + rnd.Next(); document.SetTag("customer_code", tagVal); bucket.Store(document); // let's run a query Query query = new Query(); query.IQryptWhereEqual("customer_code", tagVal); var q = bucket.Find(query); foreach (Document o in q) { if (o.GetTag <string>("customer_code") == tagVal) { Console.WriteLine("Query over encrypted data run!"); } } using (SiaqodbSync syncContext = new SiaqodbSync("http://localhost:11735/v0/", "97c7835153fd66617fad7b43f4000647", "4362kljh63k4599hhgm")) { //pull(which will trigger also push) will upload and than download changes to/from cloud/server PullResult syncResult = syncContext.Pull(bucket); if (syncResult.Error != null) { Console.WriteLine("Error downloading changes:" + syncResult.Error.Message); } else { Console.WriteLine("Sync finished!"); Console.WriteLine("Uploaded:" + syncResult.PushResult.SyncStatistics.TotalUploads + " documents!"); Console.WriteLine("Downloaded:" + syncResult.SyncStatistics.TotalDownloads + " documents!"); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
private SqoTypeInfo DeserializeSqoTypeInfoFromBuffer(byte[] readFullSqoTypeInfo, bool loadRealType) { SqoTypeInfo tInfo = new SqoTypeInfo(); tInfo.Header.headerSize = readFullSqoTypeInfo.Length; try { //reader.Close(); byte[] typeNameSize = GetBuffer(readFullSqoTypeInfo, 4, 4); tInfo.Header.typeNameSize = ByteConverter.ByteArrayToInt(typeNameSize); //read versionFirst byte[] version = GetBuffer(readFullSqoTypeInfo, tInfo.Header.typeNameSize + 28, 4); tInfo.Header.version = ByteConverter.ByteArrayToInt(version); byte[] typeName = GetBuffer(readFullSqoTypeInfo, 8, tInfo.Header.typeNameSize); tInfo.TypeName = (string)ByteConverter.DeserializeValueType(typeof(string), typeName, tInfo.Header.version); if (loadRealType) { #if SILVERLIGHT string[] tinfoArr = tInfo.TypeName.Split(','); string fullTypeName = tInfo.TypeName; if (tinfoArr.Length == 2 && !tInfo.TypeName.StartsWith("Sqo.Indexes.BTreeNode") && !tInfo.TypeName.StartsWith("KeVaSt.BTreeNode")) //written with .net version { fullTypeName = tInfo.TypeName + ", Version=0.0.0.1,Culture=neutral, PublicKeyToken=null"; tInfo.Type = Type.GetType(fullTypeName); tInfo.TypeName = tInfo.Type.AssemblyQualifiedName; } else { tInfo.Type = Type.GetType(fullTypeName); } #else string[] tinfoArr = null; int indexOfGenericsEnd = tInfo.TypeName.LastIndexOf(']'); if (indexOfGenericsEnd > 0) { string substringStart = tInfo.TypeName.Substring(0, indexOfGenericsEnd); string substringEnd = tInfo.TypeName.Substring(indexOfGenericsEnd, tInfo.TypeName.Length - indexOfGenericsEnd); tinfoArr = substringEnd.Split(','); tinfoArr[0] = substringStart + "]"; } else { tinfoArr = tInfo.TypeName.Split(','); } string fullTypeName = tInfo.TypeName; if (tinfoArr.Length > 2 && !tInfo.TypeName.StartsWith("Sqo.Indexes.BTreeNode") && !tInfo.TypeName.StartsWith("KeVaSt.BTreeNode"))//written with Silevrlight version { fullTypeName = tinfoArr[0] + "," + tinfoArr[1]; tInfo.Type = Type.GetType(fullTypeName); tInfo.TypeName = fullTypeName; } else { tInfo.Type = Type.GetType(tInfo.TypeName); } #endif } byte[] lastUpdate = GetBuffer(readFullSqoTypeInfo, tInfo.Header.typeNameSize + 8, 8); tInfo.Header.lastUpdated = (DateTime)ByteConverter.DeserializeValueType(typeof(DateTime), lastUpdate, tInfo.Header.version); byte[] nrRecords = GetBuffer(readFullSqoTypeInfo, tInfo.Header.typeNameSize + 16, 4); tInfo.Header.numberOfRecords = ByteConverter.ByteArrayToInt(nrRecords); byte[] positionFirstRecord = GetBuffer(readFullSqoTypeInfo, tInfo.Header.typeNameSize + 20, 4); tInfo.Header.positionFirstRecord = ByteConverter.ByteArrayToInt(positionFirstRecord); byte[] lengthRecord = GetBuffer(readFullSqoTypeInfo, tInfo.Header.typeNameSize + 24, 4); tInfo.Header.lengthOfRecord = ByteConverter.ByteArrayToInt(lengthRecord); int currentPosition = tInfo.Header.typeNameSize + 32; byte[] nrFields = GetBuffer(readFullSqoTypeInfo, currentPosition, 4); tInfo.Header.NrFields = ByteConverter.ByteArrayToInt(nrFields); if (tInfo.Header.version <= -30) //version >= 3.0 { currentPosition += 4; byte[] TID = GetBuffer(readFullSqoTypeInfo, currentPosition, 4); tInfo.Header.TID = ByteConverter.ByteArrayToInt(TID); currentPosition += 4; byte[] unused1 = GetBuffer(readFullSqoTypeInfo, currentPosition, 4); tInfo.Header.Unused1 = ByteConverter.ByteArrayToInt(unused1); currentPosition += 4; byte[] unused2 = GetBuffer(readFullSqoTypeInfo, currentPosition, 4); tInfo.Header.Unused2 = ByteConverter.ByteArrayToInt(unused2); currentPosition += 4; byte[] unused3 = GetBuffer(readFullSqoTypeInfo, currentPosition, 4); tInfo.Header.Unused3 = ByteConverter.ByteArrayToInt(unused3); } for (int i = 0; i < tInfo.Header.NrFields; i++) { FieldSqoInfo ai = new FieldSqoInfo(); int currentPositionField = (i * MetaExtractor.FieldSize) + currentPosition + 4; byte[] sizeOfName = GetBuffer(readFullSqoTypeInfo, currentPositionField, 4); ai.Header.SizeOfName = ByteConverter.ByteArrayToInt(sizeOfName); currentPositionField += 4; byte[] name = GetBuffer(readFullSqoTypeInfo, currentPositionField, ai.Header.SizeOfName); ai.Name = (string)ByteConverter.DeserializeValueType(typeof(string), name, tInfo.Header.version); currentPositionField += 200; byte[] length = GetBuffer(readFullSqoTypeInfo, currentPositionField, 4); ai.Header.Length = ByteConverter.ByteArrayToInt(length); currentPositionField += 4; byte[] position = GetBuffer(readFullSqoTypeInfo, currentPositionField, 4); ai.Header.PositionInRecord = ByteConverter.ByteArrayToInt(position); currentPositionField += 4; byte[] nrOrder = GetBuffer(readFullSqoTypeInfo, currentPositionField, 4); ai.Header.RealLength = ByteConverter.ByteArrayToInt(nrOrder); currentPositionField += 4; byte[] typeId = GetBuffer(readFullSqoTypeInfo, currentPositionField, 4); ai.AttributeTypeId = ByteConverter.ByteArrayToInt(typeId); if (loadRealType) { ai.FInfo = MetaExtractor.FindField(tInfo.Type, ai.Name); MetaExtractor.FindAddConstraints(tInfo, ai); MetaExtractor.FindAddIndexes(tInfo, ai); } if (ai.AttributeTypeId == MetaExtractor.complexID || ai.AttributeTypeId == MetaExtractor.dictionaryID || ai.AttributeTypeId == MetaExtractor.documentID) { if (loadRealType) { ai.AttributeType = ai.FInfo.FieldType; } } else if (ai.Header.Length - 1 == MetaExtractor.GetSizeOfField(ai.AttributeTypeId))//is Nullable<> { Type fGen = typeof(Nullable <>); ai.AttributeType = fGen.MakeGenericType(Cache.Cache.GetTypebyID(ai.AttributeTypeId)); } else if (MetaExtractor.IsTextType(ai.AttributeTypeId)) { ai.AttributeType = typeof(string); ai.IsText = true; } else if (ai.AttributeTypeId > MetaExtractor.ArrayTypeIDExtra)//is IList<> or Array { if (loadRealType) { ai.AttributeType = ai.FInfo.FieldType; } else { if (ai.AttributeTypeId - MetaExtractor.ArrayTypeIDExtra == MetaExtractor.complexID || ai.AttributeTypeId - MetaExtractor.ArrayTypeIDExtra == MetaExtractor.jaggedArrayID) { } else { Type elementType = Cache.Cache.GetTypebyID(ai.AttributeTypeId); #if CF ai.AttributeType = Array.CreateInstance(elementType, 0).GetType(); #else ai.AttributeType = elementType.MakeArrayType(); #endif } } if (ai.AttributeTypeId - MetaExtractor.ArrayTypeIDExtra == MetaExtractor.textID) { ai.IsText = true; } } else if (ai.AttributeTypeId > MetaExtractor.FixedArrayTypeId)//is IList<> or Array { if (loadRealType) { ai.AttributeType = ai.FInfo.FieldType; } else { if (ai.AttributeTypeId - MetaExtractor.FixedArrayTypeId == MetaExtractor.complexID || ai.AttributeTypeId - MetaExtractor.FixedArrayTypeId == MetaExtractor.jaggedArrayID) { } else { Type elementType = Cache.Cache.GetTypebyID(ai.AttributeTypeId); #if CF ai.AttributeType = Array.CreateInstance(elementType, 0).GetType(); #else ai.AttributeType = elementType.MakeArrayType(); #endif } } } else { ai.AttributeType = Cache.Cache.GetTypebyID(ai.AttributeTypeId); } tInfo.Fields.Add(ai); } return(tInfo); } catch (Exception ex) { SiaqodbConfigurator.LogMessage("File:" + this.filePath + " is not a valid Siaqodb database file,skipped; error:" + ex.ToString(), VerboseLevel.Info); } return(null); }
public async Task TestInclude() { SiaqodbConfigurator.LoadRelatedObjects <A>(false); SiaqodbConfigurator.LoadRelatedObjects <B>(false); try { Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder); await s_db.DropTypeAsync <A>(); await s_db.DropTypeAsync <B>(); await s_db.DropTypeAsync <C>(); for (int i = 0; i < 10; i++) { A a = new A(); a.aId = i; a.BVar = new B(); a.BVar.bId = 11; a.BVar.Ci = new C(); a.BVar.Ci.ACircular = a; a.BVar.Ci.cId = i; await s_db.StoreObjectAsync(a); } await s_db.FlushAsync(); IList <A> allA = await s_db.LoadAllAsync <A>(); IList <B> allB = await s_db.LoadAllAsync <B>(); for (int i = 0; i < 10; i++) { Assert.IsNull(allA[i].BVar); Assert.IsNull(allB[i].Ci); } var q = await(s_db.Cast <A>().Where(a => a.OID > 5).Include("BVar")).ToListAsync(); foreach (A a in q) { Assert.IsNotNull(a.BVar); Assert.IsNull(a.BVar.Ci); } var q1 = await(s_db.Cast <A>().Where(a => a.OID > 5).Include("BVar").Include("BVar.Ci")).ToListAsync(); foreach (A a in q1) { Assert.IsNotNull(a.BVar); Assert.IsNotNull(a.BVar.Ci); } var q2 = await(s_db.Cast <A>().Where(a => a.OID > 5).Include("BVar")).ToListAsync(); foreach (A a in q2) { Assert.IsNotNull(a.BVar); Assert.IsNull(a.BVar.Ci); } } finally { SiaqodbConfigurator.LoadRelatedObjects <A>(true); SiaqodbConfigurator.LoadRelatedObjects <B>(true); } }
private void Main_Shown(object sender, EventArgs e) { #if TRIAL string folder = Application.StartupPath; string trialFile = folder + System.IO.Path.DirectorySeparatorChar + "trial.lic"; if (System.IO.File.Exists(trialFile)) { string text = System.IO.File.ReadAllText(trialFile); try { SiaqodbConfigurator.SetTrialLicense(text); Sqo.Siaqodb siaqodbConfigTemp = new Sqo.Siaqodb(Application.StartupPath); siaqodbConfigTemp.Close(); TrialLicense.LicenseKey = text; } catch (Sqo.Exceptions.InvalidLicenseException ex) { MessageBox.Show(ex.Message); this.Close(); return; } catch (Exception ex) { MessageBox.Show(ex.Message); TrialLicenseFrm trialWnd = new TrialLicenseFrm(); if (trialWnd.ShowDialog() == DialogResult.OK) { string trialKey = trialWnd.GetLicenseKey(); System.IO.File.WriteAllText(trialFile, trialKey); } else { this.Close(); return; } } } else { TrialLicenseFrm trialWnd = new TrialLicenseFrm(); if (trialWnd.ShowDialog() == DialogResult.OK) { string trialKey = trialWnd.GetLicenseKey(); System.IO.File.WriteAllText(trialFile, trialKey); } else { this.Close(); return; } } #endif Sqo.Siaqodb siaqodbConfig = new Sqo.Siaqodb(Application.StartupPath); //siaqodbConfig.DropType<ConnectionItem>(); IObjectList <ConnectionItem> list = siaqodbConfig.LoadAll <ConnectionItem>(); foreach (ConnectionItem item in list) { cmbDBPath.ComboBox.Items.Add(item.Item); } siaqodbConfig.Close(); Sqo.Siaqodb siaqodbRef = new Sqo.Siaqodb(Application.StartupPath); Sqo.IObjectList <ReferenceItem> references = siaqodbRef.LoadAll <ReferenceItem>(); foreach (ReferenceItem refi in references) { if (File.Exists(refi.Item)) { try { File.Copy(refi.Item, Application.StartupPath + Path.DirectorySeparatorChar + Path.GetFileName(refi.Item), true); } catch { } } } siaqodbRef.Close(); }