Beispiel #1
0
        public DurationFieldBinder(
            StorageObjectID storageobjectID,
            EditorFile file,
            DurationField <T> field
            ) :
            base(
                storageobjectID,
                file,
                null     //TODO
                )
        {
            this.field = field;

            obj = this.Object();

            field.ItemAdded   += Field_ItemAdded;
            field.ItemMoved   += Field_ItemMoved;
            field.ItemChanged += Field_ItemChanged;
            field.ItemRemoved += Field_ItemRemoved;

            listener_added       = obj.CreateListen(IOEvent.ChildAdded, Storage_ChildAdded);
            listener_rekeyed     = obj.Graph.CreateListen(Storage_ChildRekeyed, storageobjectID, IOEvent.ChildRekeyed);
            listener_contentsset = obj.CreateListen(IOEvent.ChildContentsSet, Storage_ChildContentsSet);
            listener_removed     = obj.CreateListen(IOEvent.ChildRemoved, Storage_ChildRemoved);
        }
Beispiel #2
0
        public MusicTrack(
            EditorFile file,
            IStorageObject storage,
            TrackControllerSettings settings
            ) : base(
                storage.ID,
                file
                )
        {
            melody           = new MelodyTrack(storage.GetOrMake("melody").ID, file);
            rhythm           = new RhythmTrack(storage.GetOrMake("rhythm").ID, file);
            adornment        = new AdornmentTrack(storage.GetOrMake("adornment").ID, file);
            tempo            = new TempoTrack(storage.GetOrMake("tempo").ID, file);
            memory           = new PerceptualMemory();
            propertygraphlet = new StoragePropertyGraphlet <NoteID>(storage, propertymanager);
            propertymanager  = settings.PropertyManager;

            this.settings = settings;

            melody.FieldChanged += Melody_FieldChanged;
            rhythm.MeterSignatures.FieldChanged  += MeterSignatures_FieldChanged;
            rhythm.TimeSignatures.FieldChanged   += TimeSignatures_FieldChanged;
            adornment.KeySignatures.FieldChanged += KeySignatures_FieldChanged;
            adornment.Staffs.FieldChanged        += Staffs_FieldChanged;

            if (!storage.HasChild("state") || storage.Get("state").ReadAllString() != "inited")
            {
                Init();
                storage.GetOrMake("state").WriteAllString("inited");
            }

            Init_memory();
        }
Beispiel #3
0
        public void Retrieve(IStorageObject obj, IDataReader reader)
        {
            this.Read(obj, reader);
            DbEventArgs e = new DbEventArgs(this, DbOperationAction.Select);

            obj.OnRead(this, e);
        }
Beispiel #4
0
 private void Read(IStorageObject obj, IDataReader reader)
 {
     if ((obj != null) && (reader != null))
     {
         Type         type         = obj.GetType();
         DbObjectInfo dbObjectInfo = DbObjectReflector.GetDbObjectInfo(type);
         if (dbObjectInfo == null)
         {
             throw new Exception("Cannot retrieve DbObjectInfo of type : " + type.ToString());
         }
         foreach (KeyValuePair <string, DynamicPropertyInfo> pair in dbObjectInfo.DynamicPropertyInfos)
         {
             string key = pair.Key;
             DynamicPropertyInfo info2 = pair.Value;
             try
             {
                 ConvertUtils.SetValueToObject(reader[info2.DataFieldName], obj, key, info2.PropertyType);
             }
             catch (Exception exception)
             {
                 throw new ConvertValueException(info2.DataFieldName, exception);
             }
         }
     }
 }
