Exemplo n.º 1
0
        private void LoadTable(CATable caTable, string[] indexArray, Dictionary <string, double> dictionary, string tableName)
        {
            if (caTable == null)
            {
                string message = $"caTable name is null {tableName}";
                Logger.Error(message);
                throw new ArgumentNullException(nameof(caTable));
            }

            if (dictionary == null)
            {
                const string message = "dictionary is null";
                Logger.Error(message);
                throw new ArgumentNullException(nameof(dictionary));
            }

            if (!caTable.SetIndexOrder(indexArray))
            {
                string message = $"LoadTable() failed, SetIndexOrder() failed: indexArray = {ConvertIndexArrayToString(indexArray)}  {tableName}";
                Logger.Error(message);
                throw new Exception(message);
            }

            if (dictionary.Count == 0)
            {
                Logger.Error("LoadTable(): dictionary is empty");
                return;
            }

            foreach (KeyValuePair <string, double> keyValuePair in dictionary)
            {
                string key   = keyValuePair.Key;
                double value = keyValuePair.Value;

                const char comma       = ',';
                string[]   indexArray2 = key.Split(comma);

                if (!caTable.SetDataByLabels(value, indexArray2))
                {
                    string message = $"UpdateTable failed: SetDataByLabels() failed: indexArray = {ConvertIndexArrayToString(indexArray2)}, value = {value}, ErrorText = {_caEngine.ErrorText} {tableName}";
                    Logger.Error(message);
                    throw new Exception(message);
                }
            }

            if (!caTable.Update())
            {
                const string message = "Update() failed";
                Logger.Error(message);
                throw new Exception(message);
            }
        }
Exemplo n.º 2
0
        private void InitializeTable(CATable caTable, object initialValue)
        {
            if (caTable == null)
            {
                const string message = "caTable is null";
                Logger.Error(message);
                throw new ArgumentNullException(nameof(caTable));
            }

            dynamic safeArray = caTable.GetSafeArray();
            Array   array     = (Array)safeArray;
            int     rank      = array.Rank;

            switch (rank)
            {
            case 2:
                InitializeTableOfRank2(caTable, array, initialValue);
                break;

            case 3:
                InitializeTableOfRank3(caTable, array, initialValue);
                break;

            case 4:
                InitializeTableOfRank4(caTable, array, initialValue);
                break;

            case 5:
                InitializeTableOfRank5(caTable, array, initialValue);
                break;

            case 6:
                InitializeTableOfRank6(caTable, array, initialValue);
                break;

            default:
                const string message = "Only tables of rank 2, 3, 4, 5, and 6 can be initialized";
                Logger.Error(message);
                throw new Exception(message);
            }

            if (!caTable.Update())
            {
                const string message = "CATable.Update() failed";
                Logger.Error(message);
                throw new Exception(message);
            }
        }
Exemplo n.º 3
0
        private void SetSecondFoulPossession(NbaGame nbaGame)
        {
            CATable caTable = GetDefTable("EGT");

            string[] indexArray = { "S" };
            int      seconds    = nbaGame.NbaScore.Seconds;

            if (!caTable.SetDataByLabels(seconds, indexArray))
            {
                string message = $"SetDataByLabels() failed: seconds = {seconds}, indexArray1 = {ConvertIndexArrayToString(indexArray)}";
                Logger.Error(message);
                throw new Exception(message);
            }

            indexArray = new[] { "F" };
            int foul = nbaGame.Foul;

            if (!caTable.SetDataByLabels(foul, indexArray))
            {
                string message = $"SetDataByLabels() failed: foul = {foul}, indexArray2 = {ConvertIndexArrayToString(indexArray)}";
                throw new Exception(message);
            }

            indexArray = new[] { "P" };
            string possession = $"{nbaGame.Possession}";

            Logger.Info($"possession = {possession}, indexArray3 = {ConvertIndexArrayToString(indexArray)}");

            // todo bug here
            if (!caTable.SetDataByLabels(possession, indexArray))
            {
                throw new Exception($"SetDataByLabels() failed: possession = {possession}, indexArray3 = {ConvertIndexArrayToString(indexArray)}");
            }

            if (!caTable.Update())
            {
                throw new Exception("Update() failed");
            }
        }