示例#1
0
        public void RemovePotentialTweet(Tweet tweet, bool retweet = false)
        {
            GetPotentialTweets(retweet); //Loads them up if they are not already loaded up

            if (tweet != null)
            {
                if (!retweet)
                {
                    var remove = potentialTweets.Where(x => x.UniqueKey == tweet.UniqueKey).FirstOrDefault();
                    if (remove != null)
                    {
                        potentialTweets.Remove(remove);
                    }

                    tweetRepo.Delete(POTENTIAL_TWEETS + SettingsGuid, tweet);
                }
                else
                {
                    var remove = potentialReTweets.Where(x => x.UniqueKey == tweet.UniqueKey).FirstOrDefault();
                    if (remove != null)
                    {
                        potentialReTweets.Remove(remove);
                    }

                    tweetRepo.Delete(POTENTIAL_RETWEETS + SettingsGuid, tweet);
                }
            }
        }
示例#2
0
        public void Delete(int id)
        {
            var repo = new SimpleRepository <T>(connectionFactory);

            if (repo.Delete(id) == false)
            {
                throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);
            }
        }
示例#3
0
        public async Task <IActionResult> Delete([FromRoute] Guid id)
        {
            if (_cache.TryGetValue(id, out Entity result))
            {
                await _simpleRepository.Delete(result);

                _cache.Remove(id);
            }
            else
            {
                result = await _simpleRepository.GetById(id);

                if (result != null)
                {
                    await _simpleRepository.Delete(result);
                }
            }

            return(Ok());
        }
示例#4
0
        static void Main(string[] args)
        {
            var connectionString = ConfigurationManager.AppSettings["AzureStorageConnectionString"];

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new Exception("Config Section 'appSettings' missing AzureStorageConnectionString value!");
            }

            var storageAccount = CloudStorageAccount.Parse(connectionString);
            var blobClient     = storageAccount.CreateCloudBlobClient();

            var deleteTasks = new List <Task>(10000000);

            Action <Task> delete = t =>
            {
                lock (deleteTasks)
                {
                    deleteTasks.Add(t);
                }
                Console.Clear();
                Console.WriteLine("Deleting " + deleteTasks.Count + " items");
            };

            var version = TwitterModel.VERSION;

            bool content      = args.Any(a => a.ToLower() == "content");
            bool cleanVersion = args.Any(a => a.ToLower() == "version");
            bool shrink       = args.Any(a => a.ToLower().StartsWith("shrink"));
            int  newSize      = args.Where(a => a.ToLower().StartsWith("shrink")).Select(x => x == "shrink" ? 500 : int.Parse(x.Replace("shrink", ""))).FirstOrDefault();

            blobClient.ListContainers()
            //.Skip(1) //Short circuit for testing
            //.Take(1) //Short circuit for testing
            .ToList().AsParallel().ForAll(c =>
            {
                #region Index Cleanup
                var index = c.GetDirectoryReference("Index");
                foreach (var b in index.ListBlobs().Where(x => x is CloudBlockBlob).Cast <CloudBlockBlob>())
                {
                    if (cleanVersion && !b.Name.Contains(version))
                    {
                        //Delete Index
                        var i = c.GetBlockBlobReference(b.Name);
                        delete(i.DeleteIfExistsAsync());

                        //Delete all Tweets
                        var d = c.GetDirectoryReference(b.Name.Split('/').Last());
                        foreach (var t in d.ListBlobs().Where(x => x is CloudBlockBlob).Cast <CloudBlockBlob>())
                        {
                            delete(t.DeleteIfExistsAsync());
                        }
                    }

                    if (shrink && newSize > 0 && b.Name.Contains(version))
                    {
                        //Get Storage Index
                        var i            = c.GetBlockBlobReference(b.Name);
                        var storageIndex = Newtonsoft.Json.JsonConvert.DeserializeObject <StorageEntityIndex>(DownloadBlob(i));

                        if (storageIndex.EntityKeys.Count > newSize)
                        {
                            //Delete extra Tweets
                            var d = c.GetDirectoryReference(b.Name.Split('/').Last());
                            foreach (var t in d.ListBlobs().Where(x => x is CloudBlockBlob).Cast <CloudBlockBlob>().OrderByDescending(x => x.Properties.LastModified).Skip(newSize))
                            {
                                storageIndex.EntityKeys.Remove(t.Name.Split('/').Last());
                                delete(t.DeleteIfExistsAsync());
                            }

                            //Update Storage Index
                            UploadBlob(i, storageIndex);
                        }
                    }
                }
                #endregion

                #region Content Cleanup
                if (content)
                {
                    try
                    {
                        var repoIndex = new SimpleRepository <ArticleStubIndex>(c.Name);
                        var repoPage  = new SimpleRepository <ArticleStubPage>(c.Name);
                        var stubIndex = repoIndex.Query(TwitterModel.Instance(c.Name).CONTENT_INDEX).FirstOrDefault();
                        if (stubIndex != null)
                        {
                            var remove = new List <KeyValuePair <long, string> >();
                            for (var i = stubIndex.ArticleStubPages.Count - 31; i > -1 && i < stubIndex.ArticleStubPages.Count; i++) // Only the last month(ish)
                            {
                                var si   = stubIndex.ArticleStubPages[i];
                                var page = repoPage.Query(TwitterModel.Instance(c.Name).CONTENT + "_" + si.Value).FirstOrDefault();
                                if (page.ArticleStubs == null || page.ArticleStubs.Count == 0)
                                {
                                    repoPage.Delete(TwitterModel.Instance(c.Name).CONTENT + "_" + si.Value);
                                    remove.Add(si);
                                }
                            }
                            remove.ForEach(x => stubIndex.ArticleStubPages.Remove(x));
                            repoIndex.Save(TwitterModel.Instance(c.Name).CONTENT_INDEX, stubIndex);
                        }
                    }
                    catch { }
                }
                #endregion
            });

            Console.WriteLine("Waiting on all tasks to complete");
            Task.WaitAll(deleteTasks.ToArray());
        }
示例#5
0
        protected override void StoreInRepository(IEnumerable <Twitter.Tweet> tweets)
        {
            var start  = DateTime.Now.AddHours(-48);
            var dayTag = "_" + DateTime.Now.ToShortDateString();

            Func <Tweet, bool> where = t =>
                                       t != null &&
                                       //Should everything be displayed or do you only want content
                                       (User.OnlyTweetsWithLinks == false || (t.Links != null && t.Links.Count > 0)) &&
                                       //Minumum threshold applied so we get results worth seeing (if it is your own tweet it gets a pass on this step)
                                       ((t.RetweetCount > User.RetweetThreshold || t.User.ScreenName.ToLower() == User.TwitterScreenName.ToLower()) &&
                                       //Apply Date Range
                                        (t.CreatedAt >= start));

            Tweets = Tweets.Union(tweets.Where(where)).OrderByDescending(x => x.TweetRank).Take(MAX_CONTENT).ToList();

            var groups = Tweets
                         //Group similar tweets
                         .GroupSimilar2()
                         //Convert groups into something we can display
                         .Select(g => new TweetGroup(g)
            {
                RepositoryKey = TwitterModel.Instance(User.TwitterScreenName).CONTENT
            })
                         //Order by TweetRank
                         .OrderByDescending(g => g.TweetRank)
                         //Only the top content
                         .Take(MAX_CONTENT);

            Task <List <ArticleStub> > contentTask = null;
            Task continueTask = null;

            if (groups != null && groups.Count() > 0)
            {
                //Get Standard Deviation
                double stdev  = 0;
                var    values = groups.Select(x => x.TweetRank);
                double avg    = values.Average();
                stdev = Math.Sqrt(values.Sum(d => (d - avg) * (d - avg)) / values.Count());

                //Filter groups that are way high...
                //groups = groups.Where(x => x.TweetRank < (avg + stdev));

                var results = groups.OrderByDescending(x => x.TweetRank).ToList();
                contentTask  = CreateContent(results, Page);
                continueTask = contentTask.ContinueWith(task => {
                    if (task.Result.Count >= 25)
                    {
                        var key = TwitterModel.Instance(screenName).CONTENT.ToLower();
                        Page    = new ArticleStubPage(1, task.Result.Take(100));

                        repoPage.Delete(key);
                        repoPage.Save(key, Page);

                        repoPage.Delete(key + dayTag);
                        repoPage.Save(key + dayTag, Page);

                        var articleStubIndex = repoIndex.Query(TwitterModel.Instance(screenName).CONTENT_INDEX).FirstOrDefault() ?? new ArticleStubIndex();
                        var day = DateTime.Now.StartOfDay();
                        if (articleStubIndex.ArticleStubPages.Where(x => x.Key == day.ToFileTimeUtc()).Count() == 0)
                        {
                            articleStubIndex.ArticleStubPages.Add(new KeyValuePair <long, string>(day.ToFileTimeUtc(), day.ToShortDateString()));
                            repoIndex.Save(TwitterModel.Instance(screenName).CONTENT_INDEX, articleStubIndex);
                        }
                    }
                });
            }

            base.StoreInRepository(tweets);

            if (contentTask != null && contentTask != null)
            {
                Task.WaitAll(contentTask, continueTask);
            }
        }
 public virtual void Delete <T>(T data) where T : class, new()
 {
     dataRespository.Delete <T>(data);
 }
