Example #1
0
        /// <summary>
        ///
        /// According to the direction of the metadata of the configured process, this method will retrieve data through
        /// a specified REST API in regard to a particular list of identified records.
        ///
        /// <param name="poProcessWriter">The writer that will record the progress of this instance for the configured Process (represented by 'poProcess')</param>
        /// <param name="poRecordWriter">The writer that will record the raw payload for each record retrieved in this run</param>
        /// <param name="poProcess">The structure that represents the Process being currently run</param>
        /// <returns>The ChangeSeq (i.e., PID) assigned to this particular instance of the Process being run</returns>
        /// </summary>
        private long PullDataForHardCodedKeys(AceChangeProcessWriter poProcessWriter, AceChangeRecordWriter poRecordWriter, AceProcess poProcess)
        {
            long   nTmpKey        = -1;
            string sTmpChangeBody = "";
            string sTmpDataBody   = "";
            string sInfoMsg       = "";
            string sErrMsg        = "";
            string sSubject       = "AceEngine::PullDataForHardCodedKeys()";

            Dictionary <string, string> oTmpFilterArgs = new Dictionary <string, string>();

            if ((poProcess.ChangeAPIConfiguration.KeyList == null) || (poProcess.ChangeAPIConfiguration.KeyList.Count <= 0))
            {
                throw new Exception("ERROR!  No expected items found in the hard-coded key list.");
            }

            poProcess.ChangeSeq = poProcessWriter.InsertProcessInstance(poProcess.ProcessID);

            foreach (string sTmpKey in poProcess.ChangeAPIConfiguration.KeyList)
            {
                // The format for this change manifest request can be hard-coded (as it is here) or it could be a part of the configurable metadata
                sTmpChangeBody = String.Format(AceXmlReader.CONST_DEFAULT_CHG_MANIFEST_REQUEST_XML_BODY, sTmpKey);

                try
                {
                    nTmpKey = Convert.ToInt64(sTmpKey);
                }
                catch (Exception ex)
                {
                    LogError(sSubject, "ERROR!  Could not convert EAN (" + sTmpKey + ") to a number", ex);
                }

                oTmpFilterArgs = AceXmlReader.ExtractFilterArgs(sTmpChangeBody, poProcess.DataAPIConfiguration.RequestFilterArgs);
                sTmpDataBody   = AceXmlReader.PullData(poProcess.DataAPIConfiguration.BaseURL, oTmpFilterArgs, poProcess.DataAPIConfiguration.RequestHeaderArgs);

                if (!String.IsNullOrEmpty(sTmpKey))
                {
                    poRecordWriter.InsertProductInstance(poProcess.ChangeSeq, nTmpKey, sTmpChangeBody, sTmpDataBody);
                }
                else
                {
                    LogError(sSubject, "ERROR!  Provided key was null");
                }
            }

            return(poProcess.ChangeSeq);
        }
Example #2
0
        /// <summary>
        ///
        /// This method will do the actual work of enumerating through the REST API and making the web requests for data,
        /// both the change manifests that direct calls and/or the actual data.
        ///
        /// <param name="poProcessWriter">The writer that will record the progress of this instance for the configured Process (represented by 'poTempProcess')</param>
        /// <param name="poProductWriter">The writer that will record the raw payload for each record retrieved in this run</param>
        /// <param name="poTempProcess">The structure that represents the Process being currently run</param>
        /// <returns>The boolean that indicates whether or not the enumeration and persistence succeeded</returns>
        /// </summary>
        private bool EnumerateApiAndPersistRawData(AceChangeProcessWriter poProcessWriter, AceChangeRecordWriter poProductWriter, AceProcess poTempProcess)
        {
            bool   bSuccess       = true;
            int    nTotalRecords  = 0;
            long   nTmpKey        = 0;
            string sTmpKey        = "";
            string sTmpChangeBody = "";
            string sTmpDataBody   = "";
            string sSubject       = "AceEngine::EnumerateApiAndPersistRawData()";
            string sErrMsg        = "";

            Dictionary <string, string> oTmpFilterArgs = new Dictionary <string, string>();

            using (AceXmlReader oChangeDataReader = new AceXmlReader(poTempProcess.ChangeAPIConfiguration))
            {
                oChangeDataReader.FoundNewAnchorCallback = poProcessWriter.UpsertAnchor;

                try
                {
                    foreach (Hashtable oTmpRecord in oChangeDataReader)
                    {
                        try
                        {
                            sTmpKey        = (string)oTmpRecord[poTempProcess.ChangeAPIConfiguration.TargetKeyTag];
                            sTmpChangeBody = (string)oTmpRecord[AceXmlReader.CONST_RESPONSE_XML_BODY_KEY];

                            try
                            {
                                nTmpKey = Convert.ToInt64(sTmpKey);
                            }
                            catch (Exception ex)
                            {
                                LogError(sSubject, "ERROR!  Could not convert EAN (" + sTmpKey + ") to a number", ex);
                            }

                            if (!String.IsNullOrEmpty(sTmpKey))
                            {
                                oTmpFilterArgs = AceXmlReader.ExtractFilterArgs(sTmpChangeBody, poTempProcess.DataAPIConfiguration.RequestFilterArgs);

                                try
                                {
                                    sTmpDataBody =
                                        AceXmlReader.PullData(poTempProcess.DataAPIConfiguration.BaseURL,
                                                              oTmpFilterArgs,
                                                              poTempProcess.DataAPIConfiguration.RequestHeaderArgs);
                                }
                                catch (WebException ex)
                                {
                                    sErrMsg = "ERROR!  Web connection issues occurred when handling EAN (" + sTmpKey + ")";

                                    LogError(sSubject, sErrMsg, ex);

                                    sTmpDataBody = CONST_DATA_URL_ISSUE_ERR_MSG;
                                }

                                poProductWriter.InsertProductInstance(poTempProcess.ChangeSeq, nTmpKey, sTmpChangeBody, sTmpDataBody);
                            }
                            else
                            {
                                LogError(sSubject, "ERROR!  A provided key was null.");
                            }
                        }
                        catch (Exception ex)
                        {
                            sErrMsg = "ERROR!  Could not handle product instance for EAN (" + sTmpKey + ")";

                            LogError(sSubject, sErrMsg, ex);
                        }
                        finally
                        {
                            ++nTotalRecords;
                        }

                        if ((nTotalRecords % 1000) == 0)
                        {
                            LogInfo(sSubject, "Pulled (" + nTotalRecords + ") snapshots to the change_product table");
                            Console.Out.Flush();
                        }
                    } // foreach loop
                }
                catch (WebException ex)
                {
                    sErrMsg = "ERROR!  Web connection issues when attempting to get catalog data...pulling snapshot is stopping now.";
                    LogError(sSubject, sErrMsg, ex);

                    bSuccess = false;
                }
                catch (SqlException ex)
                {
                    sErrMsg = "ERROR!  Database issues when attempting to get catalog data...pulling snapshot is stopping now.";
                    LogError(sSubject, sErrMsg, ex);

                    bSuccess = false;
                }
                catch (Exception ex)
                {
                    sErrMsg = "ERROR!  General issue when attempting to get catalog data...pulling snapshot is stopping now.";
                    LogError(sSubject, sErrMsg, ex);

                    bSuccess = false;
                }
            }

            return(bSuccess);
        }