public RuntimeCell GetAndPinCell(int key, out IDisposable cleanupRef) { cleanupRef = null; IStorable storable = default(IStorable); bool flag; if (key < this.m_collection.Count) { cleanupRef = this.m_collection.GetAndPin(key, out storable); flag = (storable != null); } else { storable = null; flag = false; } if (flag) { if (this.IsCellReference(storable)) { if (cleanupRef != null) { cleanupRef.Dispose(); } IReference <RuntimeCell> reference = (IReference <RuntimeCell>)storable; reference.PinValue(); cleanupRef = (IDisposable)reference; return(reference.Value()); } return((RuntimeCell)storable); } return(null); }
public static byte[] GetBytes(this IStorable data) { DataStorage ds = new DataStorage(); data.WriteToData(ds); return(ds.Bytes); }
/// <summary> /// Creates an instance of this from in order to edit the selected item. /// </summary> /// <param name="parent">The parent node of an item that is to be added.</param> /// <param name="warehouse">The warehouse in which to add the item.</param> /// <param name="obj">The item to be edited.</param> public ItemEditor(TreeNode parent, Warehouse warehouse, IStorable obj) { this.parent = parent; this.warehouse = warehouse; ignoreName = obj.Name; InitializeComponent(); LeftInStockNumericUD.Maximum = int.MaxValue; GetItemInfo(obj); WarningTextLabel.Text = string.Empty; InfoTextLabel.Text = string.Empty; OKButton.Text = "Apply Changes"; ItemNameTextBox_TextChanged(new object(), new EventArgs()); PriceTextBox_TextChanged(new object(), new EventArgs()); SortingVendorCodeTextBox_TextChanged(new object(), new EventArgs()); if (parent is null) { ParentNameLabel.Text = "This item does not have a parent."; ParentNameLabel.ForeColor = Color.DarkRed; } else { ParentNameLabel.Text = parent.Name; ParentNameLabel.ForeColor = Color.Gray; } }
static void Main() { Document theNote = new Note("Test Note"); IStorable isNote = theNote as IStorable; if (isNote != null) { isNote.Read(); isNote.Write(); } Console.WriteLine("\n"); theNote.Read(); theNote.Write(); Console.WriteLine("\n"); Note note2 = new Note("Second Test"); IStorable isNote = note2 as IStorable; if (isNote != null) { isNote2.Read(); isNote.Write(); } Console.WriteLine("\n"); note2.Read(); note2.Write(); }
/// <summary> /// Returns <c>true</c> if the given statement modifies the given variable. /// </summary> /// <remarks> /// The current implementation is not capable of detecting modifications of variables which are referenced as "out" arguments of some method. /// </remarks> /// <param name="stmt">statement</param> /// <param name="variable">variable</param> public static bool Modifies(this Statement stmt, IStorable variable) { VariableModificationDetector vmd = new VariableModificationDetector(variable); stmt.Accept(vmd); return(vmd.Result); }
public static void SetBytes(this IStorable storable, byte[] data) { var ms = new MemoryStream(data); var reader = new RawDataReader(ms, Encoding.UTF8); storable.Read(reader); }
/// <summary> /// Saves a storable object in the database. /// </summary> /// <param name="obj">Storable object to save.</param> /// <param name="db">Database.</param> /// <param name="context">Serialization context.</param> /// <param name="saveChildren">If set to <c>false</c>, <see cref="IStorable"/> children are not saved.</param> internal static void SaveObject(IStorable obj, Database db, SerializationContext context = null, bool saveChildren = true) { if (context == null) { context = new SerializationContext(db, obj.GetType()); if (obj.ParentID != Guid.Empty) { context.RootID = obj.ParentID; } else { context.RootID = obj.ID; } } context.SaveChildren = saveChildren; context.Stack.Push(obj); Document doc = db.GetDocument(DocumentsSerializer.StringFromID(obj.ID, context.RootID)); doc.Update((UnsavedRevision rev) => { JObject jo = SerializeObject(obj, rev, context); IDictionary <string, object> props = jo.ToObject <IDictionary <string, object> > (); /* SetProperties sets a new properties dictionary, removing the attachments we * added in the serialization */ if (rev.Properties.ContainsKey("_attachments")) { props ["_attachments"] = rev.Properties ["_attachments"]; } rev.SetProperties(props); return(true); }); context.Stack.Pop(); }
/// <summary> /// Initializes a new instance of the <see cref="LongoMatch.DB.StorablesStackContractResolver"/> class. /// If <paramref name="parentStorable"/> is not null, this storable will be used instead of creating /// a new instance. /// </summary> /// <param name="context">The serialization context.</param> /// <param name="parentStorable">The partially loaded storable that is going to be filled.</param> /// <param name = "preservePreloadProperties">If <c>true</c> reloaded properties are preserved instead of /// re-read from the db</param> public StorablesStackContractResolver(SerializationContext context, IStorable parentStorable, bool preservePreloadProperties = false) { this.context = context; this.parentStorable = parentStorable; this.preservePreloadProperties = preservePreloadProperties; }
internal MemoryMappedStorage(IStorable variable, MemoryRegion region, MemoryLayout layout) { Kind = EKind.Variable; Variable = variable; Region = region; Layout = layout; }
static void Main() { // create a myStruct object myStruct theStruct = new myStruct(); theStruct.Status = -1; // initialize Console.WriteLine( "theStruct.Status: {0}", theStruct.Status); // Change the value theStruct.Status = 2; Console.WriteLine("Changed object."); Console.WriteLine( "theStruct.Status: {0}", theStruct.Status); // cast to an IStorable // implicit box to a reference type IStorable isTemp = ( IStorable )theStruct; // set the value through the interface reference isTemp.Status = 4; Console.WriteLine("Changed interface."); Console.WriteLine("theStruct.Status: {0}, isTemp: {1}", theStruct.Status, isTemp.Status); // Change the value again theStruct.Status = 6; Console.WriteLine("Changed object."); Console.WriteLine("theStruct.Status: {0}, isTemp: {1}", theStruct.Status, isTemp.Status); }
private void WriteItem(BaseReference itemRef) { ItemHolder item = itemRef.Item; IStorable item2 = item.Item; ReferenceID id = itemRef.Id; long num = m_storage.Allocate(item2); if (id.HasMultiPart && !id.IsTemporary) { m_partitionManager.UpdateTreePartitionOffset(id, num); if (itemRef.PinCount == 0) { CacheRemoveValue(id); } } else { id = new ReferenceID(num); id.IsTemporary = false; id.HasMultiPart = false; itemRef.Id = id; } if (itemRef.PinCount == 0) { item.Item = null; item.Reference = null; itemRef.Item = null; } }
static void Main() { //pravi objekat MyStruct MyStruct theStruct = new MyStruct(); theStruct.Status = -1; //incijalizira Console.WriteLine("theStruct.Status: {0}", theStruct.Status); Console.WriteLine(); //mijenja vrijednost theStruct.Status = 2; Console.WriteLine("Changed object."); Console.WriteLine("theStruct.Status: {0}", theStruct.Status); Console.WriteLine(); //pretvara tip u IStorable //implicitno pakira u referentni tip IStorable isTemp = (IStorable)theStruct; //postavlja vrijednost kroz referencu sucelja isTemp.Status = 4; Console.WriteLine("Changed object."); Console.WriteLine("theStruct.Status: {0}, isTemp: {1}", theStruct.Status, isTemp.Status); Console.WriteLine(); //ponovo mjenja vrijednost theStruct.Status = 6; Console.WriteLine("Changed object."); Console.WriteLine("theStruct.Status: {0}, isTemp: {1}", theStruct.Status, isTemp.Status); Console.WriteLine(); }
/// <summary> /// Ctor /// </summary> public EditCustomer(IStorable <Model.Customer> customerStorage) { _customerStorage = customerStorage; InitializeComponent(); comboBoxEditCustomer.ItemsSource = _customerStorage.Read(); }
public static T Clone <T> (this T source, SerializationType type = SerializationType.Json) { IStorable storable = source as IStorable; T retStorable; if (Object.ReferenceEquals(source, null)) { return(default(T)); } // Binary deserialization fails in mobile platforms because of // https://bugzilla.xamarin.com/show_bug.cgi?id=37300 #if OSTYPE_ANDROID || OSTYPE_IOS type = SerializationType.Json; #endif if (source is BindableBase) { type = SerializationType.Json; } retStorable = Serializer.Instance.Clone(source, type); if (storable != null) { (retStorable as IStorable).Storage = storable.Storage; } return(retStorable); }
/// <summary> /// Removes a specified Storable from the warehouse and the TreeView. /// </summary> /// <param name="node">The Storable to delete.</param> public void Remove(IStorable storable) { IContainer storableParent = storable.Parent; if (storableParent is null) { storableParent.Items.Remove(storable); } else { warehouse.Sections.Remove(storable as Section); } TreeNode node = Find(storable); TreeNode parentNode = node.Parent; if (parentNode is null) { parentNode.Nodes.Remove(node); } else { treeView.Nodes.Remove(node); } }
static void Main(string[] args) { Document theNote = new Note("Test Note"); IStorable isNote = theNote as IStorable; if (isNote != null) { isNote.Read(); isNote.Write(); } Console.WriteLine("\n"); theNote.Read(); theNote.Write(); Console.WriteLine("\n"); Note note2 = new Note("Note 2"); Console.WriteLine("\n"); IStorable isNote2 = note2 as IStorable; if (isNote != null) { isNote2.Read(); isNote2.Write(); } note2.Read(); note2.Write(); Console.ReadLine(); }
static void Main() { //stvara referencu dokumenta do objekta Note Document theNote = new Note("Test Note"); IStorable isNote = theNote as IStorable; if (isNote != null) { isNote.Read(); isNote.Write(); } Console.WriteLine(); //izravan poziv metoda theNote.Read(); theNote.Write(); Console.WriteLine(); //pravi objekat note Note note2 = new Note("Second Note"); IStorable isNote2 = note2 as IStorable; if (isNote2 != null) { isNote2.Read(); isNote2.Write(); } Console.WriteLine(); //izravno poziva metode note2.Read(); note2.Write(); }
private void DoStore(IStorable storable, IAuditMetadata auditMeta) { AuditOperation operation = AuditOperation.UPDATE; // ensure db id StorableDocument doc = (StorableDocument)storable; long dbId = doc.DbId is long?(long)doc.DbId : -1; if (dbId == -1) { dbId = ++lastDbId; storable.SetData("dbId", dbId); } IDictionary <string, object> document = new Dictionary <string, object>(); if (documents.ContainsKey(dbId)) { documents[dbId].Document.ToList().ForEach(kvp => document[kvp.Key] = kvp.Value); } else { operation = AuditOperation.INSERT; } doc.Document.ToList().ForEach(kvp => document[kvp.Key] = kvp.Value); doc = new StorableDocument(doc.Categories, null); doc.Document = document; documents[dbId] = doc; AuditRecord audit = NewAuditRecord(auditMeta); audit.InstanceDbId = dbId; audit.Operation = operation; audit.Instance = doc; auditRecords[audit.DbId] = audit; }
public void Run() { Note theNote = new Document("Test Document"); theNote.Read(); theNote.Write(); Console.WriteLine("\n"); IStorable isStorable = theNote as IStorable; if (isStorable != null) { isStorable.Read(); isStorable.Write(); } Console.WriteLine("\n"); // This time create a reference to the derived type Document theDoc = new Document("Second Test"); theDoc.Read(); theDoc.Write(); Console.WriteLine("\n"); IStorable isStorable2 = theDoc as IStorable; if (isStorable != null) { isStorable2.Read(); isStorable2.Write(); } }
public override QueryDTO Execute(QueryParameters parameters) { IStorable toStore = parameters.Subquery.Value; List <Property> propeteries = parameters.Subquery.AdditionalValue; Property property = propeteries.SingleOrDefault(p => p.Name == FieldName); if (property == null) { return new QueryDTO() { Result = new DTOQueryResult { NextResult = null, QueryResultType = ResultType.StringResult, StringOutput = "Unknown field: " + FieldName } } } ; var literalElement = SingleElement(); var literal = literalElement.Execute(parameters).Value; toStore.Properties[property] = literal; return(new QueryDTO() { Value = property }); } }
static void Main(string[] args) { var docStore = new Document(); docStore.Read(); docStore.Status = 69; //Print(docStore); var fileStore = new FlatFile(); fileStore.Read(); //Print(fileStore); fileStore.Print(); var compressStore = fileStore as ICompressable; compressStore.Print(); IStorable dumStore = docStore; dumStore.Read(); if (dumStore is FlatFile) { var dum2Store = (FlatFile)dumStore; Print(dum2Store); } var dum3store = dumStore as FlatFile; if (dum3store != null) { Print(dum3store); } }
static void Main() { // A collection of Documents Document[] docArray = new Document[2]; // First entry is a Document docArray[0] = new Document("Test Document"); // Second entry is a CompressibleDocument (ok because // CompressibleDocument is a Document) docArray[1] = new CompressibleDocument("Test compressibleDocument"); // don't know what we'll pull out of this hat foreach (Document doc in docArray) { // report your name Console.WriteLine("Got: {0}", doc); // Both pass this test IStorable isDoc = doc as IStorable; if (isDoc != null) { isDoc.Read(); } // fails for Document // passes for CompressibleDocument ICompressible icDoc = doc as ICompressible; if (icDoc != null) { icDoc.Compress(); } } }
//private static IDictionary<string, string> _sqliteDatatypeStrings = new Dictionary<string, string>() //{ // {"", ""}, // {"", ""}, // {"", ""}, // {"", ""}, //}; #region Public Methods /// <summary> /// Creates the insert or replace query. /// </summary> /// <returns>The insert or replace query.</returns> /// <param name="storable">Storable.</param> //public static string BuildCreateTableQuery(this IStorable storable) //{ // var properties = storable.GetType().GetRuntimeProperties(); // var tableName = storable.GetType().Name; // var propetiesString = ""; // var index = 0; // foreach (var property in properties) // { // propetiesString += (index == (properties.Count() - 1)) ? property.Name : property.Name + ", "; // var value = property.GetValue(storable); // var valueString = value == null ? "null" : value is bool ? "'" + ((bool)value ? 1 : 0) + "'" : "'" + value + "'"; // // if data is serialized // if (property.Name.Equals("Data") && !valueString.Equals("null")) // { // valueString = valueString.Replace("\"", "\\\""); // } // index++; // } // return string.Format("CREATE TABLE {0} ({1})", // tableName, propetiesString); //} /// <summary> /// Creates the insert or replace query. /// </summary> /// <returns>The insert or replace query.</returns> /// <param name="storable">Storable.</param> public static string BuildInsertOrReplaceQuery(this IStorable storable) { var properties = storable.GetType().GetRuntimeProperties(); var tableName = storable.GetType().Name; string propetiesString = ""; string propertyValuesString = ""; var index = 0; foreach (var property in properties) { propetiesString += (index == (properties.Count() - 1)) ? property.Name : property.Name + ", "; var value = property.GetValue(storable); var valueString = value == null ? "null" : value is bool? "'" + ((bool)value ? 1 : 0) + "'" : "'" + value + "'"; // if data is serialized if (property.Name.Equals("Data") && !valueString.Equals("null")) { valueString = valueString.Replace("\"", "\\\""); } propertyValuesString += valueString + ((index == (properties.Count() - 1)) ? string.Empty : ", "); index++; } return(string.Format("INSERT OR REPLACE INTO {0}({1}) VALUES ({2});", tableName, propetiesString, propertyValuesString)); }
/// <summary> /// Создание раздела в данном складе или секции. /// </summary> /// <param name="iStorable"></param> /// <param name="name"></param> /// <param name="sortIndex"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public static SectionModel CreateSection(IStorable iStorable, string name, int sortIndex) { SectionModel sectionModel = new SectionModel(name, sortIndex); iStorable.SectionList.Add(sectionModel); return(sectionModel); }
public AwardLogic(string p1, string p2) { path_awards = p1; path_ass = p2; MemoryStorage = new AwardStorage(path_awards); AsStorage = new AssotiationStorage(path_ass); }
static void Main() { DocBase doc = new Document(); // Now you will need a cast to reach IStorable members IStorable storable = (IStorable)doc; storable.Store(); }
protected BaseReference CreateReference(IStorable storable) { if (!m_referenceCreator.TryCreateReference(storable, out BaseReference newReference)) { Global.Tracer.Assert(false, "Cannot create reference to: {0}", storable); } return(newReference); }
// keep method async in case it became async later #pragma warning disable 1998 public async Task RemoveObj(IStorable obj) #pragma warning restore 1998 { foreach (var file in Directory.GetFiles(BaseFolder, obj.Guid.ToString("N") + "_*")) { File.Delete(file); } }
public bool InventoryContains(IStorable item) { var storedItem = this.Inventory .FirstOrDefault(i => i.Key.Type.ToString() == item.Type.ToString()) .Key; return(storedItem != null); }
/// <summary> /// Ctor /// </summary> public EditOrder(Model.Order editOrder, IStorable <Model.Order> orderStorage) { _editOrder = editOrder; _orderStorage = orderStorage; InitializeComponent(); SetToTextbox(); }
static void CheckIStorableClone(IStorable storable1) { IStorable storable2 = storable1.Clone (); Assert.AreEqual (storable1, storable2); Assert.AreNotSame (storable1, storable2); storable1.Storage = Mock.Of<IStorage> (); storable2 = storable1.Clone (); Assert.IsNotNull (storable1.Storage); Assert.AreEqual (storable1.Storage, storable2.Storage); }
protected override void MigrateStorable(IStorable storable) { if (storable is Project) { ProjectMigration.Migrate (storable as ProjectLongoMatch); } else if (storable is Team) { TeamMigration.Migrate (storable as SportsTeam); } else if (storable is DashboardLongoMatch) { DashboardMigration.Migrate (storable as DashboardLongoMatch); } }
public void AddToInventory(IStorable item) { var storedItem = this.Inventory .FirstOrDefault(i => i.Key.Type.ToString() == item.Type.ToString()) .Key; if (storedItem != null) { this.Inventory[storedItem] += 1; } else { this.Inventory.Add(item, 1); } }
public static void SaveObject(IStorable obj, Database db, IDReferenceResolver resolver = null) { Document doc = db.GetDocument (obj.ID.ToString ()); doc.Update ((UnsavedRevision rev) => { JObject jo = SerializeObject (obj, rev, db, resolver); IDictionary<string, object> props = jo.ToObject<IDictionary<string, object>> (); /* SetProperties sets a new properties dictionary, removing the attachments we * added in the serialization */ if (rev.Properties.ContainsKey ("_attachments")) { props ["_attachments"] = rev.Properties ["_attachments"]; } rev.SetProperties (props); return true; }); }
public List<ISerializedStorable> Serialize(IStorable objectToStore) { return new List<ISerializedStorable>(); }
public void Add(IStorable storable) { _lsCabinet.Add(storable); }
/// <summary> /// Returns <c>true</c> if the given statement modifies the given variable. /// </summary> /// <remarks> /// The current implementation is not capable of detecting modifications of variables which are referenced as "out" arguments of some method. /// </remarks> /// <param name="stmt">statement</param> /// <param name="variable">variable</param> public static bool Modifies(this Statement stmt, IStorable variable) { VariableModificationDetector vmd = new VariableModificationDetector(variable); stmt.Accept(vmd); return vmd.Result; }
/// <summary> /// Serializes an object into a <c>JObject</c>. /// </summary> /// <returns>A new object serialized.</returns> /// <param name="obj">The <c>IStorable</c> to serialize.</param> /// <param name="rev">The document revision to serialize.</param> /// <param name="localStorables">A list of <see cref="LongoMatch.Core.Interfaces.IStorable"/> /// types that should be serialized as local referencies instead of by document ID.</param> internal static JObject SerializeObject(IStorable obj, Revision rev, Database db, IDReferenceResolver resolver = null) { JsonSerializer serializer = GetSerializer (obj.GetType (), rev, db, resolver, GetLocalTypes (obj.GetType ())); JObject jo = JObject.FromObject (obj, serializer); jo ["DocType"] = obj.GetType ().Name; return jo; }
public void Add(IStorable r1) { _stoableList.Add(r1); }
public Oid Save(Did dbId, IStorable toStore) { var serialized = _serializer.Serialize(toStore); return new Oid(new byte[] {0x01}, new byte[] {0x02}); }
public ConsoleMenu(IStorable storage) { this._storage = storage; }
public PeopleListForm(IStorable storage) { this._storage = storage; InitializeComponent(); ViewList(); }
public AddPersonForm(IStorable storage) { this._storage = storage; InitializeComponent(); }
public void SubtractFromInventoryItem(IStorable item, int quantity) { var storedItem = this.Inventory .FirstOrDefault(i => i.Key.Type.ToString() == item.Type.ToString()) .Key; if (storedItem != null && this.Inventory[item] >= quantity) { this.Inventory[item] -= quantity; } else { throw new InsufficientAmmountException(string.Empty, item.ToString()); } }
public VariableModificationDetector(IStorable variable) { _variable = variable; }
public void RemoveFromInventory(IStorable item) { if (this.InventoryContains(item)) { this.Inventory.Remove(item); } else { throw new InsufficientAmmountException(NoItemInInventoryExcMsg, item.ToString()); } }
public bool InventoryContains(IStorable item) { var storedItem = this.Inventory .FirstOrDefault(i => i.Key.Type.ToString() == item.Type.ToString()) .Key; return storedItem != null; }
public void DeclareArgument(IStorable arg, object value) { _varValues[arg] = value; }