Esempio n. 1
0
        /// <summary>
        /// Stands for "Get Table name and Key"
        /// Returns the correct key for the current profile based on the app's equivalent of that key
        /// </summary>
        /// <param name="creationType"></param>
        /// <param name="appKey"></param>
        /// <param name="specialTableName">For table names that vary based on a setting, replaces %t with this string</param>
        /// <returns>:0:Table - 1: Sql key</returns>
        public void gtk(Export.C creationType, string appKey, string specialTableName = "")
        {
            // Select correct dictionary to searchfor creation
            Dictionary <string, Dictionary <string, string> > targetDict = null;

            switch (creationType)
            {
            case Export.C.Creature:
                targetDict = Profile.Active.Creature;
                break;

            case Export.C.Quest:
                targetDict = Profile.Active.Quest;
                break;

            case Export.C.Item:
                targetDict = Profile.Active.Item;
                break;

            case Export.C.Loot:
                targetDict = Profile.Active.Loot;
                break;

            case Export.C.Vendor:
                targetDict = Profile.Active.Vendor;
                break;
            }

            // Check if the key exists in the profile
            var table = targetDict.Where(t =>
                                         // equals in this case is equivalent to null check
                                         t.Value.Where(keysDic => keysDic.Key.ToLower() == appKey.ToLower()).FirstOrDefault().Key != null
                                         ).FirstOrDefault();

            // Key didn't exist in any table, ignore column
            IsValid = table.Key != null;
            if (!IsValid)
            {
                Logger.Log($"Notice: Export: {creationType.ToString()}.{appKey} not in profile. This isn't always an problem.");
                return;
            }

            // Key exists, generate result
            SqlTableName = table.Key; // Return table name

            // Handle unusual table names
            if (specialTableName != "")
            {
                SqlTableName = SqlTableName.Replace("%t", specialTableName);
            }

            // Find appkey again and put sqlkey in result
            SqlKey = table.Value.Where(keys => keys.Key.ToLower() == appKey.ToLower()).First().Value;
        }
Esempio n. 2
0
 /// <summary>
 /// Checks if an appKey exists in the profile
 /// This will not work for lookuptool
 /// </summary>
 /// <param name="toolName">Creature, Quest etc</param>
 /// <param name="appKey">Name of the application key requested</param>
 /// <returns></returns>
 public static bool HasAppKey(Export.C tool, string appKey)
 {
     try
     {
         // Return true if appkey exists in targetTool
         var targetTool = GetToolDataFromC(tool);
         return(targetTool.Values.Where(keys => keys.ContainsKey(appKey)).Count() > 0);
     }
     catch
     {
         Logger.Log($"Application Error: Profile.HasAppKey failed to ({tool.ToString()}, {appKey}. Please report this issue.", Logger.Status.Error, true);
         return(false);
     }
 }
Esempio n. 3
0
        public static string GetSqlKey(Export.C toolType, string appKey)
        {
            try
            {
                // Find the table containing the appkey
                Logger.Log($"ProfileHelper: GetSqlKey({toolType.ToString()}, {appKey})");
                var targetTool = GetToolDataFromC(toolType);
                var table      = targetTool.Where(kp => kp.Value
                                                  .Where(keys => keys.Key == appKey).Count() > 0
                                                  ).First().Value;

                // Find it again & return sqlkey
                string result = table.Where(keys => keys.Key == appKey).First().Value;
                Logger.Log("ProfileHelper: GetSqlKey found SQLKey: {result}");
                return(result);
            }
            catch
            {
                Logger.Log($"Profile Error: Lookup tool failed to find sqlKey for appKey {appKey}. returning 'InvalidAppKey'");
                return("InvalidAppKey");
            }
        }
Esempio n. 4
0
 public static Dictionary <string, Dictionary <string, string> > GetToolDataFromC(Export.C toolType)
 {
     try
     {
         // Find the correct Profile property (equest, creature etc) based on C
         return((Dictionary <string, Dictionary <string, string> >)Profile.Active.GetType().GetProperty(toolType.ToString()).GetValue(Profile.Active, null));
     }
     catch
     {
         Logger.Log($"Application Error: Profile.GetToolDataFromC() failed on {toolType.ToString()} Please report this issue.", Logger.Status.Error, true);
         return(null); // should be impossible anyway
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Used for UPDATE queries, determines the correct SqlKeys to base the query on
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        /// <returns>tablename, id column</returns>
        public static Dictionary <string, string> GetRelevantTablesAndIds(Export.C type, int id)
        {
            // Table name, sqlKey
            Dictionary <string, string> fieldsToCheck = new Dictionary <string, string>();
            string idAppKey = string.Empty;

            try
            {
                // Select correct dictionary to search for creation
                Dictionary <string, Dictionary <string, string> > targetDict = null;
                switch (type)
                {
                case Export.C.Creature:
                    targetDict = Profile.Active.Creature;
                    idAppKey   = "Entry";
                    break;

                case Export.C.Quest:
                    targetDict = Profile.Active.Quest;
                    idAppKey   = "EntryId";
                    break;

                case Export.C.Item:
                    targetDict = Profile.Active.Item;
                    idAppKey   = "EntryId";
                    break;

                // Other tools allow duplicate IDs and this method doesn't apply to them.
                // Defining tools here that allow duplicate entry IDs will break UPDATE queries for them because spaghetti.
                default:
                    return(null);
                }


                // Generate list of tables and IDs from profile
                // Add primary table
                var primTableData = targetDict
                                    .Where(x => x.Value.Keys.Contains(idAppKey))
                                    .First();
                fieldsToCheck.Add(primTableData.Key, primTableData.Value[idAppKey]);

                // Add secondary tables
                foreach (var tablesDict in Profile.Active.CustomFields)
                {
                    foreach (var keysDict in tablesDict.Value)
                    {
                        if (keysDict.Key.StartsWith(type.ToString()))
                        {
                            fieldsToCheck.Add(tablesDict.Key, keysDict.Value);
                        }
                    }
                }

                // Add special cases
                if (type == Export.C.Creature)
                {
                }

                // Return result
                return(fieldsToCheck);
            }
            catch (Exception ex)
            {
                Logger.Log($"Profile: CanWriteHandleOverride failed to determine ID of a table for {type}. Export failed.", Logger.Status.Error, true);
                Logger.Log(ex.Message);
                return(null); // Failed, cancel insert
            }
        }