コード例 #1
0
        public HttpResponseMessage Get(string folder, int page)
        {
            try
            {

                var applicationKeyService = new ApplicationKeyService();
                var mobilityDocumentsService = new MobilityDocumentsService();


                string user;
                string secret;
                var imageHelper = new Images(applicationKeyService, mobilityDocumentsService);
                var pageCount = 0;
                var output = new ImageResponse()
                {
                    ErrorCount = 0,
                    Content = imageHelper.GetImageInBytes(folder, page, out pageCount),
                    Token = GetResponseToken(out user, out secret).access_token,
                    Key = folder,
                    TotalCount = pageCount

                };
                
                var response = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json");
                return response;
            }
            catch (Exception ex)
            {
                var output = new ImageResponse();
                output.ErrorCount = 1;
                if (!ApplicationConfiguration.IsProduction)
                    output.Stacktrace = ex.StackTrace;

                output.Token = GetResponseToken().access_token;
                output.Message = ex.Message;

                var response = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json");
                return response;
            }

        }
コード例 #2
0
ファイル: Images.cs プロジェクト: Aranjedeath/SpecimenCode
        public Byte[] GetImageInBytes(string folder, int page,out int pageCount)
        {
            pageCount = 0;
            var applicationKeyService = new ApplicationKeyService();
            var dbApplicationKeyModel = applicationKeyService.GetAllApplicationKey().FirstOrDefault(x => x.Key == new Guid(folder));
            if (dbApplicationKeyModel.LastUpdatedDate.Date == DateTime.Now.Date &&
                dbApplicationKeyModel.LastUpdatedDate.TimeOfDay.Add(new TimeSpan(0, 0, ApplicationConfiguration.DocumentExpirationMinute.Value, 0)) >= DateTime.Now.TimeOfDay)
            {
                var localPath = Common.Configuration.ApplicationConfiguration.DocStorePath + 
                                ApplicationConfiguration.RemoveDirectoryNFileFromServer + Path.DirectorySeparatorChar + 
                                dbApplicationKeyModel.Key + Path.DirectorySeparatorChar + "Water_" + dbApplicationKeyModel.Key + page + ApplicationConfiguration.ImageExtension;
                var fileInfo = new FileInfo(localPath);
                var data = new Byte[] { };
                if (File.Exists(localPath))
                {
                    data = new byte[fileInfo.Length];
                    using (var fs = fileInfo.OpenRead())
                    {
                        fs.Read(data, 0, data.Length);
                    }

                    pageCount = dbApplicationKeyModel.PageCount;

                    //code added for proactive page creation
                    dbApplicationKeyModel.IsDeleted = false;
                    dbApplicationKeyModel.LastUpdatedDate = DateTime.Now;
                    dbApplicationKeyModel.LastUpdatedBy = dbApplicationKeyModel.UserName;
                    dbApplicationKeyModel.StatusId = 1;
                    dbApplicationKeyModel.CurrentPage = page + 1;
                    applicationKeyService.UpdateApplicationKey(dbApplicationKeyModel);

                }
                else
                {
                    dbApplicationKeyModel.IsDeleted = false;
                    dbApplicationKeyModel.CurrentPage = page;
                    dbApplicationKeyModel.LastUpdatedDate = DateTime.Now;
                    dbApplicationKeyModel.LastUpdatedBy = dbApplicationKeyModel.UserName;
                    dbApplicationKeyModel.StatusId = 1;
                    applicationKeyService.UpdateApplicationKeyCurrentPage(dbApplicationKeyModel);

                    pageCount = dbApplicationKeyModel.PageCount;

                    var status = applicationKeyService.GetProcessorStatus(dbApplicationKeyModel);

                    //This might get stuck in an infinite loop 
                    //need a logic to get over
                    while (applicationKeyService.GetProcessorStatus(dbApplicationKeyModel) != (int)ProcessorStatus.Completed)
                        status = applicationKeyService.GetProcessorStatus(dbApplicationKeyModel);
                    
                    data = new byte[fileInfo.Length];
                    using (var fs = fileInfo.OpenRead())
                    {
                        fs.Read(data, 0, data.Length);
                    }

                    //code added for proactive page creation
                    dbApplicationKeyModel.IsDeleted = false;
                    dbApplicationKeyModel.CurrentPage = page + 1;
                    dbApplicationKeyModel.LastUpdatedDate = DateTime.Now;
                    dbApplicationKeyModel.LastUpdatedBy = dbApplicationKeyModel.UserName;
                    dbApplicationKeyModel.StatusId = 1;
                    applicationKeyService.UpdateApplicationKeyCurrentPage(dbApplicationKeyModel);

                }

                var outpath = Common.Configuration.ApplicationConfiguration.DocStorePath + ApplicationConfiguration.RemoveDirectoryNFileFromServer + Path.DirectorySeparatorChar + dbApplicationKeyModel.Key + Path.DirectorySeparatorChar + "ecs_" + dbApplicationKeyModel.Key + page + ApplicationConfiguration.ImageExtension;

                File.WriteAllBytes(outpath, data);

                var stream = new MemoryStream(data);

                return stream.ToArray();

            }

            if (Directory.Exists(dbApplicationKeyModel.DocumentPath))
                Directory.Delete(dbApplicationKeyModel.DocumentPath, true);

            dbApplicationKeyModel.IsDeleted = true;
            dbApplicationKeyModel.LastUpdatedDate = DateTime.Now;
            dbApplicationKeyModel.LastUpdatedBy = dbApplicationKeyModel.UserName;
            applicationKeyService.UpdateApplicationKey(dbApplicationKeyModel);

            pageCount = dbApplicationKeyModel.PageCount;

            return new byte[12];
        }
コード例 #3
0
ファイル: Images.cs プロジェクト: Aranjedeath/SpecimenCode
        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);
        }
コード例 #4
0
        public HttpResponseMessage GetDocument(string documentName, string folderPath)
        {
   var applicationKeyService = new ApplicationKeyService();
                var mobilityDocumentsService = new MobilityDocumentsService();
            try
            {
                string docWithoutExt;
                ApplicationKey appKey;
                var user = String.Empty;
                var secret = String.Empty;
                var token = GetResponseToken(out user, out secret).access_token;
                var imageHelper = new Images(applicationKeyService, mobilityDocumentsService);
                imageHelper.CreateDocumentImage(documentName, user, secret, folderPath.Base64Decode(), out docWithoutExt, out appKey);

                appKey = applicationKeyService.GetApplicationKey(appKey);
                while (appKey.PageCount == 0)
                {
                    appKey = applicationKeyService.GetApplicationKey(appKey);
                }

                appKey.DocumentName = docWithoutExt;

                var output = new ImageResponse
                {
                    ErrorCount = 0,
                    Content = new byte[0],
                    Token = token,
                    Key = appKey.Key.ToString(),
                    TotalCount = appKey.PageCount
                };
                
                var response = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json");
                return response;
            }
            catch (Exception ex)
            {
                var output = new ImageResponse();
                output.ErrorCount = 1;
                if (!ApplicationConfiguration.IsProduction)
                    output.Stacktrace = ex.StackTrace;

                output.Token = GetResponseToken().access_token;
                output.Message = ex.Message;

                var response = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json");
                return response;
            }

        }