public bool CheckNormalDocuments(RequestObject requestObject, SyncDetails syncDetails) { ClientContext clientContext = null; bool response = false; try { if (null != requestObject && null != syncDetails && ValidationHelperFunctions.CheckRequestValidatorToken()) { string usersMySite = BriefcaseHelperFunction.GetPersonalURL(requestObject); if (!string.IsNullOrEmpty(usersMySite)) { using (clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(usersMySite), requestObject.RefreshToken)) { List <string> sourceURL = BriefcaseHelperFunction.CheckSourceURL(clientContext, syncDetails, 1); if (0 == sourceURL.Count) { response = true; } } } } } catch (Exception exception) { Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } return(response); }
private async Task <SyncDetails> UpdateSyncDetailsAsync(SyncDetails syncDetails, int studioId, int pageIndex) { if (syncDetails == null) { syncDetails = new SyncDetails { Studio = new Domain.Entities.Studio { StudioId = studioId } }; } syncDetails.LastSyncDate = DateTime.UtcNow; syncDetails.LastSyncPage = pageIndex; if (syncDetails.SyncDetailsId == 0) { var saved = await _syncDetailsRepository.AddAsync(syncDetails); syncDetails.SyncDetailsId = saved.SyncDetailsId; } else { await _syncDetailsRepository.UpdateAsync(syncDetails); } return(syncDetails); }
public async Task <SyncDetails> AddAsync(SyncDetails syncDetails) { var entity = _mapper.Map <Binding.Models.SyncDetails>(syncDetails); Add(entity); await SaveChangesAsync(); return(_mapper.Map <SyncDetails>(entity)); }
public async Task <SyncDetails> UpdateAsync(SyncDetails syncDetails) { var entity = await FindAsync(e => e.SyncDetailsId == syncDetails.SyncDetailsId); entity = _mapper.Map(syncDetails, entity); var result = Context.Set <Binding.Models.SyncDetails>().Update(entity); await SaveChangesAsync(); return(_mapper.Map <SyncDetails>(result.Entity)); }
public string SyncBriefcase(RequestObject requestObject, SyncDetails syncDetails) { CommonResponse commonResponse = new CommonResponse(); try { if (null != requestObject && null != syncDetails && ValidationHelperFunctions.CheckRequestValidatorToken()) { string usersMySite = string.Empty; ClientContext clientContext = null; usersMySite = BriefcaseHelperFunction.GetPersonalURL(requestObject); if (!string.IsNullOrEmpty(usersMySite)) { using (clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(usersMySite), requestObject.RefreshToken)) { string status = string.Empty; List <string> sourceURL = BriefcaseHelperFunction.CheckSourceURL(clientContext, syncDetails, 1); if (sourceURL.Count != 0) { return(BriefcaseHelperFunction.GetNotSupportedMessage(sourceURL)); } GetContextInList(requestObject, syncDetails, ref commonResponse, clientContext, ref status); } } else { commonResponse.ErrorMessage = ServiceConstantStrings.UserMySiteNotPresent; } } else { commonResponse.Status.Add(false); commonResponse.ErrorMessage = TextConstants.InvalidParametersMessage; } } catch (Exception exception) { commonResponse.Status.Add(false); commonResponse.ErrorMessage = ServiceUtility.RemoveEscapeCharacter(exception.Message); } return(BriefcaseHelperFunction.GetSerializeResponse(commonResponse)); }
/// <summary> /// Returns a list of source URL based on type of briefcase operation. /// </summary> /// <param name="clientContext">Client Context object</param> /// <param name="syncDetails">SyncDetails object</param> /// <param name="operationType">Indicates the type of operation to be performed</param> /// <returns>List of Source URLs</returns> internal static List <string> CheckSourceURL(ClientContext clientContext, SyncDetails syncDetails, int operationType) { List <string> sourceURL = new List <string>(); try { foreach (int itemid in syncDetails.ItemId) { string briefcaseItemQuery = string.Format(CultureInfo.InvariantCulture, ServiceConstantStrings.BriefCaseItemsQuery, itemid); ListItemCollection listItems = Lists.GetData(clientContext, ServiceConstantStrings.OneDriveDocumentLibraryTitle, briefcaseItemQuery); clientContext.Load(listItems); clientContext.ExecuteQuery(); foreach (var listitem in listItems) { switch (operationType) { case 1: if (string.IsNullOrEmpty(Convert.ToString(listitem[ServiceConstantStrings.OneDriveSiteColumn], CultureInfo.InvariantCulture))) { sourceURL.Add(Convert.ToString(listitem[ServiceConstantStrings.ColumnNameFileLeafRef], CultureInfo.InvariantCulture)); } break; case 2: sourceURL.Add(Convert.ToString(listitem[ServiceConstantStrings.OneDriveSiteColumn], CultureInfo.InvariantCulture)); break; case 3: sourceURL.Add(Convert.ToString(listitem[ServiceConstantStrings.ColumnNameFileRef], CultureInfo.InvariantCulture)); break; } } } } catch (Exception exception) { Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); sourceURL.Add(ServiceUtility.RemoveEscapeCharacter(exception.Message)); } return(sourceURL); }
public async Task <SyncDetails> UpdateAsync(SyncDetails syncDetails) { var entity = await Context.Set <Binding.Models.SyncDetails>().FirstOrDefaultAsync(e => e.StudioId == syncDetails.Studio.StudioId); EntityEntry result; if (entity == null) { entity = _mapper.Map <Binding.Models.SyncDetails>(syncDetails); result = Context.Set <Binding.Models.SyncDetails>().Add(entity); } else { entity = _mapper.Map(syncDetails, entity); result = Context.Set <Binding.Models.SyncDetails>().Update(entity); } await SaveChangesAsync(); return(_mapper.Map <SyncDetails>(result.Entity)); }
/// <summary> /// Helper function to perform Check Out, Detach, and Update document functionality. /// </summary> /// <param name="requestObject">The Web request object.</param> /// <param name="syncDetails">SyncDetails object</param> /// <param name="commonResponse">Holds response for briefcase detach operation</param> /// <param name="clientContext">Client context object for connection between SP & client</param> /// <param name="status">Sets status for send to briefcase operation</param> private void GetContextInList(RequestObject requestObject, SyncDetails syncDetails, ref CommonResponse commonResponse, ClientContext clientContext, ref string status) { List list = clientContext.Web.Lists.GetById(new Guid(syncDetails.ListId)); foreach (int itemid in syncDetails.ItemId) { ListItemCollection listItems = BriefcaseHelperFunction.GetListItemCollection(clientContext, itemid); MailAttachmentDetails mailattachmentDetails = new MailAttachmentDetails(); ServiceConstantStrings.OperationTypes operationType = (ServiceConstantStrings.OperationTypes)syncDetails.Operation; if (operationType == ServiceConstantStrings.OperationTypes.Detach) { commonResponse = BriefcaseHelperFunction.DetachOperation(commonResponse, clientContext, list, listItems); } else { foreach (var listItem in listItems) { mailattachmentDetails.FullUrl = Convert.ToString(listItem[ServiceConstantStrings.OneDriveSiteColumn], CultureInfo.InvariantCulture); mailattachmentDetails.IsOverwrite = 1; } switch (operationType) { case ServiceConstantStrings.OperationTypes.Update: status = this.SendToBriefcase(requestObject, mailattachmentDetails, false); commonResponse = BriefcaseHelperFunction.UpdateOperationStatus(commonResponse, status); break; case ServiceConstantStrings.OperationTypes.Checkout: status = this.CheckOutDocument(requestObject, mailattachmentDetails); commonResponse = BriefcaseHelperFunction.CheckoutOperationStatus(commonResponse, status); commonResponse.Status.Add(Convert.ToBoolean(status.Split(',')[0], CultureInfo.InvariantCulture)); break; } } } }
public void UploadFile(RemoteFileInfo request) { FileInfo fi = new FileInfo(Path.Combine(request.FolderPath, request.Metadata.Uri)); if (!fi.Directory.Exists) { fi.Directory.Create(); } fi.Delete(); int chunkSize = 2048; byte[] buffer = new byte[chunkSize]; using (FileStream writeStream = new FileStream(fi.FullName, FileMode.CreateNew, FileAccess.Write)) { do { // read bytes from input stream int bytesRead = request.FileByteStream.Read(buffer, 0, chunkSize); if (bytesRead == 0) { break; } // write bytes to output stream writeStream.Write(buffer, 0, bytesRead); } while (true); writeStream.Close(); // fi.LastWriteTimeUtc; } using (SyncDetails sync = new SyncDetails(request.FolderPath)) { sync.UpdateItemItem(request.Metadata); } }
public string GetVersion(RequestObject requestObject, SyncDetails syncDetails) { string response = string.Empty; VersionDetails versionDetails = new VersionDetails(); try { if (null != requestObject && null != syncDetails && ValidationHelperFunctions.CheckRequestValidatorToken()) { versionDetails.Status = false; ClientContext clientContext = null; string usersMySite = BriefcaseHelperFunction.GetPersonalURL(requestObject); if (!string.IsNullOrEmpty(usersMySite)) { using (clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(usersMySite), requestObject.RefreshToken)) { List <string> sourceURL = BriefcaseHelperFunction.CheckSourceURL(clientContext, syncDetails, 1); if (sourceURL.Count != 0) { return(BriefcaseHelperFunction.GetNotSupportedMessage(sourceURL)); } sourceURL = BriefcaseHelperFunction.CheckSourceURL(clientContext, syncDetails, 2); List <string> relativeURLList = BriefcaseHelperFunction.CheckSourceURL(clientContext, syncDetails, 3); versionDetails.RelativeURL = relativeURLList; for (int iterator = 0; iterator < sourceURL.Count; iterator++) { string url = sourceURL[iterator]; string relativeURL = Convert.ToString(url.Split(Convert.ToChar(ConstantStrings.DOLLAR, CultureInfo.InvariantCulture))[1], CultureInfo.InvariantCulture); using (clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(url.Split(Convert.ToChar(ConstantStrings.DOLLAR, CultureInfo.InvariantCulture))[0]), requestObject.RefreshToken)) { Microsoft.SharePoint.Client.File file = clientContext.Web.GetFileByServerRelativeUrl(relativeURL); string documentLibraryName = BriefcaseHelperFunction.getLibraryName(clientContext, file); List docLib = clientContext.Web.Lists.GetByTitle(documentLibraryName); clientContext.Load(docLib); clientContext.ExecuteQuery(); versionDetails.IsMajorVersion.Add(docLib.EnableVersioning); versionDetails.IsMinorVersion.Add(docLib.EnableMinorVersions); versionDetails.Status = true; if (versionDetails.IsMajorVersion[iterator] || versionDetails.IsMinorVersion[iterator]) { versionDetails.CurrentMajorVersion.Add(Convert.ToString(file.MajorVersion, CultureInfo.InvariantCulture)); if (file.CheckOutType != CheckOutType.None) { if (0 == file.MinorVersion) { versionDetails.CurrentMinorVersion.Add(Convert.ToString(file.MinorVersion, CultureInfo.InvariantCulture)); } else { int currentMinorVersion = file.MinorVersion - 1; versionDetails.CurrentMinorVersion.Add(Convert.ToString(currentMinorVersion, CultureInfo.InvariantCulture)); } clientContext.Load(file.CheckedOutByUser); clientContext.ExecuteQuery(); User user = clientContext.Web.CurrentUser; clientContext.Load(user); clientContext.ExecuteQuery(); if (user.Title == file.CheckedOutByUser.Title) { versionDetails.CheckOutStatus.Add(Convert.ToString(file.CheckedOutByUser.Title, CultureInfo.InvariantCulture)); } else { versionDetails.Status = false; versionDetails.ErrorMessage = ServiceConstantStrings.AlreadyCheckOut; } } else { versionDetails.CurrentMinorVersion.Add(Convert.ToString(file.MinorVersion, CultureInfo.InvariantCulture)); versionDetails.CheckOutStatus.Add(ConstantStrings.Space); } } } } } } else { versionDetails.ErrorMessage = ServiceConstantStrings.UserMySiteNotPresent; } } else { versionDetails.Status = false; versionDetails.ErrorMessage = TextConstants.MessageNoInputs; } } catch (Exception exception) { versionDetails.Status = false; versionDetails.ErrorMessage += ServiceUtility.RemoveEscapeCharacter(exception.Message); Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } response = BriefcaseHelperFunction.GetSerializeResponse(versionDetails); return(response); }
public void StoreKnowledgeForScope(string folderPath, SyncKnowledge knowledge, ForgottenKnowledge forgotten, string[] filters) { using (SyncDetails sync = new SyncDetails(folderPath, filters)) { sync.StoreKnowledgeForScope(knowledge, forgotten); } }
public void DeleteFile(string folderPath, SyncId itemID, string[] filters) { SyncDetails sync = new SyncDetails(folderPath, filters); sync.DeleteItem(itemID); }
public SyncKnowledge GetCurrentSyncKnowledge(string folderPath, string[] filters) { using (SyncDetails sync = new SyncDetails(folderPath, filters)) { return(sync.SyncKnowledge); } }
private async Task <SyncDetails> SaveAsync(ConcurrentDictionary <int, IEnumerable <Studios.StudioMovie> > buffer, SyncDetails syncDetails, int studioId) { var pages = buffer.OrderByDescending(e => e.Key).ToList(); if (pages.Any()) { var studioMovies = pages.SelectMany(e => e.Value.Reverse()); var moviesToSave = MapMovies(studioMovies, studioId); var saved = await _movieRepository.AddRangeAsync(moviesToSave); var first = pages.LastOrDefault(); syncDetails = await UpdateSyncDetailsAsync(syncDetails, studioId, first.Key); Console.WriteLine($"Synched ({buffer.Count} pages):\n\nLast sync page: {syncDetails.LastSyncPage}\n\nMovies saved: {saved.Count()}\n\n"); buffer.Clear(); } return(syncDetails); }
private async Task SyncMoviesAsync(IStudioClient studioClient, int startFrom, int studioId, SyncDetails syncDetails) { var buffer = new ConcurrentDictionary <int, IEnumerable <Studios.StudioMovie> >(); //await _concurrentActionHandler.ForAsync(async pageIndex => //{ // Console.WriteLine($"Retrieving {studioClient.StudioName}. Page {pageIndex}."); // var movies = await studioClient.GetMoviesAsync(pageIndex); // buffer.TryAdd(pageIndex, movies); //}, startFrom, 0, _syncConfiguration.MaxDegreeOfParallelism, async () => { syncDetails = await SaveAsync(buffer, syncDetails, studioId); }); }