Ejemplo n.º 1
0
        private async Task StoreObjectInDatabase(pe.PersistableObject obj, IMongoDatabase db, Snapshot currentSnapshot)
        {
            var thisAssembly      = System.Reflection.Assembly.GetExecutingAssembly();
            var converterAssembly = System.Reflection.Assembly.GetAssembly(typeof(IConverter));
            var converterTypes    = thisAssembly.GetTypes().Where(x => x.CustomAttributes.Any(attr => attr.AttributeType == typeof(ConvertedTypeAttribute)) &&
                                                                  typeof(IConverter).IsAssignableFrom(x)).ToList();

            converterTypes.AddRange(converterAssembly.GetTypes().Where(x => x.CustomAttributes.Any(attr => attr.AttributeType == typeof(ConvertedTypeAttribute)) &&
                                                                       typeof(IConverter).IsAssignableFrom(x)));
            ReportableObject  ro         = null;
            List <IConverter> converters = new List <IConverter>();

            foreach (var converterType in converterTypes)
            {
                string converterTypeName = converterType.GetCustomAttribute <ConvertedTypeAttribute>().ConvertedType.Name;
                if (converterTypeName == obj.GetType().Name)
                {
                    var converter = (IConverter)Activator.CreateInstance(converterType);
                    ro = converter.Convert(obj);
                    break;
                }
            }
            if (ro == null)
            {
                return;
            }

            var objectCollection = db.GetCollection <ReportableObject>("reportable_object");
            var objectHistory    = db.GetCollection <ObjectHistory>("object_history");

            await InsertObject(ro, objectCollection, objectHistory, currentSnapshot);
            await LinkObject(ro, objectCollection);
        }
Ejemplo n.º 2
0
 private void Subfolder_AspectChangedHandler(pe.PersistableObject changedObject, pe.ChangeAspect changedAspect)
 {
     lock (_syncRoot)
     {
         lastChangedDate = DateTime.Now;
         if (objectsToSync.ContainsKey(changedObject.Surrogate.ToString()))
         {
             objectsToSync[changedObject.Surrogate.ToString()] = changedObject;
         }
         else
         {
             objectsToSync.Add(changedObject.Surrogate.ToString(), changedObject);
         }
     }
 }
Ejemplo n.º 3
0
 public void RegisterObject(pe.PersistableObject po)
 {
     po.AspectChangedHandler -= Subfolder_AspectChangedHandler;
     po.AspectChangedHandler += Subfolder_AspectChangedHandler;
 }
Ejemplo n.º 4
0
 private ReportableObject ConvertObject(pe.PersistableObject item, IConverter converter)
 {
     return(converter.Convert(item));
 }