/// <summary>
        /// 从数据库得到对象的图片
        /// </summary>
        /// <param name="id"></param>
        /// <param name="propertyName"></param>
        /// <param name="timePoint"></param>
        /// <returns></returns>
        public SchemaObjectPhoto LoadObjectPhoto(string id, string propertyName, DateTime timePoint)
        {
            SchemaObjectPhoto result = null;
            SchemaObjectBase  obj    = SchemaObjectAdapter.Instance.Load(id, timePoint);

            if (obj != null)
            {
                if (obj.Properties.ContainsKey(propertyName))
                {
                    ImageProperty imgInfo = JSONSerializerExecute.Deserialize <ImageProperty>(obj.Properties[propertyName].StringValue);

                    if (imgInfo != null)
                    {
                        MaterialContent mc = MaterialContentAdapter.Instance.Load(builder => builder.AppendItem("CONTENT_ID", imgInfo.ID)).FirstOrDefault();

                        if (mc != null)
                        {
                            result = new SchemaObjectPhoto()
                            {
                                ImageInfo = imgInfo, ContentData = mc.ContentData
                            }
                        }
                        ;
                    }
                }
            }

            return(result);
        }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            string id = context.Request["id"];

            try
            {
                id.NullCheck("id");

                SchemaObjectPhoto photo = null;

                if (context.Request["time"] == "now")
                {
                    TimePointContext tpc = TimePointContext.GetCurrentState();

                    try
                    {
                        TimePointContext.Current.SimulatedTime  = DateTime.MinValue;
                        TimePointContext.Current.UseCurrentTime = true;

                        photo = SchemaObjectAdapter.Instance.GetObjectPhoto(id, "PhotoKey", DateTime.MinValue);
                    }
                    finally
                    {
                        TimePointContext.RestoreCurrentState(tpc);
                    }
                }
                else
                {
                    photo = SchemaObjectAdapter.Instance.GetObjectPhoto(id, "PhotoKey", TimePointContext.Current.SimulatedTime);
                }

                if (photo != null)
                {
                    ResponsePhoto(WebUtility.GetContentTypeByFileName(photo.ImageInfo.OriginalName), photo.ContentData);
                }
                else
                {
                    ReponseDefaultPhoto();
                }
            }
            catch (System.Exception)
            {
                ReponseDefaultPhoto();
            }
        }
        /// <summary>
        /// 从Cache中获取图片
        /// </summary>
        /// <param name="id"></param>
        /// <param name="propertyName"></param>
        /// <param name="timePoint"></param>
        /// <returns></returns>
        public SchemaObjectPhoto GetObjectPhoto(string id, string propertyName, DateTime timePoint)
        {
            SchemaObjectPhotoKey cacheKey = new SchemaObjectPhotoKey()
            {
                ObjectID = id, PropertyName = propertyName, TimePoint = timePoint
            };

            return(SchemaObjectPhotoCache.Instance.GetOrAddNewValue(cacheKey, (cache, key) =>
            {
                SchemaObjectPhoto photo = LoadObjectPhoto(id, propertyName, timePoint);

                MixedDependency dependency = new MixedDependency(new UdpNotifierCacheDependency(), new MemoryMappedFileNotifierCacheDependency());

                cache.Add(cacheKey, photo, dependency);

                return photo;
            }));
        }