public ExcelSession(ExcelSession session) { Id = session.Id; Name = session.Name; Owner = session.Owner; Created = session.Created; Users = session.Users; WorkbookName = session.WorkbookName; WatchAllFormulaCells = session.WatchAllFormulaCells; WatchAllNames = session.WatchAllNames; WatchCells = session.WatchCells; WatchNames = session.WatchNames; UseCalculationChain = session.UseCalculationChain; }
public ExcelWorkbookSession CreateSession(ExcelSession session) { var existingSession = GetSession(session.Name); if (existingSession != null) throw new Exception(string.Format("Session with name {0} already exists, session names should be unique", session.Name)); var mySession = new ExcelWorkbookSession(session); mySession.CellValueChanged += MySessionOnCellValueChanged; mySession.NameValueChanged += MySessionOnNameValueChanged; mySession.Id = sessions.Any() ? sessions.Max(s => s.Id) + 1 : 0; mySession.Created = DateTime.Now; mySession.Users = new List<string> { session.Owner }; foreach (var watchCell in mySession.WatchCells) { string worksheet,cellname; if (watchCell.Contains('!')) { var cellParts = watchCell.Split('!'); worksheet = cellParts[0]; cellname = cellParts[1]; } else { worksheet = mySession.Workbook.Worksheets[0].Name; cellname = watchCell; } mySession.WatchCell(worksheet, cellname); } foreach (var watchName in mySession.WatchNames) { mySession.WatchName(watchName); } sessions.Add(mySession); return mySession; }
public IHttpActionResult UpdateSession(int id, ExcelSession session) { log.Info("{0} - UpdateSession({1})", User.Identity.Name, id); ExcelSession mySession = excelSessionManager.GetSession(id); if (mySession.Owner != User.Identity.Name) { return Unauthorized(); } mySession = excelSessionManager.UpdateSession(id, session); return Ok(mySession); }
public IHttpActionResult CreateSession(ExcelSession session) { log.Info("{0} - CreateSession", User.Identity.Name); if (string.IsNullOrWhiteSpace(session.Name)) return InternalServerError(); if (string.IsNullOrWhiteSpace(session.WorkbookName)) return InternalServerError(); session.Owner = User.Identity.Name; ExcelWorkbookSession createdSession = null; try { createdSession = excelSessionManager.CreateSession(session); } catch (Exception ex) { log.Error("Could not create excel session: {0}", ex.Message); return InternalServerError(ex); } var myConnection = ExcelHub.UserConnectionMapping[User.Identity.Name]; log.Debug("Add connection {0} to group {1}", myConnection, session.Name); hubContext.Groups.Add(myConnection, session.Name); foreach (var watchedItem in createdSession.WatchedItems) { if (watchedItem is CellCache) { var cellCache = (CellCache) watchedItem; hubContext.Clients.Client(myConnection).CellValueUpdated(new CellValue(createdSession.Id, cellCache.Workbook, cellCache.Worksheet, cellCache.CellName, cellCache.Value)); } else if (watchedItem is NameCache) { var nameCache = (NameCache)watchedItem; hubContext.Clients.Client(myConnection).NameValueUpdated(new NameValue(createdSession.Id, nameCache.Workbook, nameCache.Name, (object[])nameCache.Value)); } } return Ok(session); }
public ExcelSession UpdateSession(int id, ExcelSession session) { var mySession = sessions.FirstOrDefault(s => s.Id == id); if (mySession == null) { return null; } mySession.Name = session.Name; mySession.Owner = session.Owner; mySession.Users = session.Users; return mySession; }