示例#7
0
        static void Main(string[] args)
        {
            var connectionString = ConfigurationManager.AppSettings["AzureStorageConnectionString"];
            if (string.IsNullOrEmpty(connectionString))
                throw new Exception("Config Section 'appSettings' missing AzureStorageConnectionString value!");

            var storageAccount = CloudStorageAccount.Parse(connectionString);
            var blobClient = storageAccount.CreateCloudBlobClient();

            var deleteTasks = new List<Task>(10000000);

            Action<Task> delete = t =>
            {
                lock (deleteTasks)
                {
                    deleteTasks.Add(t);
                }
                Console.Clear();
                Console.WriteLine("Deleting " + deleteTasks.Count + " items");
            };

            var version = TwitterModel.VERSION;

            bool content = args.Any(a => a.ToLower() == "content");
            bool cleanVersion = args.Any(a => a.ToLower() == "version");
            bool shrink = args.Any(a => a.ToLower().StartsWith("shrink"));
            int newSize = args.Where(a => a.ToLower().StartsWith("shrink")).Select(x => x == "shrink" ? 500 : int.Parse(x.Replace("shrink", ""))).FirstOrDefault();

            blobClient.ListContainers()
                //.Skip(1) //Short circuit for testing
                //.Take(1) //Short circuit for testing
                .ToList().AsParallel().ForAll(c =>
            {
                #region Index Cleanup
                var index = c.GetDirectoryReference("Index");
                foreach (var b in index.ListBlobs().Where(x => x is CloudBlockBlob).Cast<CloudBlockBlob>())
                {
                    if (cleanVersion && !b.Name.Contains(version))
                    {
                        //Delete Index
                        var i = c.GetBlockBlobReference(b.Name);
                        delete(i.DeleteIfExistsAsync());

                        //Delete all Tweets
                        var d = c.GetDirectoryReference(b.Name.Split('/').Last());
                        foreach (var t in d.ListBlobs().Where(x => x is CloudBlockBlob).Cast<CloudBlockBlob>())
                        {
                            delete(t.DeleteIfExistsAsync());
                        }
                    }

                    if (shrink && newSize > 0 && b.Name.Contains(version))
                    {
                        //Get Storage Index
                        var i = c.GetBlockBlobReference(b.Name);
                        var storageIndex =  Newtonsoft.Json.JsonConvert.DeserializeObject<StorageEntityIndex>(DownloadBlob(i));

                        if (storageIndex.EntityKeys.Count > newSize)
                        {
                            //Delete extra Tweets
                            var d = c.GetDirectoryReference(b.Name.Split('/').Last());
                            foreach (var t in d.ListBlobs().Where(x => x is CloudBlockBlob).Cast<CloudBlockBlob>().OrderByDescending(x => x.Properties.LastModified).Skip(newSize))
                            {
                                storageIndex.EntityKeys.Remove(t.Name.Split('/').Last());
                                delete(t.DeleteIfExistsAsync());
                            }

                            //Update Storage Index
                            UploadBlob(i, storageIndex);
                        }
                    }
                }
                #endregion

                #region Content Cleanup
                if (content)
                {
                    try
                    {
                        var repoIndex = new SimpleRepository<ArticleStubIndex>(c.Name);
                        var repoPage = new SimpleRepository<ArticleStubPage>(c.Name);
                        var stubIndex = repoIndex.Query(TwitterModel.Instance(c.Name).CONTENT_INDEX).FirstOrDefault();
                        if (stubIndex != null)
                        {
                            var remove = new List<KeyValuePair<long, string>>();
                            for (var i = stubIndex.ArticleStubPages.Count - 31; i > -1 && i < stubIndex.ArticleStubPages.Count; i++) // Only the last month(ish)
                            {
                                var si = stubIndex.ArticleStubPages[i];
                                var page = repoPage.Query(TwitterModel.Instance(c.Name).CONTENT + "_" + si.Value).FirstOrDefault();
                                if (page.ArticleStubs == null || page.ArticleStubs.Count == 0)
                                {
                                    repoPage.Delete(TwitterModel.Instance(c.Name).CONTENT + "_" + si.Value);
                                    remove.Add(si);
                                }
                            }
                            remove.ForEach(x => stubIndex.ArticleStubPages.Remove(x));
                            repoIndex.Save(TwitterModel.Instance(c.Name).CONTENT_INDEX, stubIndex);
                        }
                    }
                    catch { }
                }
                #endregion
            });

            Console.WriteLine("Waiting on all tasks to complete");
            Task.WaitAll(deleteTasks.ToArray());
        }
