コード例 #1
0
        public void Commit()
        {
            if (domainMap != null)
            {
                ILoggingService loggingService = engine.GetService<ILoggingService>();
                if (loggingService != null)
                    loggingService.LogInfo(this, "Saving NPersist mapping file.");

                string path = @"C:\Test\test.xml";
                IMapSerializer serialiser = new DefaultMapSerializer();
                domainMap.Save(path, serialiser);
                domainMap = null;
            }
        }
コード例 #2
0
        public IContext GetContext()
        {
            if (context == null)
            {
                ILoggingService loggingService = engine.GetService<ILoggingService>();
                if (loggingService != null)
                    loggingService.LogInfo(this, "Creating NPersist context");

                IConfigurationService configurationService = engine.GetService<IConfigurationService>();

                string path = configurationService.SchemaFilePath;

                IMapSerializer serialier = new DefaultMapSerializer();
                IDomainMap domainMap = DomainMap.Load(path, serialier, false, false);

                context = new Context(domainMap);
                GenerateAssembly(context);

                context.SetConnectionString(configurationService.ConnectionString);
                context.AutoTransactions = false;
            }
            return context;
        }
コード例 #3
0
ファイル: DomainMap.cs プロジェクト: Dawn-of-Light/Puzzle.NET
		protected static IMapSerializer GetMapSerializerFromXml(string xml)
		{
			IMapSerializer mapSerializer = null;
			XmlDocument xmlDoc = new XmlDocument();
			XmlNode xmlDom;
			if (xml.Length > 0)
			{
				xmlDoc.LoadXml(xml);
				xmlDom = xmlDoc.SelectSingleNode("domain");
				if (xmlDom != null)
				{
					if (!(xmlDom.Attributes["serializer"] == null))
					{
						if (xmlDom.Attributes["serializer"].Value.ToLower(CultureInfo.InvariantCulture) == "dotnet")
						{
							mapSerializer = null;
						}
						else
						{
							mapSerializer = new DefaultMapSerializer();
						}
					}
					else
					{
						mapSerializer = new DefaultMapSerializer();
					}
				}
				else
				{
					xmlDom = xmlDoc.SelectSingleNode("DomainMap");
					if (xmlDom != null)
					{
						mapSerializer = null;
					}
					else
					{
						mapSerializer = null;
					}
				}
			}
			return mapSerializer;
		}
コード例 #4
0
        public static IDomainMap LoadFromXml(string xml, IMapSerializer mapSerializer,bool useCache,bool validate)
        {
            IDomainMap domainMap;

            if (mapSerializer == null)
            {
                mapSerializer = new DefaultMapSerializer(); // GetMapSerializerFromXml(xml);
            }
            if (mapSerializer != null)
            {
                try
                {
                    domainMap = mapSerializer.LoadFromXml(xml);
                }
                catch (Exception ex)
                {
                    throw new MappingException("Failed loading NPersist XML mapping file! " + ex.Message, ex); // do not localize
                }
            }
            else
            {
                try
                {
                    Stream xmlStream = new MemoryStream(ASCIIEncoding.Default.GetBytes(xml));
                    XmlSerializer mySerializer = new XmlSerializer(typeof (DomainMap));
                    domainMap = ((DomainMap) (mySerializer.Deserialize(xmlStream)));
                    domainMap.MapSerializer = MapSerializer.DotNetSerializer;
                    Init(domainMap);
                }
                catch (Exception ex)
                {
                    throw new MappingException("Failed loading NPersist XML mapping file! " + ex.Message, ex); // do not localize
                }
            }

            RecalculateModel(domainMap);

            domainMap.Dirty = false;

            if (validate)
                ((DomainMap)domainMap).Validate();

            return domainMap;
        }
コード例 #5
0
        public IDomainMap GetDomainMap()
        {
            if (domainMap == null)
            {
                ILoggingService loggingService = engine.GetService<ILoggingService>();
                if (loggingService != null)
                    loggingService.LogInfo(this, "Loading NPersist mapping file.");

                IConfigurationService configurationService = engine.GetService<IConfigurationService>();

                IMapSerializer serializer = new DefaultMapSerializer();
                this.domainMap = DomainMap.Load(configurationService.SchemaFilePath, serializer, false, false);
            }
            return this.domainMap;
        }
コード例 #6
0
        private IContext GetContext(string mapPath)
        {
            IMapSerializer serialier = new DefaultMapSerializer();
            IDomainMap domainMap = DomainMap.Load(mapPath, serialier, false, false);

            IContext context = new Context(domainMap);
            GenerateAssembly(context);

            return context;
        }
コード例 #7
0
 private IContext GetContext()
 {
     //Assembly asm = this.GetType().Assembly;
     //string path = "Puzzle.FastForward.Web.Test.npersist";
     string path = @"C:\Berlioz\Puzzle\FastForward\Puzzle.FastForward.Web\Test.npersist";
     IMapSerializer serialier = new DefaultMapSerializer();
     IDomainMap domainMap = DomainMap.Load(path, serialier, false, false);
     IContext context = new Context(domainMap);
     GenerateAssembly(context);
     return context;
 }