Example #1
0
        private void DownloadInternal(IProgress <ProgressChangedEventArgs> progress)
        {
            Debug.Assert(Prefs != null);

            lock (DownloadSyncRoot)
            {
                if (!CheckLastDownloadTime())
                {
                    return;
                }

                Logger.Info("Downloading new project data from Stanford...");

                IWebOperation httpWebOperation = WebOperation.Create(Prefs.Get <string>(Preference.ProjectDownloadUrl));
                if (progress != null)
                {
                    httpWebOperation.ProgressChanged += (sender, e) =>
                    {
                        int    progressPercentage = Convert.ToInt32((e.Length / (double)e.TotalLength) * 100);
                        string message            = String.Format(CultureInfo.InvariantCulture, "Downloading {0} of {1} bytes...", e.Length, e.TotalLength);
                        progress.Report(new ProgressChangedEventArgs(progressPercentage, message));
                    };
                }
                httpWebOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                httpWebOperation.WebRequest.Proxy       = Prefs.GetWebProxy();
                httpWebOperation.Download(FilePath);

                LastDownloadTime = DateTime.Now;
            }
        }
Example #2
0
            public virtual TData Load()
            {
                if (Exists == false)
                {
                    throw new KeyNotFoundException("Trying to load Pref with key: " + Key + " even though it doesn't exist, ignoring");
                }

                return(Prefs.Get(Key, TryParse, Default));
            }
Example #3
0
        /// <summary>
        /// Handles the Client Status Returned by Log Parsing and then determines what values to feed the DetermineStatus routine.
        /// </summary>
        private void HandleReturnedStatus(SlotStatus returnedStatus, SlotModel slot)
        {
            var statusData = new LegacyClientStatusData
            {
                ClientName                = Settings.Name,
                SlotType                  = slot.UnitInfoModel.UnitInfoData.SlotType,
                UnitRetrievalTime         = slot.UnitInfoModel.UnitInfoData.UnitRetrievalTime,
                UtcOffsetIsZero           = Settings.UtcOffsetIsZero,
                UtcOffset                 = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now),
                ClientTimeOffset          = Settings.ClientTimeOffset,
                TimeOfLastUnitStart       = slot.TimeOfLastUnitStart,
                TimeOfLastFrameProgress   = slot.TimeOfLastFrameProgress,
                CurrentStatus             = slot.Status,
                ReturnedStatus            = returnedStatus,
                FrameTime                 = slot.UnitInfoModel.GetRawTime(Prefs.Get <PpdCalculationType>(Preference.PpdCalculation)),
                BenchmarkAverageFrameTime = GetBenchmarkAverageFrameTimeOrDefault(slot.UnitInfo),
                TimeOfLastFrame           = slot.UnitInfoModel.UnitInfoData.CurrentFrame == null
                                                  ? TimeSpan.Zero
                                                  : slot.UnitInfoModel.UnitInfoData.CurrentFrame.TimeOfFrame,
                UnitStartTimeStamp = slot.UnitInfoModel.UnitInfoData.UnitStartTimeStamp,
                AllowRunningAsync  = Prefs.Get <bool>(Preference.AllowRunningAsync)
            };

            SlotStatus computedStatus = LegacyClientStatus.GetSlotStatus(statusData, Logger);

            // If the returned status is EuePause and current status is not
            if (computedStatus.Equals(SlotStatus.EuePause) && statusData.CurrentStatus.Equals(SlotStatus.EuePause) == false)
            {
                if (Prefs.Get <bool>(Preference.EmailReportingEnabled) &&
                    Prefs.Get <bool>(Preference.ReportEuePause))
                {
                    SendEuePauseEmail(statusData.ClientName);
                }
            }

            // If the returned status is Hung and current status is not
            if (computedStatus.Equals(SlotStatus.Hung) && statusData.CurrentStatus.Equals(SlotStatus.Hung) == false)
            {
                if (Prefs.Get <bool>(Preference.EmailReportingEnabled) &&
                    Prefs.Get <bool>(Preference.ReportHung))
                {
                    SendHungEmail(statusData.ClientName);
                }
            }

            slot.Status = computedStatus;
        }