Beispiel #5
0
        public virtual string GetUpdateSQL(IStorageObject obj)
        {
            StringBuilder builder      = new StringBuilder();
            DbObjectInfo  dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType());

            this.CheckIsView(dbObjectInfo);
            DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(dbObjectInfo, true);

            string[] source = obj.ModifiedValues.Keys.ToArray <string>();
            foreach (KeyValuePair <string, DynamicPropertyInfo> pair in dbObjectInfo.DynamicPropertyInfos)
            {
                string key = pair.Key;
                DynamicPropertyInfo info3 = pair.Value;
                if ((!info3.PrimaryKey && !info3.ReadOnly) && ((!info3.AutoIncrement && (info3.DefaultValue == null)) && source.Contains <string>(key)))
                {
                    object obj2 = obj.GetValue(info3.PropertyName);
                    string str2 = this.FormatFieldName(info3.DataFieldName);
                    if (builder.Length > 0)
                    {
                        builder.Append(",");
                    }
                    builder.AppendFormat("{0} = {1}", str2, this.FormatValue(obj2, info3.AllowDBNull));
                }
            }
            object obj3 = obj.GetValue(pkDynamicPropertyInfo.PropertyName);
            string str3 = this.FormatFieldName(pkDynamicPropertyInfo.DataFieldName) + " = " + this.FormatValue(obj3, false);

            return(string.Format(this.GetUpdateSqlTemplate(), this.FormatTableOrViewName(dbObjectInfo.TableName), builder.ToString(), str3));
        }
Beispiel #6
0
        public static void SetValueToObject(object srcObj, IStorageObject desObj, string propertyName, Type propertyType)
        {
            bool   nullable = IsNullable(propertyType);
            object obj2     = ToObject(srcObj, propertyType, nullable);

            desObj.SetValue(propertyName, obj2);
        }
Beispiel #7
0
        public void Update(IStorageObject obj)
        {
            DbEventArgs args;

            if (obj.ModifiedValues.Count != 0)
            {
                string[] strArray  = obj.ModifiedValues.Keys.ToArray <string>();
                string   updateSQL = this.SqlFormatter.GetUpdateSQL(obj);
                Debug.WriteLine("GetUpdateSQL: " + updateSQL);
                this.DbOperator.ExecuteNonQuery(updateSQL);
                Action item = delegate
                {
                    args = new DbEventArgs(this, DbOperationAction.Update);
                    obj.OnWrote(this, args);
                };
                if (this.DbOperator.IsBeginTransaction)
                {
                    this.transActions.Add(item);
                }
                else
                {
                    item();
                }
            }
        }
Beispiel #8
0
        public async Task <IActionResult> Get(StorableIdentifier identifier, string key)
        {
            IStorageObject storageObject = await _storageService.LoadAsync(identifier).ConfigureAwait(false);

            Request.HttpContext.Response.Headers.Add("Metadata", storageObject.Metadata);
            return(new FileStreamResult(storageObject.DataStream, "application/octet-stream"));
        }
Beispiel #9
0
        public void Insert(IStorageObject obj)
        {
            DbEventArgs         args;
            string              insertSQL = this.SqlFormatter.GetInsertSQL(obj);
            Type                type      = obj.GetType();
            int                 num       = this.DbOperator.ExecuteScalar <int>(insertSQL);
            DynamicPropertyInfo autoIncrementDynamicPropertyInfo = DbObjectTools.GetAutoIncrementDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(type));

            if ((autoIncrementDynamicPropertyInfo != null) & (num != 0))
            {
                obj.SetValue(autoIncrementDynamicPropertyInfo.PropertyName, num);
            }
            Action item = delegate
            {
                args = new DbEventArgs(this, DbOperationAction.Insert);
                obj.OnWrote(this, args);
            };

            if (this.DbOperator.IsBeginTransaction)
            {
                this.transActions.Add(item);
            }
            else
            {
                item();
            }
        }
Beispiel #10
0
        public PrototypePool(IStorageObject <T> storage, ICloneable <T> prototype, int initialStoredObjectsCount, int capacity)
            : base(storage, initialStoredObjectsCount, capacity)
        {
            this.prototype = prototype ?? throw new ArgumentNullException(nameof(prototype));

            CreateObjects(initialStoredObjectsCount);
        }
Beispiel #11
0
 public StoragePropertyGraphlet(
     IStorageObject storage,
     PropertyManager propertymanager
     )
 {
     this.storage         = storage;
     this.propertymanager = propertymanager;
 }
