public async Task <HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation)
        {
            string action = ProfilerActionSplitterAttribute.GetActionDescription(actionContext);

            try
            {
                using (TimeTracker.Start(action))
                {
                    using (HeavyProfiler.Log("Web.API " + actionContext.Request.Method, () => actionContext.Request.RequestUri.ToString()))
                    {
                        var user = (IUserEntity)GetProp(actionContext, SignumAuthenticationFilterAttribute.UserKey);
                        using (user != null ? UserHolder.UserSession(user) : null)
                        {
                            var culture = SignumAuthenticationFilterAttribute.GetCurrentCultures?.Invoke(actionContext);
                            using (culture != null ? CultureInfoUtils.ChangeBothCultures(culture) : null)
                            {
                                var result = await continuation();

                                return(result);
                            }
                        }
                    }
                }
            }
            finally
            {
                Statics.CleanThreadContextAndAssert();
            }
        }
        public async Task <HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation)
        {
            string action = ProfilerActionSplitterAttribute.GetActionDescription(actionContext);

            using (TimeTracker.Start(action))
            {
                using (HeavyProfiler.Log("Web.API " + actionContext.Request.Method, () => actionContext.Request.RequestUri.ToString()))
                {
                    //if (ProfilerLogic.SessionTimeout != null)
                    //{
                    //    IDisposable sessionTimeout = Connector.CommandTimeoutScope(ProfilerLogic.SessionTimeout.Value);
                    //    if (sessionTimeout != null)
                    //        actionContext.Request.RegisterForDispose(sessionTimeout);
                    //}

                    actionContext.Request.Properties[SavedRequestKey] = await actionContext.Request.Content.ReadAsStringAsync();

                    using (Authenticate == null ? null : Authenticate(actionContext))
                    {
                        if (actionContext.Response != null)
                        {
                            return(actionContext.Response);
                        }

                        return(await continuation());
                    }
                }
            }
        }
示例#3
0
        protected override T Return <T>(MethodBase mi, string description, Func <T> function)
        {
            try
            {
                string longDescription = mi.Name + description == null ? null : (" " + description);

                using (CultureFromOperationContext())
                    using (TimeTracker.Start(longDescription))
                        using (HeavyProfiler.Log("WCF", () => longDescription))
                            using (ScopeSessionFactory.OverrideSession(session))
                            {
                                return(function());
                            }
            }
            catch (Exception e)
            {
                e.LogException(el =>
                {
                    el.ControllerName = GetType().Name;
                    el.ActionName     = mi.Name;
                    el.QueryString    = description;
                    el.Version        = Schema.Current.Version.ToString();
                });

                throw;
            }
            finally
            {
                Statics.CleanThreadContextAndAssert();
            }
        }
 public void StartTimer()
 {
     lock (_ApplicationTimerLock)
     {
         ApplicationTimer = new TimeTracker(Ids.APPLICATION_TIMER_INIT);
         ApplicationTimer.Start();
     }
 }
        private async Task LoadBlocking()
        {
            var dataStore = await GetDataStore();

            DataItemClass[]          dataClasses;
            DataItemSchedule[]       dataSchedules;
            DataItemWeightCategory[] dataWeights = null; // Weights are now needed for adding tasks/events
            DataItemSemester         dataSemester;

            using (await Locks.LockDataForReadAsync("ScheduleViewItemsGroup.LoadBlocking"))
            {
                var timeTracker = TimeTracker.Start();
                dataSemester = dataStore.TableSemesters.FirstOrDefault(i => i.Identifier == SemesterId);

                if (dataSemester == null)
                {
                    throw new SemesterNotFoundException();
                }

                dataClasses = dataStore.TableClasses.Where(i => i.UpperIdentifier == SemesterId).ToArray();

                Guid[] classIdentifiers = dataClasses.Select(i => i.Identifier).ToArray();

                dataSchedules = dataStore.TableSchedules.Where(i => classIdentifiers.Contains(i.UpperIdentifier)).ToArray();

                if (_includeWeightCategories)
                {
                    dataWeights = dataStore.TableWeightCategories.Where(i => classIdentifiers.Contains(i.UpperIdentifier)).ToArray();
                }
                timeTracker.End(3, "ScheduleViewItemsGroup.LoadBlocking loading items from database");

                timeTracker = TimeTracker.Start();
                var semester = new ViewItemSemester(dataSemester, CreateClass);

                semester.FilterAndAddChildren(dataClasses);

                foreach (var c in semester.Classes)
                {
                    c.FilterAndAddChildren(dataSchedules);

                    if (_includeWeightCategories)
                    {
                        c.FilterAndAddChildren(dataWeights);
                    }
                }

                this.Semester = semester;
                timeTracker.End(3, "ScheduleViewItemsGroup.LoadBlocking constructing view items");
            }
        }
