Exemplo n.º 1
0
        private bool UpdateCache()
        {
            var progress = new Progress <int>();

            progress.ProgressChanged += IncorporateCacheProgress;

            var keywords = GSA.Keywords;

            GSA.App.LocalCache.Clear();

            //initial estimate
            progressEstimator.UpdateTotal(WorkPhase.CacheRead, keywords.Count());
            progressEstimator.UpdateTotal(WorkPhase.CacheUpdate, keywords.Count());
            progressEstimator.UpdateTotal(WorkPhase.Conversion, 10000); //Take wild guess at having 10,000 objects to convert
            progressEstimator.UpdateTotal(WorkPhase.ApiCalls, 10);      //Take wild guess at having 10 API calls to make

            try
            {
                var data = GSA.App.Proxy.GetGwaData(keywords, false, progress);
                progressEstimator.UpdateTotal(WorkPhase.CacheRead, data.Count());
                progressEstimator.SetCurrentToTotal(WorkPhase.CacheRead); //Equalise the current and total in case the previous total estimate was wrong

                //Now that we have a better ideaof how many objects to update the cache with, and convert
                progressEstimator.UpdateTotal(WorkPhase.CacheUpdate, data.Count());
                progressEstimator.UpdateTotal(WorkPhase.Conversion, data.Count());

                for (int i = 0; i < data.Count(); i++)
                {
                    var applicationId = (string.IsNullOrEmpty(data[i].ApplicationId)) ? null : data[i].ApplicationId;
                    GSA.App.LocalCache.Upsert(
                        data[i].Keyword,
                        data[i].Index,
                        data[i].GwaWithoutSet,
                        streamId: data[i].StreamId,
                        applicationId: applicationId,
                        gwaSetCommandType: data[i].GwaSetType);

                    progressEstimator.AppendCurrent(WorkPhase.CacheRead, 1);
                }

                int numRowsupdated = data.Count();
                if (numRowsupdated > 0)
                {
                    loggingProgress.Report(new MessageEventArgs(SpeckleGSAInterfaces.MessageIntent.Display, SpeckleGSAInterfaces.MessageLevel.Information,
                                                                "Read " + numRowsupdated + " GWA lines across " + keywords.Count() + " keywords into cache"));
                }

                progressEstimator.SetCurrentToTotal(WorkPhase.CacheUpdate); //Equalise the current and total in case the previous total estimate was wrong

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
    private bool UpdateCache()
    {
      var keywords = GSA.Keywords;
      GSA.App.LocalCache.Clear();
      //initial estimate
      progressEstimator.UpdateTotal(WorkPhase.CacheRead, keywords.Count());
      progressEstimator.UpdateTotal(WorkPhase.CacheUpdate, keywords.Count());
      progressEstimator.UpdateTotal(WorkPhase.Conversion, 10000); //Take wild guess at having 10,000 objects to convert
      progressEstimator.UpdateTotal(WorkPhase.ApiCalls, 10);       //Take wild guess at having 10 API calls to make

      try
      {
        var data = GSA.App.Proxy.GetGwaData(keywords, false);
        progressEstimator.UpdateTotal(WorkPhase.CacheRead, data.Count());
        progressEstimator.SetCurrentToTotal(WorkPhase.CacheRead); //Equalise the current and total in case the previous total estimate was wrong

        //Now that we have a better ideaof how many objects to update the cache with, and convert
        progressEstimator.UpdateTotal(WorkPhase.CacheUpdate, data.Count());
        progressEstimator.UpdateTotal(WorkPhase.Conversion, data.Count());

        for (int i = 0; i < data.Count(); i++)
        {
          GSA.App.Cache.Upsert(
            data[i].Keyword,
            data[i].Index,
            data[i].GwaWithoutSet,
            streamId: data[i].StreamId,
            //This needs to be revised as this logic is in the kit too
            applicationId: (string.IsNullOrEmpty(data[i].ApplicationId)) ? ("gsa/" + data[i].Keyword + "_" + data[i].Index.ToString()) : data[i].ApplicationId,
            gwaSetCommandType: data[i].GwaSetType);

          progressEstimator.AppendCurrent(WorkPhase.CacheRead, 1);
        }

        var numRowsupdated = data.Count();
        if (numRowsupdated > 0)
        {
          this.loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, 
            "Read " + numRowsupdated + " GWA lines across " + keywords.Count() + " keywords into cache"));
        }

        progressEstimator.SetCurrentToTotal(WorkPhase.CacheUpdate); //Equalise the current and total in case the previous total estimate was wrong

        return true;
      }
      catch
      {
        return false;
      }
    }