private static void ProcessEdit(string fileId, TrackerData fileData) { if (ThirdPartySelector.GetAppByFileId(fileId) != null) { return; } var users = FileTracker.GetEditingBy(fileId); var usersDrop = new List <Guid>(); foreach (var user in fileData.Users) { Guid userId; if (!Guid.TryParse(user, out userId)) { Global.Logger.Error("DocService userId is not Guid: " + user); continue; } users.Remove(userId); try { var doc = FileShareLink.CreateKey(fileId); EntryManager.TrackEditing(fileId, userId, userId, doc); } catch (Exception e) { Global.Logger.DebugFormat("Drop command: fileId '{0}' docKey '{1}' for user {2} : {3}", fileId, fileData.Key, user, e.Message); usersDrop.Add(userId); } } if (usersDrop.Any()) { if (!DocumentServiceHelper.DropUser(fileData.Key, usersDrop, fileId)) { Global.Logger.Error("DocService drop failed for users " + string.Join(",", usersDrop)); } } foreach (var removeUserId in users) { FileTracker.Remove(fileId, userId: removeUserId); } Global.SocketManager.FilesChangeEditors(fileId); }
public static void ProcessData(string fileId, bool isNew, string trackDataString) { if (string.IsNullOrEmpty(trackDataString)) { throw new ArgumentException("DocService return null"); } var data = JObject.Parse(trackDataString); if (data == null) { throw new ArgumentException("DocService response is incorrect"); } var fileData = data.ToObject <TrackerData>(); Guid userId; switch (fileData.Status) { case TrackerStatus.NotFound: case TrackerStatus.Closed: FileTracker.Remove(fileId); break; case TrackerStatus.Editing: if (ThirdPartySelector.GetAppByFileId(fileId) != null) { break; } var users = FileTracker.GetEditingBy(fileId); var usersDrop = new List <string>(); foreach (var user in fileData.Users) { if (!Guid.TryParse(user, out userId)) { Global.Logger.Error("DocService userId is not Guid: " + user); continue; } users.Remove(userId); try { var shareLinkKey = FileShareLink.CreateKey(fileId); EntryManager.TrackEditing(fileId, userId, userId, isNew, shareLinkKey); } catch (Exception e) { Global.Logger.DebugFormat("Drop command: fileId '{0}' docKey '{1}' for user {2} : {3}", fileId, fileData.Key, user, e.Message); usersDrop.Add(user); } } if (usersDrop.Any()) { var dropString = "[\"" + string.Join("\",\"", usersDrop) + "\"]"; if (!Drop(fileData.Key, dropString, fileId)) { Global.Logger.Error("DocService drop failed for users " + dropString); } } foreach (var removeUserId in users) { FileTracker.Remove(fileId, userId: removeUserId); } break; case TrackerStatus.MustSave: case TrackerStatus.Corrupted: var comments = new List <string>(); if (fileData.Status == TrackerStatus.Corrupted) { comments.Add(FilesCommonResource.ErrorMassage_SaveCorrupted); } if (fileData.Users == null || fileData.Users.Count == 0 || !Guid.TryParse(fileData.Users[0], out userId)) { userId = FileTracker.GetEditingBy(fileId).FirstOrDefault(); } try { SecurityContext.AuthenticateMe(userId); } catch (Exception ex) { Global.Logger.Warn("DocService save error: anonymous author - " + userId, ex); if (!userId.Equals(ASC.Core.Configuration.Constants.Guest.ID)) { comments.Add(FilesCommonResource.ErrorMassage_SaveAnonymous); } } File file = null; var saved = false; if (string.IsNullOrEmpty(fileData.Url)) { try { comments.Add(FilesCommonResource.ErrorMassage_SaveUrlLost); FileTracker.Remove(fileId); file = EntryManager.CompleteVersionFile(fileId, 0, false, false); using (var fileDao = Global.DaoFactory.GetFileDao()) { fileDao.UpdateComment(file.ID, file.Version, string.Join("; ", comments)); } } catch (Exception ex) { Global.Logger.Error(string.Format("DocService save error. Version update. File id: '{0}'. UserId: {1}. DocKey '{2}'", fileId, userId, fileData.Key), ex); } } else { try { file = EntryManager.SaveEditing(fileId, -1, userId, fileData.Url, isNew, string.Empty, string.Join("; ", comments), false); saved = fileData.Status == TrackerStatus.MustSave; } catch (Exception ex) { Global.Logger.Error(string.Format("DocService save error. File id: '{0}'. UserId: {1}. DocKey '{2}'. DownloadUri: {3}", fileId, userId, fileData.Key, fileData.Url), ex); StoringFileAfterError(fileId, userId.ToString(), fileData.Url); } } if (file != null) { var user = CoreContext.UserManager.GetUsers(userId); if (user != null) { FilesMessageService.Send(file, MessageInitiator.DocsService, MessageAction.UserFileUpdated, user.DisplayUserName(false), file.Title); } SaveHistory(file, fileData.ChangesHistory, fileData.ChangesUrl); } FileTracker.Remove(fileId); Command(TrackMethod.Saved, fileData.Key, fileId, null, userId.ToString(), saved ? "1" : "0"); break; } }
private static void ProcessEdit(string fileId, TrackerData fileData) { if (ThirdPartySelector.GetAppByFileId(fileId) != null) { return; } var users = FileTracker.GetEditingBy(fileId); var usersDrop = new List <string>(); string docKey; var app = ThirdPartySelector.GetAppByFileId(fileId); if (app == null) { File fileStable; using (var fileDao = Global.DaoFactory.GetFileDao()) { fileStable = fileDao.GetFileStable(fileId); } docKey = DocumentServiceHelper.GetDocKey(fileStable); } else { docKey = fileData.Key; } if (!fileData.Key.Equals(docKey)) { Global.Logger.InfoFormat("DocService editing file {0} ({1}) with key {2} for {3}", fileId, docKey, fileData.Key, string.Join(", ", fileData.Users)); usersDrop = fileData.Users; } else { foreach (var user in fileData.Users) { Guid userId; if (!Guid.TryParse(user, out userId)) { Global.Logger.Error("DocService userId is not Guid: " + user); continue; } users.Remove(userId); try { var doc = FileShareLink.CreateKey(fileId); EntryManager.TrackEditing(fileId, userId, userId, doc); } catch (Exception e) { Global.Logger.DebugFormat("Drop command: fileId '{0}' docKey '{1}' for user {2} : {3}", fileId, fileData.Key, user, e.Message); usersDrop.Add(userId.ToString()); } } } if (usersDrop.Any()) { if (!DocumentServiceHelper.DropUser(fileData.Key, usersDrop.ToArray(), fileId)) { Global.Logger.Error("DocService drop failed for users " + string.Join(",", usersDrop)); } } foreach (var removeUserId in users) { FileTracker.Remove(fileId, userId: removeUserId); } Global.SocketManager.FilesChangeEditors(fileId); }
public static void ProcessData(string fileId, bool isNew, string trackDataString) { if (string.IsNullOrEmpty(trackDataString)) { Global.Logger.Error("DocService return null"); throw new ArgumentException("DocService return null", "trackDataString"); } var data = JObject.Parse(trackDataString); if (data == null) { Global.Logger.Error("DocService response is incorrect"); throw new ArgumentException("DocService response is incorrect", "trackDataString"); } var fileData = data.ToObject <TrackerData>(); var userId = Guid.Empty; switch (fileData.Status) { case TrackerStatus.NotFound: case TrackerStatus.Closed: FileTracker.Remove(fileId); break; case TrackerStatus.Editing: var users = FileTracker.GetEditingBy(fileId); foreach (var user in fileData.Users) { if (!Guid.TryParse(user, out userId)) { Global.Logger.Error("DocService userId is not Guid: " + user); continue; } users.Remove(userId); try { var shareLinkKey = FileShareLink.CreateKey(fileId); EntryManager.TrackEditing(fileId, userId, userId, isNew, shareLinkKey); } catch (Exception e) { Global.Logger.DebugFormat("DocService drop fileId '{0}' docKey '{1}' for user {2} : {3}", fileId, fileData.Key, user, e.Message); if (!Drop(fileData.Key, user, fileId)) { Global.Logger.Error("DocService drop failed for user " + user); } } } foreach (var removeUserId in users) { FileTracker.Remove(fileId, userId: removeUserId); } break; case TrackerStatus.MustSave: case TrackerStatus.Corrupted: if (fileData.Users != null && fileData.Users.Count > 0) { Guid.TryParse(fileData.Users[0], out userId); } SecurityContext.AuthenticateMe(userId); try { var file = EntryManager.SaveEditing(fileId, -1, userId, fileData.Url, isNew, string.Empty, fileData.Status == TrackerStatus.Corrupted ? FilesCommonResource.ErrorMassage_SaveCorrupted : String.Empty, false); var user = CoreContext.UserManager.GetUsers(userId); if (file != null && user != null) { FilesMessageService.Send(file, MessageInitiator.DocsService, MessageAction.UserFileUpdated, user.DisplayUserName(false), file.Title); } } catch (Exception ex) { Global.Logger.Error(string.Format("DocService save error. File id: '{0}'. UserId: {1}. DocKey '{2}'. DownloadUri: {3}", fileId, userId, fileData.Key, fileData.Url), ex); StoringFileAfterError(fileId, userId.ToString(), fileData.Url); } FileTracker.Remove(fileId); break; } }