示例#6
0
 protected override Composite CreateBehavior()
 {
     return(new Sequence(
                new Action(ret => TimeTracker.Start(new Timing
     {
         Name = Name,
         StartTime = DateTime.UtcNow,
         Group = Group,
         QuestIsBounty = (ZetaDia.ActInfo.ActiveBounty != null),
         QuestName = (ZetaDia.ActInfo.ActiveBounty != null) ? ZetaDia.ActInfo.ActiveBounty.Info.Quest.ToString() : ZetaDia.CurrentQuest.Name,
         QuestId = (ZetaDia.ActInfo.ActiveBounty != null) ? ZetaDia.ActInfo.ActiveBounty.Info.QuestSNO : ZetaDia.CurrentQuest.QuestSNO
     })),
                new Action(ret => _isDone = true)
                ));
 }
示例#7
0
        /*-------------------------------------------------------------- TASTI PROGETTI --------------------------------------------------------------*/

        private void StartTracking_Click(object sender, RoutedEventArgs e)
        {
            Object[] assignmentAndTimeBlock = (Object[])((Button)sender).Tag;

            if (currentAssignment != (Assignment)assignmentAndTimeBlock[0])
            {
                currentAssignment = (Assignment)assignmentAndTimeBlock[0]; // assignment da tracciare
                currentUITime     = (TextBlock)assignmentAndTimeBlock[1];  // textblock da aggiornare ogni secondo

                updateUiSecondsTimer.Start();
                updateDbMinutesTimer.Start();
                timeTracker        = new TimeTracker(currentAssignment);
                currentUITime.Text = timeTracker.Start();

                inTimeIcon.Icon = new System.Drawing.Icon("../../Resources/PlayingIcon.ico");
            }
        }
示例#8
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var routeData = actionContext.ControllerContext.RouteData.Values;

            var action = actionContext.ActionDescriptor.ControllerDescriptor.ControllerName + "." + actionContext.ActionDescriptor.ActionName;

            var rad = actionContext.ActionDescriptor as ReflectedHttpActionDescriptor;

            if (rad != null)
            {
                var attr = rad.MethodInfo.GetCustomAttributes(true).OfType <ProfilerActionSplitterAttribute>().FirstOrDefault();
                if (attr != null)
                {
                    var obj = attr.RequestKey == null?actionContext.ActionArguments.Values.Single() : actionContext.ActionArguments.GetOrThrow(attr.RequestKey, "Argument '{0}' not found in: " + rad.MethodInfo.MethodSignature());

                    if (obj != null)
                    {
                        action += " " + obj.ToString();
                    }
                }
            }


            routeData.Add("elapsed", TimeTracker.Start(action));

            IDisposable profiler = HeavyProfiler.Log("Web.API " + actionContext.Request.Method, () => actionContext.Request.RequestUri.ToString());

            if (profiler != null)
            {
                routeData.Add("profiler", profiler);
            }


            if (ProfilerLogic.SessionTimeout != null)
            {
                IDisposable sessionTimeout = Connector.CommandTimeoutScope(ProfilerLogic.SessionTimeout.Value);
                if (sessionTimeout != null)
                {
                    routeData.Add("sessiontimeout", sessionTimeout);
                }
            }
        }
