public Int32 GetProcessorStatus(ApplicationKey applicationKey) { var predicateGroup = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() }; predicateGroup.Predicates.Add(Predicates.Field<ApplicationKey>(f => f.IsDeleted, Operator.Eq, false)); predicateGroup.Predicates.Add(Predicates.Field<ApplicationKey>(f => f.AppId, Operator.Eq, applicationKey.AppId)); var output = SqlHelper.Find<ApplicationKey>(predicateGroup); return output.StatusId; }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // Write your Authentication code here IEnumerable<string> monsterApiKeyHeaderValues = null; // Checking the Header values if (request.Headers.TryGetValues("X-ViewerAppApiKey", out monsterApiKeyHeaderValues)) { var apiKeyHeaderValue = monsterApiKeyHeaderValues.First().Split(':'); var appID = apiKeyHeaderValue[0]; var appKey = apiKeyHeaderValue[1]; var userName = apiKeyHeaderValue[2]; var applicationKey = new ApplicationKey { AppId = new Guid(appID), Key = new Guid(appKey), IsDeleted = false }; ApplicationKeyService = new ApplicationKeyService(); //TODO : user DI to replace direct instantiation var dbApplicationKeyModel = ApplicationKeyService.GetApplicationKey(applicationKey); if (null == dbApplicationKeyModel) return requestCancel(request, cancellationToken, Constants.SlidingExpirationToken); if (appID.Equals(dbApplicationKeyModel.AppId.ToString()) && appKey.Equals(dbApplicationKeyModel.Key.ToString()) && userName.ToUpper().Equals(dbApplicationKeyModel.UserName.ToUpper())) { var userNameClaim = new Claim(ClaimTypes.Name, appID); var identity = new ClaimsIdentity(new[] { userNameClaim }, "MonsterAppApiKey"); identity.AddClaim(new Claim("AppKey", appKey)); identity.AddClaim(new Claim("AppId", appID)); var principal = new ClaimsPrincipal(identity); Thread.CurrentPrincipal = principal; if (HttpContext.Current != null) HttpContext.Current.User = principal; } else return requestCancel(request, cancellationToken, Constants.InvalidToken); } else if (request.Headers.TryGetValues("X-ForumSummaryKey", out monsterApiKeyHeaderValues)) { var userNameClaim = new Claim(ClaimTypes.Name, ""); var identity = new ClaimsIdentity(new[] { userNameClaim }, "MonsterAppApiKey"); identity.AddClaim(new Claim("AppKey", "")); identity.AddClaim(new Claim("AppId", "")); var principal = new ClaimsPrincipal(identity); Thread.CurrentPrincipal = principal; if (HttpContext.Current != null) HttpContext.Current.User = principal; } else return requestCancel(request, cancellationToken, Constants.MissingToken); return base.SendAsync(request, cancellationToken); }
public ActionResult Download(string documentName, string libraryName, string folderPath) { var accountInfo = new AccountInfo(); var extArr = documentName.Split('.'); var docWithoutExt = documentName.ReplaceWithEmpty("." + extArr[extArr.Length - 1]); var dirPath = ApplicationConfiguration.RemoveDirectoryNFileFromServer.StartWithSlash() + "/"; var key = Guid.NewGuid(); var guidFileName = key + "." + extArr[extArr.Length - 1]; var document = new DocumentLibrary() { Name = documentName, FolderPath = folderPath, LibraryName = libraryName, LocalDirectoryPath = dirPath, GuidDocumentName = guidFileName }; DocumentLibraryService.GetDocuments(document); var appKey = new ApplicationKey() { AppId = Guid.NewGuid(), Key = key, DocumentName = guidFileName, OriginalDocumentName = documentName, DocumentPath = dirPath, UserName = accountInfo.GetUserName(), CreatedDate = DateTime.Now, CreatedBy = accountInfo.GetUserName(), IsDeleted = false, LastUpdatedDate = DateTime.Now, LastUpdatedBy = accountInfo.GetUserName(), CurrentPage = 1, StatusId = (int)ProcessorStatus.UnProcessed }; ApplicationKeyService.InsertApplicationKey(appKey); appKey = ApplicationKeyService.GetApplicationKey(appKey); appKey.DocumentName = docWithoutExt; ViewBag.Folder = appKey.Key.ToString(); ViewBag.TotalPages = appKey.PageCount; ViewBag.DocumentName = appKey.DocumentName; return View("Viewer"); }
public Int32 GetProcessorStatus(ApplicationKey applicationKey) { if (null != ApplicationKeyDao) return ApplicationKeyDao.GetProcessorStatus(applicationKey); ApplicationKeyDao = new ApplicationKeyDao(); return ApplicationKeyDao.GetProcessorStatus(applicationKey); }
public ApplicationKey GetApplicationKey(ApplicationKey applicationKey) { if (null != ApplicationKeyDao) return ApplicationKeyDao.GetApplicationKey(applicationKey); ApplicationKeyDao = new ApplicationKeyDao(); return ApplicationKeyDao.GetApplicationKey(applicationKey); }
public bool UpdateApplicationKeyCurrentPage(ApplicationKey applicationKey) { if (null != ApplicationKeyDao) return ApplicationKeyDao.UpdateApplicationKeyCurrentPage(applicationKey); ApplicationKeyDao = new ApplicationKeyDao(); return ApplicationKeyDao.UpdateApplicationKeyCurrentPage(applicationKey); }
public bool InsertApplicationKey(ApplicationKey applicationKey) { if (null != ApplicationKeyDao) return ApplicationKeyDao.InsertApplicationKey(applicationKey); ApplicationKeyDao = new ApplicationKeyDao(); return ApplicationKeyDao.InsertApplicationKey(applicationKey); }
public void CreateDocumentImage(string documentName, string user, string secret, string folderPath, out string docWithoutExt, out ApplicationKey appKey) { var libraryName = Common.Configuration.ApplicationConfiguration.LibraryName; var applicationKeyService = new ApplicationKeyService(); var extArr = documentName.Split('.'); docWithoutExt = documentName.ReplaceWithEmpty("." + extArr[extArr.Length - 1]); var dirPath = ApplicationConfiguration.RemoveDirectoryNFileFromServer.StartWithSlash() + "/"; var key = Guid.NewGuid(); var guidFileName = key + "." + extArr[extArr.Length - 1]; var document = new DocumentLibrary() { Name = documentName, FolderPath = folderPath, LibraryName = libraryName, LocalDirectoryPath = dirPath, GuidDocumentName = guidFileName }; var mobilityDocumentsService = new MobilityDocumentsService(); mobilityDocumentsService.GetDocumentFromSharepointLibrary(document, user, secret, Common.Configuration.ApplicationConfiguration.DocStorePath); appKey = new ApplicationKey() { AppId = Guid.NewGuid(), Key = key, DocumentName = guidFileName, OriginalDocumentName = documentName, DocumentPath = dirPath, UserName = user, CreatedDate = DateTime.Now, CreatedBy = user, IsDeleted = false, LastUpdatedDate = DateTime.Now, LastUpdatedBy = user, CurrentPage = 1, StatusId = (int)ProcessorStatus.UnProcessed }; applicationKeyService.InsertApplicationKey(appKey); }
public HttpResponseMessage GetImage(int nextPrevCount) { ApplicationKeyService = new ApplicationKeyService(); //TODO : user DI to replace direct instantiation var identity = (ClaimsIdentity)HttpContext.Current.User.Identity; IEnumerable<Claim> claims = identity.Claims; var appKey = new ApplicationKey { AppId = new Guid(claims.First(x => x.Type == "AppId").Value), Key = new Guid(claims.First(x => x.Type == "AppKey").Value), IsDeleted = false }; var dbApplicationKeyModel = ApplicationKeyService.GetApplicationKey(appKey); if (dbApplicationKeyModel.LastUpdatedDate.Date == DateTime.Now.Date && dbApplicationKeyModel.LastUpdatedDate.TimeOfDay.Add(new TimeSpan(0, 0, ApplicationConfiguration.DocumentExpirationMinute.Value, 0)) >= DateTime.Now.TimeOfDay) { var localPath = AppDomain.CurrentDomain.BaseDirectory + ApplicationConfiguration.RemoveDirectoryNFileFromServer + Path.DirectorySeparatorChar + dbApplicationKeyModel.Key + Path.DirectorySeparatorChar + "Water_" + dbApplicationKeyModel.Key + nextPrevCount + ApplicationConfiguration.ImageExtension; //var localPath = string.Empty; //if(nextPrevCount%2==0) // localPath = AppDomain.CurrentDomain.BaseDirectory + "/Content/Img/Systems-Mac-Os-icon.png"; //else // localPath = AppDomain.CurrentDomain.BaseDirectory + "/Content/Img/Systems-Windows-8-icon.png"; var fileInfo = new FileInfo(localPath); byte[] data; if (File.Exists(localPath)) { data = new byte[fileInfo.Length]; using (var fs = fileInfo.OpenRead()) { fs.Read(data, 0, data.Length); } dbApplicationKeyModel.IsDeleted = false; dbApplicationKeyModel.LastUpdatedDate = DateTime.Now; dbApplicationKeyModel.LastUpdatedBy = dbApplicationKeyModel.UserName; ApplicationKeyService.UpdateApplicationKey(dbApplicationKeyModel); } else { dbApplicationKeyModel.IsDeleted = false; dbApplicationKeyModel.CurrentPage = nextPrevCount; dbApplicationKeyModel.LastUpdatedDate = DateTime.Now; dbApplicationKeyModel.LastUpdatedBy = dbApplicationKeyModel.UserName; dbApplicationKeyModel.StatusId = 1; ApplicationKeyService.UpdateApplicationKeyCurrentPage(dbApplicationKeyModel); var test = RetryHelper.Do(() => ApplicationKeyService.GetProcessorStatus(dbApplicationKeyModel), TimeSpan.FromSeconds(ApplicationConfiguration.RetryInterval.Value), (int)ProcessorStatus.Completed, ApplicationConfiguration.RetryAttempts.Value); if (test != (int)ProcessorStatus.Completed) throw new Exception("The file you are attempting to download has failed. Please try again to download a new copy of the document."); data = new byte[fileInfo.Length]; using (var fs = fileInfo.OpenRead()) { fs.Read(data, 0, data.Length); } } var httpResponseMessage = new HttpResponseMessage(); var memoryStream = new MemoryStream(data.Encrypt()); //var memoryStream = new MemoryStream(data); httpResponseMessage.Content = new ByteArrayContent(memoryStream.ToArray()); memoryStream.Dispose(); return httpResponseMessage; } if (Directory.Exists(dbApplicationKeyModel.DocumentPath)) Directory.Delete(dbApplicationKeyModel.DocumentPath, true); dbApplicationKeyModel.IsDeleted = true; dbApplicationKeyModel.LastUpdatedDate = DateTime.Now; dbApplicationKeyModel.LastUpdatedBy = dbApplicationKeyModel.UserName; ApplicationKeyService.UpdateApplicationKey(dbApplicationKeyModel); return new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(Intranet.Common.Constants.SlidingExpirationToken) }; }
public ApplicationKey GetApplicationKey(ApplicationKey applicationKey) { var predicateGroup = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() }; predicateGroup.Predicates.Add(Predicates.Field<ApplicationKey>(f => f.Id, Operator.Eq, applicationKey.Id)); return SqlHelper.Find<ApplicationKey>(predicateGroup); }
public bool UpdateApplicationKeyCurrentPage(ApplicationKey applicationKey) { applicationKey.StatusId = (Int32)ProcessorStatus.UnProcessed; SqlHelper.Update(applicationKey); return true; }
public bool UpdateApplicationKey(ApplicationKey applicationKey) { return SqlHelper.Update(applicationKey); }
public bool InsertApplicationKey(ApplicationKey applicationKey) { return SqlHelper.Insert(applicationKey); }