コード例 #1
0
ファイル: ScreenSaverForm.cs プロジェクト: stylpe/Aerial
        private void SetNextVideo(bool force)
        {
            Trace.WriteLine("SetNextVideo()");
            var cacheEnabled = new RegSettings().CacheVideos;

            if (showVideo)
            {
                //If movies is null, when we tried to parse the JSON doc with the movies it
                //failed or it was empty.
                if (Movies == null || Movies.Count == 0)
                {
                    showVideo = false;
                    MessageBox.Show("Error finding the video locations.  Please confirm that the video source " +
                                    "is a valid JSON document and can be reached.  Resart after fixing the video source");

                    return;
                }

                if (force || repeated >= Movies[currentVideoIndex].repeat)
                {
                    currentVideoIndex = selector.next(Movies.Count);
                    repeated          = 1;
                }
                else
                {
                    repeated++;
                }

                //MessageBox.Show($"{Movies[currentVideoIndex].url}\n{Movies[currentVideoIndex].repeat}\n{repeated}\n{force}");

                string url = Movies[currentVideoIndex].url;

                if (Caching.IsHit(url))
                {
                    Debug.WriteLine("Caching is hit");
                    player.Play(new Uri(Caching.Get(url)));
                }
                else
                {
                    Debug.WriteLine("Caching is not hit");
                    player.Play(url);

                    if (cacheEnabled && shouldCache &&
                        !previewMode && !Caching.IsCaching(url))
                    {
                        Caching.StartDelayedCache(url);
                    }
                }

                if (Movies[currentVideoIndex].shouldRepeatFrom && repeated != 1)
                {
                    //MessageBox.Show($"Current time: {player.Time}, setting to {Movies[currentVideoIndex].repeatFrom}");
                    player.Time = Movies[currentVideoIndex].repeatFrom;
                }

                //currentVideoIndex++;
                //if (currentVideoIndex >= Movies.Count)
                //    currentVideoIndex = 0;
            }
        }
コード例 #2
0
ファイル: ScreenSaverForm.cs プロジェクト: saihv/Aerial
        private void SetNextVideo()
        {
            Trace.WriteLine("SetNextVideo()");
            var cacheEnabled = new RegSettings().CacheVideos;

            if (ShowVideo)
            {
                string url = Movies[currentVideoIndex].url;

                if (Caching.IsHit(url))
                {
                    player.URL = Caching.Get(url);
                }
                else
                {
                    player.URL = url;
                    if (cacheEnabled && shouldCache &&
                        !previewMode && !Caching.IsCaching(url))
                    {
                        Caching.StartDelayedCache(url);
                    }
                }
                currentVideoIndex++;
                if (currentVideoIndex >= Movies.Count)
                {
                    currentVideoIndex = 0;
                }
            }
        }
コード例 #3
0
        public override async Task <IServiceResult> Intercept(IInterceptorContext context)
        {
            var service = ServiceFactory.Get(context.ServiceRoute);

            if (service.CachingConfig == null)
            {
                return(await context.Next());
            }
            var key = KeyGenerator.ReplacePlaceholder(service.CachingConfig.KeyPlaceholder, service.CachingConfig.CustomKey,
                                                      context.Args);

            if (!(context is InterceptorContext ctx))
            {
                throw new ArgumentNullException();
            }
            var(value, hasKey) = await Caching.Get(key, ctx.ReturnType);

            if (hasKey)
            {
                return(new ServiceResult(value));
            }
            var result = await context.Next();

            if (result.Status != RemotingStatus.Ok)
            {
                return(result);
            }
            await Caching.Set(key, result.Result, service.CachingConfig.ExpireSeconds);

            return(result);
        }
コード例 #4
0
        void Step4()
        {
            Thread.Sleep(delayInSec * 1000);
            var taskInfo = Caching.Get <TaskInfo>(taskKey);

            taskInfo.SetState("State 4");
            Caching.Set(taskKey, taskInfo);
        }
