public ReadResult Read(object source, DataAccessContext context) { var dropboxRepository = new DropBoxRepository(); var response = dropboxRepository.GetFileStreamContent((DropBoxFile)source); return(new ReadResult(DateTime.UtcNow) { ReadValue = response, WasValueRead = true }); }
public ActionResult UploadImage(int contestId, HttpPostedFileBase image) { var authorName = this.UserProfile.UserName; var path = DropBoxRepository.Upload(image.FileName, authorName, image.InputStream); var photo = new Photo { Name = image.FileName, Path = path, AuthorId = this.UserProfile.Id, ContestId = contestId, DateAdded = DateTime.Now, }; this.Data.Photos.Add(photo); this.Data.SaveChanges(); return(this.RedirectToAction("Details", "Contests", new { id = contestId })); }
public ActionResult GetImage(int photoId) { var image = this.Data.Photos .All() .Include(x => x.Votes) .FirstOrDefault(x => x.Id == photoId); if (image == null) { return(HttpNotFound()); } var imageViewModel = Mapper.Map <PhotoViewModel>(image); if (this.User.Identity.IsAuthenticated) { imageViewModel.UserHasVoted = image.Votes.Any(x => x.UserId == this.UserProfile.Id); } imageViewModel.Url = DropBoxRepository.Download(imageViewModel.Path); return(this.PartialView("_GetImagePartial", imageViewModel)); }
protected override DropBoxFile ResolveObject(string identifierValue, Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext) { if (!this.CanProcess(pipelineStep, pipelineContext)) { return(null); } SynchronizationSettings synchronizationSettings = Sitecore.DataExchange.Extensions.PipelineContextExtensions.GetSynchronizationSettings(pipelineContext); var settings = pipelineStep.GetPlugin <DropboxSettings>(); var itemModel = synchronizationSettings.Source as ItemModel; var itemId = itemModel[ItemModel.ItemID]; var dropboxRepository = new DropBoxRepository(); var file = new DropBoxFile(new Metadata(), settings); DataAccessContext context = new DataAccessContext(); var resolveSettings = pipelineStep.GetPlugin <ResolveDropboxFileSettings>(); file.FileName = (string)resolveSettings.ItemNameValueAccessor.ValueReader.Read(synchronizationSettings.Source, context).ReadValue; var metaData = dropboxRepository.GetMetadata(file); if (metaData == null) { var customItemRepository = new CustomItemRepository(); file.FileStream = customItemRepository.GetMediaItemFileStream(itemModel); var result = dropboxRepository.Update(file).Result; return(file); } return(null); }
protected override void ReadData( Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext) { if (endpoint == null) { throw new ArgumentNullException(nameof(endpoint)); } if (pipelineStep == null) { throw new ArgumentNullException(nameof(pipelineStep)); } if (pipelineContext == null) { throw new ArgumentNullException(nameof(pipelineContext)); } var logger = pipelineContext.PipelineBatchContext.Logger; // //get the file path from the plugin on the endpoint var settings = endpoint.GetDropboxSettings(); if (settings == null) { return; } if (string.IsNullOrWhiteSpace(settings.ApplicationName)) { logger.Error( "No application name is specified on the endpoint. " + "(pipeline step: {0}, endpoint: {1})", pipelineStep.Name, endpoint.Name); return; } if (string.IsNullOrWhiteSpace(settings.AccessToken)) { logger.Error( "No access token name is specified on the endpoint. " + "(pipeline step: {0}, endpoint: {1})", pipelineStep.Name, endpoint.Name); return; } if (string.IsNullOrWhiteSpace(settings.RootPath)) { logger.Error( "No root path is specified on the endpoint. " + "(pipeline step: {0}, endpoint: {1})", pipelineStep.Name, endpoint.Name); return; } var dropboxRepository = new DropBoxRepository(); var dropboxFiles = dropboxRepository.ReadAll(settings); // //add the data that was read from the file to a plugin var dataSettings = new IterableDataSettings(dropboxFiles); logger.Info( "{0} rows were read from the file. (pipeline step: {1}, endpoint: {2})", dropboxFiles.Count(), pipelineStep.Name, endpoint.Name); SitecoreItemUtilities sitecoreItemUtility = new SitecoreItemUtilities() { IsItemNameValid = (string x) => ItemUtil.IsItemNameValid(x), ProposeValidItemName = (string x) => ItemUtil.ProposeValidItemName(x) }; Context.Plugins.Add(sitecoreItemUtility); //add the plugin to the pipeline context pipelineContext.Plugins.Add(dataSettings); }