示例#9
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var action = filterContext.RouteData.Values["controller"] + "." + filterContext.RouteData.Values["action"];

            var rad = filterContext.ActionDescriptor as ReflectedActionDescriptor;

            if (rad != null)
            {
                var attr = rad.GetCustomAttributes(true).OfType <ActionSplitterAttribute>().FirstOrDefault();
                if (attr != null)
                {
                    var str = filterContext.HttpContext.Request[attr.RequestKey] ?? filterContext.RouteData.Values[attr.RequestKey];

                    if (str != null)
                    {
                        action += " " + str;
                    }
                }
            }

            ViewDataDictionary viewData = filterContext.Controller.ViewData;

            viewData.Add("elapsed", TimeTracker.Start(action));

            IDisposable profiler = HeavyProfiler.Log("MvcRequest", () => filterContext.HttpContext.Request.Url.PathAndQuery);

            if (profiler != null)
            {
                viewData.Add("profiler", profiler);
            }


            if (ProfilerLogic.SessionTimeout != null)
            {
                IDisposable sessionTimeout = Connector.CommandTimeoutScope(ProfilerLogic.SessionTimeout.Value);
                if (sessionTimeout != null)
                {
                    viewData.Add("sessiontimeout", sessionTimeout);
                }
            }
        }
        /// <summary>
        /// Thread safe, runs on own thread for data lock.
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public static async Task Save(AccountDataItem account)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                // Serialize on current thread
                GetSerializer().WriteObject(stream, account);
                stream.Position = 0;

                await Task.Run(async delegate
                {
                    using (await Locks.LockAccounts())
                    {
                        // Get the account folder
                        var timeTracker       = TimeTracker.Start();
                        IFolder accountFolder = await FileHelper.GetOrCreateAccountFolder(account.LocalAccountId);
                        timeTracker.End(3, "AccountsManager.Save GetOrCreateAccountFolder");

                        // Create a temp file to write to
                        timeTracker           = TimeTracker.Start();
                        IFile tempAccountFile = await accountFolder.CreateFileAsync("TempAccountData.dat", CreationCollisionOption.ReplaceExisting);
                        timeTracker.End(3, "AccountsManager.Save creating temp file");

                        // Write the data to the temp file
                        timeTracker = TimeTracker.Start();
                        using (Stream s = await tempAccountFile.OpenAsync(StorageEverywhere.FileAccess.ReadAndWrite))
                        {
                            timeTracker.End(3, "AccountsManager.Save opening file stream");

                            timeTracker = TimeTracker.Start();
                            stream.CopyTo(s);
                            timeTracker.End(3, "AccountsManager.Save copying stream to file");
                        }

                        // Move the temp file to the actual file
                        timeTracker = TimeTracker.Start();
                        await tempAccountFile.RenameAsync(FileNames.ACCOUNT_FILE_NAME, NameCollisionOption.ReplaceExisting);
                        timeTracker.End(3, "AccountsManager.Save renaming temp file to final");
                    }
                });
            }
        }
        /// <summary>
        /// Not thread safe. Loads and returns the account if it exists, otherwise returns null
        /// </summary>
        /// <param name="localAccountId"></param>
        /// <returns></returns>
        private static async Task <AccountDataItem> Load(Guid localAccountId)
        {
            var   timeTracker = TimeTracker.Start();
            IFile file        = await GetFile(localAccountId);

            timeTracker.End(3, "AccountsManager.Load GetFile");

            // If doesn't exist
            if (file == null)
            {
                return(null);
            }

            // Otherwise
            AccountDataItem account;

            timeTracker = TimeTracker.Start();
            using (Stream s = await file.OpenAsync(StorageEverywhere.FileAccess.Read))
            {
                timeTracker.End(3, "AccountsManager.Load open file stream");

                timeTracker = TimeTracker.Start();
                try
                {
                    account = (AccountDataItem)GetSerializer().ReadObject(s);
                }
                catch (Exception ex)
                {
                    // Sometimes the file becomes corrupt, nothing we can do, they'll have to log in again
                    TelemetryExtension.Current?.TrackEvent("Error_FailDeserializeAccount", new Dictionary <string, string>()
                    {
                        { "Exception", ex.ToString() }
                    });
                    return(null);
                }
                timeTracker.End(3, "AccountsManager.Load deserializing stream");
            }

            account.LocalAccountId = localAccountId;

            SyncLayer.Sync.ChangedSetting?changedSettings = null;
            bool needsClassRemindersReset = false;

            // Upgrade account data
            if (account.AccountDataVersion < 2)
            {
                // We introduced syncing selected semester in this version.
                // So if we upgraded, we need to make sure we force sync
                if (account.CurrentSemesterId != Guid.Empty)
                {
                    account.NeedsToSyncSettings = true;

                    if (changedSettings == null)
                    {
                        changedSettings = SyncLayer.Sync.ChangedSetting.SelectedSemesterId;
                    }
                    else
                    {
                        changedSettings = changedSettings.Value | SyncLayer.Sync.ChangedSetting.SelectedSemesterId;
                    }
                }
            }

            if (account.AccountDataVersion < 3)
            {
                // We introduced auto-selecting the week that the schedule changes on,
                // so users in Spain will now have everything as Monday for first day
                DayOfWeek cultureFirstDayOfWeek = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek;
                if (account.WeekChangesOn == DayOfWeek.Sunday && account.WeekChangesOn != cultureFirstDayOfWeek)
                {
                    account.NeedsToSyncSettings = true;
                    account.SetWeekSimple(cultureFirstDayOfWeek, account.CurrentWeek);

                    if (changedSettings == null)
                    {
                        changedSettings = SyncLayer.Sync.ChangedSetting.WeekOneStartsOn;
                    }
                    else
                    {
                        changedSettings = changedSettings.Value | SyncLayer.Sync.ChangedSetting.WeekOneStartsOn;
                    }

                    // While we technically should update their reminders/schedule tile (since if
                    // they were using two-week schedules, that info changed), we'll skip doing that
                    // since it's extra complicated to load the data items here while also loading the
                    // account, and if they were using two week, they probably already have this set
                    // correctly anyways
                }
            }

            if (account.AccountDataVersion < 4)
            {
                // Set to the default timespan (otherwise this would be null when upgrading)
                account.ClassRemindersTimeSpan = AccountDataItem.DefaultClassRemindersTimeSpan;
                needsClassRemindersReset       = true;
            }

            if (account.AccountDataVersion < AccountDataItem.CURRENT_ACCOUNT_DATA_VERSION)
            {
                account.AccountDataVersion = AccountDataItem.CURRENT_ACCOUNT_DATA_VERSION;
                _ = Save(account); // Don't wait, otherwise we would get in a dead lock
            }

            if (changedSettings != null)
            {
                _ = SyncLayer.Sync.SyncSettings(account, changedSettings.Value);
            }

            if (needsClassRemindersReset)
            {
                _ = ClassRemindersExtension.Current?.ResetAllRemindersAsync(account);
            }

            return(account);
        }
