Пример #1
0
        public ImagesModel GetImages(string searchValue, int pageIndex, int pageSize)
        {
            if (string.IsNullOrEmpty(searchValue))
            {
                return(null);
            }
            var cache = MemoryCacheUtil.GetCacheItem <ImagesModel>($"PixabayApi_Images_{searchValue}_{pageIndex}_{pageSize}");

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

            var url = string.Format("https://pixabay.com/api/?key={0}&q={1}&image_type=photo&lang=zh&page={2}&per_page={3}", key, searchValue, pageIndex, pageSize);

            try
            {
                logger.Debug($"Get:{url}");
                var result     = Get(url);
                var resultJson = JsonConvert.DeserializeObject <ImagesModel>(result);
                // 缓存24小时
                MemoryCacheUtil.Set($"PixabayApi_Images_{searchValue}_{pageIndex}_{pageSize}", resultJson, 3600 * 24);
                return(resultJson);
            }
            catch (Exception ex)
            {
                logger.Error($"获取图片资源:{searchValue} 失败", ex);
                throw ex;
            }
        }
Пример #2
0
        /// <summary>
        /// 获取日志
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ILog GetLogger(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            if (MemoryCacheUtil.Contains(name))
            {
                return(MemoryCacheUtil.GetCacheItem <ILog>(name));
            }
            else
            {
                lock (lockObject)
                {
                    if (MemoryCacheUtil.Contains(name))
                    {
                        return(MemoryCacheUtil.GetCacheItem <ILog>(name));
                    }
                    var logger     = CreateLoggerInstance(name);
                    var now        = DateTime.Now.AddDays(1);
                    var expireDate = new DateTime(now.Year, now.Month, now.Day); // 晚上0点过期
                    MemoryCacheUtil.Set(name, logger, expireDate);
                    return(logger);
                }
            }
        }
Пример #3
0
        public VideosModel GetVideos(string searchValue)
        {
            if (string.IsNullOrEmpty(searchValue))
            {
                return(null);
            }
            var cache = MemoryCacheUtil.GetCacheItem <VideosModel>("PixabayApi_videos_" + searchValue);

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

            var url = string.Format("https://pixabay.com/api/videos/?key={0}&q={1}", key, searchValue);

            try
            {
                logger.Debug($"Get:{url}");
                var result     = Get(url);
                var resultJson = JsonConvert.DeserializeObject <VideosModel>(result);
                MemoryCacheUtil.Set("PixabayApi_videos_" + searchValue, resultJson, 3600 * 24);
                return(resultJson);
            }
            catch (Exception ex)
            {
                logger.Error($"获取视频资源:{searchValue} 失败", ex);
                throw ex;
            }
        }
Пример #4
0
        /// <summary>
        /// 通过存储过程获取CGL不良信息及不良条数
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public List <AIORAA> GetCGLNgInfoByProc(DateTime startDate, DateTime endDate)
        {
            aIORAAs = new List <AIORAA>();
            int MaxNgCount = 0;

            sampleRaas = new List <AIORAA>();
            OracleParameter[] oracleParameters = new OracleParameter[]
            {
                new OracleParameter("startDate", OracleDbType.Varchar2),
                new OracleParameter("endDate", OracleDbType.Varchar2),
                new OracleParameter("rs", OracleDbType.RefCursor, ParameterDirection.Output),
                new OracleParameter("NGCOUNT", OracleDbType.Int32, ParameterDirection.Output)
            };
            oracleParameters[0].Value = startDate.GetDateTimeFormats()[99];
            oracleParameters[1].Value = endDate.GetDateTimeFormats()[99];
            DataSet dataSet = MemoryCacheUtil.GetOrAddCacheItem(startDate.ToShortDateString() + endDate.ToShortDateString(),
                                                                () =>
            {
                ReadingDb(100, 2);   //进入数据库访问时初始化一个进度到窗口
                return(OraHelper.GetDataSet("pkg_aio.proc_GetCGL_NG_INFO", oracleParameters, CommandType.StoredProcedure));
            }, "cglNgInfo");

            aIORAAs    = Util.ToList <AIORAA>(dataSet.Tables[0]);
            MaxNgCount = MemoryCacheUtil.GetOrAddCacheItem(startDate.ToShortDateString() + endDate.ToShortDateString() + "MaxNgCount",
                                                           () => Convert.ToInt32(oracleParameters[3].Value.ToString()), "MaxNgCount");

            string snIn = "";
            //for (int i = 0; i < aIORAAs.Count; i++)
            //{
            //    snIn+= aIORAAs[i].SN.Substring(36, 17)+"'";
            //    aIORAAs[i] = GetMachineInfo(aIORAAs[i]);
            //    processCount++;
            //}
            int pageSize  = 1000;
            int totalPage = MaxNgCount % pageSize == 0 ? MaxNgCount / pageSize : MaxNgCount / pageSize + 1;

            if (MemoryCacheUtil.GetCacheItem <object>(startDate.ToShortDateString() + endDate.ToShortDateString() + "completeCglNg") == null)
            {
                for (int i = 0; i < totalPage; i++)
                {
                    List <string> ss = (aIORAAs.Skip(i * pageSize).Take(pageSize)).Select(p => "'" + p.SN.Substring(36, 17) + "'").ToList();
                    snIn = string.Join(",", ss);
                    GetMachineInfo(snIn, aIORAAs);
                    ReadingDb(totalPage, i + 1);
                }
            }
            else
            {
                ReadingDb(100, 100);//如果缓存中有数据直接将进度条置为 100%
            }
            sampleRaas = MemoryCacheUtil.GetOrAddCacheItem(startDate.ToShortDateString() + endDate.ToShortDateString() + "completeCglNg",
                                                           () => { return(sampleRaas); }, "completeCglNg");
            return(sampleRaas);
        }
Пример #5
0
        private void InitControls()
        {
            klineMenu.Tag = MemoryCacheUtil.GetCacheItem <Form>(nameof(FormKline));
            AnaMenu.Tag   = MemoryCacheUtil.GetCacheItem <Form>(nameof(FormAnalysis));


            ContextMenuStrip contextMenuStrip = new ContextMenuStrip(new Container());

            contextMenuStrip.Items.AddRange(new ToolStripItem[]
            {
                new ToolStripMenuItem("Exit", null, Exit)
            });

            _notifyIcon = new NotifyIcon()
            {
                Icon             = Resources.Bitcoin,
                ContextMenuStrip = contextMenuStrip,
                Visible          = true
            };
            _notifyIcon.DoubleClick += new EventHandler(HandleDoubleClick);
        }