Exemplo n.º 1
0
        /// <summary>
        /// Loads the specified file as assembly. This will throw exception if there are problems. It's possible that the assembly was loaded anyway.
        /// Loading a file with same name again will attempt to return same assembly even if the file versions are different.
        /// </summary>
        /// <param name="file">The file to load from.</param>
        /// <param name="result">The result is set here. Result may be set even when an exception is thrown.</param>
        public static void Load(FileInfo file, ref Assembly result)
        {
            lock (Locker)
            {
                AssemblyLoadResult r = Loaded.FirstOrDefault(q => q.FileName.Equals(file.Name, StringComparison.OrdinalIgnoreCase));
                if (r != null)
                {
                    result = r.Assembly;
                    if (r.Exception != null)
                    {
                        throw r.Exception;
                    }
                    return;
                }

                if (!file.Exists)
                {
                    throw new FileNotFoundException("Specified assembly file was not found!", file.FullName);
                }

                // Must use LoadFile instead of LoadFrom or the load context will not allow types to match up.
                Assembly a = Assembly.LoadFile(file.FullName);

                r           = new AssemblyLoadResult();
                r.Assembly  = a;
                r.FileName  = file.Name;
                r.Exception = null;

                Loaded.Add(r);
                result = a;
            }
        }
Exemplo n.º 2
0
        private Member LoadPerson(Person person)
        {
            Member member = null;

            if (person == null)
            {
                return(null);
            }
            member = Loaded.FirstOrDefault(l => l.Id.Equals(person.Id));
            if (member == null)
            {
                member = new Member
                {
                    Id         = person.Id,
                    CreatedAt  = person.CreatedAt,
                    ModifiedAt = person.ModifiedAt,
                    Father     = LoadPerson(person.Father),
                    FatherId   = person.FatherId,
                    Mother     = LoadPerson(person.Mother),
                    MotherId   = person.MotherId,
                    Firstname  = person.Firstname,
                    Lastname   = person.Lastname,
                    Middlename = person.Middlename,
                };
                Loaded.Add(member);
                List <Couple> couple = null;
                if (person.Relationships != null)
                {
                    couple = person.Relationships.Select(partner => new Couple()
                    {
                        Partner  = LoadPerson(partner.Partner),
                        Children = person.Children.Where(c => partner.Partner.Children.Contains(c))
                                   .Select(LoadPerson).ToList()
                    }).ToList();
                    member.Relationships = couple;
                }
            }

            return(member);
        }
Exemplo n.º 3
0
 public SpecialEventObject GetByGuid(string guid)
 {
     return(Loaded.FirstOrDefault(x => x.Guid == guid));
 }