Exemple #1
0
 public CarManager(ICarDal _cardal, ICarImagesDal _carImagesDal, IFileProcess fileProcess)
 {
     //Constructor Injection
     cardal           = _cardal;
     carImagesDal     = _carImagesDal;
     this.fileProcess = fileProcess;
 }
Exemple #2
0
        public void init()
        {
            List <SettingsDataObject> settings = new List <SettingsDataObject>
            {
                new SettingsDataObject {
                    Key = "IDEA_TITLE_LENGTH", Value = "25"
                },
                new SettingsDataObject {
                    Key = "IDEA_CONTENT_LENGTH", Value = "1000"
                },
                new SettingsDataObject {
                    Key = "IDEA_FILE_LIMIT", Value = "2"
                },
                new SettingsDataObject {
                    Key = "IDEA_FILE_MAX_SIZE", Value = "2"
                },
                new SettingsDataObject {
                    Key = "IDEA_SHOW_OTHER_FIELDOFWATER", Value = "true"
                }
            };
            SettingsGroupDataObject groupSettings = new SettingsGroupDataObject();

            groupSettings.Settings = settings;
            settingsData           = new Mock <ISettingsData>();
            settingsData.Setup(s => s.GetGroupSettings(SettingsKeys.IdeaForm.GroupKEY)).Returns(groupSettings);

            IFieldofwaterData fieldOfWater = Mock.Of <IFieldofwaterData>();
            IFileProcess      fileprocess  = Mock.Of <IFileProcess>();

            ideasData = new Mock <IIdeasData>();
            ideasData.Setup(x => x.Insert(It.IsAny <IdeaDataObject>())).Returns(1);
            process = new IdeaProcess(fieldOfWater, settingsData.Object, ideasData.Object, fileprocess);
        }
Exemple #3
0
 public IdeaProcess(IFieldofwaterData fieldOfWaterData,
                    ISettingsData settingsData,
                    IIdeasData ideaData,
                    IFileProcess fileProcess)
 {
     this.fieldOfWaterData = fieldOfWaterData;
     this.settingsData     = settingsData;
     this.ideaData         = ideaData;
     this.fileProcess      = fileProcess;
 }
Exemple #4
0
        /// <summary>
        /// Ctor needs a MonoBehaviour instance to run the coroutine.
        /// </summary>
        /// <param name="mb">Mb.</param>
        /// <param name="path">Path.</param>
        /// <param name="fileProcess">File process.</param>
        /// <param name="amountLimit">Amount limit.</param>
        public LoaderControlSystem(MonoBehaviour mb, string path, IFileProcess fileProcess, int amountLimit)
        {
            if (fileProcess == null)
            {
                throw new NullReferenceException();
            }
            this.m_fileProcess = fileProcess;

            this.m_amountLimit = amountLimit;
            // Start the coroutine attached to the Program instance
            mb.StartCoroutine(StartParse(path));
        }