示例#12
0
 public void StartTimer()
 {
     lock (_ApplicationTimerLock)
       {
       ApplicationTimer = new TimeTracker(Ids.APPLICATION_TIMER_INIT);
         ApplicationTimer.Start();
       }
 }
示例#13
0
        public override IDisposable GetResource(ResourceExecutingContext context)
        {
            string action = ProfilerActionSplitterAttribute.GetActionDescription(context);

            return(TimeTracker.Start(action));
        }
示例#14
0
        /// <summary>
        /// Not thread safe. Loads and returns the account if it exists, otherwise returns null
        /// </summary>
        /// <param name="localAccountId"></param>
        /// <returns></returns>
        private static async Task <AccountDataItem> Load(Guid localAccountId)
        {
            var   timeTracker = TimeTracker.Start();
            IFile file        = await GetFile(localAccountId);

            timeTracker.End(3, "AccountsManager.Load GetFile");

            // If doesn't exist
            if (file == null)
            {
                return(null);
            }

            // Otherwise
            AccountDataItem account;

            timeTracker = TimeTracker.Start();
            using (Stream s = await file.OpenAsync(FileAccess.Read))
            {
                timeTracker.End(3, "AccountsManager.Load open file stream");

                timeTracker = TimeTracker.Start();
                try
                {
                    account = (AccountDataItem)GetSerializer().ReadObject(s);
                }
                catch (Exception ex)
                {
                    // Sometimes the file becomes corrupt, nothing we can do, they'll have to log in again
                    TelemetryExtension.Current?.TrackEvent("Error_FailDeserializeAccount", new Dictionary <string, string>()
                    {
                        { "Exception", ex.ToString() }
                    });
                    return(null);
                }
                timeTracker.End(3, "AccountsManager.Load deserializing stream");
            }

            account.LocalAccountId = localAccountId;

            bool needsSyncSettings = false;

            // Upgrade account data
            if (account.AccountDataVersion < 2)
            {
                // We introduced syncing selected semester in this version.
                // So if we upgraded, we need to make sure we force sync
                if (account.CurrentSemesterId != Guid.Empty)
                {
                    account.NeedsToSyncSettings = true;
                    needsSyncSettings           = true;
                }
            }

            if (account.AccountDataVersion < AccountDataItem.CURRENT_ACCOUNT_DATA_VERSION)
            {
                account.AccountDataVersion = AccountDataItem.CURRENT_ACCOUNT_DATA_VERSION;
                var dontWait = Save(account); // Don't wait, otherwise we would get in a dead lock
            }

            if (needsSyncSettings)
            {
                var dontWait = SyncLayer.Sync.SyncSettings(account);
            }

            return(account);
        }