Beispiel #12
0
        /// <summary>
        /// Creates new instance of <see cref="DelegatePool{T}"/> with given storage, allocation function
        /// and initial objects. Can be provided with capacity to limit the count of pooled objects.
        /// </summary>
        public DelegatePool(IStorageObject <T> storage, Func <T> instantiate, int initialStoredObjectsCount, int capacity)
            : base(storage, initialStoredObjectsCount, capacity)

        {
            this.instantiate = instantiate ?? throw new ArgumentNullException(nameof(instantiate));

            CreateObjects(initialStoredObjectsCount);
        }
Beispiel #13
0
 public static string ReadAllString(this IStorageObject obj)
 {
     using (var stream = obj.OpenRead()) {
         using (var tr = new StreamReader(stream)) {
             return(tr.ReadToEnd());
         }
     }
 }
Beispiel #14
0
 public static void WriteAllString(this IStorageObject obj, string value)
 {
     using (var stream = obj.OpenWrite()) {
         using (var tw = new StreamWriter(stream)) {
             tw.Write(value);
         }
     }
 }
Beispiel #15
0
        /// <summary>
        /// Creates new instance of <see cref="Pool{T}"/> with given initial objects count and
        /// optional capacity.
        /// </summary>
        public Pool(IStorageObject <T> storage, int initialStoredObjectsCount, int capacity)
            : base(storage, initialStoredObjectsCount, capacity)
        {
            // Wrap constructor call to delegate, this is a much faster than calling new on the generic T.
            instantiate = (Func <T>)DynamicConstructorBinder.Bind(typeof(T).GetConstructor(Type.EmptyTypes), typeof(Func <T>));

            CreateObjects(initialStoredObjectsCount);
        }
Beispiel #16
0
        public void Delete(IStorageObject obj)
        {
            string deleteSQL = this.SqlFormatter.GetDeleteSQL(obj);

            this.DbOperator.ExecuteNonQuery(deleteSQL);
            DbEventArgs e = new DbEventArgs(this, DbOperationAction.Delete);

            obj.OnWrote(this, e);
        }
Beispiel #17
0
        public void DeleteData(IStorageObject storageObject)
        {
            var data = Data.FirstOrDefault(x => x != null && x.GetType() == storageObject.GetType() && x.DataId == storageObject.DataId);

            if (data != null)
            {
                Data.Remove(data);
            }
        }
Beispiel #18
0
        public bool RetrieveByKey(IStorageObject obj, object keyValue)
        {
            DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectReflector.GetDbObjectInfo(obj.GetType()), true);

            if (pkDynamicPropertyInfo == null)
            {
                throw new ArgumentException("Primary Key Not Found");
            }
            return(this.Retrieve(obj, pkDynamicPropertyInfo.DataFieldName, keyValue));
        }
Beispiel #19
0
 public static PropertyBinder <Duration> Bind(
     this ObservableProperty <Duration> property,
     IStorageObject storageobject
     ) =>
 Bind(
     property,
     storageobject,
     CodeTools.ReadDuration,
     CodeTools.WriteDuration
     );
Beispiel #20
0
 public static PropertyBinder <Time> Bind(
     this ObservableProperty <Time> property,
     IStorageObject storageobject
     ) =>
 Bind(
     property,
     storageobject,
     CodeTools.ReadTime,
     CodeTools.WriteTime
     );
Beispiel #21
0
 public static PropertyBinder <string> Bind(
     this ObservableProperty <string> property,
     IStorageObject storageobject
     ) =>
 Bind(
     property,
     storageobject,
     StorageExtensions.ReadAllString,
     StorageExtensions.WriteAllString
     );