コード例 #5
0
        private void SetNextVideo()
        {
            Trace.WriteLine("SetNextVideo()");
            var cacheEnabled = new RegSettings().CacheVideos;

            if (showVideo)
            {
                //If movies is null, when we tried to parse the JSON doc with the movies it
                //failed or it was empty.
                if (Movies == null || Movies.Count == 0)
                {
                    showVideo = false;
                    MessageBox.Show("Error finding the video locations.  Please confirm that the video source " +
                                    "is a valid JSON document and can be reached.  Resart after fixing the video source");

                    return;
                }

                DetermineCurrentVideo();

                string url = Movies[currentVideoIndex].url;

                if (Caching.IsHit(url))
                {
                    player.URL = Caching.Get(url);
                }
                else
                {
                    player.URL = url;



                    if (cacheEnabled && shouldCache &&
                        !previewMode && !Caching.IsCaching(url))
                    {
                        Caching.StartDelayedCache(url);
                    }
                }

                // start video from X
                //the currentPosition property gets or sets the current position in the media item in seconds from the beginning.
                //player.Ctlcontrols.currentPosition = 60;

                //var diff = fakeNow - fileStart;
                var diff = new TimeSpan(Now().Hour, Now().Minute, Now().Second) - fileStartTime;

                player.Ctlcontrols.currentPosition = diff.TotalSeconds;


                //currentVideoIndex++;
                if ((currentVideoIndex + 1) >= Movies.Count)
                {
                    //TODO: use DateTime to determine next video?
                    //currentVideoIndex = 0;
                    DetermineCurrentVideo();
                }
            }
        }
コード例 #6
0
        public override T Get <T>(string index = null)
        {
            var configFileName = GetConfigFileName <T>(index);
            var name           = "ConfigFile_" + configFileName;
            var obj2           = Caching.Get(name);

            if (obj2 != null)
            {
                return((T)obj2);
            }
            var local = base.Get <T>(index);

            Caching.Set(name, local, new CacheDependency(ConfigService.GetFilePath(configFileName)));
            return(local);
        }
コード例 #7
0
ファイル: SettingsLookup.cs プロジェクト: dbartels13/Common
 private static CaseInsensitiveBinaryList <TS> GetItems(int cachingSeconds, T service, ICache cache)
 {
     // Possibly populate the cache and pull from that cache
     // If this fails for whatever reason, we still want to cache an empty list (or null)
     // This is done so that the consuming API will not repeatedly make calls that will fail
     // It will be up to all consumers to likely specify a default value to properly handle this
     cache.Options.Seconds = cachingSeconds;
     return(Caching.Get(
                cache,
                service.Key,
                () => service
                .GetAll()
                .Result // We are inside a possibly recursive lock, so cannot await this with semaphore locking
                .ToCaseInsensitiveBinaryList(x => x.Key)
                ));
 }
コード例 #8
0
        /// <summary>
        /// 重写基类的取配置,加入缓存机制
        /// </summary>
        public override T Get <T>(string index = null)
        {
            var fileName = this.GetConfigFileName <T>(index);
            var key      = "ConfigFile_" + fileName;
            var content  = Caching.Get(key);

            if (content != null)
            {
                return((T)content);
            }

            var value = base.Get <T>(index);

            Caching.Set(key, value, new CacheDependency(ConfigService.GetFilePath(fileName)));
            return(value);
        }
コード例 #9
0
 private string DownImage(string fakeid)
 {
     try
     {
         CookieContainer cookie = null;
         string          token  = null;
         cookie = (CookieContainer)Caching.Get("LoginCookie");
         token  = (string)Caching.Get("Token");
         string         Url         = string.Format("https://mp.weixin.qq.com/misc/getheadimg?token={0}&fakeid={1}", token, fakeid);
         HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(Url);
         webRequest2.CookieContainer = cookie;
         webRequest2.ContentType     = "image/jpeg";
         webRequest2.Method          = "GET";
         webRequest2.UserAgent       = "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
         HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
         var             str2      = response2.GetResponseStream();
         string          rootpath  = Server.MapPath("~/corvers/");
         if (Directory.Exists(rootpath) == false)
         {
             Directory.CreateDirectory(rootpath);
         }
         Stream     reader = response2.GetResponseStream();
         FileStream writer = new FileStream(Path.Combine(rootpath, fakeid + ".jpg"), FileMode.OpenOrCreate, FileAccess.Write);
         byte[]     buff   = new byte[512];
         int        c      = 0; //实际读取的字节数
         while ((c = reader.Read(buff, 0, buff.Length)) > 0)
         {
             writer.Write(buff, 0, c);
         }
         writer.Flush();
         str2.Close();
         writer.Close();
         writer.Dispose();
         reader.Close();
         reader.Dispose();
         response2.Close();
         return(Path.Combine(rootpath, fakeid + ".jpg"));
     }
     catch (Exception ex)
     {
     }
     return("");
 }
