예제 #1
0
 /// <summary>
 /// Called when [changed convert].
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="e">The <see cref="FileSystemEventArgs"/> instance containing the event data.</param>
 private static void OnChangedConvert(object source, FileSystemEventArgs e)
 {
     try
     {
         // prevent of garbage
         if (GetExt(e.Name) == "html" || GetExt(e.Name) == "docx" || GetExt(e.Name) == "htm" || GetExt(e.Name) == "doc" || GetExt(e.Name) == "pdf")
         {
             NameConstructor             nameConstructor             = new NameConstructor();
             ConvertParametersForService convertParametersForService = nameConstructor.ParseName(e.Name);
             if (GetExt(e.Name) == "html" && convertParametersForService.McfParams.C == "12")
             {
                 // html - pdf - docx start
                 String input = String.Format("{1}{0}", e.Name, globalRoutes.InputConvertRoute);
                 WorkConsoleConvertHtmlDocStart(input, convertParametersForService);
             }
             else if (GetExt(e.Name) == "pdf" && convertParametersForService.McfParams.C == "12")
             {
                 //   pdf - docx start
                 String input  = String.Format("{1}{0}", e.Name, globalRoutes.InputConvertRoute);
                 String output = String.Format("{2}{0}.{1}", convertParametersForService.ServiceFileNames.OutputName + "_converted", convertParametersForService.ServiceFileNames.OutputExtension, globalRoutes.OutputConvertRoute);
                 WorkConsoleConvertDocPdfStart(input, output, convertParametersForService);
             }
             else
             {
                 String input  = String.Format("{1}{0}", e.Name, globalRoutes.InputConvertRoute);
                 String output = String.Format("{2}{0}.{1}", convertParametersForService.ServiceFileNames.OutputName + "_converted", convertParametersForService.ServiceFileNames.OutputExtension, globalRoutes.OutputConvertRoute);
                 WorkConsoleConvert(input, output, convertParametersForService.McfParams.C, convertParametersForService.McfParams.F, convertParametersForService.McfParams.M);
             }
         }
     }
     catch (Exception ex)
     {
         LogError(ex);
     }
 }
예제 #2
0
        /// <summary>
        /// Called when [changed end diff].
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="e">The <see cref="FileSystemEventArgs"/> instance containing the event data.</param>
        private static void OnChangedEndDiff(object source, FileSystemEventArgs e)
        {
            try
            {
                String directoryDiffResult = globalRoutes.DiffresultRoute;
                String directoryEnd        = globalRoutes.DiffEndRoute;

                NameConstructor          nameConstructor          = new NameConstructor();
                ConvertParametersForDiff convertParametersForDiff = nameConstructor.ParseDiffName(e.Name);
                if (File.Exists(directoryEnd + convertParametersForDiff.PartnerDiffName))
                {
                    WorkConsoleDiffDocs(directoryEnd + convertParametersForDiff.OriginalDiffName, directoryEnd + convertParametersForDiff.ModifiedDiffName, directoryDiffResult + convertParametersForDiff.DiffResult);
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
            }
        }
예제 #3
0
        public HttpResponseMessage Post()
        {
            Byte[] fileStreamOriginal       = null;
            Byte[] fileStreamModified       = null;
            String originalExtension        = "";
            String modifiedExtension        = "";
            String originalName             = "";
            String modifiedName             = "";
            HttpResponseMessage resultError = new HttpResponseMessage();


            MediaTypeHeaderValue content = Request.Content.Headers.ContentType;

            if (content == null)
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.NotAcceptable); // 406
                resultError.Content = new StringContent("Not Acceptable MediaType");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                return(resultError);
            }

            if (Request.Content.Headers.ContentType.MediaType != "multipart/form-data")
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.NotAcceptable); // 406
                resultError.Content = new StringContent("Not Acceptable MediaType");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                return(resultError);
            }

            if (Request.Content != null)
            {
                MultipartFormDataParser parser = new MultipartFormDataParser(Request.Content.ReadAsStreamAsync().Result);
                foreach (var currentFile in parser.Files)
                {
                    if (currentFile.Name == "original")
                    {
                        fileStreamOriginal = ToByteArray(currentFile.Data);
                        if (fileStreamOriginal == null)
                        {
                            resultError         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                            resultError.Content = new StringContent("Unable to handle the supplied document(s)");
                            resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
                            return(resultError);
                        }
                        originalExtension = currentFile.ContentType;
                        originalName      = currentFile.FileName;
                    }
                    else if (currentFile.Name == "modified")
                    {
                        fileStreamModified = ToByteArray(currentFile.Data);
                        if (fileStreamModified == null)
                        {
                            resultError         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                            resultError.Content = new StringContent("Unable to handle the supplied document(s)");
                            resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
                            return(resultError);
                        }
                        modifiedExtension = currentFile.ContentType;
                        modifiedName      = currentFile.FileName;
                    }
                }
            }
            else
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                resultError.Content = new StringContent("Unable to handle the supplied document(s)");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
                return(resultError);
            }

            NameConstructor nameConstructor = new NameConstructor();

            ConvertParametersForDiff convertParametersForDif = nameConstructor.CenereateDiffDocName(originalName, modifiedName, originalExtension, modifiedExtension);

            String originalDiffName = convertParametersForDif.OriginalDiffName;
            String originalInput    = String.Format("{1}{0}", originalDiffName, globalRoutes.DiffStartRoute);

            String modifiedDiffName = convertParametersForDif.ModifiedDiffName;
            String modifiedInput    = String.Format("{1}{0}", modifiedDiffName, globalRoutes.DiffStartRoute);

            String diffResult       = convertParametersForDif.DiffResultEnd;
            String diffResultOutput = String.Format("{1}{0}", diffResult, globalRoutes.DiffresultRoute);

            OutputDirecroy = diffResultOutput;

            if (fileStreamModified == null || fileStreamOriginal == null)
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                resultError.Content = new StringContent("Unable to handle the supplied document(s)");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
                return(resultError);
            }
            String originalExstension = GetExt(originalName);

            if (originalExstension != "html" && originalExstension != "htm" && originalExstension != "docx" && originalExstension != "pdf")
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                resultError.Content = new StringContent("Unable to handle the supplied document(s)");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
                return(resultError);
            }
            String modifExstention = GetExt(modifiedName);

            if (modifExstention != "html" && modifExstention != "htm" && modifExstention != "docx" && modifExstention != "pdf")
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                resultError.Content = new StringContent("Unable to handle the supplied document(s)");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
                return(resultError);
            }

            //before save parse html and save images
            if (GetExt(originalName) == "html" || GetExt(originalName) == "htm")
            {
                ParseHtmlAndCreateInages(originalInput, fileStreamOriginal, originalDiffName);
            }
            else
            {
                SaveFile(originalInput, fileStreamOriginal);
            }

            //before save parse html and save images
            if (GetExt(modifiedName) == "html" || GetExt(modifiedName) == "htm")
            {
                ParseHtmlAndCreateInages(modifiedInput, fileStreamModified, modifiedDiffName);
            }
            else
            {
                SaveFile(modifiedInput, fileStreamModified);
            }

            Stream resultStream        = null;
            HttpResponseMessage result = new HttpResponseMessage();

            try
            {
                resultStream   = Work(diffResult);
                result         = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new StreamContent(resultStream);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            }
            catch (Exception ex)
            {
                result         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                result.Content = new StringContent("Unable to handle the supplied document(s)");
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                LogError(ex);
            }
            return(result);
        }