示例#8
0
        static void Main(string[] args)
        {
            if (!EnsureSingleLoad())
            {
                Console.WriteLine("{0}: Another Instance Currently Running", DateTime.Now);
                return;
            }

            var start = DateTime.Now;

            Console.WriteLine("{0}: Started", start);

            var users = UsersCollection.PrimaryUsers() ?? new List <PostworthyUser>();

            var tasks = new List <Task>();

            users.AsParallel().ForAll(u =>
            {
                var tweet     = "";
                var repoIndex = new SimpleRepository <ArticleStubIndex>(u.TwitterScreenName);
                var repoPage  = new SimpleRepository <ArticleStubPage>(u.TwitterScreenName);
                ArticleStubIndex articleStubIndex = null;
                string dayTag = "";
                DateTime day  = DateTime.MinValue;
                if (args.Length > 0)
                {
                    if (DateTime.TryParse(args[0], out day))
                    {
                        day = day.StartOfDay();

                        dayTag           = "_" + day.ToShortDateString();
                        articleStubIndex = repoIndex.Query(TwitterModel.Instance(u.TwitterScreenName).CONTENT_INDEX).FirstOrDefault() ?? new ArticleStubIndex();
                        if (articleStubIndex.ArticleStubPages.Where(x => x.Key == day.ToFileTimeUtc()).Count() == 0)
                        {
                            articleStubIndex.ArticleStubPages.Add(new KeyValuePair <long, string>(day.ToFileTimeUtc(), day.ToShortDateString()));
                        }
                        else
                        {
                            articleStubIndex = null;
                        }
                    }
                }
                else
                {
                    articleStubIndex = repoIndex.Query(TwitterModel.Instance(u.TwitterScreenName).CONTENT_INDEX).FirstOrDefault() ?? new ArticleStubIndex();
                    day = DateTime.Now.AddDays(-1);
                    day = day.StartOfDay();
                    if (articleStubIndex.ArticleStubPages.Where(x => x.Key == day.ToFileTimeUtc()).Count() == 0)
                    {
                        dayTag = "_" + day.ToShortDateString();
                        articleStubIndex.ArticleStubPages.Add(new KeyValuePair <long, string>(day.ToFileTimeUtc(), day.ToShortDateString()));
                        var domain = u.PrimaryDomains.OrderBy(x => x.Length).FirstOrDefault();
                        if (!string.IsNullOrEmpty(domain) && !domain.StartsWith("beta"))
                        {
                            tweet = "Here are the top articles from " + day.ToShortDateString().Replace('/', '-') + " http://" + domain + "/" + day.ToShortDateString().Replace('/', '-');
                        }
                    }
                    else
                    {
                        articleStubIndex = null;
                        day    = DateTime.MinValue;
                        dayTag = "";
                    }
                }


                var groupingResults = CreateGroups(u, day == DateTime.MinValue ? null : (DateTime?)day);
                var existing        = repoPage.Query(TwitterModel.Instance(u.TwitterScreenName).CONTENT + dayTag).FirstOrDefault();
                var contentTask     = CreateContent(u, groupingResults, existing);
                Console.WriteLine("{0}: Waiting on content for {1}", DateTime.Now, u.TwitterScreenName);
                var continueTask = contentTask.ContinueWith(task =>
                {
                    Console.WriteLine("{0}: Content completed for {1}", DateTime.Now, u.TwitterScreenName);
                    var stubs = task.Result.Take(MAX_CONTENT);
                    if (stubs.Count() > 0 || !string.IsNullOrEmpty(dayTag))
                    {
                        var articleStubPage = new ArticleStubPage(1, stubs);

                        if (existing != null && existing.ExcludedArticleStubs.Count > 0)
                        {
                            articleStubPage.ExcludedArticleStubs = existing.ExcludedArticleStubs.Where(e => articleStubPage.ArticleStubs.Contains(e)).ToList();
                        }

                        Console.WriteLine("{0}: Deleting old data from files from storage for {1}", DateTime.Now, u.TwitterScreenName);
                        repoPage.Delete(TwitterModel.Instance(u.TwitterScreenName).CONTENT + dayTag);

                        Console.WriteLine("{0}: Storing data in repository for {1}", DateTime.Now, u.TwitterScreenName);
                        repoPage.Save(TwitterModel.Instance(u.TwitterScreenName).CONTENT + dayTag, articleStubPage);

                        if (articleStubIndex != null)
                        {
                            repoIndex.Save(TwitterModel.Instance(u.TwitterScreenName).CONTENT_INDEX, articleStubIndex);
                        }

                        if (!string.IsNullOrEmpty(tweet))
                        {
                            try
                            {
                                TwitterModel.Instance(u.TwitterScreenName).UpdateStatus(tweet, processStatus: false);
                            }
                            catch (Exception ex) { Console.WriteLine("{0}: Could not tweet message: {1}" + Environment.NewLine + "The following exception was thrown: {2}", DateTime.Now, tweet, ex.ToString()); }
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0}: No articles found for {1}", DateTime.Now, u.TwitterScreenName);
                    }
                });
                tasks.Add(contentTask);
                tasks.Add(continueTask);
            });

            Task.WaitAll(tasks.ToArray());

            var end = DateTime.Now;

            Console.WriteLine("{0}: Ending and it took {1} minutes to complete", end, (end - start).TotalMinutes);
        }
