public void ShouldLogAtDebugLevel()
        {
            //arrange 
            var logger = new ConsoleOutLogger("Testing", LogLevel.Trace, true, true, true, string.Empty);
            var target = new DataContext(Settings.Default.Connection, new DriversEducationMappings(), logger);

            //act
            var firstDriver = new Driver("Devlin", "Liles");
            target.Add(firstDriver);
            target.Add(new Driver("Tim", "Rayburn"));
            target.Add(new Driver("Jay", "Smith"));
            target.Add(new Driver("Brian", "Sullivan"));
            target.Add(new Driver("Cori", "Drew"));

            target.Commit();

            target.Reload(firstDriver);

            foreach (var driver in target.AsQueryable<Driver>())
            {
                target.Remove(driver);
            }


            target.Commit();

            target.ExecuteSqlQuery<Driver>("Select * from Drivers Where LastName = @lastName",
                new DbParameter[] {new SqlParameter("lastName", "Liles")});

            //assert
            //Assert.Inconclusive("We fail here to get the output from console nice and easy");
        }
        protected virtual IDataContext GetDataContext(View view, Context context, IAttributeSet attrs)
        {
            var dataContext = new DataContext();
            var strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Binding, BindingAttrIndex);
            if (strings != null && strings.Count != 0)
                dataContext.Add(ViewFactoryConstants.Bindings, strings);

            SetAttributeValue(view, context, attrs, Resource.Styleable.ItemsControl,
                Resource.Styleable.ItemsControl_ItemTemplate, AttachedMemberConstants.ItemTemplate, dataContext,
                ViewFactoryConstants.ItemTemplateId);

            SetAttributeValue(view, context, attrs, Resource.Styleable.ItemsControl,
                Resource.Styleable.ItemsControl_DropDownItemTemplate, AttachedMembers.AdapterView.DropDownItemTemplate,
                dataContext,
                ViewFactoryConstants.DropDownItemTemplateId);

            SetAttributeValue(view, context, attrs, Resource.Styleable.Control,
                Resource.Styleable.Control_ContentTemplate, AttachedMemberConstants.ContentTemplate, dataContext,
                ViewFactoryConstants.ContentTemplateId);

            SetAttributeValue(view, context, attrs, Resource.Styleable.Menu,
                Resource.Styleable.Menu_MenuTemplate, AttachedMembers.Toolbar.MenuTemplate, dataContext,
                ViewFactoryConstants.MenuTemplateId);


            SetAttributeValue(view, context, attrs, Resource.Styleable.Menu,
                Resource.Styleable.Menu_PopupMenuTemplate, AttachedMembers.View.PopupMenuTemplate, dataContext,
                ViewFactoryConstants.PopupMenuTemplateId);

            strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Menu,
                new[] { Resource.Styleable.Menu_PopupMenuEvent });
            if (strings != null && strings.Count > 0)
            {
                string eventName = strings[0];
                dataContext.Add(ViewFactoryConstants.PopupMenuEvent, eventName);
                IBindingMemberInfo member = BindingServiceProvider
                    .MemberProvider
                    .GetBindingMember(view.GetType(), AttachedMembers.View.PopupMenuEvent, false, false);
                if (member != null)
                    member.SetValue(view, new object[] { eventName });
            }

            strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Menu,
                new[] { Resource.Styleable.Menu_PlacementTargetPath });
            if (strings != null && strings.Count > 0)
            {
                string path = strings[0];
                dataContext.Add(ViewFactoryConstants.PlacementTargetPath, path);
                IBindingMemberInfo member = BindingServiceProvider
                    .MemberProvider
                    .GetBindingMember(view.GetType(), AttachedMembers.View.PopupMenuPlacementTargetPath, false, false);
                if (member != null)
                    member.SetValue(view, new object[] { path });
            }

            return dataContext;
        }
        private static void CreateAndSaveDefaultCharity(Administrator defaultAdministrator, DataContext context)
        {
            var defaultCharity = new Charity
                {
                    SiteName = "My Charity",
                    Description = "This is a test charity"
                };

            defaultCharity.AddAdministrators(defaultAdministrator);

            context.Add(defaultCharity);
            context.SaveChanges();
        }