Example #4
0
        ///---------------------------------------------------------------------
        #region Behaviour
        private void InitDatas()
        {
            if (prateekUpdaterDir == null)
            {
                prateekUpdaterDir = Prefs.Get(GetType().Name + ".prateekUpdaterDir", "/Scripts");
            }

            if (prateekRunInTestMode == null)
            {
                prateekRunInTestMode = Prefs.Get(GetType().Name + ".prateekRunInTestMode", false);
            }

            if (scriptTemplateUpdater == null)
            {
                scriptTemplateUpdater = Tools.GetScriptTemplateUpdater(prateekUpdaterDir.Value);
                if (scriptTemplateUpdater != null)
                {
                    scriptTemplateUpdater.Init();
                }
            }

#if PRATEEK_ALLOW_INTERNAL_TOOLS
            if (prateekExportDir == null)
            {
                prateekExportDir = Prefs.Get(GetType().Name + ".prateekExportDir", string.Empty);
            }

            if (prateekSourceDir == null)
            {
                prateekSourceDir = Prefs.Get(GetType().Name + ".prateekSourceDir", string.Empty);
            }

            if (prateekSourceDir0 == null)
            {
                prateekSourceDir0 = Prefs.Get(GetType().Name + ".prateekSourceDir0", (List <string>)null);
            }

            if (prateekScriptGenerator == null)
            {
                prateekScriptGenerator = Tools.GetPrateekScriptGenerator();
                prateekScriptGenerator.Init();
            }
#endif //PRATEEK_ALLOW_INTERNAL_TOOLS
        }
Example #5
0
        /// <summary>
        /// Send Hung Status Email
        /// </summary>
        private void SendHungEmail(string name)
        {
            string messageBody = String.Format("HFM.NET detected that Client '{0}' has entered a Hung state.", name);

            try
            {
                NetworkOps.SendEmail(Prefs.Get <bool>(Preference.EmailReportingServerSecure),
                                     Prefs.Get <string>(Preference.EmailReportingFromAddress),
                                     Prefs.Get <string>(Preference.EmailReportingToAddress),
                                     "HFM.NET - Client Hung Error", messageBody,
                                     Prefs.Get <string>(Preference.EmailReportingServerAddress),
                                     Prefs.Get <int>(Preference.EmailReportingServerPort),
                                     Prefs.Get <string>(Preference.EmailReportingServerUsername),
                                     Prefs.Get <string>(Preference.EmailReportingServerPassword));
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "{0}", ex.Message);
            }
        }
        private void WriteToLocalFahLogCache(StringBuilder logText, bool createNew)
        {
            const int sleep      = 100;
            const int timeout    = 60 * 1000;
            string    fahLogPath = Path.Combine(Prefs.Get <string>(Preference.CacheDirectory), Settings.CachedFahLogFileName());

            try
            {
                using (var stream = FileSystem.TryFileOpen(fahLogPath, createNew ? FileMode.Create : FileMode.Append, FileAccess.Write, FileShare.Read, sleep, timeout))
                    using (var writer = new StreamWriter(stream))
                    {
                        foreach (var chunk in logText.GetChunks())
                        {
                            writer.Write(chunk);
                        }
                    }
            }
            catch (Exception ex)
            {
                Logger.WarnFormat(ex, "Failed to write to {0}", fahLogPath);
            }
        }
Example #7
0
        ///---------------------------------------------------------------------
        private static bool Foldout(bool isLayout, Rect rect, GUIContent content, string key, bool toggleOnLabelClick = true)
        {
            var foldoutActive = Prefs.Get(key, false);

            EditorGUI.BeginChangeCheck();
            var tempActive = foldoutActive.Value;

            if (!isLayout)
            {
                tempActive = EditorGUI.Foldout(rect, foldoutActive.Value, content, toggleOnLabelClick);
            }
            else
            {
                tempActive = EditorGUILayout.Foldout(foldoutActive.Value, content, toggleOnLabelClick);
            }

            if (EditorGUI.EndChangeCheck())
            {
                foldoutActive.Value = tempActive;
            }

            return(tempActive);
        }
