Example #1
0
        public CarGen(string oplstr)
        {
            OPLStr = oplstr;
            string[] parts = oplstr.Split(',');

            PosX          = float.Parse(parts[0].Trim(), CultureInfo.InvariantCulture);
            PosY          = float.Parse(parts[1].Trim(), CultureInfo.InvariantCulture);
            PosZ          = float.Parse(parts[2].Trim(), CultureInfo.InvariantCulture);
            RotX          = float.Parse(parts[3].Trim(), CultureInfo.InvariantCulture);
            RotY          = float.Parse(parts[4].Trim(), CultureInfo.InvariantCulture);
            Length        = float.Parse(parts[5].Trim(), CultureInfo.InvariantCulture);
            ModelName     = parts[6].Trim().ToLowerInvariant();
            CarColor1     = int.Parse(parts[7].Trim(), CultureInfo.InvariantCulture);
            CarColor2     = int.Parse(parts[8].Trim(), CultureInfo.InvariantCulture);
            CarColor3     = int.Parse(parts[9].Trim(), CultureInfo.InvariantCulture);
            SpecularColor = int.Parse(parts[10].Trim(), CultureInfo.InvariantCulture);
            Flags         = uint.Parse(parts[11].Trim(), CultureInfo.InvariantCulture);
            Alarm         = int.Parse(parts[12].Trim(), CultureInfo.InvariantCulture);
            Unk2          = int.Parse(parts[13].Trim(), CultureInfo.InvariantCulture);

            //if (model.StartsWith("hash:"))
            //{
            //    ModelName = model.Substring(5);
            //    if (ModelName == "0") ModelName = string.Empty;
            //}
            //else
            //{
            //    ModelName = model;
            //}
            if (ModelName.StartsWith("hash:"))
            {
                string[] hparts = ModelName.Split(':');
                uint     hash;
                if (uint.TryParse(hparts[1].Trim(), out hash))
                {
                    string str = JenkIndex.TryGetString(hash);
                    if (!string.IsNullOrEmpty(str))
                    {
                        ModelName = str.ToLowerInvariant();
                    }
                    else
                    {
                        ModelName = "hash_" + hash.ToString("X").ToLowerInvariant();
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// The MySqlCommand initialized for this query, including any and all parameters.
        /// </summary>
        public DBHelperCommandArgs ModelQueryCommand()
        {
            List <string>         lstWhereTerms = new List <string>();
            List <MySqlParameter> lstParams     = new List <MySqlParameter>();

            // Add each of the terms
            string[] rgTerms = FullText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < rgTerms.Length; i++)
            {
                AddQueryTerm(rgTerms[i], String.Format(CultureInfo.InvariantCulture, "FullText{0}", i), "Concat(model, ' ', manufacturers.manufacturer, ' ', typename, ' ', family, ' ', modelname, ' ', categoryclass.CatClass)", lstWhereTerms, lstParams);
            }

            string szPreferred = "0";

            if (PreferModelNameMatch)
            {
                string szModelMatch = String.Format(CultureInfo.InvariantCulture, "%{0}%", ConvertWildcards(FullText));
                szPreferred = "IF(model LIKE ?modelMatch, 1, 0)";
                lstParams.Add(new MySqlParameter("modelMatch", szModelMatch));
            }

            AddQueryTerm(CatClass, "qCatClass", "catclass", lstWhereTerms, lstParams);
            AddQueryTerm(rNormalizeModel.Replace(Model, string.Empty), "qModel", "REPLACE(REPLACE(model, ' ', ''), '-', '')", lstWhereTerms, lstParams);
            if (ModelName.StartsWith(ICAOPrefix, StringComparison.CurrentCultureIgnoreCase))
            {
                AddQueryTerm(ModelName.Substring(ICAOPrefix.Length), "qFamilyName", "family", lstWhereTerms, lstParams);
            }
            else
            {
                AddQueryTerm(ModelName, "qModelName", "modelname", lstWhereTerms, lstParams);
            }
            AddQueryTerm(ManufacturerName, "qMan", "manufacturer", lstWhereTerms, lstParams);
            AddQueryTerm(TypeName, "qType", "typename", lstWhereTerms, lstParams);

            if (ManufacturerID != Manufacturer.UnsavedID)
            {
                lstWhereTerms.Add(" (models.idManufacturer = ?manID) ");
                lstParams.Add(new MySqlParameter("manID", ManufacturerID));
            }

            string szHavingPredicate = String.Join(" AND ", lstWhereTerms.ToArray());

            const string szQTemplate        = @"SELECT
models.*,
manufacturers.manufacturer,
categoryclass.CatClass as 'Category/Class',
{0} AS AircraftIDs,
{1} AS preferred
FROM models
  INNER JOIN manufacturers on manufacturers.idManufacturer = models.idmanufacturer
  INNER JOIN categoryclass on categoryclass.idCatClass = models.idcategoryclass
{2}
{3}
{4}
{5}";
            const string szQSamplesTemplate = @"LEFT OUTER JOIN (SELECT ac.idmodel, group_concat(DISTINCT img.imageKey separator ',') AS AircraftIDs
                    FROM Images img
                    INNER JOIN aircraft ac ON CAST(img.imageKey AS Unsigned)=ac.idaircraft
                    WHERE img.VirtPathID=1
                    GROUP BY ac.idmodel) Samples
       ON models.idmodel=Samples.idmodel";

            string szQ = String.Format(CultureInfo.InvariantCulture, szQTemplate,
                                       IncludeSampleImages ? "Samples.AircraftIDs" : "NULL",
                                       szPreferred,
                                       IncludeSampleImages ? szQSamplesTemplate : string.Empty,
                                       szHavingPredicate.Length == 0 ? string.Empty : String.Format(CultureInfo.InvariantCulture, " WHERE {0} ", szHavingPredicate),
                                       SortOrderFromSortModeAndDirection(SortMode, SortDir),
                                       (Limit > 0 && Skip >= 0) ? String.Format(CultureInfo.InvariantCulture, " LIMIT {0},{1} ", Skip, Limit) : string.Empty);

            DBHelperCommandArgs args = new DBHelperCommandArgs(szQ, lstParams);

            return(args);
        }