Esempio n. 1
0
        /// <summary>
        /// Calls the API that extracts out data from PMS(Created by Delphi)
        /// </summary>
        /// <returns>call result: True-success; False-failed</returns>
        private bool Call()
        {
            // 1. call private method "LoadApiDll()" to load API dll
            DllInvoker invoker = this.LoadApiDll();

            if (invoker == null)
            {
                this.objStringBuilder.Clear();
                this.objStringBuilder.Append("Invokes ");
                this.objStringBuilder.Append(this.ApiPath);
                this.objStringBuilder.Append("failed!(LoadLibrary return null)");
                LogHelper.GetLoggerHandle().Error(LogTag, this.Id, this.objStringBuilder.ToString());

                return(false);
            }

            // Notity api to run under debug mode if api implement debug mode
            if (ApiAssistor.IsDebugMode(ApiAssistor.StrToDebugLevel(this.ApiDebugLevel)))
            {
                this.CallApiDebugAPIToLog(invoker);
            }

            try
            {
                // 2. call private method "CallApiInitialize()" to Invoke dll's Initialize() function
                int custCount = this.CallApiInitialize(invoker);
                if (custCount > 0)
                {
                    this.objStringBuilder.Clear();
                    this.objStringBuilder.Append("Invokes 'Initialize()' successful! The customers count is: ");
                    this.objStringBuilder.Append(custCount);
                    LogHelper.GetLoggerHandle().Info(LogTag, this.Id, this.objStringBuilder.ToString());

                    // 3. call private method "CallApiGetData()" to Invoke dll's "GetData()" function
                    this.CallApiGetData(invoker);
                }
                else
                {
                    // if no records returned then output to log
                    LogHelper.GetLoggerHandle().Info(LogTag, this.Id, "No records returned!");
                }
            }
            finally
            {
                // 4. call private method "CallApiCleanup()" to Invoke dll's "Cleanup()" function
                this.CallApiCleanup(invoker);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Calls the API's DebugAPIToLog() function
        /// </summary>
        /// <param name="invoker">
        ///     the handle of dynamic link library
        /// </param>
        private void CallApiDebugAPIToLog(DllInvoker invoker)
        {
            var funcDebugApiToLog = (DebugAPIToLog)invoker.Invoke(APIFuncDebugAPIToLog, typeof(DebugAPIToLog));

            if (funcDebugApiToLog == null)
            {
                this.objStringBuilder.Clear();
                this.objStringBuilder.Append("Invokes ");
                this.objStringBuilder.Append(this.ApiPath);
                this.objStringBuilder.Append("failed!(GetProcAddress('DebugAPIToLog') return null)");
                LogHelper.GetLoggerHandle().Error(LogTag, this.Id, this.objStringBuilder.ToString());

                return;
            }

            funcDebugApiToLog(ApiAssistor.StrToDebugLevel(this.ApiDebugLevel), this.Version, this.OptionList);
        }