Ejemplo n.º 1
0
    /// <summary>
    /// 写入
    /// </summary>
    /// <param name="path">地址</param>
    /// <param name="data">数据</param>
    /// <param name="fileFormatType">文件类型</param>
    /// <param name="encryptModeType">加密类型</param>
    public static void Write(string path, byte[] data, FileFormatType fileFormatType = FileFormatType.txt, EncryptModeType encryptModeType = EncryptModeType.None)
    {
        switch (fileFormatType)
        {
        case FileFormatType.txt:
            txtFileSave.WriteData(path, data, encryptModeType);
            break;

        case FileFormatType.json:
            jsonFileSave.WriteData(path, data, encryptModeType);
            break;

        case FileFormatType.xml:
            xmlFileSave.WriteData(path, data, encryptModeType);
            break;

        case FileFormatType.png:
            pngFileSave.WriteData(path, data, encryptModeType);
            break;

        case FileFormatType.jpg:
            jpgFileSave.WriteData(path, data, encryptModeType);
            break;

        case FileFormatType.exr:
            exrFileSave.WriteData(path, data, encryptModeType);
            break;

        default:
            break;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 读取
    /// </summary>
    /// <typeparam name="T">返回类型</typeparam>
    /// <param name="path">地址</param>
    /// <param name="fileFormatType">文件类型</param>
    /// <param name="encryptModeType">加密类型</param>
    /// <returns></returns>
    public static FileObject Read(string path, FileFormatType fileFormatType = FileFormatType.txt, EncryptModeType encryptModeType = EncryptModeType.None)
    {
        FileObject fileObject = default(FileObject);

        switch (fileFormatType)
        {
        case FileFormatType.txt:
            fileObject = txtFileSave.ReadData(path, encryptModeType);
            break;

        case FileFormatType.json:
            fileObject = jsonFileSave.ReadData(path, encryptModeType);
            break;

        case FileFormatType.xml:
            fileObject = xmlFileSave.ReadData(path, encryptModeType);
            break;

        case FileFormatType.png:
            fileObject = pngFileSave.ReadData(path, encryptModeType);
            break;

        case FileFormatType.jpg:
            fileObject = jpgFileSave.ReadData(path, encryptModeType);
            break;

        case FileFormatType.exr:
            fileObject = exrFileSave.ReadData(path, encryptModeType);
            break;

        default:
            break;
        }
        return(fileObject);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 异步读取
    /// </summary>
    /// <typeparam name="T">返回类型</typeparam>
    /// <param name="path">地址</param>
    /// <param name="fileFormatType">文件类型</param>
    /// <param name="encryptModeType">加密类型</param>
    /// <returns></returns>
    public static void ReadAsync(string path, System.Action <FileObject> OnCall, FileFormatType fileFormatType = FileFormatType.txt, EncryptModeType encryptModeType = EncryptModeType.None)
    {
        switch (fileFormatType)
        {
        case FileFormatType.txt:
            txtFileSave.ReadAsyncData(path, encryptModeType, OnCall);
            break;

        case FileFormatType.json:
            jsonFileSave.ReadAsyncData(path, encryptModeType, OnCall);
            break;

        case FileFormatType.xml:
            xmlFileSave.ReadAsyncData(path, encryptModeType, OnCall);
            break;

        case FileFormatType.png:
            pngFileSave.ReadAsyncData(path, encryptModeType, OnCall);
            break;

        case FileFormatType.jpg:
            jpgFileSave.ReadAsyncData(path, encryptModeType, OnCall);
            break;

        case FileFormatType.exr:
            exrFileSave.ReadAsyncData(path, encryptModeType, OnCall);
            break;

        default:
            break;
        }
    }
Ejemplo n.º 4
0
 public FileContainer(FileType fileType, FileFormatType fileFormatType, string name, string description, IEnumerable <string> extensions)
 {
     this.FileType       = fileType;
     this.FileFormatType = fileFormatType;
     this.Name           = name;
     this.Description    = description;
     this.Extensions     = new ReadOnlyCollection <string>(extensions.ToList());
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="config">SMWriterBaseConfig to configure how to write the Chart.</param>
        /// <param name="logger">ILogger for logging.</param>
        /// <param name="fileFormatType">FileFormatType of file being written.</param>
        protected SMWriterBase(SMWriterBaseConfig config, ILogger logger, FileFormatType fileFormatType)
        {
            Config         = config;
            Logger         = logger;
            FileFormatType = fileFormatType;

            PerformStartupChecks();
            DetermineChartDifficultyTypes();
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Create an object using the contents of the corresponding MzIdentML object
        /// </summary>
        /// <param name="ff"></param>
        /// <param name="idata"></param>
        public FileFormatInfo(FileFormatType ff, IdentDataObj idata)
            : base(idata)
        {
            _cvParam = null;

            if (ff.cvParam != null)
            {
                _cvParam = new CVParamObj(ff.cvParam, IdentData);
            }
        }
Ejemplo n.º 7
0
        public static void DataSet2Excel(string filePath, DataSet ds, bool[] showColumnNameArray = null, int[,] positionArray = null)
        {
            FileFormatType fileFormatType = FileFormatType.Xlsx;

            if (filePath.EndsWith("xlsx", StringComparison.InvariantCultureIgnoreCase))
            {
                fileFormatType = FileFormatType.Xlsx;
            }
            else if (filePath.EndsWith("xls", StringComparison.InvariantCultureIgnoreCase))
            {
                fileFormatType = FileFormatType.Xlsx;
            }

            Workbook workbook = new Workbook(fileFormatType: fileFormatType);

            for (int index = 0; index < ds.Tables.Count; index++)
            {
                Worksheet workSheet = workbook.Worksheets[index];

                DataTable dt = ds.Tables[index];
                if (dt.TableName.IsNullOrEmpty() == true)
                {
                    workSheet.Name = "Sheet{0}".FormatWith(index + 1);
                }
                else
                {
                    workSheet.Name = dt.TableName;
                }

                bool isFieldNameShown = true;
                if (showColumnNameArray != null)
                {
                    isFieldNameShown = showColumnNameArray[index];
                }

                int tmpFirstRow    = 0;
                int tmpFirstColumn = 0;
                if (positionArray != null)
                {
                    tmpFirstRow    = positionArray[index, 0];
                    tmpFirstColumn = positionArray[index, 1];
                }

                workSheet.Cells.ImportDataTable
                (
                    dataTable: dt,
                    isFieldNameShown: isFieldNameShown,
                    firstRow: tmpFirstRow,
                    firstColumn: tmpFirstColumn
                );
            }

            workbook.Save(filePath);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new workbook within a "standard" environment which ensures that
        /// the range of write-related helper methods in this library behave as expected.
        /// </summary>
        /// <param name="fileFormatType">The file format type to use.</param>
        /// <returns>
        /// A new workbook.
        /// </returns>
        public static Workbook CreateStandardWorkbook(
            FileFormatType fileFormatType = FileFormatType.Xlsx)
        {
            AsposeCellsLicense.ThrowIfNotRegistered();

            EnsureSizingOperationsHonorPixelsSpecified();

            var result = new Workbook(fileFormatType);

            return(result);
        }
Ejemplo n.º 9
0
        private void ConvertH3D(System.IO.Stream stream)
        {
            CanSave = true;

            System.IO.BinaryReader Reader = new System.IO.BinaryReader(stream);
            using (FileReader reader = new FileReader(stream, true))
            {
                uint magicNumber = reader.ReadUInt32();

                switch (magicNumber)
                {
                case 0x15122117:
                    FormatType = FileFormatType.GFModel;
                    H3DFile    = new H3D();
                    H3DFile.Models.Add(new SPICA.Formats.GFL2.Model.GFModel(Reader, "Model").ToH3DModel());
                    break;
                }

                string mbnPath = FilePath.Replace("bch", "mbn");

                if (reader.CheckSignature(3, "BCH"))
                {
                    H3DFile    = H3D.Open(stream.ToBytes());
                    FormatType = FileFormatType.BCH;
                    return;
                }
                else if (reader.CheckSignature(4, "CGFX"))
                {
                    H3DFile    = SPICA.Formats.CtrGfx.Gfx.Open(stream);
                    FormatType = FileFormatType.BCRES;
                }
                else if (GFPackage.IsValidPackage(stream))
                {
                    GFPackage.Header PackHeader = GFPackage.GetPackageHeader(stream);
                    switch (PackHeader.Magic)
                    {
                    case "PC": H3DFile = GFPkmnModel.OpenAsH3D(stream, PackHeader, null); break;
                    }
                }
                else if (System.IO.File.Exists(mbnPath))
                {
                    var ModelBinary = new SPICA.Formats.ModelBinary.MBn(new System.IO.BinaryReader(
                                                                            System.IO.File.OpenRead(mbnPath)), H3DFile);

                    H3DFile    = ModelBinary.ToH3D();
                    FormatType = FileFormatType.MBN;
                }
                else
                {
                    H3DFile = H3D.Open(stream.ToBytes());
                }
            }
        }
Ejemplo n.º 10
0
        public static void Run()
        {
            //ExStart: PreserveEmbeddedMSGFormatDuringLoad
            string dataDir = RunExamples.GetDataDir_Email();

            MailMessage mail = MailMessage.Load(dataDir + "tnefWithMsgInside.eml", new EmlLoadOptions()
            {
                PreserveEmbeddedMessageFormat = true
            });

            FileFormatType fileFormat = FileFormatUtil.DetectFileFormat(mail.Attachments[0].ContentStream).FileFormatType;

            Console.WriteLine("Embedded message file format: " + fileFormat);
            //ExEnd: PreserveEmbeddedMSGFormatDuringLoad
        }
Ejemplo n.º 11
0
    public static FileFormatType ResolveFileType(byte[] fileBytes)
    {
        var rg = FileFormatType.GetAll().ToArray();

        foreach (var fileType in rg)
        {
            foreach (byte[] sig1 in fileType.Signature)
            {
                if (fileBytes.StartsWith(sig1))
                {
                    return(fileType);
                }
            }
        }


        return(FileFormatType.Unknown);
    }
Ejemplo n.º 12
0
 public static byte[] ConvertFormat(Workbook workbook, FileFormatType format)
 {
     using (var streamForDoc = new MemoryStream())
     {
         //Start magic. After new build we get an exception 'Unsupported sfnt version' on first load
         //On seccond request It works well.
         try
         {
             workbook.Save(streamForDoc, format);
             return(streamForDoc.ToArray());
         }
         catch (Exception)
         {
             workbook.Save(streamForDoc, format);
             return(streamForDoc.ToArray());
         }
         //End magic
     }
 }
        public static byte[] ConvertFormat(Workbook workbook, FileFormatType format)
        {
            if (format == FileFormatType.Pdf)
            {
                workbook.Worksheets[0].PageSetup.Orientation = PageOrientationType.Landscape;
            }

            using (var streamForDoc = new MemoryStream())
            {
                try
                {
                    workbook.Save(streamForDoc, format);
                    return(streamForDoc.ToArray());
                }
                catch (Exception)
                {
                    workbook.Save(streamForDoc, format);
                    return(streamForDoc.ToArray());
                }
            }
        }
        /// <summary>
        /// Updates the Recorder file format and codec.
        /// Invokes "FileFormatUpdated" to other application's modules.
        /// </summary>
        /// <param name="item">Setting new value indicator.</param>
        public void UpdateRecorderFileFormat(FileFormatType item)
        {
            var oldCodec      = _recorder.AudioCodec;
            var oldFileFormat = _recorder.FileFormat;

            try
            {
                _recorder.Unprepare();
                _recorder.SetFormatAndCodec(FILE_FORMATS_DICTIONARY[item].Item2,
                                            FILE_FORMATS_DICTIONARY[item].Item1);
                _recorder.Prepare();
            }
            catch (Exception exception)
            {
                _recorder.SetFormatAndCodec(oldCodec, oldFileFormat);
                _recorder.Prepare();
                ErrorHandler(exception.Message);
                return;
            }

            FileFormatUpdated?.Invoke(this, item);
        }
Ejemplo n.º 15
0
        private void CutFile(Worksheet sheet,FileFormatType saveFileType,string outputFolder)
        {
            string filePre = txtFilePrefix.Text.Trim();
            int headerLastLine = (int) nudHeaderLastLine.Value;
            int count = sheet.Cells.Rows.Count;

            int num = (int)nudLines.Value;//每个文件的行数(不包括表头)
            int pages = (int)Math.Ceiling( (count-headerLastLine) * 1.0 / num );//计算切割成几个文件
            List<Workbook> books = new List<Workbook>();
            for (int i = 0; i < pages; i++)
            {
                int start = i * num + headerLastLine;
                int end = start + num;
                if (end > count)
                    end = count;

                Workbook b = new Workbook();
                Worksheet s = b.Worksheets[0];
                //拷贝表头
                for (int r = 0; r < headerLastLine; r++)
                {
                    s.Cells.CopyRow(sheet.Cells, r, r);
                }
                //拷贝数据
                for (int r = start, m = headerLastLine; r < end; r++, m++)
                {
                    s.Cells.CopyRow(sheet.Cells,r,m);
                }
                books.Add(b);
            }
            for (int i = 0; i < books.Count;i++ )
            {
                string f = string.Format(@"{0}\{1}{2}.{3}", outputFolder, filePre, i, FileFormatDesc(saveFileType));
                books[i].Save(f, saveFileType);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Handles "FileFormatUpdated" of the IVoiceRecorderService object.
 /// Invokes "FileFormatUpdated" to other application's modules.
 /// </summary>
 /// <param name="sender">Instance of the VoiceRecorderService class.</param>
 /// <param name="newValue">New value of the recorder file format setting.</param>
 private void FileFormatUpdatedEventHandler(object sender, FileFormatType newValue)
 {
     FileFormatUpdated?.Invoke(sender, newValue);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Updates recorder file format setting.
 /// </summary>
 /// <param name="item">New file format value to set.</param>
 public void UpdateRecorderFileFormat(FileFormatType item)
 {
     _service.UpdateRecorderFileFormat(item);
 }
Ejemplo n.º 18
0
 private string FileFormatDesc(FileFormatType format)
 {
     foreach (var type in dicFileType)
     {
         if (type.Value == format)
             return type.Key;
     }
     return string.Empty;
 }
Ejemplo n.º 19
0
        public static void WriteExcel(string fileName, string sheetName, DataTable dataTable,
                                      bool createFileAndSheet, bool exportColumnName, FileFormatType fileFormatType)
        {
            Workbook workbook = new Workbook();

            if (!File.Exists(fileName))
            {
                if (createFileAndSheet)
                {
                    if (!workbook.Worksheets.OfType <Worksheet>().Select(w => w.Name).Contains(sheetName))
                    {
                        workbook.Worksheets.Add(sheetName);
                    }

                    workbook.Save(fileName);
                }
            }

            workbook = new Workbook();
            workbook.Open(fileName);

            int column = 0;

            foreach (DataColumn dataColumn in dataTable.Columns)
            {
                workbook.Worksheets[sheetName].Cells[0, column++].Value = dataColumn.Caption;
            }

            Style style = workbook.CreateStyle();

            style.Number = 49; // TEXT format

            int row = 1;

            column = 0;
            foreach (DataRow dataRow in dataTable.Rows)
            {
                foreach (object item in dataRow.ItemArray)
                {
                    Cell cell = workbook.Worksheets[sheetName].Cells[row, column];

                    cell.SetStyle(style);
                    cell.Value = dataRow[column] + "";
                    column++;
                }
                column = 0;
                row++;
            }

            workbook.Save(fileName, fileFormatType);
        }
Ejemplo n.º 20
0
 public FileContainer(FileType fileType, FileFormatType fileFormatType, string name, string description, string extension)
     : this(fileType, fileFormatType, name, description, new string [] { extension })
 {
 }
Ejemplo n.º 21
0
 Task<AppConfig.ReturnCode> ICatalogReader.Parse(System.Windows.Forms.OpenFileDialog ofd, FileFormatType formatType, MainFormViewModel viewModel)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 22
0
 public FileContainer(FileType fileType, FileFormatType fileFormatType, string name, string description, params string [] extensions)
     : this(fileType, fileFormatType, name, description, extensions as IEnumerable <string>)
 {
     this.Extensions = new ReadOnlyCollection <string>(extensions);
 }
Ejemplo n.º 23
0
 public static bool IsFileTypeDocument(FileFormatType fileFormatType)
 {
     return(DocumentUtilities.FileFormatFileTypes [fileFormatType] == FileType.Document);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Main parsing method implementing ICatalogReader interface.
        /// </summary>
        /// <param name="ofd"></param>
        /// <param name="formatType"></param>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task<ReturnCode> Parse(OpenFileDialog ofd, FileFormatType formatType, MainFormViewModel viewModel = null)
        {
            if (ofd == null)
            {
                return ReturnCode.ModulesImportDefaultParseEmptyStream;
            }

            if (formatType == FileFormatType.ExcelWorkbook || formatType == FileFormatType.ExcelXml2003)
            {
                _fileFormatType = formatType;
            }
            else 
            {
                return ReturnCode.ModulesImportDefaultParseUnknownFormat;
            }

            switch (_fileFormatType)
            {
                case FileFormatType.ExcelWorkbook:
                    _excelLastRow = new Dictionary<String, int>();
                    _excelLastColumn = new Dictionary<String, int>();
                    if (String.IsNullOrEmpty(ofd.FileName))
                    {
                        return ReturnCode.ModulesImportDefaultParseEmptyStream;
                    }
                    _excelApplication = new Excel.Application();
                    _excelDocument = _excelApplication.Workbooks.Open(ofd.FileName);
                    if (_excelDocument == null)
                    {
                        return ReturnCode.ModulesImportDefaultParseEmptyStream;
                    }
                    break;
                case FileFormatType.ExcelXml2003:
                    try
                    {
                        Stream s = ofd.OpenFile();
                        _xmlDocument = new XmlDocument();
                        _xmlDocument.Load(s);
                        break;
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(this, "TemplatedCatalogReader.Parse, case=FileFormatType.ExcelXml2003, exception=" + ex.Message);
                        Notify("The XML parsing failed.");
                        return ReturnCode.ModulesImportDefaultParseEmptyStream;
                    }
            }

            if (viewModel != null)
            {
                _mainFormViewModel = viewModel;
                _mainFormViewModel.InputProgressBarValue = 0;
                _mainFormViewModel.InputProgressBarMax = InitPayload + 1; // initial payload and 'symbolic' last bit of payload before last return 
            }

            if (!(await IsValidWorkbook()))
            {
                Notify("Invalid Workbook.");
                return ReturnCode.ModulesImportDefaultParseInvalidWorkbook;
            }

            if (_mainFormViewModel != null)
            {
                if (_langs != null) _mainFormViewModel.InputProgressBarMax += _langs.Count;
                if (_tags != null) _mainFormViewModel.InputProgressBarMax += _tags.Count;
                if (_roles != null) _mainFormViewModel.InputProgressBarMax += _roles.Count;
                if (_qualities != null) _mainFormViewModel.InputProgressBarMax += _qualities.Count;
                if (_artists != null) _mainFormViewModel.InputProgressBarMax += _artists.Count;
                if (_works != null) _mainFormViewModel.InputProgressBarMax += _works.Count;
                if (_assets != null) _mainFormViewModel.InputProgressBarMax += _assets.Count;
                if (_albums != null) _mainFormViewModel.InputProgressBarMax += _albums.Count;
                if (_tracks != null) _mainFormViewModel.InputProgressBarMax += _tracks.Count;

                // Init phase 'completed'
                _mainFormViewModel.InputProgressBarValue = InitPayload;

                // Langs were already parsed
                if (_langs != null) _mainFormViewModel.InputProgressBarValue += _langs.Count;

            }

            await ParseTags();
            await ParseRoles();
            await ParseQualities();
            await ParseArtists();
            await ParseWorks();
            await ParseAssets();
            await ParseAlbums();
            await ParseTracks();

            Notify("Finalization...");
            FinalizeAlbums();
            FinalizeAssets();

            if (_mainFormViewModel != null)
            {
                if (_mainFormViewModel.FilterArtistChecked)
                {
                    CatalogContext.Instance.FilterUnusedArtists();
                }
                else if (_mainFormViewModel.FilterWorkChecked)
                {
                    CatalogContext.Instance.FilterUnusedWorks();
                }
                _mainFormViewModel.InputProgressBarValue = _mainFormViewModel.InputProgressBarMax;
            }

            CatalogContext.Instance.Initialized = true;
            Notify("Parsing completed.");
            return ReturnCode.Ok;
        }
Ejemplo n.º 25
0
 private FileFormat(FileFormatType type, string extension)
 {
     Type      = type;
     Extension = extension;
     ExtensionWithSeparator = "." + extension;
 }
        private int SetupResultPcm(AudioData from, out AudioData to, FileFormatType toFileFormat)
        {
            to = new AudioData();
            to.fileFormat = toFileFormat;

            var fmt = FilterSetup(from, mFilters);

            to.meta = new WWFlacRWCS.Metadata(from.meta);
            to.meta.sampleRate = fmt.SampleRate;
            to.meta.totalSamples = fmt.NumSamples;
            to.meta.channels = fmt.Channels;

            switch (toFileFormat) {
            case FileFormatType.FLAC:
            #if true
                to.meta.bitsPerSample = 24;
            #endif
                break;
            case FileFormatType.DSF:
                to.meta.bitsPerSample = 1;
                break;
            }

            if (from.picture != null) {
                to.picture = new byte[from.picture.Length];
                System.Array.Copy(from.picture, to.picture, to.picture.Length);
            }

            // allocate "to" pcm data
            to.pcm = new List<AudioDataPerChannel>();
            for (int ch=0; ch < to.meta.channels; ++ch) {
                byte [] data;

                // set silent sample values to output buffer
                switch (toFileFormat) {
                case FileFormatType.DSF:
                    if (0x7FFFFFC7 < (to.meta.totalSamples + 7) / 8) {
                        return (int)WWFlacRWCS.FlacErrorCode.OutputFileTooLarge;
                    }
                    data = new byte[(to.meta.totalSamples + 7) / 8];
                    for (long i=0; i < data.LongLength; ++i) {
                        data[i] = 0x69;
                    }
                    break;
                case FileFormatType.FLAC:
                    if (0x7FFFFFC7 < to.meta.totalSamples * (to.meta.bitsPerSample / 8)) {
                        return (int)WWFlacRWCS.FlacErrorCode.OutputFileTooLarge;
                    }
                    data = new byte[to.meta.totalSamples * (to.meta.bitsPerSample / 8)];
                    break;
                default:
                    System.Diagnostics.Debug.Assert(false);
                    data = null;
                    break;
                }

                var adp = new AudioDataPerChannel();
                adp.data = data;
                adp.bitsPerSample = to.meta.bitsPerSample;
                adp.totalSamples = to.meta.totalSamples;
                to.pcm.Add(adp);
            }
            return 0;
        }
Ejemplo n.º 27
0
 public static Workbook SetFileFormat(this Workbook wb, FileFormatType fileFormat)
 {
     wb.FileFormat = fileFormat;
     return(wb);
 }
Ejemplo n.º 28
0
        private int SetupResultPcm(AudioData from, List <FilterBase> filters, out AudioData to, FileFormatType toFileFormat)
        {
            to            = new AudioData();
            to.fileFormat = toFileFormat;

            var fmt = FilterSetup(from, 0, filters);

            to.meta              = new WWFlacRWCS.Metadata(from.meta);
            to.meta.sampleRate   = fmt.SampleRate;
            to.meta.totalSamples = fmt.NumSamples;
            to.meta.channels     = fmt.NumChannels;

            switch (toFileFormat)
            {
            case FileFormatType.FLAC:
#if true
                to.meta.bitsPerSample = 24;
#endif
                break;

            case FileFormatType.DSF:
                to.meta.bitsPerSample = 1;
                break;
            }

            if (from.picture != null)
            {
                to.picture = new byte[from.picture.Length];
                System.Array.Copy(from.picture, to.picture, to.picture.Length);
            }

            // allocate "to" pcm data
            to.pcm = new List <AudioDataPerChannel>();
            for (int ch = 0; ch < to.meta.channels; ++ch)
            {
                byte[] data;

                // set silent sample values to output buffer
                switch (toFileFormat)
                {
                case FileFormatType.DSF:
                    if (0x7FFFFFC7 < (to.meta.totalSamples + 7) / 8)
                    {
                        return((int)WWFlacRWCS.FlacErrorCode.OutputFileTooLarge);
                    }
                    data = new byte[(to.meta.totalSamples + 7) / 8];
                    for (long i = 0; i < data.LongLength; ++i)
                    {
                        data[i] = 0x69;
                    }
                    break;

                case FileFormatType.FLAC:
                    if (0x7FFFFFC7 < to.meta.totalSamples * (to.meta.bitsPerSample / 8))
                    {
                        return((int)WWFlacRWCS.FlacErrorCode.OutputFileTooLarge);
                    }
                    data = new byte[to.meta.totalSamples * (to.meta.bitsPerSample / 8)];
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false);
                    data = null;
                    break;
                }

                var adp = new AudioDataPerChannel();
                adp.data          = data;
                adp.bitsPerSample = to.meta.bitsPerSample;
                adp.totalSamples  = to.meta.totalSamples;
                to.pcm.Add(adp);
            }
            return(0);
        }
Ejemplo n.º 29
0
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                String workbookFullName = FilePath.Get(context);
                String newFileName      = NewFileName.Get(context);
                string newfilePath      = NewFilePath.Get(context);

                string   fileFormat               = ToDescriptionString(FileFormatType);
                String[] fileFormatTypeStr        = FileFormatType.ToString().TrimStart().Split('_');
                String   extension                = String.Concat(".", fileFormatTypeStr[0]);
                string   newFileNameWithExtension = String.Concat(newFileName, extension);

                string  workbookName     = string.Empty;
                dynamic xlWorkbook       = null;
                bool    excelFileVisible = false;

                if (true == NeedToOpen)
                {
                    excelFileVisible = true;
                }

                // Combine 2 path parts.
                string workbooknameas = Path.Combine(newfilePath, newFileName);
                string workbooknameasWithExtension = Path.Combine(newfilePath, newFileNameWithExtension);

                if (File.Exists(workbookFullName))
                {
                    ExcelHelper.Shared.Close_OpenedFile(workbookFullName);
                    workbookName = Path.GetFileName(workbookFullName);

                    ExcelHelper.Shared.GetApp(excelFileVisible).DisplayAlerts = false;
                    xlWorkbook = ExcelHelper.Shared.GetApp(excelFileVisible).Workbooks.Open(workbookFullName);

                    if (File.Exists(workbooknameasWithExtension))
                    {
                        if (true == IsOverride)
                        {
                            // xlWorkbook.SaveAs(workbooknameas, FileFormatType, Missing.Value, Missing.Value, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlUserResolution, true, Missing.Value, Missing.Value, Missing.Value);
                            XlFileFormat fm = (XlFileFormat)Enum.Parse(typeof(XlFileFormat), fileFormat);
                            xlWorkbook.SaveAs(workbooknameas, fm, Missing.Value, Missing.Value, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlUserResolution, true, Missing.Value, Missing.Value, Missing.Value);
                        }
                        else
                        {
                            Log.Logger.LogData("The file \"" + newFileName + "\" is already exists in activity Excel_Workbook_SaveAs", LogLevel.Error);
                            if (!ContinueOnError)
                            {
                                context.Abort();
                            }
                        }
                    }
                    else
                    {
                        // xlWorkbook.SaveAs(workbooknameas, XlFileFormat.xlWorkbookDefault, Missing.Value, Missing.Value, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlUserResolution, true, Missing.Value, Missing.Value, Missing.Value);
                        //xlWorkbook.SaveAs(workbooknameas, FileFormatType, Missing.Value,Missing.Value, false, false, XlSaveAsAccessMode.xlNoChange,XlSaveConflictResolution.xlUserResolution, true, Missing.Value, Missing.Value, Missing.Value);
                        XlFileFormat fm = (XlFileFormat)Enum.Parse(typeof(XlFileFormat), fileFormat);
                        xlWorkbook.SaveAs(workbooknameas, fm, Missing.Value, Missing.Value, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlUserResolution, true, Missing.Value, Missing.Value, Missing.Value);
                    }
                    if (true == NeedToClose)
                    {
                        xlWorkbook.Close();
                    }
                    if (false == NeedToClose && false == NeedToOpen)
                    {
                        xlWorkbook.Close();
                    }
                    if (false == NeedToClose && true == NeedToOpen)
                    {
                        xlWorkbook.Close();
                        ExcelHelper.Shared.GetApp(excelFileVisible).Workbooks.Open(workbookFullName);
                    }
                    if (ExcelHelper.Shared.GetApp(excelFileVisible).Workbooks.Count == 0)
                    {
                        ExcelHelper.Shared.Dispose();
                    }
                }
                else
                {
                    Log.Logger.LogData("Excel file does not exist:\"" + workbookFullName + "\" in activity Excel_Workbook_SaveAs", LogLevel.Error);
                    if (!ContinueOnError)
                    {
                        context.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message + " in activity Excel_Workbook_SaveAs", LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }