public byte[] ExportSettingsAsZippedBytes(ImportExportSettings settingsToExport, NodeVisit visit) { ValidateByRole(visit, SystemRoleType.Admin); NodeSettings nodeSettings = new NodeSettings(); string errorMessage = null; if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.GlobalArguments)) { nodeSettings.SetGlobalArguments(ConfigManager.Get(ConfigurationType.All)); } if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.DataSources)) { nodeSettings.SetDataSources(DataProviderManager.Get()); } if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.NetworkPartners)) { nodeSettings.SetNetworkPartners(PartnerManager.Get()); } bool exportExchanges = EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.Exchanges); bool exportServices = EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.Services); if (exportExchanges || exportServices) { IList <DataFlow> flows = FlowManager.GetAllDataFlows(exportServices, false); if (exportExchanges) { nodeSettings.SetExchanges(flows); } if (exportServices) { nodeSettings.SetServices(flows); } } if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.Schedules)) { IDictionary <string, string> flowIdToNameMap = FlowManager.GetAllFlowsIdToNameMap(); IDictionary <string, string> serviceIdToNameMap = ServiceManager.GetAllServicesIdToNameMap(); IDictionary <string, string> partnerIdToNameMap = PartnerManager.GetAllPartnersIdToNameMap(); nodeSettings.SetSchedules(ScheduleManager.GetSchedules(), flowIdToNameMap, serviceIdToNameMap, partnerIdToNameMap, out errorMessage); } string tempFilePath = SettingsProvider.NewTempFilePath(); _compressionHelper.Compress("Settings.xml", _serializationHelper.SerializeWithLineBreaks(nodeSettings), tempFilePath); if (errorMessage != null) { _compressionHelper.Compress("Errors.txt", Encoding.UTF8.GetBytes(errorMessage), tempFilePath); } byte[] zippedData = File.ReadAllBytes(tempFilePath); ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} exported the following node settings: {1}.", visit.Account.NaasAccount, settingsToExport); return(zippedData); }
private bool CheckToCompressDocument(Document ioDocument) { if (_alwaysCompressDocumentContents) { if (!ioDocument.DontAutoCompress && !ioDocument.IsZipFile) { if (!string.IsNullOrEmpty(ioDocument.DocumentName)) { if ((ioDocument.DocumentName == "Node20.Report") || (ioDocument.DocumentName == "Node20.Error") || (ioDocument.DocumentName == "Node20.Original")) { // Don't compress these special files return(false); } } else { ioDocument.DocumentName = Guid.NewGuid().ToString(); } string originalDocumentName = ioDocument.DocumentName; string zipExtension = CommonContentAndFormatProvider.GetFileExtension(CommonContentType.ZIP); ioDocument.DocumentName = Path.ChangeExtension(ioDocument.DocumentName, zipExtension); ioDocument.Type = CommonContentType.ZIP; if (!CollectionUtils.IsNullOrEmpty(ioDocument.Content)) { ioDocument.Content = _compressionHelper.Compress(originalDocumentName, ioDocument.Content); } return(true); } } return(false); }
protected byte[] CreateRandomXMLQueryResult(bool doCompress, int start, int count, out int actualCount, out bool isLast, out string documentName) { string QUERY_XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<QueryResult:QueryResult xmlns:QueryResult=\"http://www.exchangenetwork.net/schema/NCT/1\" xmlns=\"http://www.exchangenetwork.net/schema/NCT/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"; string QUERY_XML_BODY_ROW = "<row>Row {0} text</row>"; string QUERY_XML_FOOTER = "</QueryResult:QueryResult>"; const int totalCount = 10; int endIndex; if (count == -1) { if (start != 0) { throw new ArgumentException("Invalid Arguments", "Paging.Start"); } endIndex = totalCount; } else { if (start < 0) { throw new ArgumentException("Invalid Arguments", "Paging.Start"); } if (count <= 0) { throw new ArgumentException("Invalid Arguments", "Paging.Count"); } endIndex = Math.Min(totalCount, start + count); } isLast = (endIndex == totalCount); StringBuilder sb = new StringBuilder(); sb.Append(QUERY_XML_HEADER); actualCount = endIndex - start; for (int i = start + 1; i <= endIndex; ++i) { sb.AppendFormat(QUERY_XML_BODY_ROW, i.ToString()); } sb.Append(QUERY_XML_FOOTER); byte[] rtnArray = StringUtils.UTF8.GetBytes(sb.ToString()); documentName = Guid.NewGuid().ToString() + ".xml"; if (doCompress) { rtnArray = _compressionHelper.Compress(documentName, rtnArray); } return(rtnArray); }
/// <summary> /// 压缩数据。 /// </summary> /// <param name="bytes">要压缩的数据的二进制流。</param> /// <param name="offset">要压缩的数据的二进制流的偏移。</param> /// <param name="length">要压缩的数据的二进制流的长度。</param> /// <param name="compressedStream">压缩后的数据的二进制流。</param> /// <returns>是否压缩数据成功。</returns> public static bool Compress(byte[] bytes, int offset, int length, Stream compressedStream) { if (s_CompressionHelper == null) { throw new GameFrameworkException("Compressed helper is invalid."); } if (bytes == null) { throw new GameFrameworkException("Bytes is invalid."); } if (offset < 0 || length < 0 || offset + length > bytes.Length) { throw new GameFrameworkException("Offset or length is invalid."); } if (compressedStream == null) { throw new GameFrameworkException("Compressed stream is invalid."); } try { return(s_CompressionHelper.Compress(bytes, offset, length, compressedStream)); } catch (Exception exception) { if (exception is GameFrameworkException) { throw; } throw new GameFrameworkException(Text.Format("Can not compress with exception '{0}'.", exception.ToString()), exception); } }
public override byte[] SerializeToBytes <T>(T obj) { return(_compressionHelper.Compress("obj", _serializationHelper.BinarySerialize <T>(obj))); }