Example #1
0
        public virtual IContext GetContext(IDomainMap domainMap, ref bool hasSource)
        {
            IContext context = null;

            if (domainMap != null)
            {
                context = new Context(domainMap);
                if (!GenerateAssembly(context))
                {
                    return null;
                }
            }
            else
            {
                if (this.domainConfig.MapPath.Length > 0)
                {
                    context = new Context(this.domainConfig.MapPath);

                    if (this.domainConfig.UseCustomDataSource)
                    {
                        if (this.domainConfig.PersistenceType == PersistenceType.ObjectRelational)
                        {
                            context.DomainMap.UnFixate() ;
                            ISourceMap sourceMap = context.GetSourceMap();
                            sourceMap.ConnectionString = this.domainConfig.ConnectionString;
                            sourceMap.SourceType = this.domainConfig.SourceType;
                            sourceMap.ProviderType = this.domainConfig.ProviderType;
                            context.DomainMap.Fixate() ;
                            hasSource = true;
                        }
                        else if (this.domainConfig.PersistenceType == PersistenceType.ObjectService)
                        {
                            IPersistenceEngine remotingEngine = new WebServiceRemotingEngine(new XmlFormatter(), this.domainConfig.Url, this.domainConfig.DomainKey, new DefaultWebServiceCompressor(), true);
                            context.PersistenceEngine = remotingEngine;
                            hasSource = true;
                        }
                        else if (this.domainConfig.PersistenceType == PersistenceType.ObjectDocument)
                        {

                            hasSource = true;
                        }
                    }
                }
                else if (this.domainConfig.Url.Length > 0)
                {
                    context = new Context(this.domainConfig.Url, this.domainConfig.DomainKey);
                    hasSource = true;
                }
                else if (this.domainConfig.ConnectionString.Length > 0)
                {
                    //Wrap db on the fly
                    WrapDatabase();
                    hasSource = true;
                }
                else
                {
                    return null;
                }

                if (this.domainConfig.AssemblyPath.Length > 0)
                {
                    domain = System.Reflection.Assembly.LoadFrom(this.domainConfig.AssemblyPath);
                }
                else
                {
                    GenerateAssembly(context);
                }
            }

            context.ValidateBeforeCommit = false;

            if (domain != null)
            {
                context.AssemblyManager.RegisterAssembly(domain);

                context.ExecutingSql += new ExecutingSqlEventHandler(this.HandleExecutingSql) ;
                context.CallingWebService += new CallingWebServiceEventHandler(this.HandleCallingWebService) ;
            }

            SyntaxBoxConfigurator config = new SyntaxBoxConfigurator(npathTextBox.SyntaxBoxControl) ;
            config.SetupNPath() ;

            return context;
        }