Example #1
0
        /// <summary>
        /// Parse the static CSV keys file and return a list of keys and descriptions based on the filter and rules
        /// </summary>
        /// <param name="path">full path to csv file to operate on</param>
        /// <param name="keyFilter">Filter target</param>
        /// <returns>List of KeyDataObject</returns>
        public static IEnumerable <KeyDataObject> ParseCSV(string path, KeyTypesFilter keyFilter = KeyTypesFilter.ALL)
        {
            if (!File.Exists(path))
            {
                yield break;
            }

            using (TextFieldParser parser = new TextFieldParser(path))
            {
                parser.CommentTokens = new string[] { "#" };
                parser.SetDelimiters(new string[] { ";", "," });
                parser.HasFieldsEnclosedInQuotes = true;

                // Skip over header line.
                parser.ReadLine();
                while (!parser.EndOfData)
                {
                    string[]      fields = parser.ReadFields();
                    KeyDataObject data;
                    if (fields.Length == 4)
                    {
                        data = new KeyDataObject()
                        {
                            Description = fields[1],
                            FeatureKey  = fields[0],
                            MinorKey    = fields[3],
                            KeyType     = fields[2]
                        };

                        bool           includeKeyRow = false;
                        KeyTypesFilter rowKeyType;
                        if (Enum.TryParse(fields[2], true, out rowKeyType))
                        {
                            bool includeInBeta     = BETA_KEYS.HasFlag(rowKeyType);
                            bool includeInPreAlpha = DEVELOPMENT_KEYS.HasFlag(rowKeyType);
                            bool includeInGA       = RC_KEYS.HasFlag(rowKeyType);

                            if (keyFilter.HasFlag(KeyTypesFilter.RC))
                            {
                                includeKeyRow = includeInGA;
                            }
                            else if (keyFilter.HasFlag(KeyTypesFilter.BETA))
                            {
                                includeKeyRow = includeInBeta;
                            }
                            else if (keyFilter.HasFlag(KeyTypesFilter.DEVELOPMENT))
                            {
                                includeKeyRow = includeInPreAlpha;
                            }
                            else
                            {
                                includeKeyRow = includeInPreAlpha;  // No key, show only in development mode
                            }
                        }

                        // Ignore type and include
                        if (keyFilter == KeyTypesFilter.ALL)
                        {
                            includeKeyRow = true;
                        }


                        if (includeKeyRow)
                        {
                            yield return(data);
                        }
                    }
                }
            }
        }
        public static int GetFeaturesForPortalRev(string connectionString, out List <KeyDataObject> featureList)
        {
            featureList = new List <KeyDataObject>();
            string verStrValue = null;
            string versionValue;

            try
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    con.Open();
                    using (SqlCommand command = new SqlCommand("SELECT src.theValue FROM dbo.list_variables src WHERE src.theLabel = 'RingtailDatabaseModel'", con))
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    verStrValue = reader.GetString(reader.GetOrdinal("theValue"));
                                }
                            }
                        }

                    if (string.IsNullOrEmpty(verStrValue))
                    {
                        return(7);
                    }

                    using (SqlCommand comm = new SqlCommand("dbo.rf_convert_version_to_bigint", con))
                    {
                        comm.CommandType = CommandType.StoredProcedure;
                        SqlParameter p1 = new SqlParameter("@version", SqlDbType.VarChar);
                        p1.Direction = ParameterDirection.Input;
                        SqlParameter p2 = new SqlParameter("@Result", SqlDbType.BigInt);
                        p2.Direction = ParameterDirection.ReturnValue;

                        p1.Value = verStrValue;
                        comm.Parameters.Add(p1);
                        comm.Parameters.Add(p2);


                        comm.ExecuteNonQuery();

                        if (p2.Value == DBNull.Value)
                        {
                            return(7);
                        }

                        versionValue = p2.Value.ToString();
                    }

                    using (SqlCommand command = new SqlCommand("SELECT * FROM dbo.featureset_list where active_version='" + versionValue + "'", con))
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    KeyDataObject keyDataObject = new KeyDataObject();
                                    string        feature_key, minor_key, date_added, description;

                                    featureList.Add(
                                        keyDataObject = new KeyDataObject()
                                    {
                                        Description = reader.GetString(reader.GetOrdinal("description")),
                                        FeatureKey  = reader.GetString(reader.GetOrdinal("feature_key")),
                                        MinorKey    = minor_key = reader.GetString(reader.GetOrdinal("minor_key"))
                                    });
                                }
                            }
                        }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error, connecting to database: {0}", e.Message);
                return(6);
            }

            return(0);
        }