Exemple #5
0
        /// <summary>
        /// 获取文件流
        /// </summary>
        /// <param name="fileID">文件ID</param>
        /// <returns>文件流</returns>
        public static Stream GetFileStream(decimal fileID)
        {
            if (fileID <= 0)
            {
                return(null);
            }

            IFileProcess service = GetFileProcess();

            byte[] bites = service.GetFile((int)fileID);
            if (bites != null)
            {
                return(new MemoryTributary(bites));
            }
            else
            {
                return(new MemoryTributary());
            }
        }
        //Create callback methods here. For more information about adding callback methods, visit https://go.microsoft.com/fwlink/?LinkID=271226

        public void SaveToFileButton_OnAction(Office.IRibbonControl control)
        {
            Outlook.Inspector inspector = null;
            Outlook.MailItem  thisMail  = null;
            try
            {
                if (control.Context is Outlook.Inspector)
                {
                    inspector = control.Context as Outlook.Inspector;
                    thisMail  = inspector.CurrentItem as Outlook.MailItem;
                    ChannelFactory <IFileProcess> pipeFactory = new ChannelFactory <IFileProcess>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/Save"));
                    IFileProcess fileProxy = pipeFactory.CreateChannel();
                    //?await?
                    fileProxy.SaveToFile(thisMail.Subject, thisMail.Body);

                    //Close client channel and Channel factory
                    if (fileProxy != null)
                    {
                        ((IClientChannel)fileProxy).Close();
                    }
                    if (pipeFactory != null)
                    {
                        pipeFactory.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to initiate message save. Please, launch a server.\n" +
                                $"Exception message - {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (thisMail != null && Marshal.IsComObject(thisMail))
                {
                    Marshal.ReleaseComObject(thisMail);
                }
                if (inspector != null && Marshal.IsComObject(inspector))
                {
                    Marshal.ReleaseComObject(inspector);
                }
            }
        }
Exemple #7
0
        public FileTests()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddEnvironmentVariables();

            IConfiguration config = builder.Build();

            var client = config.GetSection(nameof(ClientSettings)).Get <ClientSettings>();

            //trying moq
            _clientSetting = new Mock <IOptions <ClientSettings> >();
            _clientSetting.Setup(o => o.Value).Returns(client);

            var currentDirectory = Directory.GetCurrentDirectory();
            // bad code
            var filePath = Path.GetDirectoryName($"{currentDirectory.Substring(0, currentDirectory.IndexOf("opg-201910Base-master") + 22)}opg-201910Base-master\\");

            fileProvider = new PhysicalFileProvider(filePath);
            _fileProcess = new FileProcess(_clientSetting.Object, fileProvider);
        }
Exemple #8
0
        /// <summary>
        /// Calculates the new field value. The new value is stored in the <see cref="NewValue" /> property.
        /// </summary>
        /// <param name="sourceData">The source data set.</param>
        /// <param name="destination">The destination item.</param>
        /// <exception cref="System.InvalidOperationException">Source field is not a file.</exception>
        public void CalculateNewValue(DataTriggerSourceData sourceData, IEditableRoot destination)
        {
            var newValue = ValueCalculator(sourceData, destination);
            var fileValue = newValue as IFileProcess;

            if (newValue != fileValue)
                throw new InvalidOperationException("Source field is not a file.");

            NewValue = fileValue;
        }
Exemple #9
0
        /// <summary>
        /// Updates the file process.
        /// </summary>
        /// <param name="file">The file.</param>
        public static void UpdateFileProcess(IFileProcess file)
        {
            if (file != null && (!file.IsNewVersion || string.IsNullOrEmpty(file.FileName)))
                return;

            var sysOptions = SystemOptionsInfo.GetSystemOptionsInfo();
            if (sysOptions == null)
                return;

            if (file == null)
                return;

            var newFileName = Guid.NewGuid() + Path.GetExtension(file.FileName);

            UpdateFileProcess(file.FileName, newFileName, sysOptions.FileProcessorURI);

            if (file.IsReadyForPdf())
            {
                string newFileNameWithPdfExtension = FileHelper.GetNewFileNameWithPdfExtension(newFileName);
                UpdateFileProcess(file.ConvertedFileName, newFileNameWithPdfExtension, sysOptions.FileProcessorURI);
            }

            file.FileName = newFileName;
        }
Exemple #10
0
        private void GeneratePdfFromReport(IEditableRoot item, IFileProcess file, ISystemOptionsInfo sysOptions)
        {
            if (string.IsNullOrEmpty(file.ReportName)) return;

            var ms = GetReportStream(item, file.ReportName);
            UploadFile(file.FileName, ms, sysOptions);
        }
Exemple #11
0
        public void UpdatePdf(IEditableRoot item, IFileProcess file)
        {
            if (file == null || item == null || string.IsNullOrEmpty(file.FileName)) return;

            var sysOptions = SystemOptionsInfo.GetSystemOptionsInfo();
            if (sysOptions == null)
                return;

            if (file.UseReport.HasValue && file.UseReport.Value)
            {
                GeneratePdfFromReport(item, file, sysOptions);
                return;
            }

            if (!file.IsReadyForPdf())
            {
                return;
            }

            if (!file.IsPdfWithReport())
            {
                return;
            }

            DownloadDocument(
                file.FileName,
                sysOptions,
                fileStream =>
                {
                    if (fileStream == null || fileStream.Length == 0)
                        return;

                    try
                    {
                        var isLandscape = false;

                        using (var documentStream = new MemoryStream())
                        {
                            if (!SavePdfToStream(file.FileName, fileStream, documentStream, ref isLandscape)) return;

                            //watermarks
                            using (var pdfDoc = new Aspose.Pdf.Document(documentStream))
                            {
                                if (pdfDoc.Pages.Count == 0)
                                    return;

                                var watermarkReport = isLandscape ? file.WatermarkLandscapeReportName : file.WatermarkPortraitReportName;
                                if (!string.IsNullOrEmpty(watermarkReport))
                                {
                                    var ms = GetReportStream(item, watermarkReport);

                                    var watermarkPdf = new Aspose.Pdf.Document(ms);
                                    if (watermarkPdf.Pages.Count > 0)
                                    {
                                        var pageStamp = new Aspose.Pdf.PdfPageStamp(watermarkPdf.Pages[1]) { Background = false, Opacity = 0.0 };

                                        var page = (file.FirstPageWatermark.HasValue && file.FirstPageWatermark.Value) ? 1 : 2;
                                        for (var i = page; i <= pdfDoc.Pages.Count; i++)
                                            pdfDoc.Pages[i].AddStamp(pageStamp);
                                    }
                                }

                                //cover page
                                var coverPageReport = isLandscape ? file.CoverPageLandscapeReportName : file.CoverPagePortraitReportName;
                                if (!string.IsNullOrEmpty(coverPageReport))
                                {
                                    var ms = GetReportStream(item, coverPageReport);

                                    var coverPagePdf = new Aspose.Pdf.Document(ms);
                                    pdfDoc.Pages.Insert(1, coverPagePdf.Pages);
                                }

                                //Appendix
                                var appendixReport = isLandscape ? file.AppendixLandscapeReportName : file.AppendixPortraitReportName;
                                if (!string.IsNullOrEmpty(appendixReport))
                                {
                                    var ms = GetReportStream(item, appendixReport);

                                    var appendixePdf = new Aspose.Pdf.Document(ms);
                                    pdfDoc.Pages.Insert(pdfDoc.Pages.Count + 1, appendixePdf.Pages);
                                }

                                var outputStream = new MemoryStream();
                                pdfDoc.Save(outputStream);

								var newFileNameWithPdfExtension = string.IsNullOrEmpty(file.ConvertedFileName) ?
									FileHelper.GetNewFileNameWithPdfExtension(file.FileName) :
									file.ConvertedFileName;

								UploadFile(newFileNameWithPdfExtension, outputStream, sysOptions);

                                if (file.ConvertedFileName != newFileNameWithPdfExtension)
                                {
                                    file.ConvertedFileName = newFileNameWithPdfExtension;
                                    ((ISavable)file).Save();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Log(LogSeverity.Error, "FileManager.UpdatePdf", e.ToString());
                    }
                });
        }
Exemple #12
0
 public LoggerManager(ILoggerRepository ILoggerRepository, IFileProcess fileProcess)
 {
     _loggerRepository = ILoggerRepository;
     _fileProcess      = fileProcess;
 }
 public CarsController(ICarService carService, ICarImageService carImageService, IFileProcess fileProcess)
 {
     this.carService      = carService;
     this.carImageService = carImageService;
     this.fileProcess     = fileProcess;
 }
Exemple #14
0
        private void UpdateFileFromLocation(IFileProcess fileField, IDataContext dataContext)
        {
            var fileLocation = TypeConverter.Convert<string>(LocationExpression(dataContext));
            var tempFile = FileManager.GetTempFileName(null);
            var originalFileName = DownloadFile(fileLocation, tempFile);

            string extension = null;

            if (NameExpression != null)
            {
                var fileName = TypeConverter.Convert<string>(NameExpression(dataContext));
                if (!string.IsNullOrWhiteSpace(fileName) && Path.HasExtension(fileName))
                    extension = Path.GetExtension(fileName);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(originalFileName) && Path.HasExtension(originalFileName))
                    extension = Path.GetExtension(originalFileName);
            }

            if (!string.IsNullOrEmpty(extension))
            {
                var newTempFile = Path.ChangeExtension(tempFile, extension);

                File.Move(tempFile, newTempFile);
                tempFile = newTempFile;
            }

            if (NameExpression == null)
                fileField.OriginalFileName = !string.IsNullOrEmpty(originalFileName) ? originalFileName : Path.GetFileName(tempFile);
            fileField.FileName = Path.GetFileName(tempFile);

            fileField.UploadFile();
        }
Exemple #15
0
        private void UpdateFileFromContent(IFileProcess fileField, IDataContext dataContext)
        {
            var data = TypeConverter.Convert<byte[]>(ContentExpression(dataContext)) ?? new byte[0];

            string extension = null;

            if (NameExpression != null)
            {
                var fileName = TypeConverter.Convert<string>(NameExpression(dataContext));
                if (!string.IsNullOrWhiteSpace(fileName) && Path.HasExtension(fileName))
                    extension = Path.GetExtension(fileName);
            }

            var tempFile = FileManager.GetTempFileName(extension);

            File.WriteAllBytes(tempFile, data);

            if (NameExpression == null)
                fileField.OriginalFileName = Path.GetFileName(tempFile);
            fileField.FileName = Path.GetFileName(tempFile);

            fileField.UploadFile();
        }
Exemple #16
0
        /// <summary>
        /// 获取远程文件操作接口
        /// </summary>
        /// <returns>远程文件操作接口</returns>
        public static IFileProcess GetFileProcess()
        {
            IFileProcess fileCline = CreateServiceClient <IFileProcess>();

            return(fileCline);
        }
Exemple #17
0
 public FileService(IFileProcess fileMapper)
 {
     FileMapper = fileMapper;
 }
Exemple #18
0
 public HomeController(ILogger <HomeController> logger, IFileProcess fileProcess)
 {
     _logger      = logger;
     _fileProcess = fileProcess;
 }
Exemple #19
0
 public CarImageManager(ICarImagesDal _carImagesDal, ICarDal _cardal, IFileProcess fileProcess)
 {
     carImagesDal     = _carImagesDal;
     cardal           = _cardal;
     this.fileProcess = fileProcess;
 }
 public LoggerRepository(ApsiyonDBContext dbContext, IFileProcess fileProcess)
 {
     _dbContext   = dbContext;
     _fileProcess = fileProcess;
 }
 public CarImagesController(IFileProcess fileProcess, ICarImageService carImageService)
 {
     this.fileProcess     = fileProcess;
     this.carImageService = carImageService;
 }