예제 #4
0
        public HttpResponseMessage Post()
        {
            HttpResponseMessage resultError = new HttpResponseMessage();

            MediaTypeHeaderValue content = Request.Content.Headers.ContentType;

            if (content == null)
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.NotAcceptable); // 406
                resultError.Content = new StringContent("Unable to convert to specified format");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                return(resultError);
            }

            MediaTypeEnum contentType = ResolveMediaType(content.MediaType);

            if (contentType == MediaTypeEnum.Empty)
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.NotAcceptable); // 406
                resultError.Content = new StringContent("Unable to convert to specified format");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                return(resultError);
            }

            MediaTypeWithQualityHeaderValue accept = Request.Headers.Accept.FirstOrDefault();

            if (accept == null)
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.NotAcceptable); // 406
                resultError.Content = new StringContent("Unable to convert to specified format");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                return(resultError);
            }

            MediaTypeEnum acceptType = ResolveMediaType(accept.MediaType);

            if (acceptType == MediaTypeEnum.Empty)
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.NotAcceptable); // 406
                resultError.Content = new StringContent("Unable to convert to specified format");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                return(resultError);
            }

            AcceptTypePubl = acceptType;

            Byte[] fileStream = null;

            if (Request.Content != null)
            {
                fileStream = GetFileStream(Request.Content);
            }
            else
            {
                resultError         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                resultError.Content = new StringContent("Unable to convert the supplied document");
                resultError.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                return(resultError);
            }

            NameConstructor nameConstructor = new NameConstructor();



            String        inputExtension  = "";
            MediaTypeEnum multipartType   = new MediaTypeEnum();
            String        outputExtension = acceptType.Attribute <ConvertDocumentAttribute>().Extension;

            if (contentType == MediaTypeEnum.MultiPart)
            {
                multipartType  = ResolveMediaType(GlobalInputExt);
                inputExtension = multipartType.Attribute <ConvertDocumentAttribute>().Extension;
            }
            else
            {
                inputExtension = contentType.Attribute <ConvertDocumentAttribute>().Extension;
            }

            ConvertParametersForService convertParametersForService = nameConstructor.GenerateName(inputExtension,
                                                                                                   outputExtension);

            //  save input
            String inputName = convertParametersForService.ServiceFileNames.InputName;
            String input     = String.Format("{2}{0}.{1}", inputName, inputExtension, globalRoutes.InputConvertRoute);

            //  save output
            String outputName = convertParametersForService.ServiceFileNames.OutputName;
            String output     = String.Format("{2}{0}.{1}", outputName, outputExtension, globalRoutes.OutputConvertRoute);

            OutputDirecroy = output;

            //before save parse html and save images
            if (contentType == MediaTypeEnum.Html || multipartType == MediaTypeEnum.Html)
            {
                ParseHtmlAndCreateInages(input, fileStream, inputName, inputExtension);
            }
            else
            {
                //save file
                FileStream wFile = new FileStream(input, FileMode.Create);
                wFile.Write(fileStream, 0, fileStream.Length);
                wFile.Close();
            }


            Stream resultStream        = null;
            HttpResponseMessage result = new HttpResponseMessage();

            try
            {
                resultStream   = Work(outputName + "." + outputExtension);
                result         = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new StreamContent(resultStream);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue(accept.MediaType);
            }
            catch (Exception ex)
            {
                result         = new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType); // 415
                result.Content = new StringContent("Unable to convert the supplied document");
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");

                LogError(ex);
            }



            return(result);
        }