示例#15
0
        private void StartSearch()
        {
            IConfigurationProxy cfgProxy = ProxyHome.Instance.RetrieveConfigurationProxy(EngineKeyKeeper.Instance.AccessKey);

              List<LinkFile2Language> bindedProj2LanguageFileType = null;

              // Retrieve project definitions from the Configuration component.
              Dictionary<int, IProjectDefinition> projects = cfgProxy.Projects();

              // Let's run through all the projects and do our thing.
              foreach (KeyValuePair<int, IProjectDefinition> pair in projects)
              {
            IProjectDefinition project = pair.Value;
            if (!project.Enabled)
              continue; // Project definition was disabled.

            // Here we create the language file type containers for all the languages
            // that are in play for the current project.
            bindedProj2LanguageFileType = BindProjectLanguagesToFileTypes(project);

            // Find all files associated with the language file extension in
            // the current file container 'linkFile2Language'.
            foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
            {
              foreach (IDirectoryDefinition dir in project.Directories)
              {
                        if (!dir.Enabled)
                            continue;

            if (!Directory.Exists(dir.Path))
            {
              string s = string.Format("No directory found ({0})", dir.Path);
              throw new IOException(s);
            }

            IRootDirectoryStatistics rds = ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).CreateRootDirectory(project.Id);
            rds.RootDirectory = dir.Path;

            FileSearchEngine fileSearchEngine = new FileSearchEngine(dir, linkFile2Language.Language.Extension);
            fileSearchEngine.ExcludeDirs = project.ExcludedDirectories.Select(d => d).ToList();
            fileSearchEngine.IncludeSubDirsInSearch = true;
            fileSearchEngine.Search();

            // Adding all the files found with the extention given by
            // 'linkFile2Language.Language.Extension' to the file container 'linkFile2Language'.
            linkFile2Language.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);

            // Adding all the files found to the StatisticsComponentProxy.
            ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.Files, fileSearchEngine.FileCount);
            rds.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);
              }
            }

            TimeTracker tt = new TimeTracker("Execution of regular expression on each file.");
            tt.Start();

              IMatchProxy matchProxy = ProxyHome.Instance.RetrieveMatchProxy(EngineKeyKeeper.Instance.AccessKey);

            // Let's execute each regular expression from each rule that are enabled
            // and should be applied to the current language.
            foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
            {
              foreach (KeyValuePair<int, ICategoryDefinition> categoryDefinition in project.Categories)
              {
            if (!categoryDefinition.Value.Enabled)
              continue;

            foreach (KeyValuePair<int, IRuleDefinition> ruleDefinition in categoryDefinition.Value.Rules)
            {
              if (!ruleDefinition.Value.Enabled)
                continue;

              // Let's check whether or not the current 'rule' is associated with the current 'language'?
              IRuleDeclaration ruleDeclaration = cfgProxy.RuleDeclarationFromCategoryIdAndRuleId(categoryDefinition.Value.CategoryDeclarationReferenceId, ruleDefinition.Value.RuleDeclarationReferenceId);
              foreach (KeyValuePair<int, ILanguageDeclaration> languageRef in ruleDeclaration.Languages)
              {
                if (languageRef.Key == linkFile2Language.Language.Id)
                {
                  // The language reference on the current rule is identical to the current 'linkFile2Language'
                  // meaning that we should execute the regular expression from the current rule on all the
                  // files placed in the 'linkFile2Language':
                    IMatchInfoReferences references = matchProxy.MatchesFactory<IMatchInfoReferences>(typeof(IMatchInfoReferences));

                  references.ProjectDefinitionReference   = project;
                  references.CategoryDeclarationReference = cfgProxy.CategoryDeclaration(categoryDefinition.Value.CategoryDeclarationReferenceId);
                                    references.CategoryDefinitionReference  = categoryDefinition.Value;
                    references.RuleDeclarationReference     = ruleDeclaration;
                                    references.RuleDefinitionReference      = ruleDefinition.Value;
                    references.LanguageDeclarationReference = languageRef.Value;

                  Parallel.ForEach(linkFile2Language.Filenames, file => ExecuteRegularExpressionsOnBuffer(file, references, ruleDeclaration));
                }
              }
            }
              }
            }

            tt.Stop("We are done.");
            tt.ToLog(Log);
              }
        }
