/// <summary> /// Add additional footer information to the xml file /// </summary> /// <param name="fileName"> /// the xml file /// </param> private void AddFooterToFile(string fileName) { this.objStringBuilder.Clear(); this.objStringBuilder.AppendLine("</Business>"); this.objStringBuilder.AppendLine("</DemandForce>"); PmsDataHandler dataHandler = new PmsDataHandler(); dataHandler.AppendToFile(fileName, this.objStringBuilder.ToString()); }
/// <summary> /// Calls the API's GetData() function /// </summary> /// <param name="invoker"> /// the handle of dynamic link library /// </param> private void CallApiGetData(DllInvoker invoker) { var funcGetData = (GetData)invoker.Invoke(APIFuncGetData, typeof(GetData)); if (funcGetData == null) { this.objStringBuilder.Clear(); this.objStringBuilder.Append("Invokes "); this.objStringBuilder.Append(this.ApiPath); this.objStringBuilder.Append("failed!(GetProcAddress('GetData') return null)"); LogHelper.GetLoggerHandle().Error(LogTag, this.Id, this.objStringBuilder.ToString()); return; } // Define a byte array with BufferSize length byte[] outBuffer = new byte[BufferSize]; PmsDataHandler dataHandler = new PmsDataHandler(); int lastRec = funcGetData(outBuffer, 0); if (lastRec > 0) { // Generate a complete xml file name string xmlPath = dataHandler.GenXmlFilePath(); dataHandler.MakePathExist(xmlPath); string extractFileName = dataHandler.GenXmlFileName(xmlPath); string xmlContent = Encoding.ASCII.GetString(outBuffer).TrimEnd('\0'); // 1. add header this.AddHeaderToFile(extractFileName); // 2. add body: put data into xml file via PmsDataHandler.AppendToFile method dataHandler.AppendToFile(extractFileName, xmlContent); while (lastRec > 0) { Array.Clear(outBuffer, 0, outBuffer.Length); lastRec = funcGetData(outBuffer, ++lastRec); xmlContent = Encoding.ASCII.GetString(outBuffer).TrimEnd('\0'); dataHandler.AppendToFile(extractFileName, xmlContent); } // 3. add footer this.AddFooterToFile(extractFileName); } else { this.objStringBuilder.Clear(); this.objStringBuilder.Append("Invokes "); this.objStringBuilder.Append(this.ApiPath); this.objStringBuilder.Append("failed!('GetData--record No returned is not > 0')"); LogHelper.GetLoggerHandle().Error(LogTag, this.Id, this.objStringBuilder.ToString()); } }
/// <summary> /// Add additional header information to the xml file /// </summary> /// <param name="fileName"> /// the xml file /// </param> /// <returns>call result: True-success; False-failed</returns> private bool AddHeaderToFile(string fileName) { this.objStringBuilder.Clear(); // "xml" elemet this.objStringBuilder.AppendLine(@"<?xml version=""1.0""?>"); // "DemandForce" element and its attributes this.objStringBuilder.Append("<DemandForce"); this.objStringBuilder.Append(@" licenseKey="""); this.objStringBuilder.Append(this.businessLicense); this.objStringBuilder.Append(@""""); this.objStringBuilder.Append(@" dFAPI="""); this.objStringBuilder.Append(Path.GetFileName(this.ApiPath)); this.objStringBuilder.Append(@""""); this.objStringBuilder.Append(@" dFAPIVersion="""); this.objStringBuilder.Append(this.Version); this.objStringBuilder.Append(@""""); this.objStringBuilder.Append(@" dataLocation="""); this.objStringBuilder.Append(this.DataLocation); this.objStringBuilder.AppendLine(@""">"); // "Business" elemet this.objStringBuilder.AppendLine("<Business>"); // "Extract" elemet and its attributes this.objStringBuilder.Append("<Extract"); this.objStringBuilder.Append(@" managementSystemName="""); this.objStringBuilder.Append(Path.GetFileName(this.ApiPath)); this.objStringBuilder.Append(@""""); this.objStringBuilder.Append(@" managementSystemVersion="""); this.objStringBuilder.Append(this.Version); this.objStringBuilder.Append(@""""); this.objStringBuilder.Append(@" manual=""1"""); this.objStringBuilder.AppendLine(">"); this.objStringBuilder.AppendLine("</Extract>"); PmsDataHandler dataHandler = new PmsDataHandler(); dataHandler.AppendToFile(fileName, this.objStringBuilder.ToString()); return(true); }