コード例 #10
0
        public SaveFamilyMember(WorkflowContext context, string cacheKey, Dictionary <string, object> parameters)
        {
            this.context    = context;
            this.TaskInfo   = Caching.Get <TaskInfo>(CacheKey) ?? new TaskInfo();
            this.Parameters = parameters;

            InitDocument();

            TaskInfo.SetState("шаг 3 из 4. Сохранен, привязка к заявлению...");
            Caching.Set(CacheKey, TaskInfo);

            Execute();

            TaskInfo.SetState("шаг 4 из 4. Привязан, обновление информации о составе семьи...");
            Caching.Set(CacheKey, TaskInfo);

            FamilyRecalc();

            TaskInfo.SetState("Обновлена. Процесс завершен.");
            Caching.Set(CacheKey, TaskInfo);
        }
コード例 #11
0
ファイル: ScreenSaverForm.cs プロジェクト: Haxine/Aerial-1
        private void SetNextVideo()
        {
            Trace.WriteLine("SetNextVideo()");
            var cacheEnabled = new RegSettings().CacheVideos;

            if (showVideo)
            {
                //If movies is null, when we tried to parse the JSON doc with the movies it
                //failed or it was empty.
                if (Movies == null || Movies.Count == 0)
                {
                    showVideo = false;
                    MessageBox.Show("Error finding the video locations.  Please confirm that the video source " +
                                    "is a valid JSON document and can be reached.  Resart after fixing the video source");

                    return;
                }

                string url = Movies[currentVideoIndex].url;

                if (Caching.IsHit(url))
                {
                    player.URL = Caching.Get(url);
                }
                else
                {
                    player.URL = url;
                    if (cacheEnabled && shouldCache &&
                        !previewMode && !Caching.IsCaching(url))
                    {
                        Caching.StartDelayedCache(url);
                    }
                }
                currentVideoIndex++;
                if (currentVideoIndex >= Movies.Count)
                {
                    currentVideoIndex = 0;
                }
            }
        }
コード例 #12
0
        public override T Get <T>(string index = null)
        {
            var fileName = this.GetConfigName <T>(index);
            var key      = string.Format("{0}_{1}", InternalConstant.CacheKeyPrefixes.ConfigFile.ToString(), fileName);
            var content  = Caching.Get <T>(key);

            if (content != null)
            {
                return(content);
            }

            var filePath         = string.Empty;
            var tmpConfigService = this.ConfigService as FileConfigService;

            if (tmpConfigService != null)
            {
                filePath = tmpConfigService.GetFilePath(fileName);
            }

            var value = base.Get <T>(index);

            Caching.Set(key, value, new CacheDependency(filePath));
            return(value);
        }
コード例 #13
0
ファイル: CachedDbConfigContext.cs プロジェクト: xh91900/Src
        public override T Get <T>(string index = null)
        {
            var fileName = this.GetConfigName <T>(index);
            var key      = string.Format("{0}_{1}", InternalConstant.CacheKeyPrefixes.ConfigDatabase.ToString(), fileName);
            var content  = Caching.Get <T>(key);

            if (content != null)
            {
                return(content);
            }

            SqlCommand command          = null;
            var        tmpConfigService = this.ConfigService as DbConfigServices;

            if (tmpConfigService != null)
            {
                command = tmpConfigService.GetSqlCommand(null);
            }

            var value = base.Get <T>(index);

            Caching.Set(key, value, new SqlCacheDependency(command));
            return(value);
        }
コード例 #14
0
ファイル: RemoteServiceFactory.cs プロジェクト: MM1314/QG
        private T CreateService <T>(string uri)
        {
            var key = string.Format("{0} - {1}", typeof(T), uri);

            if (Caching.Get(key) == null)
            {
                var binding = new BasicHttpBinding();
                binding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding.ReaderQuotas           = new XmlDictionaryReaderQuotas();
                binding.ReaderQuotas.MaxStringContentLength = maxReceivedMessageSize;
                binding.ReaderQuotas.MaxArrayLength         = maxReceivedMessageSize;
                binding.ReaderQuotas.MaxBytesPerRead        = maxReceivedMessageSize;

                ChannelFactory <T> chan = new ChannelFactory <T>(binding, new EndpointAddress(uri));
                chan.Endpoint.Behaviors.Add(new SOA.WLIMS.WCFExtension.InspectorBehavior());
                foreach (var op in chan.Endpoint.Contract.Operations)
                {
                    var dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                    if (dataContractBehavior != null)
                    {
                        dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                    }
                }

                chan.Open();

                var service = chan.CreateChannel();
                Caching.Set(key, service);

                return(service);
            }
            else
            {
                return((T)Caching.Get(key));
            }
        }
コード例 #15
0
        /// <summary>
        /// 加载所有启用菜单
        /// </summary>
        /// <returns></returns>
        public static List <sys_module> loadModule()
        {
            Model.adminlogin loginModel = LoginInfo;
            if (loginModel == null)
            {
                string url = HttpContext.Current.Request.Url.Host + "/Home/Login";
                HttpContext.Current.Response.Redirect(url);
                return(null);
            }
            List <sys_module> list = new List <sys_module>();
            ////如果缓存中找到了就直接返回
            object cahingList = Caching.Get("loadModule");

            if (cahingList != null)
            {
                return(cahingList as List <sys_module>);
            }

            ////1.如果是超级管理员直接返回所有
            var groupUser  = groupUserBll.GetSingleModel(m => m.userID == loginModel.UserID);
            var adminRoles = groupBll.GetSingleModel(m => m.groupID == groupUser.groupID);

            //2.找出显示的所有菜单
            // var asys_actionList = actBll.LoadEntities(m => m.actionKey == "Show");
            //3.找出当前登陆权限
            if (adminRoles.groupName == "超级管理组")
            {
                var userModelacl = actBll.LoadEntities(w => w.actionKey == "Show");//一级菜单
                foreach (var item in userModelacl)
                {
                    var sys_modules = moduleBll.GetSingleModel(m => m.moduleKey == item.moduleKey && m.class_layer == 1);
                    if (sys_modules != null)
                    {
                        list.Add(sys_modules);
                    }
                }
                Caching.Set("loadModule", list);
                return(list);
            }
            //获取用户自己独立权限
            var sys_acl_userList = acluserBll.LoadEntities(m => m.userID == loginModel.UserID);

            foreach (var item in sys_acl_userList)
            {
                var userModelacl = actBll.GetSingleModel(w => w.actionKey == "Show" && w.actionID == item.actionID);
                var sys_modules  = moduleBll.GetSingleModel(m => m.moduleKey == userModelacl.moduleKey && m.class_layer == 1);
                if (sys_modules != null)
                {
                    list.Add(sys_modules);
                }
            }
            ////获取用户角色组权限
            if (groupUser != null)
            {
                var aclGroupList = aclgroupBll.LoadEntities(w => w.groupID == groupUser.groupID);
                foreach (var item in aclGroupList)
                {
                    var GroupModelacl = actBll.GetSingleModel(w => w.actionID == item.actionID);
                    var sys_modules   = moduleBll.GetSingleModel(m => m.moduleKey == GroupModelacl.moduleKey && m.class_layer == 1);
                    if (sys_modules != null)
                    {
                        list.Add(sys_modules);
                    }
                }
            }

            Caching.Set("loadModule", list);
            return(list);
        }
