示例#1
0
文件: Cacher.cs 项目: swinghu/Ocell
        public static IEnumerable <TwitterStatus> GetFromCache(TwitterResource resource)
        {
            string fileName   = GetCacheName(resource);
            var    serializer = new SharpSerializer(SerializerSettings);

            IEnumerable <TwitterStatus> statuses = null;

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                try
                {
                    using (var stream = FileAbstractor.GetFileStream(fileName))
                    {
                        if (stream.Length != 0)
                        {
                            statuses = serializer.Deserialize(stream) as IEnumerable <TwitterStatus>;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            });

            return(statuses ?? new List <TwitterStatus>());
        }
示例#2
0
 public TweetLoader(TwitterResource resource, bool cached)
     : this()
 {
     Resource            = resource;
     service             = ServiceDispatcher.GetService(resource.User);
     conversationService = new ConversationService(resource.User);
     Cached = cached;
 }
示例#3
0
        public override bool Equals(Object obj)
        {
            // Check for null and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            TwitterResource p = (TwitterResource)obj;

            return(p.Data == Data && p.Type == Type && p.User == User);
        }
示例#4
0
文件: Cacher.cs 项目: swinghu/Ocell
        public static void SaveToCache(TwitterResource resource, IEnumerable <TwitterStatus> list)
        {
            string fileName = GetCacheName(resource);

            var serializer = new SharpSerializer(SerializerSettings);

            MutexUtil.DoWork("OCELL_FILE_MUTEX" + fileName, () =>
            {
                try
                {
                    using (var stream = FileAbstractor.GetFileStream(fileName))
                    {
                        serializer.Serialize(list.Distinct().OfType <TwitterStatus>().ToList(), stream);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            });
        }
示例#5
0
文件: Cacher.cs 项目: swinghu/Ocell
        private static string GetCacheName(TwitterResource resource)
        {
            string Key = "Cache" + RemoveSymbols(resource.String);

            return(Key);
        }
示例#6
0
 public TweetLoader(TwitterResource resource)
     : this(resource, true)
 {
     LoadCacheAsync();
 }