示例#16
0
        private void StartSearch()
        {
            IConfigurationProxy cfgProxy = ProxyHome.Instance.RetrieveConfigurationProxy(EngineKeyKeeper.Instance.AccessKey);

            List <LinkFile2Language> bindedProj2LanguageFileType = null;

            // Retrieve project definitions from the Configuration component.
            Dictionary <int, IProjectDefinition> projects = cfgProxy.Projects();

            // Let's run through all the projects and do our thing.
            foreach (KeyValuePair <int, IProjectDefinition> pair in projects)
            {
                IProjectDefinition project = pair.Value;
                if (!project.Enabled)
                {
                    continue; // Project definition was disabled.
                }
                // Here we create the language file type containers for all the languages
                // that are in play for the current project.
                bindedProj2LanguageFileType = BindProjectLanguagesToFileTypes(project);


                // Find all files associated with the language file extension in
                // the current file container 'linkFile2Language'.
                foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
                {
                    foreach (IDirectoryDefinition dir in project.Directories)
                    {
                        if (!dir.Enabled)
                        {
                            continue;
                        }

                        if (!Directory.Exists(dir.Path))
                        {
                            string s = string.Format("No directory found ({0})", dir.Path);
                            throw new IOException(s);
                        }

                        IRootDirectoryStatistics rds = ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).CreateRootDirectory(project.Id);
                        rds.RootDirectory = dir.Path;

                        FileSearchEngine fileSearchEngine = new FileSearchEngine(dir, linkFile2Language.Language.Extension);
                        fileSearchEngine.ExcludeDirs            = project.ExcludedDirectories.Select(d => d).ToList();
                        fileSearchEngine.IncludeSubDirsInSearch = true;
                        fileSearchEngine.Search();

                        // Adding all the files found with the extention given by
                        // 'linkFile2Language.Language.Extension' to the file container 'linkFile2Language'.
                        linkFile2Language.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);

                        // Adding all the files found to the StatisticsComponentProxy.
                        ProxyHome.Instance.RetrieveStatisticsProxy(EngineKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.Files, fileSearchEngine.FileCount);
                        rds.Filenames.AddRange(fileSearchEngine.FileFoundDuringSearch);
                    }
                }


                TimeTracker tt = new TimeTracker("Execution of regular expression on each file.");
                tt.Start();


                IMatchProxy matchProxy = ProxyHome.Instance.RetrieveMatchProxy(EngineKeyKeeper.Instance.AccessKey);

                // Let's execute each regular expression from each rule that are enabled
                // and should be applied to the current language.
                foreach (LinkFile2Language linkFile2Language in bindedProj2LanguageFileType)
                {
                    foreach (KeyValuePair <int, ICategoryDefinition> categoryDefinition in project.Categories)
                    {
                        if (!categoryDefinition.Value.Enabled)
                        {
                            continue;
                        }


                        foreach (KeyValuePair <int, IRuleDefinition> ruleDefinition in categoryDefinition.Value.Rules)
                        {
                            if (!ruleDefinition.Value.Enabled)
                            {
                                continue;
                            }


                            // Let's check whether or not the current 'rule' is associated with the current 'language'?
                            IRuleDeclaration ruleDeclaration = cfgProxy.RuleDeclarationFromCategoryIdAndRuleId(categoryDefinition.Value.CategoryDeclarationReferenceId, ruleDefinition.Value.RuleDeclarationReferenceId);
                            foreach (KeyValuePair <int, ILanguageDeclaration> languageRef in ruleDeclaration.Languages)
                            {
                                if (languageRef.Key == linkFile2Language.Language.Id)
                                {
                                    // The language reference on the current rule is identical to the current 'linkFile2Language'
                                    // meaning that we should execute the regular expression from the current rule on all the
                                    // files placed in the 'linkFile2Language':
                                    IMatchInfoReferences references = matchProxy.MatchesFactory <IMatchInfoReferences>(typeof(IMatchInfoReferences));

                                    references.ProjectDefinitionReference   = project;
                                    references.CategoryDeclarationReference = cfgProxy.CategoryDeclaration(categoryDefinition.Value.CategoryDeclarationReferenceId);
                                    references.CategoryDefinitionReference  = categoryDefinition.Value;
                                    references.RuleDeclarationReference     = ruleDeclaration;
                                    references.RuleDefinitionReference      = ruleDefinition.Value;
                                    references.LanguageDeclarationReference = languageRef.Value;

                                    Parallel.ForEach(linkFile2Language.Filenames, file => ExecuteRegularExpressionsOnBuffer(file, references, ruleDeclaration));
                                }
                            }
                        }
                    }
                }

                tt.Stop("We are done.");
                tt.ToLog(Log);
            }
        }
示例#17
0
 private void button1_Click(object sender, EventArgs e)
 {
     TimeTracker.Start();
     RefreshTimer.Start();
     RefreshTrackingButtons();
 }