Пример #1
0
        internal static int SyncPortalKeysToBulkDataFile(string connectionString, string bulkLoadFilePath)
        {
            try
            {
                List <KeyDataObject> featureKeyList = new List <KeyDataObject>();
                if (DataBaseOperations.GetFeaturesForPortalRev(connectionString, out featureKeyList) != 0)
                {
                    return(8);
                }

                if (!TextOperations.WriteBuklLoadFeatureFile(bulkLoadFilePath, featureKeyList, null))
                {
                    return(4);
                }
            }
            catch (Exception e)
            {
                Console.Write("Error, key list could not be deserialized: ", e.Message);
                {
                    return(8);
                }
            }

            return(0);
        }
Пример #2
0
        /// <summary>
        /// Parse the static csv file and send back the json keys with the minor keys
        /// </summary>
        /// <param name="cmdLineOpts"></param>
        /// <param name="serializer">JavaScriptSerializer</param>
        /// <param name="serializedResult">serialized results</param>
        /// <returns></returns>
        internal static int HandleStaticSqlFile(CommandLineOptions cmdLineOpts, JavaScriptSerializer serializer, out string serializedResult)
        {
            serializedResult = String.Empty;

            string pathToFile;

            if (cmdLineOpts.useDefaultKeyFile && string.IsNullOrEmpty(cmdLineOpts.pathToSqlFile))
            {
                pathToFile = RingtailStaticKeyFile;
            }
            else
            {
                pathToFile = cmdLineOpts.pathToSqlFile;
            }

            if (!File.Exists(pathToFile))
            {
                Console.WriteLine("Error, static data file not found.");
                {
                    return(3);
                }
            }

            // Simple filtering based on type
            KeyTypesFilter filterType = KeyTypesFilter.ALL;

            if (!String.IsNullOrEmpty(cmdLineOpts.filter))
            {
                // Might have a direct match passed in, so handle that first
                if (!Enum.TryParse(cmdLineOpts.filter, true, out filterType))
                {
                    // TRY PREVIEW, BETA, RC FIRST - simple mappings on the command line
                    if (string.Compare("RC", cmdLineOpts.filter, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        filterType = KeyTypesFilter.RC;
                    }
                    else if (string.Compare("DEVELOPMENT", cmdLineOpts.filter, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        filterType = KeyTypesFilter.ALL;
                    }
                    else if (string.Compare("BETA", cmdLineOpts.filter, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        filterType = KeyTypesFilter.BETA;
                    }
                    else
                    {
                        filterType = KeyTypesFilter.ALL; // Default back to all if we go garbage
                    }
                }
            }

            // Parse the csv and serialize the results
            var darkLaunchKeysList = TextOperations.ParseCSV(pathToFile, filterType);

            serializedResult = serializer.Serialize(darkLaunchKeysList);
            return(0);
        }
Пример #3
0
        internal static int WriteBuklLoadFeatureFile(string[] args, CommandLineOptions cmdLineOpts, JavaScriptSerializer serializer)
        {
            try
            {
                if (!string.IsNullOrEmpty(cmdLineOpts.featureLaunchKeysPath))
                {
                    if (System.IO.File.Exists(cmdLineOpts.featureLaunchKeysPath))
                    {
                        try
                        {
                            cmdLineOpts.featureLaunchKeys = File.ReadAllText(cmdLineOpts.featureLaunchKeysPath);
                        }
                        catch (Exception e)
                        {
                            Console.Write("Error, key list file could not be read: ", e.Message);
                            cmdLineOpts.featureLaunchKeys = null;
                        }
                    }
                    else
                    {
                        Console.Write("Error, key list file not found at: ", cmdLineOpts.featureLaunchKeysPath);
                        cmdLineOpts.featureLaunchKeys = null;
                    }
                }
                else if (cmdLineOpts.useBase64Encoding)
                {
                    byte[] byteArray = Convert.FromBase64String(cmdLineOpts.featureLaunchKeys);
                    cmdLineOpts.featureLaunchKeys = Encoding.UTF8.GetString(byteArray);
                }
                else
                {
                    var formatedString = FormatKeysInputJson(args, cmdLineOpts.GetKeysCommandLine());
                    if (!string.IsNullOrEmpty(formatedString))
                    {
                        cmdLineOpts.featureLaunchKeys = formatedString;
                    }
                }

                List <KeyDataObject> darkLaunchKeysList = serializer.Deserialize <List <KeyDataObject> >(cmdLineOpts.featureLaunchKeys);
                if (darkLaunchKeysList.Any())
                {
                    if (!TextOperations.WriteBuklLoadFeatureFile(cmdLineOpts.pathToBulkDataKeyFile, darkLaunchKeysList, RingtailBulkDataFile))
                    {
                        return(4);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write("Error, key list could not be deserialized: ", e.Message);
                {
                    return(5);
                }
            }
            return(0);
        }
Пример #4
0
        ////////////////////////////////////////////////////////////
        // Return codes:
        // 0 - success
        // 1 - bad command line - error parsing
        // 2 - disply help
        // 3 - static csv file not found or could not be read
        // 4 - error writing build data key file
        // 5 - key list deserialization error
        // 6 - DB error
        // 7 - Error getting current database version
        // 8 - Error syncing builk data file from DB
        ////////////////////////////////////////////////////////////
        static int Main(string[] args)
        {
#if DEBUG
            Debugger.Launch();
#endif
            var serializer = new JavaScriptSerializer();

            // command line options
            CommandLineOptions cmdLineOpts = new CommandLineOptions();

            List <string> extra;
            var           commandLineWasProcessed = ProcessCommandLineOpts(args, cmdLineOpts);

            // Show help if the option was passed or there was a problem processing command line args
            if (cmdLineOpts.show_help || !commandLineWasProcessed)
            {
                Help.ShowHelp(cmdLineOpts.optionSet, serializer);
                return(2);
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////
            // Return true/false based on if the specified portal has had keys written to it already
            ////////////////////////////////////////////////////////////////////////////////////////////////////
            if (!string.IsNullOrEmpty(cmdLineOpts.portalConnectionString) && cmdLineOpts.hasKeys)
            {
                if (cmdLineOpts.useBase64Encoding)
                {
                    cmdLineOpts.portalConnectionString = TextOperations.GetConnectionStringFromB64(cmdLineOpts.portalConnectionString);
                }

                var ret = DataBaseOperations.DatabaseKeysExist(cmdLineOpts.portalConnectionString);
                var serializedResult = serializer.Serialize(ret);
                Console.WriteLine(serializedResult);
                return(0);
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////
            // Retrieve the illuminated feature keys from the database  - return json keys list
            ////////////////////////////////////////////////////////////////////////////////////////////////////
            if (!string.IsNullOrEmpty(cmdLineOpts.portalConnectionString) && cmdLineOpts.getfeaturekeys)
            {
                if (cmdLineOpts.useBase64Encoding)
                {
                    cmdLineOpts.portalConnectionString = TextOperations.GetConnectionStringFromB64(cmdLineOpts.portalConnectionString);
                }

                List <string> featuresList;
                var           ret = DataBaseOperations.GetIlluminatedFeatures(cmdLineOpts.portalConnectionString, out featuresList);
                var           serializedResult = serializer.Serialize(featuresList);
                Console.WriteLine(serializedResult);
                return(ret);
            }


            ////////////////////////////////////////////////////////////////////////////////////////////////////
            // Retrieve the keys from the static csv file and return them as a string in the a kvp Json form.
            ////////////////////////////////////////////////////////////////////////////////////////////////////
            if ((!string.IsNullOrEmpty(cmdLineOpts.pathToSqlFile)) || (cmdLineOpts.useDefaultKeyFile))
            {
                string serializedResult;
                int    ret = Operations.HandleStaticSqlFile(cmdLineOpts, serializer, out serializedResult);
                Console.WriteLine(serializedResult);
                return(ret);
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////
            // Generate bulk load data file for insertion into database based on selected feature keys
            ////////////////////////////////////////////////////////////////////////////////////////////////////
            if ((!string.IsNullOrEmpty(cmdLineOpts.pathToBulkDataKeyFile)) && (!string.IsNullOrEmpty(cmdLineOpts.featureLaunchKeys) || !string.IsNullOrEmpty(cmdLineOpts.featureLaunchKeysPath)))
            {
                return(Operations.WriteBuklLoadFeatureFile(args, cmdLineOpts, serializer));
            }
            else if ((!string.IsNullOrEmpty(cmdLineOpts.pathToBulkDataKeyFile)) && (!string.IsNullOrEmpty(cmdLineOpts.portalConnectionString)))
            {
                //////////////////////////////////////////////////////////////////////////////////////////////////////
                /// This case is responsible for getting the extended dark launch keys out of the portal
                /// and writing them to the bulk data file for the case - essentially sync up the keys for the case.
                /////////////////////////////////////////////////////////////////////////////////////////////////////
                return(Operations.SyncPortalKeysToBulkDataFile(cmdLineOpts.portalConnectionString, cmdLineOpts.pathToBulkDataKeyFile));
            }
            else if (cmdLineOpts.testMode && (string.IsNullOrEmpty(cmdLineOpts.featureLaunchKeys)))
            {
                // Simple mode used for testing
                var darkLaunchKeysList = MockData.GenerateMockFeatureLaunchKeysList();
                var serializedResult   = serializer.Serialize(darkLaunchKeysList);
                Console.WriteLine(serializedResult);

                return(0);
            }
            else
            {
                Help.ShowHelp(cmdLineOpts.optionSet, serializer);
                return(0);
            }
        }