示例#9
0
 public int DeleteCalendar(int Id, string uId)
 {
     return(_rep.Delete <Calendar>(Id));
 }
示例#10
0
        static void Main(string[] args)
        {
            var loss = 0;

            EGT_OTA.Models.Repository.UpdateDB();
            SimpleRepository db = Repository.GetRepo();

            try
            {
                var CurrDatabase = Tools.SafeString(System.Web.Configuration.WebConfigurationManager.AppSettings["CurrDatabase"]);

                Console.WriteLine("正在运行");

                var music01 = new List <Music01>();
                var music02 = new List <Music02>();
                var music03 = new List <Music03>();
                var music04 = new List <Music04>();
                var music05 = new List <Music05>();
                var music06 = new List <Music06>();
                var music07 = new List <Music07>();
                var music08 = new List <Music08>();
                var music09 = new List <Music09>();
                var music10 = new List <Music10>();
                var music11 = new List <Music11>();
                var music12 = new List <Music12>();
                var music13 = new List <Music13>();

                Console.WriteLine("读取Music01");

                if (CurrDatabase.Contains(",1,"))
                {
                    music01 = db.All <Music01>().ToList();
                    music01.ForEach(x =>
                    {
                        x.DataBaseNumber = 1;
                    });
                }

                Console.WriteLine("读取Music02");

                if (CurrDatabase.Contains(",2,"))
                {
                    music02 = db.All <Music02>().ToList();
                    music02.ForEach(x =>
                    {
                        x.DataBaseNumber = 2;
                    });
                }

                Console.WriteLine("读取Music03");

                if (CurrDatabase.Contains(",3,"))
                {
                    music03 = db.All <Music03>().ToList();
                    music03.ForEach(x =>
                    {
                        x.DataBaseNumber = 3;
                    });
                }

                Console.WriteLine("读取Music04");

                if (CurrDatabase.Contains(",4,"))
                {
                    music04 = db.All <Music04>().ToList();
                    music04.ForEach(x =>
                    {
                        x.DataBaseNumber = 4;
                    });
                }

                Console.WriteLine("读取Music05");

                if (CurrDatabase.Contains(",5,"))
                {
                    music05 = db.All <Music05>().ToList();
                    music05.ForEach(x =>
                    {
                        x.DataBaseNumber = 5;
                    });
                }

                Console.WriteLine("读取Music06");

                if (CurrDatabase.Contains(",6,"))
                {
                    music06 = db.All <Music06>().ToList();
                    music06.ForEach(x =>
                    {
                        x.DataBaseNumber = 6;
                    });
                }

                Console.WriteLine("读取Music07");

                if (CurrDatabase.Contains(",7,"))
                {
                    music07 = db.All <Music07>().ToList();
                    music07.ForEach(x =>
                    {
                        x.DataBaseNumber = 7;
                    });
                }

                Console.WriteLine("读取Music08");

                if (CurrDatabase.Contains(",8,"))
                {
                    music08 = db.All <Music08>().ToList();
                    music08.ForEach(x =>
                    {
                        x.DataBaseNumber = 8;
                    });
                }

                Console.WriteLine("读取Music09");

                if (CurrDatabase.Contains(",9,"))
                {
                    music09 = db.All <Music09>().ToList();
                    music09.ForEach(x =>
                    {
                        x.DataBaseNumber = 9;
                    });
                }

                Console.WriteLine("读取Music10");

                if (CurrDatabase.Contains(",10,"))
                {
                    music10 = db.All <Music10>().ToList();
                    music10.ForEach(x =>
                    {
                        x.DataBaseNumber = 10;
                    });
                }

                Console.WriteLine("读取Music11");

                if (CurrDatabase.Contains(",11,"))
                {
                    music11 = db.All <Music11>().ToList();
                    music11.ForEach(x =>
                    {
                        x.DataBaseNumber = 11;
                    });
                }

                Console.WriteLine("读取Music12");

                if (CurrDatabase.Contains(",12,"))
                {
                    music12 = db.All <Music12>().ToList();
                    music12.ForEach(x =>
                    {
                        x.DataBaseNumber = 12;
                    });
                }

                Console.WriteLine("读取Music13");

                if (CurrDatabase.Contains(",13,"))
                {
                    music13 = db.All <Music13>().ToList();
                    music13.ForEach(x =>
                    {
                        x.DataBaseNumber = 13;
                    });
                }

                var list = new List <Music>();
                list.AddRange(music01);
                list.AddRange(music02);
                list.AddRange(music03);
                list.AddRange(music04);
                list.AddRange(music05);
                list.AddRange(music06);
                list.AddRange(music07);
                list.AddRange(music08);
                list.AddRange(music09);
                list.AddRange(music10);
                list.AddRange(music11);
                list.AddRange(music12);
                list.AddRange(music13);

                var LineCount = Tools.SafeInt(System.Web.Configuration.WebConfigurationManager.AppSettings["LineCount"]);


                for (var i = 0; i < LineCount; i++)
                {
                    Thread thread = new Thread(delegate()
                    {
                        while (list.Count > 0)
                        {
                            lock (locker)
                            {
                                var model  = list[0];
                                var result = CheckFile(model);
                                if (!result)
                                {
                                    switch (model.DataBaseNumber)
                                    {
                                    case 1:
                                        db.Delete <Music01>(model.ID);
                                        break;

                                    case 2:
                                        db.Delete <Music02>(model.ID);
                                        break;

                                    case 3:
                                        db.Delete <Music03>(model.ID);
                                        break;

                                    case 4:
                                        db.Delete <Music04>(model.ID);
                                        break;

                                    case 5:
                                        db.Delete <Music05>(model.ID);
                                        break;

                                    case 6:
                                        db.Delete <Music06>(model.ID);
                                        break;

                                    case 7:
                                        db.Delete <Music07>(model.ID);
                                        break;

                                    case 8:
                                        db.Delete <Music08>(model.ID);
                                        break;

                                    case 9:
                                        db.Delete <Music09>(model.ID);
                                        break;

                                    case 10:
                                        db.Delete <Music10>(model.ID);
                                        break;

                                    case 11:
                                        db.Delete <Music11>(model.ID);
                                        break;

                                    case 12:
                                        db.Delete <Music12>(model.ID);
                                        break;

                                    case 13:
                                        db.Delete <Music13>(model.ID);
                                        break;

                                    default:
                                        break;
                                    }

                                    loss++;
                                }
                                list.RemoveAt(0);
                            }
                            Thread.Sleep(1000);
                        }
                    });
                    thread.IsBackground = true;
                    thread.Name         = "过滤音乐接口线程" + i;
                    thread.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
示例#11
0
        static void Main(string[] args)
        {
            if (!EnsureSingleLoad())
            {
                Console.WriteLine("{0}: Another Instance Currently Running", DateTime.Now);
                return;
            }

            var start = DateTime.Now;
            Console.WriteLine("{0}: Started", start);

            var users = UsersCollection.PrimaryUsers() ?? new List<PostworthyUser>();

            var tasks = new List<Task>();

            users.AsParallel().ForAll(u =>
            {
                var tweet = "";
                var repoIndex = new SimpleRepository<ArticleStubIndex>(u.TwitterScreenName);
                var repoPage = new SimpleRepository<ArticleStubPage>(u.TwitterScreenName);
                ArticleStubIndex articleStubIndex = null;
                string dayTag = "";
                DateTime day = DateTime.MinValue;
                if (args.Length > 0)
                {
                    if (DateTime.TryParse(args[0], out day))
                    {
                        day = day.StartOfDay();

                        dayTag = "_" + day.ToShortDateString();
                        articleStubIndex = repoIndex.Query(TwitterModel.Instance(u.TwitterScreenName).CONTENT_INDEX).FirstOrDefault() ?? new ArticleStubIndex();
                        if (articleStubIndex.ArticleStubPages.Where(x => x.Key == day.ToFileTimeUtc()).Count() == 0)
                            articleStubIndex.ArticleStubPages.Add(new KeyValuePair<long, string>(day.ToFileTimeUtc(), day.ToShortDateString()));
                        else
                            articleStubIndex = null;
                    }
                }
                else
                {
                    articleStubIndex = repoIndex.Query(TwitterModel.Instance(u.TwitterScreenName).CONTENT_INDEX).FirstOrDefault() ?? new ArticleStubIndex();
                    day = DateTime.Now.AddDays(-1);
                    day = day.StartOfDay();
                    if (articleStubIndex.ArticleStubPages.Where(x => x.Key == day.ToFileTimeUtc()).Count() == 0)
                    {
                        dayTag = "_" + day.ToShortDateString();
                        articleStubIndex.ArticleStubPages.Add(new KeyValuePair<long, string>(day.ToFileTimeUtc(), day.ToShortDateString()));
                        var domain = u.PrimaryDomains.OrderBy(x => x.Length).FirstOrDefault();
                        if (!string.IsNullOrEmpty(domain) && !domain.StartsWith("beta"))
                            tweet = "Here are the top articles from " + day.ToShortDateString().Replace('/', '-') + " http://" + domain + "/" + day.ToShortDateString().Replace('/', '-');
                    }
                    else
                    {
                        articleStubIndex = null;
                        day = DateTime.MinValue;
                        dayTag = "";
                    }
                }


                var groupingResults = CreateGroups(u, day == DateTime.MinValue ? null : (DateTime?)day);
                var existing = repoPage.Query(TwitterModel.Instance(u.TwitterScreenName).CONTENT + dayTag).FirstOrDefault();
                var contentTask = CreateContent(u, groupingResults, existing);
                Console.WriteLine("{0}: Waiting on content for {1}", DateTime.Now, u.TwitterScreenName);
                var continueTask = contentTask.ContinueWith(task =>
                {
                    Console.WriteLine("{0}: Content completed for {1}", DateTime.Now, u.TwitterScreenName);
                    var stubs = task.Result.Take(MAX_CONTENT);
                    if (stubs.Count() > 0 || !string.IsNullOrEmpty(dayTag))
                    {
                        var articleStubPage = new ArticleStubPage(1, stubs);

                        if (existing != null && existing.ExcludedArticleStubs.Count > 0)
                        {
                            articleStubPage.ExcludedArticleStubs = existing.ExcludedArticleStubs.Where(e => articleStubPage.ArticleStubs.Contains(e)).ToList();
                        }

                        Console.WriteLine("{0}: Deleting old data from files from storage for {1}", DateTime.Now, u.TwitterScreenName);
                        repoPage.Delete(TwitterModel.Instance(u.TwitterScreenName).CONTENT + dayTag);

                        Console.WriteLine("{0}: Storing data in repository for {1}", DateTime.Now, u.TwitterScreenName);
                        repoPage.Save(TwitterModel.Instance(u.TwitterScreenName).CONTENT + dayTag, articleStubPage);

                        if (articleStubIndex != null)
                            repoIndex.Save(TwitterModel.Instance(u.TwitterScreenName).CONTENT_INDEX, articleStubIndex);

                        if (!string.IsNullOrEmpty(tweet))
                        {
                            try
                            {
                                TwitterModel.Instance(u.TwitterScreenName).UpdateStatus(tweet, processStatus: false);
                            }
                            catch(Exception ex) { Console.WriteLine("{0}: Could not tweet message: {1}" + Environment.NewLine + "The following exception was thrown: {2}", DateTime.Now, tweet, ex.ToString()); }
                        }
                    }
                    else
                        Console.WriteLine("{0}: No articles found for {1}", DateTime.Now, u.TwitterScreenName);
                });
                tasks.Add(contentTask);
                tasks.Add(continueTask);
            });

            Task.WaitAll(tasks.ToArray());

            var end = DateTime.Now;
            Console.WriteLine("{0}: Ending and it took {1} minutes to complete", end, (end - start).TotalMinutes);
        }