private Common.FeatureUsageData.Feature MergeFeature(Common.FeatureUsageData.Feature oldFeature, Common.FeatureUsageData.Feature newFeature) { try { Common.FeatureUsageData.Feature mergedFeature = new Common.FeatureUsageData.Feature { Name = oldFeature.Name, LastUsageTime = oldFeature.LastUsageTime, CreationTime = oldFeature.CreationTime }; if (newFeature.LastUsageTime > oldFeature.LastUsageTime) { mergedFeature.UpdateUsageTime(newFeature.LastUsageTime); } var oldSubFeatures = oldFeature.Features(); var newSubFeatures = newFeature.Features(); if (oldSubFeatures != null && oldSubFeatures.Count > 0 && newSubFeatures != null && newSubFeatures.Count > 0) { mergedFeature.SubFeatures = newSubFeatures; IDictionary <string, Common.FeatureUsageData.Feature> oldCopiedSubFeatures = new Dictionary <string, Common.FeatureUsageData.Feature>(oldSubFeatures); foreach (var feature in oldCopiedSubFeatures) { if (mergedFeature.SubFeatures.ContainsKey(feature.Key)) { mergedFeature.SubFeatures[feature.Key] = MergeFeature(feature.Value, mergedFeature.SubFeatures[feature.Key]); } else { mergedFeature.SubFeatures.Add(feature.Key, feature.Value); } } } else if (oldSubFeatures != null && oldSubFeatures.Count > 0) { mergedFeature.SubFeatures = oldSubFeatures; } else if (newSubFeatures != null && newSubFeatures.Count > 0) { mergedFeature.SubFeatures = newSubFeatures; } return(mergedFeature); } catch (Exception ex) { if (NCacheServiceLogger.Logger != null) { NCacheServiceLogger.Logger.Error("MergeAccumulatedFeatureReport", ex.ToString()); } return(null); } }
private Feature MergeFeatures(Feature configFeature, Common.FeatureUsageData.Feature reportedFeature) { Feature finalFeature = new Feature { Name = configFeature.Name, LastUsedOn = DateTime.Compare(Convert.ToDateTime(configFeature.LastUsedOn), reportedFeature.LastUsageTime) > 0 ? configFeature.LastUsedOn : reportedFeature.LastUsageTime.Date.ToString("d") }; if (string.IsNullOrEmpty(configFeature.CreationTime)) { finalFeature.CreationTime = reportedFeature.CreationTime.ToString("d"); } else { finalFeature.CreationTime = configFeature.CreationTime; } Feature[] subfeatures = Common.FeatureUsageData.Feature.ConvertFeatures(reportedFeature.Features()); if (reportedFeature.Features() != null && reportedFeature.Features().Count > 0 && configFeature.Subfeatures != null && configFeature.Subfeatures.Length > 0) { IDictionary <string, Feature> commonFeatures = new Dictionary <string, Feature>(); for (int i = 0; i < configFeature.Subfeatures.Length; i++) { if (reportedFeature.Features().ContainsKey(configFeature.Subfeatures[i].Name)) { commonFeatures.Add(configFeature.Subfeatures[i].Name, MergeFeatures(configFeature.Subfeatures[i], reportedFeature.GetFeature(configFeature.Subfeatures[i].Name))); } else { commonFeatures.Add(configFeature.Subfeatures[i].Name, configFeature.Subfeatures[i]); } } foreach (var feature in reportedFeature.Features()) { if (!commonFeatures.ContainsKey(feature.Key)) { commonFeatures.Add(feature.Key, new Feature { Name = feature.Value.Name, LastUsedOn = feature.Value.LastUsageTime.ToString("d"), CreationTime = feature.Value.CreationTime.ToString("d"), Subfeatures = Common.FeatureUsageData.Feature.ConvertFeatures(feature.Value.Features()) }); } } finalFeature.Subfeatures = commonFeatures.Values.ToArray(); } else if (reportedFeature.Features() != null && reportedFeature.Features().Count > 0) { subfeatures = Common.FeatureUsageData.Feature.ConvertFeatures(reportedFeature.Features()); finalFeature.Subfeatures = subfeatures; } else { finalFeature.Subfeatures = configFeature.Subfeatures; } return(finalFeature); }