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
        public List<DocumentLibraryModel> GetDocumentModel(string folderPath, string libraryName,string user,string secret)
        {
            var docLib = new DocumentLibrary
            {
                FolderPath = folderPath.Replace(Common.Configuration.ApplicationConfiguration.FolderPath + "/", "/").
                Equals(Common.Configuration.ApplicationConfiguration.RootFolderPath)
                ? Common.Configuration.ApplicationConfiguration.RootFolderPath :
                folderPath.Replace(Common.Configuration.ApplicationConfiguration.FolderPath + "/", "/"),
                LibraryName = libraryName
            };

            var documentService = new MobilityDocumentsService();
            var documentsResult = documentService.GetDocuments(docLib, user, secret);
            var documents = new List<DocumentLibraryModel>();

            documents.AddRange(documentsResult.ToDocumentLibraryModels(folderPath));

            return documents;

        }
示例#3
0
        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 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;
            }

        }