public void WriteOperationToLog(OperationParameters operation) { WriteUnicodeString("Original file path = " + operation.FilePath); WriteUnicodeString("Params and output file name = " + operation.OutputFilePath); if (operation.ErrCodes == string.Empty) { WriteUnicodeString("Error code = None"); } else { WriteUnicodeString("Error code = " + operation.ErrCodes); } WriteUnicodeString("Time of convertation = " + operation.Time); WriteUnicodeString("Params and output file name = " + operation.OutputFilePath); }
private static List <OperationParameters> GenerateTaskList(string[] inputFilePaths, string foderToSaveFiles) { var operationTaskParams = new List <OperationParameters>(); foreach (var fileName in inputFilePaths) { foreach (var compMode in CompMode) { var methodsCount = GetValidCountMethodsForCompMode(compMode); for (var methodsNumber = 0; methodsNumber < methodsCount; methodsNumber++) //Type of compression { var maxQuality = 0; if ((compMode == "Grayscale") || (compMode == "Color")) { if (methodsNumber == 1) { maxQuality = 5; } else if (methodsNumber == 2) { maxQuality = 4; } } for (var quality = 0; quality <= maxQuality; quality++) { var opParams = "_" + compMode + "_" + TransformMethodToUserFriendly(compMode, methodsNumber) + "_" + quality.ToString(CultureInfo.CurrentCulture); var outputFilePath = TransformFileName(fileName, foderToSaveFiles, opParams); if (!File.Exists(outputFilePath)) { var operationParameters = new OperationParameters { FilePath = fileName, CompMode = compMode, Method = methodsNumber, Quality = quality, OutputFilePath = outputFilePath }; operationTaskParams.Add(operationParameters); } } } } } return(operationTaskParams); }
public void OptimizeDocument(OperationParameters operation) { try { var nId = MInst.Str2ID(@"op.document.optimize", false); var op = MInst.CreateOp(nId); var input = op.Params.Root["Input"]; var impPath = FsInst.DefaultFileSys.StringToName(operation.FilePath); ICabNode options = op.Params.Root["Options"]; ICabNode images = options["Images"]; images["Enabled"].v = true; images["ReducedOnly"].v = false; ICabNode comp = images["Comp"]; //set all methods to retain existing comp["Color.Method"].v = 0; comp["Grayscale.Method"].v = 0; comp["Indexed.Method"].v = 0; comp["Mono.Method"].v = 0; //set my params var opParam = operation.CompMode + "." + "Method"; comp[opParam].v = operation.Method; if (((operation.CompMode == "Color") || (operation.CompMode == "Grayscale")) && ((operation.Method == 1) || (operation.Method == 2))) { comp[operation.CompMode + "." + "JPEGQuality"].v = operation.Quality; } var resDoc = MPxcInst.OpenDocumentFrom(impPath, null); input.Add().v = resDoc; op.Do(); resDoc.WriteToFile(operation.OutputFilePath); resDoc.Close(); operation.ErrCodes = string.Empty; } catch (Exception e) { operation.ErrCodes = e.Message; Console.WriteLine(e.Message); } }