示例#4
0
        public static void SynchronizePageTypes() {
            using (var context = new DataContext()) {
                var fetchStrategy = new FetchStrategy {MaxFetchDepth = 1};
                fetchStrategy.LoadWith<PageTypeEntity>(pt => pt.Properties);
                fetchStrategy.LoadWith<PropertyEntity>(p => p.PropertyType);
                context.FetchStrategy = fetchStrategy;

                var pageTypeEntities = context.PageTypes.ToList();
                var pageTypes = new List<PageType>();
                var typesWithAttribute = AttributeReader.GetTypesWithAttribute(typeof(PageTypeAttribute)).ToList();

                foreach (var type in typesWithAttribute) {
                    var attribute = AttributeReader.GetAttribute<PageTypeAttribute>(type);

                    var pageTypeEntity = pageTypeEntities.SingleOrDefault(pt => pt.Name == attribute.Name);

                    if (pageTypeEntity == null) {
                        pageTypeEntity = new PageTypeEntity();
                        pageTypeEntities.Add(pageTypeEntity);
                    }

                    pageTypeEntity.DefaultChildSortDirection = attribute.DefaultChildSortDirection;
                    pageTypeEntity.DefaultChildSortOrder = attribute.DefaultChildSortOrder;
                    pageTypeEntity.DisplayName = attribute.DisplayName;
                    pageTypeEntity.Name = attribute.Name;
                    pageTypeEntity.PageTemplate = attribute.PageTemplate;
                    pageTypeEntity.PageTypeDescription = attribute.PageTypeDescription;

                    if (pageTypeEntity.PageTypeId == 0) {
                        context.Add(pageTypeEntity);
                    }
                    context.SaveChanges();
                    
                    var pageType = Mapper.Map<PageTypeEntity, PageType>(pageTypeEntity);
                    pageType.Type = type;
                    pageType.AllowedTypes = attribute.AllowedTypes;
                    pageType.PreviewImage = attribute.PreviewImage;
                    pageType.Instance = (CmsPage)Activator.CreateInstance(type);

                    pageTypes.Add(pageType);

                    SynchronizeProperties(context, pageType, type, pageTypeEntity.Properties);
                }

                PageType.PageTypes = pageTypes;
            }
        }
 /// <summary>
 ///     Starts the current bootstrapper.
 /// </summary>
 public virtual void Start()
 {
     InitializationContext = new DataContext(InitializationContext);
     if (!InitializationContext.Contains(NavigationConstants.IsDialog))
         InitializationContext.Add(NavigationConstants.IsDialog, false);
     Initialize();
     var viewModelType = GetMainViewModelType();
     CreateMainViewModel(viewModelType)
         .ShowAsync((model, result) =>
         {
             model.Dispose();
             if (ShutdownOnMainViewModelClose)
                 Application.Exit();
         }, context: new DataContext(InitializationContext));
     if (AutoRunApplication)
         Application.Run();
 }
 public virtual void Start()
 {
     Initialize();
     var app = MvvmApplication.Current;
     var ctx = new DataContext(app.Context);
     if (!ctx.Contains(NavigationConstants.IsDialog))
         ctx.Add(NavigationConstants.IsDialog, false);
     app.IocContainer
         .Get<IViewModelProvider>()
         .GetViewModel(app.GetStartViewModelType(), ctx)
         .ShowAsync((model, result) =>
         {
             model.Dispose();
             if (ShutdownOnMainViewModelClose)
                 Application.Exit();
         }, context: ctx);
     if (AutoRunApplication)
         Application.Run();
 }
示例#7
0
 public void Create(Customer customer)
 {
     _context.Add(customer);
 }
示例#8
0
 public void Add <T>(T entity) where T : class
 {
     _context.Add(entity);
 }
 public void insert(T obj)
 {
     m_context.Add(obj).State = EntityState.Added;
     save();
 }
 public void Add(Publisher publisher)
 {
     _context.Add(publisher);
     _context.SaveChanges();
 }
示例#11
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override UserInfo AddEntity(UserInfo t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#12
0
 public void Add(User entity)
 {
     context.Add(entity);
 }
示例#13
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Seminar AddEntity(Seminar t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#14
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override SystemSetting AddEntity(SystemSetting t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#15
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override PostHistoryVersion AddEntity(PostHistoryVersion t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#16
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Category AddEntity(Category t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#17
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Notice AddEntity(Notice t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#18
0
 public virtual void insert(Tentity entity)
 {
     context.Add <Tentity>(entity);
     context.SaveChanges();
 }
示例#19
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override PostMergeRequest AddEntity(PostMergeRequest t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#20
0
 //Bætir höfundi við gagnasafnið
 public void AddAuthor(Author author)
 {
     db.Add(author);
     db.SaveChanges();
 }
示例#21
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Advertisement AddEntity(Advertisement t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#22
0
 public async Task <bool> CriarAsync(Divida entity)
 {
     _context.Add(entity);
     return(await _context.SaveChangesAsync() > 0);
 }
示例#23
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Variables AddEntity(Variables t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#24
0
 public void Add(StoreChain storeChain)
 {
     dataContext.Add(storeChain);
 }
示例#25
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Donate AddEntity(Donate t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#26
0
 public T Add(T entity)
 {
     Context.Add(entity);
     Context.SaveChanges();
     return(entity);
 }
示例#27
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override FastShare AddEntity(FastShare t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#28
0
 public Produto Add(Produto entity)
 {
     _dataContext.Add(entity);
     _dataContext.SaveChanges();
     return(entity);
 }
示例#29
0
 public void AddUser(User user)
 {
     _context.Add(user);
     _context.SaveChangesAsync();
 }
示例#30
0
 public void Insert(TEntity entity)
 {
     db.Add <TEntity>(entity);
     db.SaveChanges();
 }
示例#31
0
        public static void SynchronizeSiteProperties() {
            var typesWithAttribute = AttributeReader.GetTypesWithAttribute(typeof(SiteSettingsAttribute)).ToList();
            if (typesWithAttribute.Count > 1) {
                throw new Exception("More than one class implementing Site was found!");
            }
            if (!typesWithAttribute.Any()) {
                CmsSite.PropertyDefinitions = new List<PropertyDefinition>();
                return;
            }

            var type = typesWithAttribute.First();
            var siteSettingsAttribute = AttributeReader.GetAttribute<SiteSettingsAttribute>(type);
            CmsSite.AllowedTypes = siteSettingsAttribute.AllowedTypes;
            CmsSite.DefaultChildSortDirection = siteSettingsAttribute.DefaultChildSortDirection;
            CmsSite.DefaultChildSortOrder = siteSettingsAttribute.DefaultChildSortOrder;

            var definition = new List<PropertyDefinition>();
            var propertyAttributeType = typeof(PropertyAttribute);
            var requiredAttributeType = typeof(RequiredAttribute);
            var sortOrder = 0;

            using (var context = new DataContext()) {
                var properties = context.SitePropertyDefinitions.ToList();
                
                foreach (var propertyInfo in type.GetProperties()) {
                    var attributes = propertyInfo.GetCustomAttributes(true);

                    var propertyAttribute = (PropertyAttribute)attributes.SingleOrDefault(propertyAttributeType.IsInstanceOfType);

                    if (propertyAttribute != null) {
                        var propertyName = propertyInfo.Name;
                        var declaringType = propertyInfo.PropertyType;
                        var propertyTypeId = PropertyType.GetPropertyTypeId(declaringType);

                        if (!propertyAttribute.IsTypeValid(declaringType)) {
                            var notSupportedException = new NotSupportedException(string.Format("The property attribute of '{0}' on site settings ({1}) does not support the propertytype!", propertyName, type.FullName));
                            Logger.Write(notSupportedException, Logger.Severity.Critical);
                            throw notSupportedException;
                        }

                        var required = attributes.Count(requiredAttributeType.IsInstanceOfType) > 0;

                        sortOrder++;

                        var property = properties.SingleOrDefault(p => p.Name == propertyName);

                        if (property == null) {
                            property = new SitePropertyDefinitionEntity {Name = propertyName};
                            properties.Add(property);
                        }

                        property.PropertyTypeId = propertyTypeId;
                        property.SortOrder = sortOrder;
                        property.Header = propertyAttribute.Header;
                        property.Required = required;

                        // If generic and standard attribute, store generic type as parameter. Required for list types like CollectionProperty.
                        if (declaringType.IsGenericType && propertyAttribute.GetType() == typeof(PropertyAttribute)) {
                            var subType = declaringType.GetGenericArguments()[0];
                            property.Parameters = subType.FullName + ", " + subType.Assembly.GetName().Name;
                        }
                        else {
                            property.Parameters = propertyAttribute.Parameters;
                        }

                        if (property.PropertyId == 0) {
                            context.Add(property);
                        }

                        var propertyDefinition = Mapper.Map<SitePropertyDefinitionEntity, PropertyDefinition>(property);
                        propertyDefinition.TabGroup = propertyAttribute.TabGroup;
                        definition.Add(propertyDefinition);
                    }
                }

                context.SaveChanges();
            }

            CmsSite.PropertyDefinitions = definition;
        }
示例#32
0
        public async Task <IActionResult> Create(Criterion l)
        {
            Criterion criterion = new Criterion();

            criterion.Name   = Request.Form.FirstOrDefault(p => p.Key == "Name").Value;
            criterion.Range  = 0;
            criterion.Weight = 0;
            var type = Request.Form.FirstOrDefault(p => p.Key == "Type").Value[0];

            criterion.Type = (type == "Quantitative") ? Models.Enums.CriteriaType.Quantitative : Models.Enums.CriteriaType.Qualitative;
            var optimType = (Request.Form.FirstOrDefault(p => p.Key == "OptimalityType").Value[0]);

            criterion.OptimType = (optimType == "None") ? Models.Enums.OptimalityType.None : (optimType == "Maximum") ? Models.Enums.OptimalityType.Maximum : Models.Enums.OptimalityType.Minimum;
            var unit = (Request.Form.FirstOrDefault(p => p.Key == "Units").Value[0]);

            switch (unit)
            {
            case "None":
                criterion.Unit = Models.Enums.Units.None;
                break;

            case "USD":
                criterion.Unit = Models.Enums.Units.USD;
                break;

            case "year":
                criterion.Unit = Models.Enums.Units.year;
                break;

            case "m":
                criterion.Unit = Models.Enums.Units.m;
                break;

            case "km":
                criterion.Unit = Models.Enums.Units.km;
                break;

            case "kg":
                criterion.Unit = Models.Enums.Units.kg;
                break;

            case "Liter":
                criterion.Unit = Models.Enums.Units.Liter;
                break;

            case "kmPerHour":
                criterion.Unit = Models.Enums.Units.kmPerHour;
                break;

            case "hp":
                criterion.Unit = Models.Enums.Units.hp;
                break;

            case "second":
                criterion.Unit = Models.Enums.Units.second;
                break;

            case "litersPer100Km":
                criterion.Unit = Models.Enums.Units.litersPer100Km;
                break;

            case "mm":
                criterion.Unit = Models.Enums.Units.mm;
                break;
            }
            switch (Request.Form.FirstOrDefault(p => p.Key == "ScaleTypes").Value[0])
            {
            case "Nominal":
                criterion.ScaleType = Models.Enums.ScaleTypes.Nominal;
                break;

            case "Interval":
                criterion.ScaleType = Models.Enums.ScaleTypes.Interval;
                break;

            case "Ordinal":
                criterion.ScaleType = Models.Enums.ScaleTypes.Ordinal;
                break;

            case "Relation":
                criterion.ScaleType = Models.Enums.ScaleTypes.Relation;
                break;

            case "Difference":
                criterion.ScaleType = Models.Enums.ScaleTypes.Difference;
                break;

            case "Absolute":
                criterion.ScaleType = Models.Enums.ScaleTypes.Absolute;
                break;
            }
            if (ModelState.IsValid)
            {
                _context.Add(criterion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(criterion));
        }
示例#33
0
        private static void SynchronizeProperties(DataContext context, PageType pageType, Type type, IList<PropertyEntity> propertyEntities) {
            var propertyAttributeType = typeof(PropertyAttribute);
            var requiredAttributeType = typeof(RequiredAttribute);
            var properties = propertyEntities;
            var sortOrder = 0;

            foreach (var propertyInfo in type.GetProperties()) {
                var attributes = propertyInfo.GetCustomAttributes(true);

                var propertyAttribute = (PropertyAttribute)attributes.SingleOrDefault(propertyAttributeType.IsInstanceOfType);

                if (propertyAttribute != null) {
                    var propertyName = propertyInfo.Name;
                    var declaringType = propertyInfo.PropertyType;
                    var propertyTypeId = PropertyType.GetPropertyTypeId(declaringType);

                    if (!propertyAttribute.IsTypeValid(declaringType)) {
                        var notSupportedException = new NotSupportedException(string.Format("The property attribute of '{0}' on pagetype '{1}' ({2}) does not support the propertytype!", propertyName, pageType.Name, type.FullName));
                        Logger.Write(notSupportedException, Logger.Severity.Critical);
                        throw notSupportedException;
                    }

                    var required = attributes.Count(requiredAttributeType.IsInstanceOfType) > 0;

                    sortOrder++;

                    var property = properties.SingleOrDefault(p => p.Name == propertyName);

                    if (property == null) {
                        property = new PropertyEntity {Name = propertyName};
                        properties.Add(property);
                    }

                    property.PropertyTypeId = propertyTypeId;
                    property.PageTypeId = pageType.PageTypeId;
                    property.SortOrder = sortOrder;
                    property.Header = propertyAttribute.Header;
                    property.Required = required;

                    // If generic and standard attribute, store generic type as parameter. Required for list types like CollectionProperty.
                    if (declaringType.IsGenericType && propertyAttribute.GetType() == typeof(PropertyAttribute)) {
                        var subType = declaringType.GetGenericArguments()[0];
                        property.Parameters = subType.FullName + ", " + subType.Assembly.GetName().Name;
                    }
                    else {
                        property.Parameters = propertyAttribute.Parameters;
                    }

                    if (property.PropertyId == 0) {
                        context.Add(property);
                    }
                    
                    var propertyDefinition = Mapper.Map<PropertyEntity, PropertyDefinition>(property);
                    propertyDefinition.TabGroup = propertyAttribute.TabGroup;
                    pageType.Properties.Add(propertyDefinition);
                }
            }

            context.SaveChanges();
        }
示例#34
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override InternalMessage AddEntity(InternalMessage t)
 {
     DataContext.Add(t);
     return(t);
 }
 public async Task InsertPerson(Person person)
 {
     db.Add(person);
     await db.SaveChangesAsync();
 }
 public IList<IDataContext> Parse(object target, string bindingExpression, IList<object> sources, IDataContext context)
 {
     Should.NotBeNull(bindingExpression, nameof(bindingExpression));
     if (context == null)
         context = DataContext.Empty;
     KeyValuePair<KeyValuePair<string, int>, Action<IDataContext>[]>[] bindingValues;
     lock (_cache)
     {
         if (!_cache.TryGetValue(bindingExpression, out bindingValues))
         {
             try
             {
                 if (ReferenceEquals(context, DataContext.Empty))
                     context = _defaultContext;
                 context.AddOrUpdate(BindingBuilderConstants.Target, target);
                 _context = context;
                 _expression = Handle(bindingExpression, context);
                 _tokenizer = CreateTokenizer(Expression);
                 _memberVisitor.Context = context;
                 var value = ParseInternal()
                     .Select((pair, i) => new KeyValuePair<KeyValuePair<string, int>, Action<IDataContext>[]>(new KeyValuePair<string, int>(pair.Key, i), pair.Value))
                     .ToList();
                 value.Sort(MemberComparison);
                 bindingValues = value.ToArray();
                 if (!context.Contains(BindingBuilderConstants.NoCache))
                     _cache[bindingExpression] = bindingValues;
             }
             finally
             {
                 if (ReferenceEquals(_defaultContext, context))
                     _defaultContext.Clear();
                 _tokenizer = null;
                 _expression = null;
                 _context = null;
                 _memberVisitor.Context = null;
             }
         }
     }
     var result = new IDataContext[bindingValues.Length];
     if (sources != null && sources.Count > 0)
     {
         for (int i = 0; i < bindingValues.Length; i++)
         {
             var pair = bindingValues[i];
             var dataContext = new DataContext(context);
             dataContext.AddOrUpdate(BindingBuilderConstants.Target, target);
             if (pair.Key.Value < sources.Count)
             {
                 object src = sources[pair.Key.Value];
                 if (src != null)
                     dataContext.Add(BindingBuilderConstants.Source, src);
             }
             var actions = pair.Value;
             for (int j = 0; j < actions.Length; j++)
                 actions[j].Invoke(dataContext);
             result[i] = dataContext;
         }
     }
     else
     {
         for (int i = 0; i < bindingValues.Length; i++)
         {
             var actions = bindingValues[i].Value;
             var dataContext = new DataContext(context);
             dataContext.AddOrUpdate(BindingBuilderConstants.Target, target);
             for (int j = 0; j < actions.Length; j++)
                 actions[j].Invoke(dataContext);
             result[i] = dataContext;
         }
     }
     return result;
 }
示例#37
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Links AddEntity(Links t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#38
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override LoginRecord AddEntity(LoginRecord t)
 {
     DataContext.Add(t);
     return(t);
 }
示例#39
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="t">需要添加的实体</param>
 /// <returns>添加成功</returns>
 public override Misc AddEntity(Misc t)
 {
     DataContext.Add(t);
     return(t);
 }
 /// <summary>
 ///     Starts the current bootstrapper.
 /// </summary>
 public virtual void Start()
 {
     InitializationContext = new DataContext(InitializationContext);
     if (!InitializationContext.Contains(NavigationConstants.IsDialog))
         InitializationContext.Add(NavigationConstants.IsDialog, false);
     Initialize();
     Type viewModelType = GetMainViewModelType();
     NavigationWindow rootWindow = null;
     var mappingProvider = IocContainer.Get<IViewMappingProvider>();
     IViewMappingItem mapping = mappingProvider.FindMappingForViewModel(viewModelType, InitializationContext.GetData(NavigationConstants.ViewName), true);
     if (typeof(Page).IsAssignableFrom(mapping.ViewType))
     {
         rootWindow = CreateNavigationWindow();
         var service = CreateNavigationService(rootWindow);
         IocContainer.BindToConstant(service);
     }
     var vm = CreateMainViewModel(viewModelType);
     vm.ShowAsync((model, result) =>
     {
         model.Dispose();
         if (ShutdownOnMainViewModelClose)
         {
             Application app = Application.Current;
             if (app != null)
             {
                 Action action = app.Shutdown;
                 app.Dispatcher.BeginInvoke(action);
             }
         }
     }, context: new DataContext(InitializationContext));
     if (rootWindow != null)
     {
         IWindowViewMediator mediator = new WindowViewMediator(rootWindow, vm, IocContainer.Get<IThreadManager>(),
             IocContainer.Get<IViewManager>(), IocContainer.Get<IWrapperManager>(),
             IocContainer.Get<IOperationCallbackManager>());
         mediator.UpdateView(new PlatformWrapperRegistrationModule.WindowViewWrapper(rootWindow), true, new DataContext(InitializationContext));
         rootWindow.Show();
     }
 }
示例#41
0
        private static void KeepDatabaseUpToDate() {
            using (var context = new DataContext(true)) {
                // Keep schema up to date
                context.UpdateSchema();

                // TODO: Read languages from web.config (i.e. don't hard code 'English')
                // Ensure that at least one language is available
                if (!context.SiteLanguages.Any()) {
                    context.Add(new SiteLanguageEntity {
                        ShortName = "en",
                        LongName = "English"
                    });
                    context.SaveChanges();
                }
            }
        }