コード例 #16
0
        /// <summary>
        /// 检查用户登录
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) ||
                filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
            {
                return;                                                   //表示支持控制器、action的AllowAnonymousAttribute
            }
            var sessionUser = HttpContext.Current.Session["CurrentUser"]; //使用session

            //var memberValidation = HttpContext.Current.Request.Cookies.Get("CurrentUser");//使用cookie
            //也可以使用数据库、nosql等介质
            if (sessionUser == null || !(sessionUser is CurrentUser))
            {
                HttpContext.Current.Session["CurrentUrl"] = filterContext.RequestContext.HttpContext.Request.RawUrl;
                //filterContext.Result = new RedirectResult(this._loginPath);
                //filterContext.HttpContext.Response.Write("<script>window.parent.location.href='/Auth/Login';</script>");
                filterContext.Result = new RedirectResult(this._loginPath);
            }
            else
            {
                CurrentUser    currentUser = (CurrentUser)filterContext.RequestContext.HttpContext.Session["CurrentUser"];
                string         url         = filterContext.RequestContext.HttpContext.Request.RawUrl;
                List <TS_MENU> menus       = new List <TS_MENU>();
                List <TS_MENU> useMenus    = new List <TS_MENU>();
                var            logger      = NF.Framework.Logger.CreateLogger(this.GetType());
                object         oMenu       = Caching.Get("menu" + currentUser.Id);
                if (oMenu != null)
                {
                    logger.Info($"menu{ currentUser.Id} 菜单使用缓存");
                    return;
                }
                else
                {
                    logger.Info($"menu{ currentUser.Id} 菜单刷新");
                    //menus 一级菜单
                    menus = service.GetMenus(1);
                    List <TS_FUNCTIONDTO> fDtos = currentUser.MenuFuncs;
                    foreach (var m in menus)
                    {
                        //useMenus.Add(m);
                        if (fDtos.ExistsOrDefault <TS_FUNCTIONDTO>(x => x.MenuID == m.C_ID))
                        {
                            useMenus.Add(m);
                        }
                    }
                }
                List <TS_MENUDTO> menuDtos = MAPPING.ConvertEntityToDtoList <TS_MENU, TS_MENUDTO>(useMenus);
                List <TS_MENUDTO> newMenus = new List <TS_MENUDTO>();
                List <TS_MENUDTO> pMenus   = menuDtos.FindAll(x => x.C_PARENT_ID == null);
                foreach (var parent in pMenus)
                {
                    var parentDto = parent;
                    List <TS_MENUDTO> childrenMenus = menuDtos.FindAll(x => x.C_PARENT_ID == parent.C_ID);
                    if (childrenMenus.Count > 0)
                    {
                        foreach (var children in childrenMenus)
                        {
                            parentDto.Menus.Add(children);
                        }
                    }
                    newMenus.Add(parentDto);
                }

                List <MENUDTO> menu = MAPPING.ConvertMenu(newMenus);

                string strMenu = NF.Framework.SerializationHelper.JsonSerialize(menu);
                string path    = "/Common/main.html";
                if (currentUser.Type == "1")
                {
                    path = "/Common/main2.html";
                }
                string newUrl = "{ id: '0',text: '首页',icon: 'icon-cog',url: '',menus: [{ id: '00',text: '首页',icon: 'icon-glass',close: false,url: '" + path + "' }]},";
                string str    = strMenu.Insert(1, newUrl);
                Caching.Set("menu" + currentUser.Id, str);
            }
        }
コード例 #17
0
 public virtual object Get(string key)
 {
     return(Caching.Get(key));
 }
コード例 #18
0
ファイル: CacheHelper.cs プロジェクト: daydream163/ktproject
 /// <summary>
 /// 取得缓存数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cacheKey"></param>
 /// <returns></returns>
 private static T GetCacheRedis <T>(string cacheKey, string source = _CacheSource)
 {
     return(Caching.Get <T>(source, cacheKey));
 }