public async Task <int> RefreshAllCommunityInfo() { SeashellContext context = new SeashellContext(); List <AdministrativeDistrict> districts = context.AdministrativeDistrict.ToList(); List <Community> communities = new List <Community>(); foreach (AdministrativeDistrict district in districts) { List <Community> communitiesByDistrict = await ReadAllCommunities(district.CommunityMainPageURL); communities = communities.Concat(communitiesByDistrict).ToList(); } communities = await ReadCommunityDetailInfo(communities); CommunityRepository repo = new CommunityRepository(context); repo.AddOrUpdate(communities); repo.Save(); return(communities.Count()); }
public async static Task HandleInformationCommand(SocketMessage message, CommunityRepository repository) { string originalMessage = message.Content; string[] splitMessage = originalMessage.Split(new char[] { ' ' }, 2); string stageName = splitMessage[1]; Stage stage = new Stage() { Name = stageName.ToLower(), }; if (!repository.StageExists(stage)) { string possibleStrings = repository.GetPossibleStageNames(stage.Name); if (possibleStrings != String.Empty) { string reply = String.Format("Failed to grab information for the stage \"{0}\" because it does not exist in the repository.\n\n Could you mean one of these?\n\n{1}", stageName, possibleStrings); await message.Channel.SendMessageAsync(reply); return; } string response = String.Format(@"Failed to grab information for the stage ""{0}"" because it does not exist in the community repository", stageName); await message.Channel.SendMessageAsync(response); return; } Stage foundStage = repository.GetStage(stage.Name); string reponse = String.Format("Information for stage {0}\n\nAuthor: {1}\n\nUpload Date: {2}\n\nDescription: {3}", foundStage.Name, foundStage.Author, foundStage.Date, foundStage.Description); await message.Channel.SendMessageAsync(reponse); }
public async static Task HandleSearchCommand(SocketMessage message, CommunityRepository repository) { string originalMessage = message.Content; string[] splitMessage = originalMessage.Split(new char[] { ' ' }, 2); string stageName = splitMessage[1]; Stage stage = new Stage() { Name = stageName.ToLower(), }; string possibleStrings = repository.GetPossibleStageNames(stage.Name); if (possibleStrings == String.Empty) { await message.Channel.SendMessageAsync("I did not found any stages matching your query :("); return; } string response = String.Format("Here are the stages that I have found that contains the search query \"{0}\" within the stage name.\n\n{1}", stageName, possibleStrings); await message.Channel.SendMessageAsync(response); return; }
public async static Task HandleGetCommand(SocketMessage message, CommunityRepository repository) { string originalMessage = message.Content; string[] splitMessage = originalMessage.Split(new char[] { ' ' }, 2); string stageName = splitMessage[1]; Stage stage = new Stage() { Name = stageName }; string filePath = repository.GetPathToStageInCommunityRepository(stage); if (filePath == String.Empty) { string reply = String.Format(@"Failed to find the stage ""{0}"". because it does not exist in the community repository. If you are not sure what you are looking for, use !search instead.", stageName); await message.Channel.SendMessageAsync(reply); return; } await message.Channel.SendMessageAsync("Uploading the stage now..."); string response = "Here is the requested stage that you asked for."; await message.Channel.SendFileAsync(filePath, response); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //=============================================== //==Repository config============================ var config = new ServerConfig(); Configuration.Bind(config); //_logger.LogInformation("config.MongoDB : " + config.MongoDB.ConnectionString); var cmnContext = new CommunityContext(config.MongoDB); var cmnRepo = new CommunityRepository(cmnContext); services.AddSingleton <ICommunityRepository>(cmnRepo); //==Seed config================================== var cmnSeeder = new CommunitySeeder(cmnRepo); services.AddSingleton <ISeed>(cmnSeeder); //==MVC========================================== services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); //===Auto Mapper Configurations================== var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MappingProfile()); }); IMapper mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); }
public void Setup() { _communityDao = Substitute.For <ICommunityDao>(); Func <HttpRequestMessage> fakeFunc = () => FakeHttpMessageBuilder.CreateFakeHttpMessage(); _modelFactory = new ModelFactory(new ObjectDifferenceManager(), fakeFunc); _communityRepo = new CommunityRepository(_communityDao, _modelFactory); _fixture = new Fixture(); }
public ProdutCommandHandler(IUnitOfWork unitOfWork, CommunityRepository domainRepository, // IEventBus eventBus, IMessageContext commandContext) { _UnitOfWork = unitOfWork; _DomainRepository = domainRepository; _CommandContext = commandContext; // _EventBus = eventBus; }
/// <summary> /// Initializes this instance. /// </summary> /// <param name="context">The instance context.</param> public void Initialize(InitializationEngine context) { var contentEvents = context.Locate.ContentEvents(); groupRepository = ServiceLocator.Current.GetInstance <CommunityRepository>(); moderationRepository = ServiceLocator.Current.GetInstance <CommunityMembershipModerationRepository>(); contentEvents.CreatingContent += SociaCommunityPage_CreationEvent; contentEvents.SavedContent += SociaCommunityPage_PublishedEvent; }
public CommunityCommandHandler(IUnitOfWork unitOfWork, CommunityRepository domainRepository, IEventBus eventBus, IMessageContext commandContext, IContainer container) { _UnitOfWork = unitOfWork; _DomainRepository = domainRepository; _CommandContext = commandContext; _EventBus = eventBus; _container = container; }
public async Task StartBot(string token) { Client = new DiscordSocketClient(); Client.MessageReceived += MessageReceived; const string COMMUNITY_REPOSITORY_FILE = "CommunityStages.json"; Repository = CommunityRepository.Load(COMMUNITY_REPOSITORY_FILE); await Client.LoginAsync(TokenType.Bot, token); await Client.StartAsync(); await Task.Delay(-1); }
public static async Task HandleAuthorCommand(SocketMessage message, CommunityRepository repository) { string originalMessage = message.Content; string[] splitMessages = originalMessage.Split(new char[] { ' ' }, 3); if (splitMessages.Length < 3) { await message.Channel.SendMessageAsync(@"You did not specify a stage name or author. Type in ""!help author"" if you need help."); return; } string author = splitMessages[1]; string stageName = splitMessages[2]; Stage stage = new Stage() { Name = stageName, Author = author, Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }; if (!repository.StageExists(stage)) { await message.Channel.SendMessageAsync(String.Format(@"Failed to update the author for the stage ""{0}"" because the stage does not exist in the community repository.", stageName)); return; } Stage oldStage = repository.GetStage(stage.Name); string messageAuthor = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()); if (oldStage.Author != messageAuthor) { await message.Channel.SendMessageAsync("Failed to update the author of the stage because you are not the author"); return; } repository.UpdateStage(oldStage, stage); await message.Channel.SendMessageAsync("Updating the author for the stage in the community repository now..."); string commitMessage = String.Format(@"Updated the author for the stage {0} from ""{1}"" to ""{2}"".", stageName, oldStage.Author, stage.Author); MainClass.UpdateGitHub(commitMessage); await message.Channel.SendMessageAsync("Successfully updated the author of the stage!"); }
private void RefreshDataView() { damnedDataView.Rows.Clear(); string link = "https://raw.githubusercontent.com/Sweats/Damned-Community-Stages/master/CommunityStages.json"; if (!(DamnedFiles.DownloadFile(link, JSON_FILE_NAME))) { MessageBox.Show("Failed to download the latest stages listing from the community repository. Do you have a valid internet connection?", "Failed To Update the Stage Listing", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } CommunityRepository repository = JsonConvert.DeserializeObject <CommunityRepository>(File.ReadAllText(JSON_FILE_NAME)); for (int i = 0; i < repository.Stages.Count; i++) { Stage stage = repository.Stages[i]; string stageToFind = String.Format("{0}.stage", stage.Name).Replace(" ", "_"); if (String.IsNullOrEmpty(stage.Description)) { stage.Description = "No description provided."; } if (String.IsNullOrEmpty(stage.Date)) { stage.Date = "Unknown upload date."; } if (damnedStages.StageExists(stageToFind)) { string[] newRow = new string[] { stage.Name, stage.Author, stage.Date, stage.Description, "Yes" }; int newIndex = damnedDataView.Rows.Add(newRow); damnedDataView.Rows[newIndex].ReadOnly = true; damnedDataView.Rows[newIndex].DefaultCellStyle.ForeColor = Color.FromArgb(255, 168, 38); } else { string[] newRow = new string[] { stage.Name, stage.Author, stage.Date, stage.Description, "No" }; int newIndex = damnedDataView.Rows.Add(newRow); damnedDataView.Rows[newIndex].ReadOnly = true; damnedDataView.Rows[newIndex].DefaultCellStyle.ForeColor = Color.White; } } File.Delete(JSON_FILE_NAME); }
public async Task <int> GetHistoryInfoForAllCommunities() { SeashellContext context = new SeashellContext(); List <Community> communities = context.Communities.ToList(); communities = await ReadCommunityDetailInfo(communities); CommunityRepository repo = new CommunityRepository(context); repo.AddOrUpdate(communities); repo.Save(); return(communities.Count()); }
public async static Task HandleRemoveCommand(SocketMessage message, CommunityRepository repository) { string originalMessage = message.Content; string[] splitMessage = originalMessage.Split(new char[] { ' ' }, 2); string stageName = splitMessage[1]; Stage stage = new Stage() { Name = stageName.ToLower(), Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()) }; if (!repository.StageExists(stage)) { string reply = String.Format(@"Failed to remove the stage ""{0}"" from the community repository because it does not exist", stageName); await message.Channel.SendMessageAsync(reply); return; } Stage repositoryStage = repository.GetStage(stage.Name); if (repositoryStage.Author.ToLower() != stage.Author.ToLower()) { string reply = String.Format(@"Failed to remove the stage ""{0}"" from the community repository because you are not the author for that stage.", stageName); await message.Channel.SendMessageAsync(reply); return; } await message.Channel.SendMessageAsync("Removing your stage from the community repository now..."); repository.RemoveStage(stage); string commitMessage = String.Format("Removed the stage {0} from the community repository", repositoryStage.Name); MainClass.UpdateGitHub(commitMessage); string response = String.Format(@"Successfully removed the stage ""{0}"" from the community repository!", stageName); await message.Channel.SendMessageAsync(response); }
private void Form1_Load(object sender, EventArgs e) { PositionRepository repo2 = new PositionRepository(); repo = new CommunityRepository(); Location locTest = new Location(); locTest.x = 1.635; locTest.y = 0; locTest.W1 = 27; locTest.W2 = 14; locTest.W3 = 7; repo2.CalculatePosition(locTest); communities = repo.GetCommunities(); foreach (var community in communities) { CommunityCmbx.DataSource = new BindingSource(communities, null); CommunityCmbx.DisplayMember = "Name"; CommunityCmbx.ValueMember = "ID"; //CommunityCmbx.Items.Add(community.Name); } }
public CommunityGateway(ApplicationContext context) { _communityRepository = new CommunityRepository(context); }
public static async Task <ResultsItem> VoteBBComment(int commentId, bool isUpvote, PegaUser user) { return(await CommunityRepository.VoteBBComment(commentId, isUpvote, user)); }
public static async Task <ResultsItem> VoteBBThread(int threadId, bool isUpvote, PegaUser user) { return(await CommunityRepository.VoteBBThread(threadId, isUpvote, user)); }
public static async Task <ResultsItem> DeleteBBComment(int commentId, PegaUser user) { return(await CommunityRepository.DeleteBBComment(commentId, user)); }
public static async Task <ResultsItem> CreateBBComment(BBComment comment, PegaUser user) { return(await CommunityRepository.CreateBBComment(comment, user)); }
public static async Task <ResultsItem> DeleteBBThread(int threadId, PegaUser user) { return(await CommunityRepository.DeleteBBThread(threadId, user)); }
public static async Task <ResultsItem> CreateBBThread(BBThread thread, PegaUser user) { return(await CommunityRepository.CreateBBThread(thread, user)); }
public static async Task <BBThread> GetThreadWithComments(int threadId, PegaUser user) { BBThread thread = await CommunityRepository.GetBBThreadWithComments(threadId, user); return(thread); }
public static async Task <List <BBThread> > GetMessageThreads(int take, List <Types.ConvThreadCategory> categories, PegaUser currentUser, int officialCoinId = 0) { List <BBThread> threads = await CommunityRepository.GetBBThreads(take, categories, currentUser, officialCoinId); return(threads); }
public void initialize() { com = new CommunityRepository(); }
public async static Task HandleUploadCommand(SocketMessage message, CommunityRepository repository) { var attachments = message.Attachments; if (attachments.Count == 0) { await message.Channel.SendMessageAsync("You did not attach a zip file to your message. Please try again."); return; } if (attachments.Count > 1) { await message.Channel.SendMessageAsync("Please upload only one stage package at a time."); return; } Attachment attachment = attachments.ElementAt(0); string oldFileName = attachment.Filename; bool changesMade = false; if (oldFileName.Contains("-") || oldFileName.Contains("_")) { changesMade = true; } string fileName = oldFileName.Replace("-", " ").Replace("_", " "); Stage stage = new Stage() { Name = Path.GetFileNameWithoutExtension(fileName), Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()), Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }; if (repository.StageExists(stage)) { string response = String.Format("This stage already exists in the community repository. If you are the author of the existing stage, please use !update instead to update your stage."); await message.Channel.SendMessageAsync(response); return; } string URL = attachment.Url; using (WebClient client = new WebClient()) { client.DownloadFile(new Uri(URL), fileName); } DamnedPackage package = new DamnedPackage(); await message.Channel.SendMessageAsync("Checking your stage archive now..."); if (!package.Check(fileName)) { string reason = package.reasonForFailedCheck; await message.Channel.SendMessageAsync(reason); Directory.Delete(package.tempDirectory, true); Directory.Delete(fileName); return; } await message.Channel.SendMessageAsync("Stage check successful! I am adding your stage into the community repository now..."); repository.AddStage(stage); string commitMessage = String.Format("Added in new stage {0} to the community repository", stage.Name); MainClass.UpdateGitHub(commitMessage); Directory.Delete(package.tempDirectory, true); if (changesMade) { string response = String.Format("Success! Your stage has been added into the community repository!\n\nBy the way, I have renamed your zip file from \"{0}\" to \"{1}.zip\" because it looks nicer and is slightly easier to search for", fileName, stage.Name); await message.Channel.SendMessageAsync(response); return; } await message.Channel.SendMessageAsync("Success! Your stage has been added into the community repository!"); }
public void TestInit() { IApplicationUnitOfWork unitOfWork = new DapperUnitOfWork(); ICommunityRepository communityReposity = new CommunityRepository(unitOfWork); _areaContract = new AreaService(unitOfWork, communityReposity); }
public async static Task HandleUpdateCommand(SocketMessage message, CommunityRepository repository) { var attachments = message.Attachments; if (attachments.Count == 0) { await message.Channel.SendMessageAsync("You did not upload a file for me to update in the community repository"); return; } if (attachments.Count > 1) { await message.Channel.SendMessageAsync("Please only send one file at a time."); return; } var attachment = message.Attachments.ElementAt(0); string stageName = Path.GetFileNameWithoutExtension(attachment.Filename).Replace("_", " ").Replace("-", " "); Stage stage = new Stage() { Name = stageName, Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()), Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }; if (!repository.StageExists(stage)) { await message.Channel.SendMessageAsync("Failed to update the stage because the stage does not exist in the community repository."); return; } Stage repositoryStage = repository.GetStage(stage.Name); if (stage.Author != repositoryStage.Author) { await message.Channel.SendMessageAsync("Failed to update the stage because you are not the author of the stage."); return; } string URL = attachment.Url; string fileName = attachment.Filename.Replace("_", " ").Replace("-", " "); int randomNumber = new Random().Next(); string damnedStageCheckerDirectoryName = String.Format("DamnedStageChecker_{0}", randomNumber); string tempArchive = Path.Combine(Path.GetTempPath(), damnedStageCheckerDirectoryName, fileName); string parentTempArchive = Path.Combine(Path.GetTempPath(), damnedStageCheckerDirectoryName); if (Directory.Exists(parentTempArchive)) { Directory.Delete(parentTempArchive, true); } Directory.CreateDirectory(parentTempArchive); using (WebClient client = new WebClient()) { client.DownloadFile(new Uri(URL), tempArchive); } DamnedPackage package = new DamnedPackage(); await message.Channel.SendMessageAsync("Checking your updated stage archive now..."); if (!package.Check(tempArchive)) { Directory.Delete(parentTempArchive, true); Directory.Delete(package.tempDirectory, true); await message.Channel.SendMessageAsync(package.reasonForFailedCheck); return; } await message.Channel.SendMessageAsync("Stage check successful! I am updating your stage in the community repository now..."); string oldFilePath = repository.GetPathToStageInCommunityRepository(repositoryStage); File.Delete(oldFilePath); File.Copy(tempArchive, fileName); Directory.Delete(parentTempArchive, true); Directory.Delete(package.tempDirectory, true); repository.UpdateStage(repositoryStage, stage); string commitMessage = String.Format("Updated the stage {0} in the community repository", stage.Name); MainClass.UpdateGitHub(commitMessage); await message.Channel.SendMessageAsync("Succcessfully updated your stage that is in the community repository!"); }
// Called once when the bot is started. public static CommunityRepository Load(string jsonFile) { CommunityRepository repository = JsonConvert.DeserializeObject <CommunityRepository>(File.ReadAllText(jsonFile)); return(repository); }
private CommunityService() { communityRepo = new CommunityRepository(); communitySocialRepo = new CommunitySocialRepository(); }