/// <summary>
        /// using Microsoft.Extensions.DependencyInjection;
        /// </summary>
        /// <returns></returns>
        public IActionResult GeteServicesInFunction()
        {
            StringBuilder stringBuilder = new StringBuilder();

            //sms
            ISms smsService = HttpContext.RequestServices.GetService <ISms>();

            stringBuilder.Append(smsService.SmsSend() + " \n");

            //mails
            IEnumerable <IMail> mailServices = HttpContext.RequestServices.GetServices <IMail>();

            foreach (var mail in mailServices)
            {
                stringBuilder.Append(mail.Send() + "\n");
            }

            //file Converter
            IFileConverter fileConverterService = HttpContext.RequestServices.GetService <IFileConverter>();                                    //v1
            Func <string, IFileConverter> fileConverterServiceDelg = HttpContext.RequestServices.GetService <Func <string, IFileConverter> >(); //v2

            stringBuilder.Append(fileConverterService.Convert());                                                                               //v1
            ///stringBuilder.Append(fileConverterServiceDelg("XmlConverter").Convert());//v2

            return(Content(stringBuilder.ToString()));
        }
示例#2
0
        };                                                                            // 0 1 2

        public static object Convert(object input, string inputFileFormat, string outputFileFormat)
        {
            int        source = convertersNames.FindIndex(a => a.Contains(inputFileFormat));  // as 0 1 2
            int        dest   = convertersNames.FindIndex(a => a.Contains(outputFileFormat)); // as 0 1 2
            object     output = null;
            List <int> path   = graph.BFS(source, dest);

            if (source == -1 || dest == -1)
            {
                throw new Exception("inputFileFormat doesn't exist"
                                    + "or outputFileFormat doesn't exist");
            }
            if (path.Count <= 1)
            {
                throw new FileConveterNotFoundException("FileConverter doesn't exist");
            }

            String myKey;                            // Converter's key

            for (int i = 0; i < path.Count - 1; i++) // path.Count-1 is end of vertex does not go to other vertex
            {
                myKey = convertersNames[path[i]] + "2" + convertersNames[path[i + 1]];
                IFileConverter currentConverter = fileConverters[myKey];
                output = currentConverter.Convert(input);
                input  = output; //refresh input
            }

            return(output);
        }
