Exemple #1
0
        /// <summary>
        /// Returns the parent ResourceWindowsCategory for the passed-in ResourceWindowsCategory item.
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="name"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private static ResourceWindowsCategory GetParent(EnterpriseTestEntities entities, string name, ResourceWindowsCategory item, string categoryType)
        {
            //Try to find the parent in the item's Parent collection
            ResourceWindowsCategory result = item.Parents.Where(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (result == null)
            {
                //Not in the item's parent collection.  Try to find the parent in the table
                result = Select(entities, categoryType, name).FirstOrDefault();
            }

            if (result == null)
            {
                //Not in the item's parent collection or the database.  Create a new item
                result = ResourceWindowsCategory.CreateResourceWindowsCategory(NextId(entities), name, categoryType);
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Adds a new set of PerfMon counters.
        /// </summary>
        /// <param name="entities">The data context.</param>
        /// <param name="categoryName">The category name.</param>
        /// <param name="instanceName">The instance name.</param>
        /// <param name="counterName">The counter name.</param>
        public static void AddPerfMon(EnterpriseTestEntities entities, string categoryName, string instanceName, string counterName, ResourceWindowsCategoryType categoryType)
        {
            string categoryTypeName          = categoryType.ToString();
            ResourceWindowsCategory category = null;
            ResourceWindowsCategory instance = null;
            ResourceWindowsCategory counter  = Select(entities, categoryTypeName, counterName).FirstOrDefault();

            if (counter == null)
            {
                counter = ResourceWindowsCategory.CreateResourceWindowsCategory(NextId(entities), counterName, categoryTypeName);
            }

            //If instance is blank, use the constant string.  This is because in the ResourceWindowsCategory table the blank category is the root,
            //so we can't reuse it further down in the hierarchy.
            instance = GetParent(entities, instanceName == string.Empty ? InstanceDoesNotApply : instanceName, counter, categoryTypeName);
            category = GetParent(entities, categoryName, instance, categoryTypeName);

            //Wire up the parent relationships so that the EF can handle it.
            if (counter.EntityState == System.Data.EntityState.Detached)
            {
                counter.Parents.Add(instance);
            }
            if (instance.EntityState == System.Data.EntityState.Detached)
            {
                instance.Parents.Add(category);
            }
            if (category.EntityState == System.Data.EntityState.Detached)
            {
                //We're adding a new category, so hook it up the the root parent
                ResourceWindowsCategory root = Select(entities, categoryTypeName, string.Empty).FirstOrDefault();
                if (root != null)
                {
                    category.Parents.Add(root);
                }
            }
        }