Beispiel #22
0
        public PolylineData(
            IStorageObject storage,
            EditorFile file,
            float constant = 0
            ) :
            base(
                storage.ID,
                file,
                FactoryInstance
                )
        {
            this.storage = storage;

            if (storage.IsEmpty)
            {
                Add(0f, constant);
            }

            listener_add =
                storage.CreateListen(IOEvent.ChildAdded, (key, pt_objID) => {
                var t = float.Parse(key);
                var v = float.Parse(storage.Graph[pt_objID].ReadAllString());

                Add_ram(t, v);
            });

            listener_rekey =
                storage.Graph.CreateListen(
                    msg => {
                var t0 = float.Parse(msg.Relation);
                var t1 = float.Parse(msg.NewRelation);

                MoveX_ram(t0, t1);
            },
                    storage.ID,
                    IOEvent.ChildRekeyed
                    );

            listener_contentsset =
                storage.CreateListen(IOEvent.ChildContentsSet, (key, pt_objID) => {
                var t  = float.Parse(key);
                var v1 = float.Parse(storage.Graph[pt_objID].ReadAllString());

                MoveY_ram(t, v1);
            });

            listener_remove =
                storage.CreateListen(IOEvent.ChildRemoved, (key, pt_objID) => {
                var t = float.Parse(key);
                var v = float.Parse(storage.Graph[pt_objID].ReadAllString());

                RemoveExact_ram(t, v);
            });
        }
Beispiel #23
0
        public virtual string GetDeleteSQL(IStorageObject obj)
        {
            DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType());

            this.CheckIsView(dbObjectInfo);
            DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(dbObjectInfo, true);
            object obj2 = obj.GetValue(pkDynamicPropertyInfo.PropertyName);
            string str  = string.Format(" where {0} = {1}", this.FormatFieldName(pkDynamicPropertyInfo.DataFieldName), this.FormatValue(obj2, false));

            return(string.Format(this.GetDeleteSqlTemplate(), this.FormatTableOrViewName(dbObjectInfo.TableName), str));
        }
Beispiel #24
0
        public Task <IStorageObject> LoadAsync(StorableIdentifier identifier)
        {
            IStorageObject storageObject = _context.StorageObjects.Where(so => so.Category == identifier.Category && so.UniqueName == identifier.UniqueName).FirstOrDefault();

            if (storageObject == null)
            {
                return(Task.FromResult <IStorageObject>(null));
            }

            return(Task.FromResult(storageObject));
        }
Beispiel #25
0
        public void SaveOrUpdateData(IStorageObject storageObject)
        {
            var data = Data.FirstOrDefault(x => x.DataId == storageObject.DataId && x.GetType() == storageObject.GetType());

            if (data != null)
            {
                Data.Remove(data);
            }

            Data.Add(storageObject);
        }
Beispiel #26
0
 public static IOListener CreateListen(
     this IStorageObject storage,
     IOEvent verb,
     Action responder
     ) =>
 storage
 .Graph
 .CreateListen_Node(
     storage.ID,
     verb,
     responder
     );
Beispiel #27
0
 public static PropertyBinder <T> Bind <T>(
     this ObservableProperty <T> property,
     IStorageObject storageobject,
     Func <IStorageObject, T> deserializer,
     Action <IStorageObject, T> serializer
     ) =>
 new PropertyBinder <T>(
     storageobject,
     property,
     deserializer,
     serializer
     );
Beispiel #28
0
 public static PropertyBinder <T> Bind <T>(
     this ObservableProperty <T> property,
     IStorageObject storageobject,
     Func <string, T> deserializer,
     Func <T, string> serializer
     ) =>
 Bind(
     property,
     storageobject,
     (IStorageObject obj) => deserializer(obj.ReadAllString()),
     (obj, @string) => obj.WriteAllString(serializer(@string))
     );
Beispiel #29
0
        public static IStorageObject GetOrDefault(this IStorageObject parent, string child)
        {
            var sink =
                parent[child];

            if (sink == default(StorageObjectID))
            {
                return(null);
            }

            return(parent.Graph[sink]);
        }
Beispiel #30
0
        public static IStorageObject GetOrMake(this IStorageObject parent, string child)
        {
            try {
                return(parent.Graph[parent[child]]);
            }
            catch (KeyNotFoundException) {
                var childID = parent.Graph.Create();

                parent.Add(child, childID);

                return(parent.Graph[childID]);
            }
        }