//NOTE: startposition is zero-based here
 public string ToFormat(Rec[] recommendationList, ResultFormats format, int startPosition)
 {
     string result;
     switch (format)
     {
         case ResultFormats.SpaceDelimited:
             result = ToSeparatedValueString(recommendationList, startPosition, " ");
             break;
         case ResultFormats.TabDelimited:
             result = ToSeparatedValueString(recommendationList, startPosition, "\t");
             break;
         case ResultFormats.CommaDelimited:
             result = ToSeparatedValueString(recommendationList, startPosition, ", ");
             break;
         case ResultFormats.XML:
             result = ToXmlString(recommendationList, startPosition);
             break;
         case ResultFormats.Ruby:
             result = "[";
             result += ToSeparatedValueString(recommendationList, startPosition, ", ");
             result += "]";
             break;
         default:
             goto case ResultFormats.TabDelimited;
     }
     return result;
 }
Ejemplo n.º 2
0
        public int ReadConfig()
        {
            bool configFileExist;

            m_warning = 0; m_warningText = "";

            // Input =====================================
            string[] tagValues = null;

            // Determine version //
            // Open file
            configFileExist = true;
            m_configFilename = ConfigBasename;
            try
            {
                m_configFile = new StreamReader(m_clientDataPath + m_configFilename);
            }
            catch (Exception)
            {
                m_configVersion = 3;
                configFileExist = false;
            }

            if (configFileExist)
            {
                // Get version
                // Although file can have other configTags in any order, version must be first!
                string inputLine = m_configFile.ReadLine();
                if (inputLine == null)
                {
                    m_errorText = String.Format("The first line of {0} should be Version <tab> <versionNum>.", ConfigBasename);
                    m_configFile.Close();
                    return 1;
                }
                string[] tempSplit = inputLine.Split(m_tabSeparator);
                if (tempSplit.Length < 2 || !tempSplit[0].Equals("version", StringComparison.CurrentCultureIgnoreCase))
                {
                    m_errorText = String.Format("The first line of {0} should be Version <tab> <versionNum>.", ConfigBasename);
                    m_configFile.Close();
                    return 1;
                }
                if (!GetVersion(tempSplit[1], out m_configVersion, m_newestVersion, ConfigBasename))
                {
                    m_configFile.Close();
                    return 1;
                }
                // Close file
                m_configFile.Close();
            }

            // Read for Correct Version
            if (m_configVersion < 2)
            {
                m_errorText = "Your config file is version 1, and needs to be updated to version 3.";
                return 1;
            }

            // Read Config Files //
            tagValues = new string[configTags.Length];
            for (int i = 0; i < configTags.Length; i++)
                tagValues[i] = "";

            // Read ConfigBoostDefault
            m_error = ReadKeywordFile(ConfigDefaultBasename, configTags, ref tagValues);
            if (m_error != 0)
                return m_error;

            // Read ConfigBoost
            // This is that automated export
            m_error = ReadKeywordFile(ConfigBasename, configTags, ref tagValues);
            if (m_error != 0)
                return m_error;

            // Read ConfigBoostOverride
            // This is second so OVERWRITES previous configTags
            m_error = ReadKeywordFile(ConfigOverrideBasename, configTags, ref tagValues);
            if (m_error != 0)
                return m_error;

            // Assign values //
            // version already set = values[0];

            // Owner
            m_owner = tagValues[(int)eConfigTags.Owner];

            // Email
            m_ownerEmail = tagValues[(int)eConfigTags.Email];

            // ReportLevel
            try
            {
                //m_reportLevel = (ReportLevel)Enum.Parse(typeof(ReportLevel), tagValues[pos], true);
                m_reportLevel = BoostLog.GetReportLevel( tagValues[(int)eConfigTags.ReportLevel] );
            }
            catch
            {
                m_reportLevel = ReportLevel.Error;
            }

            // Currency
            m_currency = tagValues[(int)eConfigTags.Currency];
            if (m_currency == "")
            {
                m_currency = "$";
            }

            // Attribute Names
            m_attribute1Name = tagValues[(int)eConfigTags.Attribute1Name];
            if (m_attribute1Name == "")// && m_att1Exists)
            {
                m_attribute1Name = "Category";
            }
            m_attribute2Name = tagValues[(int)eConfigTags.Attribute2Name];
            if (m_attribute2Name == "") // && m_att2Exists)
            {
                m_attribute2Name = "Brand";
            }

            // Resell
            if (!ConvertToBool(ref m_resell, tagValues[(int)eConfigTags.Resell], configTags[(int)eConfigTags.Resell], (int)eConfigTags.Resell))
            {
                m_resell = true;
            }

            // MinLikelihood
            if (!ConvertToInt(ref m_minLikelihood, tagValues[(int)eConfigTags.MinLikelihood], configTags[(int)eConfigTags.MinLikelihood], (int)eConfigTags.MinLikelihood))
            {
                m_minLikelihood = 3;
            }

            // MinCommon
            if (!ConvertToInt(ref m_minCommon, tagValues[(int)eConfigTags.MinCommon], configTags[(int)eConfigTags.MinCommon], (int)eConfigTags.MinCommon))
            {
                m_minCommon = 2;
            }

            // ResultFormat
            try
            {
                m_resultFormat = (ResultFormats)Enum.Parse(typeof(ResultFormats), tagValues[(int)eConfigTags.ResultFormat], true);
            }
            catch
            {
                m_resultFormat = ResultFormats.TabDelimited;
            }

            // Depricated on 5-10-2012
            // DoNotRecommendExists
            // ExclusionsExist takes priority, but also check for DoNotRecommendExists
            if (!ConvertToBool(ref m_doNotRecommendExists, tagValues[(int)eConfigTags.ExclusionsExist], configTags[(int)eConfigTags.ExclusionsExist], (int)eConfigTags.ExclusionsExist))
            {
                if (!ConvertToBool(ref m_doNotRecommendExists, tagValues[(int)eConfigTags.DoNotRecommendExists], configTags[(int)eConfigTags.DoNotRecommendExists], (int)eConfigTags.DoNotRecommendExists))
                    m_doNotRecommendExists = false;
            }

            // Depricated on 5-10-2012
            // ReplacementExists
            if (!ConvertToBool(ref m_replacementsExists, tagValues[(int)eConfigTags.ReplacementsExist], configTags[(int)eConfigTags.ReplacementsExist], (int)eConfigTags.ReplacementsExist))
            {
                m_replacementsExists = false;
            }

            // MaxSalesDataAgeInMonths
            if (!ConvertToInt(ref m_maxSalesDataAgeInMonths, tagValues[(int)eConfigTags.MaxSalesDataAgeInMonths], configTags[(int)eConfigTags.MaxSalesDataAgeInMonths], (int)eConfigTags.MaxSalesDataAgeInMonths))
            {
                m_maxSalesDataAgeInMonths = 18;
            }

            // SimilarTopSellerRule
            if (tagValues[(int)eConfigTags.SimilarTopSellerRule] != "")
                m_similarTopSellerRule = tagValues[(int)eConfigTags.SimilarTopSellerRule];

            // SimilarClickStreamRule
            if (tagValues[(int)eConfigTags.SimilarClickStreamRule] != "")
                m_similarClickStreamRule = tagValues[(int)eConfigTags.SimilarClickStreamRule];

            // !!! THIS DOES NOT WORK PROPERLY. NOT USED IN WEBENGINE. SEE GENERATOR ReadConfigFileV3 !!!
             // If ConfigBoost or ConfigBoostOverride add new rules, they should accumulate, whereas they overwrite here
            // RulesEnabled
            try
            {
                // RulesEnabled takes precedence
                if (tagValues[(int)eConfigTags.RulesTypes] != "")
                    m_rulesEnabled = (RulesTypes)Enum.Parse(typeof(RulesTypes), tagValues[(int)eConfigTags.RulesTypes], true);
                m_rulesEnabled = (RulesTypes)Enum.Parse(typeof(RulesTypes), tagValues[(int)eConfigTags.RulesEnabled], true);
                if (m_rulesEnabled != RulesTypes.NoRules)
                    m_rulesExist = true;
            }
            catch
            {
                m_rulesEnabled = RulesTypes.NoRules;
            }

            // RulesDisabled
            // See ReadConfigFileV3 in Generator

            // UniversalFilterIDs
            m_universalFilterIDs = tagValues[(int)eConfigTags.UniversalFilterIDs];

            // FilterFilename
            m_filterFilename = tagValues[(int)eConfigTags.FilterFilename];

            // UpsellFactor
            if (!ConvertToFloat(ref m_upsellFactor, tagValues[(int)eConfigTags.UpsellFactor], configTags[(int)eConfigTags.UpsellFactor], (int)eConfigTags.UpsellFactor))
                m_upsellFactor = 0.2F;

            // CrossAtt1IDs
            m_crossAtt1IDs = tagValues[(int)eConfigTags.CrossAtt1IDs];

            return 0;
        }