예제 #1
0
파일: Dispatcher.cs 프로젝트: mind0n/hive
	    static Dispatcher()
	    {
	        instance = LoadRoutes();
            FileSystemWatcher w = new FileSystemWatcher(configpath);
            w.Changed += w_Changed;
	        w.NotifyFilter = NotifyFilters.LastWrite;
	        w.EnableRaisingEvents = true;
	    }
예제 #2
0
파일: Dispatcher.cs 프로젝트: mind0n/hive
		public static Dispatcher LoadRoutes()
		{
		    lock (locker)
		    {
		        try
		        {
		            string file = configfile;
		            Dispatcher rlt = null;
		            if (File.Exists(file))
		            {
		                string json = File.ReadAllText(file);
		                if (!string.IsNullOrEmpty(json))
		                {
		                    rlt = json.FromJson<Dispatcher>();
		                }
		            }
		            else
		            {
		                rlt = new Dispatcher();
		                File.WriteAllText(file, rlt.ToJson());
		            }
		            if (rlt != null)
		            {
		                if (rlt.EnableAuthService)
		                {
                            rlt.Mappings.Add("auth", new RouteInfo { TypeName = typeof(AuthService).FullName });
                        }
		                foreach (KeyValuePair<string, RouteInfo> i in rlt.Mappings)
		                {
		                    RouteInfo info = i.Value;
		                    info.LoadType();
		                }
		            }
		            else
		            {
		                rlt = new Dispatcher();
		            }
		            instance = rlt;
	                URoles.Instance.EnableAnonymousAccess = rlt.EnableAnonymousAccess;
		            URoles.Instance.EnableAutoAddRole = rlt.EnableAutoAddRole;
		            return rlt;
		        }
		        catch
		        {
                    instance = new Dispatcher();
		            return instance;
		        }
		    }
		}