Пример #1
0
 protected virtual K ExecuteFunction <K>(HealthTrackType type, string methodName, Func <K> function, params object[] parameters)
 {
     using (var scope = HealthReporter.BeginTrack(type, string.Format(HealthReporter.BUSINESS_FORMAT, this.TrackPrefix + "." + methodName)))
     {
         return(base.ExecuteFunction <K>(methodName, function, parameters));
     }
 }
Пример #2
0
 protected virtual void ExecuteMethod(HealthTrackType type, string methodName, Action action, params object[] parameters)
 {
     using (var scope = HealthReporter.BeginTrack(type, string.Format(HealthReporter.BUSINESS_FORMAT, this.TrackPrefix + "." + methodName)))
     {
         base.ExecuteMethod(methodName, action, parameters);
     }
 }
Пример #3
0
 protected override K ExecuteFunction <K>(string methodName, Func <K> function, params object[] parameters)
 {
     using (var scope = HealthReporter.BeginTrack(HealthTrackType.CountAndDurationAverage, string.Format(HealthReporter.BUSINESS_FORMAT, this.TrackPrefix + "." + methodName)))
     {
         return(base.ExecuteFunction <K>(methodName, function, parameters));
     }
 }
Пример #4
0
 protected override void ExecuteMethod(string methodName, Action action, params object[] parameters)
 {
     using (var scope = HealthReporter.BeginTrack(HealthTrackType.CountAndDurationAverage, string.Format(HealthReporter.BUSINESS_FORMAT, this.TrackPrefix + "." + methodName)))
     {
         base.ExecuteMethod(methodName, action, parameters);
     }
 }
Пример #5
0
 protected override T ExecuteFunction <T>(string methodName, bool forceThrow, Func <T> function, params object[] parameters)
 {
     using (var scope = HealthReporter.BeginTrack(HealthTrackType.CountAndDurationAverage, string.Format(HealthReporter.RESTAPI_FORMAT, this.TrackPrefix + "." + methodName)))
     {
         return(base.ExecuteFunction <T>(methodName, forceThrow, function, parameters));
     }
 }
Пример #6
0
        protected virtual void PerformProcessSync(string specificTable)
        {
            base.ExecuteMethod("PerformProcessSync", delegate()
            {
                IFindClassTypes finder                  = this.IFoundation.Resolve <IFindClassTypes>();
                IEnumerable <Type> synchronizers        = FindInterfacesOfType(typeof(ISynchronizer), finder.GetAssemblies(null));
                List <ISynchronizer> synchronizersToRun = new List <ISynchronizer>();
                foreach (Type item in synchronizers)
                {
                    if (string.IsNullOrEmpty(specificTable) || item.Name.Contains(specificTable)) // not perfect.. but should be good enough, its just for dev ease anyway
                    {
                        base.IFoundation.LogWarning(string.Format("ElasticSearchDaemon.{0} Loading", item.ToString()));
                        if (!item.IsGenericTypeDefinition && item != typeof(ISynchronizer))
                        {
                            try
                            {
                                ISynchronizer synchronizer = this.IFoundation.Container.Resolve(item, string.Empty) as ISynchronizer;
                                base.IFoundation.LogWarning(string.Format("ElasticSearchDaemon.{0} Running", item.ToString()));
                                if (synchronizer != null)
                                {
                                    synchronizersToRun.Add(synchronizer);
                                }
                            }
                            catch
                            {
                                // gulp, can't resolve
                            }
                        }
                        else
                        {
                            base.IFoundation.LogWarning("ElasticSearchDaemon: " + item.ToString() + "is a generic or the base interface");
                        }
                    }
                }

                // order them
                synchronizersToRun = synchronizersToRun.OrderBy(x => x.Priority).ToList();

                // process them by bulk-priority
                while (synchronizersToRun.Count > 0)
                {
                    int priority = synchronizersToRun[0].Priority;
                    List <ISynchronizer> itemsWithPriority = synchronizersToRun.Where(x => x.Priority == priority).ToList();
                    List <Task> tasks = new List <Task>();

                    foreach (var synchronizer in itemsWithPriority)
                    {
                        synchronizersToRun.Remove(synchronizer);

                        tasks.Add(Task.Run(delegate()
                        {
                            try
                            {
                                using (var scope = HealthReporter.BeginTrack(HealthTrackType.DurationAverage, string.Format(HealthReporter.INDEXER_QUEUE_TIME_FORMAT, synchronizer.EntityName)))
                                {
#pragma warning disable 612, 618
                                    int count = synchronizer.PerformSynchronization(this.AgentName);
#pragma warning restore 612, 618
                                    if (count > 0)
                                    {
                                        HealthReporter.Current.UpdateMetric(HealthTrackType.Count, string.Format(HealthReporter.INDEXER_QUEUE_SIZE_FORMAT, synchronizer.EntityName), 0, count);
                                    }
                                }

                                base.IFoundation.LogWarning(string.Format("ElasticSearchDaemon.{0} Complete", synchronizer.ToString()));
                            }
                            catch (Exception ex)
                            {
                                base.IFoundation.LogError(ex, "PerformProcessSync" + synchronizer.GetType().ToString());
                                base.IFoundation.LogWarning(string.Format("ElasticSearchDaemon.{0} Error", synchronizer.ToString()));
                            }
                        }));
                    }

                    base.IFoundation.LogWarning(string.Format("ElasticSearchDaemon.Waiting"));
                    Task.WaitAll(tasks.ToArray());
                    base.IFoundation.LogWarning(string.Format("ElasticSearchDaemon.Done"));
                }
            });
        }