Пример #1
0
        /// <summary>
        /// getApplicationContext
        /// </summary>
        /// <param name="section"></param>
        /// <returns></returns>
        private Spring.Context.IApplicationContext getApplicationContext(System.Xml.XmlNode section)
        {
            System.Xml.XmlNodeList nodes = section.SelectNodes("resource");
            string[] xmlPath             = new string[nodes.Count];

            for (int index = 0; index < nodes.Count; index++)
            {
                foreach (System.Xml.XmlAttribute attribute in nodes[index].Attributes)
                {
                    if (attribute.Name.Trim().ToUpper() == "URI" || attribute.Name.Trim().ToUpper() == "URL")
                    {
                        xmlPath[index] = attribute.Value.Trim();
                        break;
                    }
                }
            }
            for (int index = 0; index < xmlPath.Length; index++)
            {
                xmlPath[index] = System.AppDomain.CurrentDomain.BaseDirectory + xmlPath[index];
            }

            if (_IApplicationContext == null)
            {
                _IApplicationContext = new Spring.Context.Support.XmlApplicationContext(xmlPath);
            }
            Spring.Context.Support.ContextRegistry.RegisterContext(_IApplicationContext);
            return(_IApplicationContext);
        }
Пример #2
0
        public static void doMain(string[] args)
        {
            try
            {
                //XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Config/log4net.config"));
                Spring.Context.IApplicationContext ctx = ContextRegistry.GetContext();
                //ISqlMapper mapper = new DomSqlMapBuilder().Configure(AppDomain.CurrentDomain.BaseDirectory + @"\Config\SqlMap.config");
                //ISqlMapper mapper = ctx.GetObject<ISqlMapper>("SqlSessionTemplate");

                //executeDictionary(mapper);
                //executeList(mapper);

                DemoService ser = ctx.GetObject("demoService") as DemoService;
                Demo        d   = ser.GetShow(2);
                Console.WriteLine(d.title);

                /*
                 * try
                 * {
                 *      Demo d = new Demo();
                 *      d.id = 4;
                 *      d.title = "heihei";
                 *      d.content = "test";
                 *      d.foundtime = DateTime.Now.ToString();
                 *      ser.Save(d);
                 * }
                 * catch(Exception e)
                 * {
                 *      Console.WriteLine(e.Message);
                 * }
                 */

                Hashtable ht = new Hashtable();
                ht.Add("title", "heihei");
                PageRequest pageRequest = new PageRequest();
                pageRequest.PageSize    = 2;
                pageRequest.CurrentPage = 2;
                pageRequest.Filters     = ht;
                Page <Demo> page = ser.QueryPage(pageRequest);
                foreach (Demo o in page.GetResult <Demo>())
                {
                    Console.WriteLine("Service.QueryPage : {ID:'" + o.id + "',TITLE:'" + o.title + "',CONTENT:'" + o.content + "',FOUNDTIME:'" + o.foundtime + "'} : " + o.ToString());
                }
                Console.WriteLine("总数是:" + page.TotalCount);

                IList <Demo> list = ser.QueryList(pageRequest);
                foreach (Demo o in list)
                {
                    Console.WriteLine("Service.QueryList : {ID:'" + o.id + "',TITLE:'" + o.title + "',CONTENT:'" + o.content + "',FOUNDTIME:'" + o.foundtime + "'} : " + o.ToString());
                }
                Console.Read();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        static WebHelper()
        {
            log4net.Config.XmlConfigurator.Configure();
            Logger = log4net.LogManager.GetLogger("logger");

            Spring.Context.IApplicationContext ctx = Spring.Context.Support.ContextRegistry.GetContext();
            UserService           = (IUserService)ctx["UserService"];
            PositionService       = (IPositionService)ctx["PositionService"];
            AuthenticationService = (IAuthenticationService)ctx["AuthenticationService"];
            KehuService           = (IKehuService)ctx["KehuService"];
            ChanpinService        = (IChanpinService)ctx["ChanpinService"];
            DingdanService        = (IDingdanService)ctx["DingdanService"];
            Version = "1.0.4";
        }
Пример #4
0
        private static void SetSpringServiceLocator()
        {
            Spring.Context.IApplicationContext ctx = Spring.Context.Support.ContextRegistry.GetContext();

            DefaultServiceProvider.Instance.EnableAll();
            var sp = new ComboServiceProvider(
                new Microsoft.Practices.ServiceLocation.SpringAdapter.SpringServiceLocatorAdapter(ctx),
                DefaultServiceProvider.Instance);

            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(new Microsoft.Practices.ServiceLocation.ServiceLocatorProvider(
                                                                                      delegate()
            {
                return(sp);
            }));
        }
Пример #5
0
 protected virtual bool Init()
 {
     try
     {
         if (HttpContext.Current.Request == null)
         {
             // Spring.Context.Support.ContextRegistry.GetContext() requires HttpContext.Current.Request
             return(false);
         }
     }
     catch (Exception)
     {
         // Spring.Context.Support.ContextRegistry.GetContext() requires HttpContext.Current.Request
         return(false);
     }
     if (HttpContext.Current != null)
     {
         if (ApplicationContext == null)
         {
             lock (s_LockObject)
             {
                 if (ApplicationContext == null)
                 {
                     try
                     {
                         Spring.Context.IApplicationContext ctx = Spring.Context.Support.ContextRegistry.GetContext();
                         ApplicationContext = ctx;
                     }
                     catch (Exception)
                     {
                         throw;
                     }
                 }
             }
         }
     }
     return(true);
 }
Пример #6
0
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="configContext"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public new object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     Spring.Context.IApplicationContext IApplicationContext = getApplicationContext(section);
     return(IApplicationContext);
 }
Пример #7
0
 /// <summary>
 /// 初始化
 /// </summary>
 public SpringContainer()
 {
     _context = Spring.Context.Support.ContextRegistry.GetContext();
 }
        private bool GetLatestStateFromConfigurationManagement(object entity, object[] state, string[] propertyNames)
        {
            bool?appFrontend = false;
            Type classType;

            Domain.Application application;

            classType = NHibernate.Proxy.NHibernateProxyHelper.GetClassWithoutInitializingProxy(entity);
            if (typeof(IVersionControlled).IsAssignableFrom(classType))
            {
                if (((bool)state[propertyNames.ToList().IndexOf("IsLocked")]) && ((string)state[propertyNames.ToList().IndexOf("LockedBy")]) != Environment.UserName)
                {
                    IVersionControlled dbobject = (IVersionControlled)GetObjectFromState(classType, state, propertyNames);
                    dbobject.Id = ((IVersionControlled)entity).Id;


                    application = GetApplicationForDomainObject(dbobject);
                    appFrontend = application.IsFrontend.Value;


                    if (appFrontend == null)
                    {
                        return(false);
                    }


                    Spring.Context.IApplicationContext ctx            = Spring.Context.Support.ContextRegistry.GetContext();
                    NHibernate.ISessionFactory         sessionFactory = ((NHibernate.ISessionFactory)ctx["SessionFactory"]);
                    NHibernate.ISession session = Spring.Data.NHibernate.SessionFactoryUtils.GetSession(sessionFactory, false);

                    System.Configuration.AppSettingsReader appReader = new System.Configuration.AppSettingsReader();
                    string rootPath   = appReader.GetValue("RepositoryPath", typeof(System.String)).ToString();
                    string parentPath = System.IO.Path.Combine(rootPath, application.Name + (appFrontend.Value ? "_Frontend" : "_Backend"));
                    string filePath   = System.IO.Path.Combine(parentPath, classType.Name);
                    string fileName   = ((IVersionControlled)dbobject).RepositoryFileName + ".xml";
                    string fullPath   = System.IO.Path.Combine(filePath, fileName);

                    System.IO.FileInfo fi = new System.IO.FileInfo(fullPath);

                    if (fi.Exists)
                    {
                        System.Xml.Serialization.XmlSerializer xmlSerie = new System.Xml.Serialization.XmlSerializer(classType);

                        System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader(fi.OpenText().ReadToEnd()));

                        DataAccess.DomainXmlSerializationHelper.VisualComponentRefObjects.Clear();

                        object domainObject = xmlSerie.Deserialize(reader);

                        foreach (IDomainObject obj in DataAccess.DomainXmlSerializationHelper.VisualComponentRefObjects)
                        {
                            session.Merge(obj);
                        }

                        ((IVersionControlled)domainObject).IsLocked   = true;
                        ((IVersionControlled)domainObject).LockedBy   = dbobject.LockedBy;
                        ((IVersionControlled)domainObject).LockedDate = dbobject.LockedDate;
                        ((IDomainObject)domainObject).IsTransient     = false;

                        SetStateFromObject(domainObject, classType, state, propertyNames);

                        return(true);
                    }
                }
            }

            return(true);
        }