示例#3
0
文件: MainForm.cs 项目: radtek/Thingy
 private void SmdButton_Click(object sender, EventArgs e)
 {
     if (OpenSmdFileDialog.ShowDialog() == DialogResult.OK)
     {
         smdConverter.Convert(OpenSmdFileDialog.FileName);
     }
 }
        public IActionResult ConvertXmlToJson()
        {
            try
            {
                if (Request.Form.Files.Count > 0)
                {
                    var file = Request.Form.Files[0];
                    Console.WriteLine(file.FileName);
                    var serializedFile = _converter.Convert(file, FileFormat.Xml, FileFormat.Json);
                    return(new FileStreamResult(new MemoryStream((Encoding.UTF8).GetBytes(serializedFile)),
                                                "application/octet-stream"));
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                _logger.Log(ex.Message);
                return(StatusCode(500));
            }
        }
示例#5
0
        public static void ParallelTestThread(object parameters)
        {
            Debug.WriteLine($"Thread started: {Thread.CurrentThread.ManagedThreadId}");

            ThreadParameters threadParams = (ThreadParameters)parameters;

            IFileConverter converter = threadParams.Converter ?? new LOToPdfConverter();

            Debug.WriteLine("Converter created: {Thread.CurrentThread.ManagedThreadId}");

            for (int i = 1; i <= threadParams.IterationsCount; i++)
            {
                File.WriteAllBytes(threadParams.DestinationFileNameTemplate.Replace("{iterationNumber}", i.ToString()),
                                   converter.Convert(threadParams.SourceFileBytes, threadParams.SourceFileExtension));
            }
        }
示例#6
0
        public async Task <IActionResult> ImportFromFile(IFormFile file, NotePackageDetailDto dto)
        {
            var notes       = _converter.Convert(file);
            var nodePackage = new NotePackage()
            {
                Title    = dto.Title,
                Category = new Category()
                {
                    Id = dto.CategoryId
                },
                Notes = notes.ToList()
            };
            await _userNotesService.AddNotePackage(GetIdentityName(), nodePackage);

            return(StatusCode(201));
        }
示例#7
0
        public string Convert(string inputFilePath,
                              string outputFilePath,
                              List <BookMarker> bookMarkers,
                              DynamicBookMarker dynamicData,
                              string signatureKeyPath = null,
                              string posText          = null)
        {
            string inputExt  = GetFileExt(inputFilePath);
            string outputExt = GetFileExt(outputFilePath);

            IFileConverter fileConverter = SatisfiedBy(
                inputExt,
                outputExt);

            if (fileConverter == null)
            {
                throw new InvalidOperationException(string.Format("未找到从{0}转到{1}的文件转换器", inputExt, outputExt));
            }
            fileConverter.Convert(inputFilePath, outputFilePath, bookMarkers, dynamicData);
            FileInfo fi          = new FileInfo(outputFilePath);
            var      resourceKey = fi.Name;
            var      finalPath   = outputFilePath;

            if (signatureKeyPath != null && posText != null)
            {
                string savePath = Path.Combine(fi.DirectoryName, sigPrefix + fi.Name);
                fileConverter.Signature(outputFilePath, savePath, signatureKeyPath, posText);

                fi          = new FileInfo(savePath);
                resourceKey = fi.Name;
                finalPath   = savePath;
            }

            resourceManager.Put(resourceKey, File.Open(resourceKey, FileMode.Open));
            File.Delete(finalPath);
            return(finalPath);
        }
        public IActionResult Index()
        {
            StringBuilder stringBuilder = new StringBuilder();

            //sms
            stringBuilder.Append(_sms.SmsSend() + " \n");

            //mails
            ///var mailA = _mails.First(o =>o is MailA);
            ///var mailA = _mails.First(o => o.GetType() == typeof(MailA));
            //or
            ///var mailA = _mails.First(o => o.GetType().Name.Equals("MailA"));
            foreach (var mail in _mails)
            {
                stringBuilder.Append(mail.Send() + "\n");
            }

            //file Converter
            stringBuilder.Append(_fileConverter.Convert());//v1
            ///stringBuilder.Append(_fileConverterDelg("XmlConverter").Convert());//v2


            return(Content(stringBuilder.ToString()));
        }
        private String _ConvertDocument(FileConversionUpdate _FileConversionUpdate, String Destination)
        {
            IFileInformation ConvertedFileInfo = _FileConversionUpdate.Original;

            if (ConvertedFileInfo.FormatInformation.FileExtension != EFileExtension.XML)
            {
                IFileInformation _AutoXML = TryGenerateXMLFile(ConvertedFileInfo, Destination, _FileConversionUpdate);

                if (_AutoXML == null)
                {
                    return(null);
                }


                try
                {
                    if (!Settings.Default.EnablePDF)
                    {
                        return(null);
                    }

                    ConvertedFileInfo = _FEFileConverter.Convert(_AutoXML);

                    _FileConversionUpdate.AddTransformation(EFileTransformation.ConvertedToCopied, _AutoXML, ConvertedFileInfo);

                    if (ConvertedFileInfo == null)
                    {
                        return(null);
                    }
                }
                catch (Exception Ex)
                {
                    _FileConversionUpdate.AddTransformation(EFileTransformation.Failed,
                                                            _AutoXML,
                                                            null,
                                                            new StateEventArgs(ESourceState.Failed, Ex));

                    throw Ex;
                }
                finally
                {
                    if (!Settings.Default.EnableXML)
                    {
                        File.Delete(_AutoXML.Path.LocalPath);

                        _FileConversionUpdate.AddTransformation(EFileTransformation.Deleted, null);
                    }
                }
            }
            else
            {
                if (!Settings.Default.EnablePDF)
                {
                    return(null);
                }

                try
                {
                    ConvertedFileInfo = Convert(ConvertedFileInfo);

                    _FileConversionUpdate.AddTransformation(EFileTransformation.ConvertedToCopied, ConvertedFileInfo);
                }
                catch (Exception Ex)
                {
                    _FileConversionUpdate.AddTransformation(EFileTransformation.Failed,
                                                            ConvertedFileInfo,
                                                            new StateEventArgs(ESourceState.Failed, Ex));

                    throw Ex;
                }



                if (ConvertedFileInfo == null)
                {
                    return(null);
                }
            }

            if (ConvertedFileInfo != null)
            {
                if (!Settings.Default.InheritFileName)
                {
                    if (File.Exists(ConvertedFileInfo.FallbackPath))
                    {
                        File.Delete(ConvertedFileInfo.FallbackPath);
                    }

                    File.Move(ConvertedFileInfo.Path.LocalPath, ConvertedFileInfo.FallbackPath);

                    ConvertedFileInfo = new FileInformation(ConvertedFileInfo.FormatInformation, ConvertedFileInfo.FallbackPath);

                    _FileConversionUpdate.AddTransformation(EFileTransformation.RenamedTo, ConvertedFileInfo);
                }

                if (Destination != ConvertedFileInfo.Directory)
                {
                    if (File.Exists(Destination + "\\" + ConvertedFileInfo.FileName))
                    {
                        File.Delete(Destination + "\\" + ConvertedFileInfo.FileName);
                    }

                    File.Move(ConvertedFileInfo.Path.LocalPath, Destination + "\\" + ConvertedFileInfo.FileName);

                    _FileConversionUpdate.AddTransformation(EFileTransformation.RenamedTo, new FileInformation(ConvertedFileInfo.FormatInformation,
                                                                                                               Destination + "\\" + ConvertedFileInfo.FileName));

                    return(Destination + "\\" + ConvertedFileInfo.FileName);
                }

                return(ConvertedFileInfo.Path.LocalPath);
            }

            return(null);
        }