Example #8
0
        /// <summary>
        /// Process the cached log files that exist on this machine
        /// </summary>
        private void Process()
        {
            var sw = Stopwatch.StartNew();

            // Set successful Last Retrieval Time
            LastRetrievalTime = DateTime.Now;
            // Re-Init Slot Level Members Before Processing
            _slotModel.Initialize();

            #region Setup Aggregator

            var dataAggregator = new LegacyDataAggregator {
                Logger = Logger
            };
            dataAggregator.ClientName = Settings.Name;
            string queueFilePath       = Path.Combine(Prefs.CacheDirectory, Settings.CachedQueueFileName());
            string fahLogFilePath      = Path.Combine(Prefs.CacheDirectory, Settings.CachedFahLogFileName());
            string unitInfoLogFilePath = Path.Combine(Prefs.CacheDirectory, Settings.CachedUnitInfoFileName());

            #endregion

            #region Run the Aggregator

            var queue    = ReadQueueFile(queueFilePath);
            var fahLog   = FahLog.Read(File.ReadLines(fahLogFilePath), FahLogType.Legacy);
            var unitInfo = ReadUnitInfoFile(unitInfoLogFilePath);

            var result = dataAggregator.AggregateData(fahLog, queue, unitInfo);
            // Issue 126 - Use the Folding ID, Team, User ID, and Machine ID from the FAHlog data.
            // Use the Current Queue Entry as a backup data source.
            PopulateRunLevelData(result, _slotModel);
            if (result.Queue != null)
            {
                PopulateRunLevelData(result.Queue.Current, _slotModel);
            }

            _slotModel.Queue           = result.Queue;
            _slotModel.CurrentLogLines = result.CurrentLogLines;
            _slotModel.UnitLogLines    = result.UnitInfos.OrderBy(x => x.Key).Select(x => x.Value != null ? x.Value.LogLines : null).ToArray();

            #endregion

            var parsedUnits = new UnitInfoModel[result.UnitInfos.Count];
            for (int i = 0; i < result.UnitInfos.Count; i++)
            {
                if (result.UnitInfos[i] != null)
                {
                    parsedUnits[i] = BuildUnitInfoLogic(result.UnitInfos[i], true);
                }
            }

            // *** THIS HAS TO BE DONE BEFORE UPDATING SlotModel.UnitInfoLogic ***
            UpdateBenchmarkData(_slotModel.UnitInfoModel, parsedUnits, result.CurrentUnitIndex);

            // Update the UnitInfoLogic if we have a Status
            if (result.Status != SlotStatus.Unknown)
            {
                _slotModel.UnitInfoModel = parsedUnits[result.CurrentUnitIndex];
            }

            HandleReturnedStatus(result.Status, _slotModel);

            _slotModel.UnitInfoModel.ShowPPDTrace(Logger, _slotModel.Name, _slotModel.Status,
                                                  Prefs.Get <PpdCalculationType>(Preference.PpdCalculation),
                                                  Prefs.Get <BonusCalculationType>(Preference.BonusCalculation));

            string statusMessage = String.Format(CultureInfo.CurrentCulture, "Client Status: {0}", _slotModel.Status);
            Logger.InfoFormat(Constants.ClientNameFormat, _slotModel.Name, statusMessage);

            string message = String.Format(CultureInfo.CurrentCulture, "Retrieval finished: {0}", sw.GetExecTime());
            Logger.InfoFormat(Constants.ClientNameFormat, Settings.Name, message);
        }
        private void Process()
        {
            var sw = Stopwatch.StartNew();

            // Set successful Last Retrieval Time
            LastRetrievalTime = DateTime.Now;

            var options = _messages.Options;
            var info    = _messages.Info;

            _slotsLock.EnterReadLock();
            try
            {
                foreach (var slotModel in _slots)
                {
                    // Re-Init Slot Level Members Before Processing
                    slotModel.Initialize();

                    // Run the Aggregator
                    var dataAggregator = new FahClientDataAggregator {
                        Logger = Logger
                    };
                    dataAggregator.ClientName = slotModel.Name;
                    DataAggregatorResult result = dataAggregator.AggregateData(_fahLog.ClientRuns.LastOrDefault(),
                                                                               _messages.UnitCollection,
                                                                               info,
                                                                               options,
                                                                               slotModel.SlotOptions,
                                                                               slotModel.UnitInfo,
                                                                               slotModel.SlotId);
                    PopulateRunLevelData(result, info, slotModel);

                    slotModel.Queue           = result.Queue;
                    slotModel.CurrentLogLines = result.CurrentLogLines;
                    //slotModel.UnitLogLines = result.UnitLogLines;

                    var parsedUnits = new Dictionary <int, UnitInfoModel>(result.UnitInfos.Count);
                    foreach (int key in result.UnitInfos.Keys)
                    {
                        if (result.UnitInfos[key] != null)
                        {
                            parsedUnits[key] = BuildUnitInfoLogic(slotModel, result.UnitInfos[key]);
                        }
                    }

                    // *** THIS HAS TO BE DONE BEFORE UPDATING SlotModel.UnitInfoLogic ***
                    UpdateBenchmarkData(slotModel.UnitInfoModel, parsedUnits.Values, result.CurrentUnitIndex);

                    // Update the UnitInfoLogic if we have a current unit index
                    if (result.CurrentUnitIndex != -1 && parsedUnits.ContainsKey(result.CurrentUnitIndex))
                    {
                        slotModel.UnitInfoModel = parsedUnits[result.CurrentUnitIndex];
                    }

                    SetSlotStatus(slotModel);

                    slotModel.UnitInfoModel.ShowProductionTrace(Logger, slotModel.Name, slotModel.Status,
                                                                Prefs.Get <PpdCalculationType>(Preference.PpdCalculation),
                                                                Prefs.Get <BonusCalculationType>(Preference.BonusCalculation));

                    string statusMessage = String.Format(CultureInfo.CurrentCulture, "Slot Status: {0}", slotModel.Status);
                    Logger.InfoFormat(Constants.ClientNameFormat, slotModel.Name, statusMessage);
                }
            }
            finally
            {
                _slotsLock.ExitReadLock();
            }

            string message = String.Format(CultureInfo.CurrentCulture, "Retrieval finished: {0}", sw.GetExecTime());

            Logger.InfoFormat(Constants.ClientNameFormat, Settings.Name, message);
        }