// GET api/records/5
        public IHttpActionResult Get(string str)
        {
            if (String.IsNullOrEmpty(str))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            ConverterUrl converter = new ConverterUrl(10);
            long         recordId  = converter.Decode(str);

            HistoryRecord historyRecord = historyRecordService.GetHistoryRecord(recordId);

            if (historyRecord == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            historyRecord.HitCount++;
            historyRecordService.UpdateHistoryRecord(historyRecord);
            historyRecordService.SaveHistoryRecord();

            //var response = Request.CreateResponse(HttpStatusCode.Moved);
            //response.Headers.Location = new Uri(historyRecord.UrlLong);

            return(Redirect(historyRecord.UrlLong));
        }
示例#2
0
        public async Task SaveHistoryRecordAsync(HistoryRecord historyRecord,
                                                 CancellationToken cancellationToken)
        {
            var historyRecordEntity = _mapper.Map <HistoryRecordEntity>(historyRecord);

            await HistoryRecordsCollection.InsertOneAsync(historyRecordEntity, null, cancellationToken);
        }
示例#3
0
        public HistoryRecord SaveHistory(HistoryRecord record)
        {
            var result = Records.Add(record);

            this.SaveChanges();
            return(result.Entity);
        }
示例#4
0
 private void OnMonitorUpdateServerInfo(object sender, PerformanceRecordEventArgs e)
 {
     if (this.IsHandleCreated && !this.IsDisposed)
     {
         this.BeginInvoke((MethodInvoker) delegate()
         {
             if (!chkShowPerformanceHistory.Checked)
             {
                 try
                 {
                     var record        = e.Data;
                     var now           = DateTime.Now;
                     var historyRecord = new HistoryRecord(record)
                     {
                         Date = now.ToString(), Value16 = now
                     };
                     _currentRecords.Add(historyRecord);
                     AddPerformanceHistoryRecord(record, now, now, now.AddMinutes(1));
                     SetPerformanceInfo(record);
                 }
                 catch (Exception ex)
                 {
                     _engine.DisablePerformance();
                     Monitor.Instance.ShowMessage(ex.Message);
                 }
             }
         });
     }
 }
        public async Task <ActionResult> GetWeather(string city = "Kiev", int qtyDays = 7)
        {
            try
            {
                var result = await weatherService.GetWeatherAsync(city, qtyDays);

                var record = new HistoryRecord(result);
                await unitOfWork.History.InsertAsync(record);

                await unitOfWork.SaveChangesAsync();

                return(View(result));
            }
            catch (ArgumentOutOfRangeException)
            {
                return(HttpNotFound("Quantity days must be between 1 and 16"));
            }
            catch (ArgumentNullException)
            {
                return(HttpNotFound("City can't be whitespaces or empty"));
            }
            catch (ArgumentException)
            {
                return(HttpNotFound("City can't be null"));
            }
            catch (AggregateException)
            {
                return(HttpNotFound("Error occured"));
            }
            catch (HttpRequestException)
            {
                return(HttpNotFound("Bad city name"));
            }
        }
        public async Task StartUpdateProcessAsync(CancellationToken cancellationToken)
        {
            var tvShowsToUpdateIds = await _tvShowUpdateService.GetOutdatedTvShowInfosIdsAsync(cancellationToken);

            if (tvShowsToUpdateIds.IsNullOrEmpty())
            {
                return;
            }

            _logger.LogInformation($"{tvShowsToUpdateIds.Count} TV shows to update found. Update process started.");

            var historyRecord = new HistoryRecord(_dateTimeService.UtcNow);

            var policies = _policyFactory.CreateUpdateTaskPolicies(() => _workloadService.IncreaseDelayTime());

            foreach (var tvShowToUpdateId in tvShowsToUpdateIds)
            {
                await Task.Delay(_workloadService.UpdateTvShowInfoTaskExecutionDelay, cancellationToken);

                await policies.ExecuteAsync(() =>
                                            _tvShowUpdateService.CreateOrUpdateTvShowAsync(tvShowToUpdateId, cancellationToken));
            }

            await _integrationDal.SaveHistoryRecordAsync(historyRecord, cancellationToken);
        }
        /*--------------------------------------------------------------------------------------------*/
        private void CullHistory()
        {
            HistoryRecord current            = vHistory[vHistory.Count - 1];
            float         currDistFromCenter = (current.WorldPosition - WorldPosition).magnitude;

            if (currDistFromCenter > InteractionSettings.IdleDistanceThreshold)
            {
                vHistory.Clear();
                return;
            }

            float maxMs      = InteractionSettings.IdleMilliseconds;
            int   staleIndex = -1;

            for (int i = vHistory.Count - 2; i >= 0; i--)
            {
                HistoryRecord record = vHistory[i];

                if ((current.Time - record.Time).TotalMilliseconds > maxMs)
                {
                    staleIndex = i;
                    break;
                }

                //HistoryRecord recordPrev = vHistory[i+1];
                //Debug.DrawLine(recordPrev.WorldPosition, record.WorldPosition, Color.yellow);
            }

            if (staleIndex < 0)
            {
                vHistory.RemoveRange(0, staleIndex + 1);
            }
        }
        private void _Initialize()
        {
            try
            {
                Records                  = new ObservableCollection <HistoryRecord>();
                RecordsViewSource        = new CollectionViewSource();
                RecordsViewSource.Source = Records;


                HistoryRecord hr = new HistoryRecord();
                hr.Id           = "123";
                hr.ItemFullPath = "c:\\file.txt";
                hr.Count        = 1;
                hr.DeviceName   = "user1";
                hr.ItemSize     = 100;
                Records.Add(hr);

                hr              = new HistoryRecord();
                hr.Id           = "123";
                hr.ItemFullPath = "c:\\HAHA.txt";
                hr.Count        = 2;
                hr.DeviceName   = "user1";
                hr.ItemSize     = 100;
                Records.Add(hr);
            }
            catch (Exception ex)
            {
            }
        }
        public void NavigateForward()
        {
            HistoryRecord historyRecord = this.GetNextHistoryRecord();
            Frame         frame         = historyRecord.ParrentFrame;

            this.NavigateForward(frame);
        }
示例#10
0
        /// <summary>
        /// draw prescription that includes medicines were written to patient
        /// with these doses and these alternatives
        /// </summary>
        /// <returns>prescription image</returns>
        public Bitmap Draw(HistoryRecord historyRecord, string[] medicines,
                           List <List <string> > medicinesAlternatives, string [] doses)
        {
            // decide page structure to know the sutable legth of it
            string pageStructure = "\n\n\n\nName \n Patient name \n\n Drugs " + "\n\n"
                                   + " Doctor \n Doctor name \n\n\n Address \n medicalPlaceAddress\n\n";

            for (int i = 0; i < medicinesAlternatives.Count; i++)
            {
                for (int c = 0; c < medicinesAlternatives[i].Count; c++)
                {
                    pageStructure += "\n";
                }
                pageStructure += "\n";
            }

            pageWidth  = 500;
            pageHeight = (int)graphics.MeasureString(pageStructure, bold).Height + logoHeight;

            bitmap   = new Bitmap(bitmap, new Size(pageWidth, pageHeight));
            graphics = Graphics.FromImage(bitmap);
            graphics.Clear(Color.White); // white background

            // Drawing
            DrawPrescriptionHeader(historyRecord.MedicalPlace.Name, historyRecord.MedicalPlace.Photo);
            DrawPrescriptionBody(historyRecord.Citizen.Name, historyRecord.Specialist.Name,
                                 historyRecord.Date, medicines, medicinesAlternatives, doses);
            DrawPrescriptionFooter(historyRecord.MedicalPlace.Address, historyRecord.MedicalPlace.Phone);

            graphics.Flush();
            graphics.Dispose();

            return(bitmap);
        }
        /// <summary>
        /// Navigates backward frame according to the history
        /// </summary>
        public void NavigateBack()
        {
            HistoryRecord historyRecord = this.GetPreviousHistoryRecord();
            Frame         frame         = historyRecord.ParrentFrame;

            this.NavigateBack(frame);
        }
        // POST api/records
        public HistoryRecordViewModel Post([FromBody] HistoryRecordViewModel viewModelHistoryRecord)
        {
            if (ModelState.IsValid)
            {
                HistoryRecord historyRecord = Mapper.Map <HistoryRecordViewModel, HistoryRecord>(viewModelHistoryRecord);
                try
                {
                    historyRecord.CreateDate = DateTime.Now; //todo настроить в EF автогенерацию
                    historyRecordService.CreateHistoryRecord(historyRecord);
                    historyRecordService.SaveHistoryRecord();
                }
                catch (Exception ex)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }



                ConverterUrl converter = new ConverterUrl(10); //todo вынести в настройки 10
                string       hash      = converter.Encode(historyRecord.Id);

                //historyRecord.UrlShort = $"{Request.RequestUri.Authority}api/values/{hash}"; //to do Или проще так?
                historyRecord.UrlShort = $"{Request.RequestUri.Authority}/Home/Record/{hash}";
                historyRecordService.UpdateHistoryRecord(historyRecord);
                historyRecordService.SaveHistoryRecord();
                viewModelHistoryRecord = Mapper.Map <HistoryRecord, HistoryRecordViewModel>(historyRecord);
            }
            return(viewModelHistoryRecord);
        }
示例#13
0
        private async Task <string> GetVmHistoryAsync(int vmid)
        {
            var history = new VmHistory();

            history.HistoryRecords = new List <HistoryRecord>();

            var records = await _context.History
                          .Where(vm => vm.VirtualMachineId == vmid)
                          .Include(v => v.VirtualMachine)
                          .ThenInclude(h => h.Hypervisor)
                          .ToListAsync();

            if (records == null || records.Count == 0)
            {
                return(null);
            }

            foreach (var rec in records)
            {
                history.Hypervisor = rec.VirtualMachine.Hypervisor.Name;

                var h = new HistoryRecord();
                h.BackupDateStart  = rec.BackupDateStart;
                h.BackupDateEnd    = rec.BackupDateEnd;
                h.Success          = rec.Success;
                h.LastKnownStatus  = rec.LastKnownStatus;
                h.ExportedToFolder = rec.ExportedToFolder;
                h.ArchivedToFile   = rec.ArchivedToFile;

                history.HistoryRecords.Add(h);
            }

            return(JsonConvert.SerializeObject(history));
        }
示例#14
0
        protected override void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (_currentRecord != null)
                    {
                        LogJobEnd();
                    }

                    _cmdSelectFolder = null;
                    _cmdSaveList     = null;
                    _cmdCopyFiles    = null;
                    _cmdLaunchEditor = null;
                    _currentRecord   = null;

                    if (watcher != null)
                    {
                        watcher.Dispose();
                    }
                    if (fileHelper != null)
                    {
                        fileHelper.Dispose();
                    }
                }

                _changedFiles  = null;
                _customFilters = null;
                _scanModes     = null;
                _subFolders    = null;

                base.Dispose(disposing);
            }
        }
        // Forward
        /// <summary>
        /// Navigates forward frame according to the history
        /// </summary>
        public void NavigateForward(Frame frame)
        {
            HistoryRecord historyRecord = this.GoNextHistoryRecord();
            Type          targetPage    = PagesManager.GetTypeOfPageByString(historyRecord.PageFullName);

            frame.Navigate(targetPage); // TODO NO DAFAULT NAVIGATION!!!
            this.RaizeOnNavigated(targetPage, frame);
        }                               // Main navigate forward method
示例#16
0
        public async Task <HistoryRecord> SaveHistoryAsync(HistoryRecord record)
        {
            var result = await Records.AddAsync(record);

            await this.SaveChangesAsync();

            return(result.Entity);
        }
示例#17
0
        public void AjaxReturn2(ASPdb.Ajax.AjaxResponse ajaxResponse)
        {
            if (UI.Errors.ExceptionHandler.Check(ajaxResponse))
            {
                return;
            }
            jF(".EmptyPanel").hide();
            jF(".Loading2").hide();
            jF(".CompareTbl").show();
            jF(".FieldView").hide();
            this.SubModel = ajaxResponse.ReturnObj.As <HistoryRecord>();

            var compareTbl = jF(".CompareTbl");

            compareTbl.find(".TrRow").detach();
            for (int i = 0; i < this.SubModel.Fields_3ValArr.Length; i++)
            {
                var item = this.SubModel.Fields_3ValArr[i];

                string v1 = item.v1;
                string v2 = item.v2;
                string v3 = item.v3;
                if (v1 == null)
                {
                    v1 = "&nbsp;";
                }
                if (v2 == null)
                {
                    v2 = "&nbsp;";
                }
                if (v3 == null)
                {
                    v3 = "&nbsp;";
                }

                string matchTDsClass = "";
                if (!item.match)
                {
                    matchTDsClass = "Hightlight";
                }

                string altClass = "TrRow1";
                if (i % 2 == 1)
                {
                    altClass = "TrRow2";
                }
                compareTbl.append(st.New(@"
                    <tr class='TrRow {0}' Index='{1}'>
                        <td><div>{2}</div></td>
                        <td class='{6}'><div>{3}</div></td>
                        <td class='{6}'><div>{4}</div></td>
                        <td><div>{5}</div></td>
                    </tr>").Format7(altClass, i, item.ColumnName_OrigCasing, v1, v2, v3, matchTDsClass).TheString);
            }
            var thisObj = this;

            eval(@" compareTbl.find('.TrRow').click(function(){ thisObj.FieldItem_Click( $(this).attr('Index') ); }); ");
        }
示例#18
0
        public SqlDateTime ToDateTimeStamp(DateTime deviceDateTime)
        {
            var dateTimeStamp = new HistoryRecord()
            {
                HistoryPointNumber = this.HistoryPointNumber, HistorySegment = this.HistorySegment, Index = this.Index, Value = this.Value
            }.ToDateTimeStamp(deviceDateTime);

            return(dateTimeStamp.HasValue ? dateTimeStamp.Value : SqlDateTime.Null);
        }
示例#19
0
        public SqlSingle ToFloat()
        {
            var floatValue = new HistoryRecord()
            {
                HistoryPointNumber = this.HistoryPointNumber, HistorySegment = this.HistorySegment, Index = this.Index, Value = this.Value
            }.ToNullableFloat();

            return(floatValue.HasValue ? floatValue.Value : SqlSingle.Null);
        }
示例#20
0
        public static HistoryModel GetHistoryFromModel <T>(T from, T to, string Autor) where T : Base
        {
            if (from == null)
            {
                from = (T)Activator.CreateInstance(to.GetType());
            }

            if (from.GetType() != to.GetType())
            {
                throw new ArgumentException();
            }

            string TableName = to.GetType().Name;
            string RecordID  = to.ID;

            PropertyInfo[] properties = to.GetType().GetProperties();

            HistoryRecord record = new HistoryRecord();

            record.Table    = TableName;
            record.RecordID = RecordID;
            record.Autor    = Autor;

            List <HistoryDetail> details = new List <HistoryDetail>();

            foreach (PropertyInfo info in properties)
            {
                HistoryFieldAttribute attr = info.GetCustomAttribute <HistoryFieldAttribute>();
                if (attr == null)
                {
                    continue;
                }

                var fromValue = info.GetValue(from);
                var toValue   = info.GetValue(to);

                if (fromValue != toValue)
                {
                    HistoryDetail detail = new HistoryDetail();
                    detail.Field         = info.Name;
                    detail.PrevValue     = fromValue == null ? "" : fromValue.ToString();
                    detail.NewValue      = toValue == null ? "" : toValue.ToString();
                    detail.HistoryRecord = record.ID;

                    details.Add(detail);
                }
            }

            HistoryModel returnData = new HistoryModel();

            returnData.Details = details;
            returnData.Records = new List <HistoryRecord> {
                record
            };

            return(returnData);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private void AddToHistory(Vector3 pWorldPosition)
        {
            var current = new HistoryRecord {
                Time          = DateTime.UtcNow,
                WorldPosition = pWorldPosition
            };

            vHistory.Add(current);
        }
示例#22
0
 /// <summary>
 /// Добавление записи в историю undo-операций.
 /// </summary>
 /// <param name="record"></param>
 public void AddUndo(HistoryRecord record)
 {
     if (CurrentHistoryLevel < _records.Count)
     {
         _records.RemoveRange(CurrentHistoryLevel, _records.Count - CurrentHistoryLevel);
     }
     _records.Add(record);
     CurrentHistoryLevel++;
 }
示例#23
0
        public void RemoveHistoryRecord(HistoryRecord record)
        {
            if (record == null)
            {
                return;
            }

            _context.History.Remove(record);
            _context.SaveChanges();
        }
        /// <summary>
        /// Navigates frame to type without adding to history
        /// </summary>
        public void NavigateFrameSilentByHistoryRecord(HistoryRecord historyRecord)
        {
            Type pageType = PagesManager.GetTypeOfPageByString(historyRecord.PageFullName);

            Frame parrentFrame = historyRecord.ParrentFrame;

            this.SetHistoryCurrentNode(historyRecord);

            this.NavigateFrameSilent(parrentFrame, pageType);
        }
示例#25
0
 internal static HistoryViewModel ToViewModel(this HistoryRecord historyRecord)
 {
     return(new HistoryViewModel
     {
         Id = historyRecord.Id,
         Operation = historyRecord.Operation,
         OldValue = historyRecord.OldValue,
         NewValue = historyRecord.NewValue
     });
 }
 public Task <int> SaveRecordAsync(HistoryRecord record)
 {
     if (record.Id != 0)
     {
         return(_database.UpdateAsync(record));
     }
     else
     {
         return(_database.InsertAsync(record));
     }
 }
        /// <summary>
        /// Gets next history item
        /// </summary>
        /// <returns></returns>
        public HistoryRecord GetNextHistoryRecord()
        {
            HistoryRecord result = null;

            if (this.CanNavigateForward())
            {
                result = this.History.CurrentNode.Next.Value;
            }

            return(result);
        }
        /// <summary>
        /// Gets previous history item
        /// </summary>
        /// <returns>the value of the previous record</returns>
        public HistoryRecord GetPreviousHistoryRecord()
        {
            HistoryRecord result = null;

            if (this.CanNavigateBack())
            {
                result = this.History.CurrentNode.Previous.Value;
            }

            return(result);
        }
示例#29
0
        private void LogJobStart()
        {
            _currentRecord = new HistoryRecord
            {
                Directory = WatchedFolder,
                Start     = DateTime.Now,
            };
            Globals.History.Add(_currentRecord);

            SetTemporaryStatusMessage("New job started.");
        }
示例#30
0
        public void Add(IEnumerable <string> userIds, T message)
        {
            var record = new HistoryRecord <T> {
                UserIds = userIds, Record = message
            };

            lock (records)
            {
                startIndex          = (startIndex + 1) % records.Length;
                records[startIndex] = record;
            }
        }
示例#31
0
        private void LogJobStart()
        {
            _currentRecord = new HistoryRecord
            {
                Directory = WatchedFolder,
                Start = DateTime.Now,
            };
            Globals.History.Add(_currentRecord);

            SetTemporaryStatusMessage("New job started.");
        }
示例#32
0
        protected void GetHistoryDetails()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = DateTime.UtcNow
                };

                this.Repository.CreateWorker(workerRecord, null);

                HistoryRecord historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    Exception = new ExceptionXElement(new Exception()).ToString(),
                    FinishedOn = DateTime.UtcNow,
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    QueuedOn = DateTime.UtcNow,
                    StartedOn = DateTime.UtcNow,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                HistoryDetailsRecord historyDetailsRecord = this.Repository.GetHistoryDetails(historyRecord.Id.Value, null);
                Assert.IsNotNull(historyDetailsRecord);
                Assert.AreEqual(historyDetailsRecord.Id, historyRecord.Id);
                Assert.IsFalse(string.IsNullOrEmpty(historyDetailsRecord.Data));
                Assert.IsFalse(string.IsNullOrEmpty(historyDetailsRecord.Exception));
                Assert.IsFalse(string.IsNullOrEmpty(historyDetailsRecord.WorkerMachineAddress) && string.IsNullOrEmpty(historyDetailsRecord.WorkerMachineName));
                Assert.IsFalse(string.IsNullOrEmpty(historyDetailsRecord.WorkerName));
            }
        }
示例#33
0
        /// <summary>
        /// Create history tests.
        /// </summary>
        protected void CreateHistory()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = DateTime.UtcNow
                };

                this.Repository.CreateWorker(workerRecord, null);

                WorkingRecord workingRecord = new WorkingRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JsonConvert.SerializeObject(job),
                    JobName = job.Name,
                    JobType = job.GetType().FullName + ", " + job.GetType().Assembly.GetName().Name,
                    QueueName = "*",
                    QueuedOn = DateTime.UtcNow,
                    Signal = WorkingSignal.Cancel,
                    StartedOn = DateTime.UtcNow,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateWorking(workingRecord, null);

                HistoryRecord historyRecord = new HistoryRecord()
                {
                    ApplicationName = workingRecord.ApplicationName,
                    Data = workingRecord.Data,
                    FinishedOn = DateTime.UtcNow,
                    JobName = workingRecord.JobName,
                    JobType = workingRecord.JobType,
                    QueuedOn = workingRecord.QueuedOn,
                    QueueName = workingRecord.QueueName,
                    StartedOn = workingRecord.StartedOn,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = workingRecord.TryNumber,
                    WorkerId = workingRecord.WorkerId
                };

                this.Repository.CreateHistory(historyRecord, null);
                Assert.IsNotNull(historyRecord.Id);
            }
        }
示例#34
0
        /// <summary>
        /// Get statistics tests.
        /// </summary>
        protected void GetStatistics()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };
                string jobData = JobSerializer.Serialize(job);
                string typeName = JobSerializer.GetTypeName(job.GetType());
                DateTime date = new DateTime(2011, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                DateTime now = DateTime.UtcNow.FloorWithSeconds();
                HistoryRecord historyRecord;

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = DateTime.UtcNow
                };

                this.Repository.CreateWorker(workerRecord, null);

                StatisticsRecord stats = this.Repository.GetStatistics(workerRecord.ApplicationName, date.AddDays(-1), date.AddDays(-14), date, null);
                Assert.IsNotNull(stats);

                /*
                 * Dequeued per hour by day.
                 */

                for (int i = 0; i < 14; i++)
                {
                    for (int j = 0; j < 24; j++)
                    {
                        for (int k = 0; k < 10; k++)
                        {
                            DateTime finished = date.AddDays(i).AddHours(j);

                            historyRecord = new HistoryRecord()
                            {
                                ApplicationName = workerRecord.ApplicationName,
                                Data = jobData,
                                FinishedOn = finished,
                                JobName = job.Name,
                                JobType = typeName,
                                QueuedOn = finished.AddSeconds(-1),
                                QueueName = "*",
                                StartedOn = finished.AddSeconds(-11),
                                Status = HistoryStatus.Succeeded,
                                TryNumber = 1,
                                WorkerId = workerRecord.Id.Value
                            };

                            this.Repository.CreateHistory(historyRecord, null);
                        }
                    }
                }

                stats = this.Repository.GetStatistics(workerRecord.ApplicationName, date.AddDays(13), date, date.AddDays(14), null);
                Assert.AreEqual(14, stats.JobsPerHourByDay.Count);

                for (int i = 0; i < stats.JobsPerHourByDay.Count; i++)
                {
                    Assert.AreEqual(date.AddDays(i), stats.JobsPerHourByDay[i].Date);
                    Assert.AreEqual(10, stats.JobsPerHourByDay[i].JobsPerHour);
                }

                /*
                 * Dequeued per hour by day - multiple queues.
                 */

                this.Repository.DeleteAll(BlueCollarSection.Section.ApplicationName, null);

                workerRecord.Id = null;
                this.Repository.CreateWorker(workerRecord, null);

                historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = jobData,
                    FinishedOn = now.AddHours(-1),
                    JobName = job.Name,
                    JobType = typeName,
                    QueuedOn = now.AddHours(-1),
                    QueueName = "*",
                    StartedOn = now.AddHours(-1),
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = jobData,
                    FinishedOn = now.AddHours(-1),
                    JobName = job.Name,
                    JobType = typeName,
                    QueuedOn = now.AddHours(-1),
                    QueueName = "*",
                    StartedOn = now.AddHours(-1),
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = jobData,
                    FinishedOn = now.AddHours(-1),
                    JobName = job.Name,
                    JobType = typeName,
                    QueuedOn = now.AddHours(-1),
                    QueueName = "test",
                    StartedOn = now.AddHours(-1),
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = jobData,
                    FinishedOn = now.AddHours(-1),
                    JobName = job.Name,
                    JobType = typeName,
                    QueuedOn = now.AddHours(-1),
                    QueueName = "test",
                    StartedOn = now.AddHours(-1),
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                stats = this.Repository.GetStatistics(workerRecord.ApplicationName, now.AddDays(-1), now.AddDays(-14), now, null);
                Assert.AreEqual(2, stats.JobsPerHourByDay.Count);
                Assert.AreEqual("*", stats.JobsPerHourByDay[0].QueueName);
                Assert.AreEqual(2L, stats.JobsPerHourByDay[0].JobsPerHour);
                Assert.AreEqual("test", stats.JobsPerHourByDay[1].QueueName);
                Assert.AreEqual(2L, stats.JobsPerHourByDay[1].JobsPerHour);

                /*
                 * History status counts.
                 */

                this.Repository.DeleteAll(BlueCollarSection.Section.ApplicationName, null);

                Func<int, DateTime> getDate = (int i) =>
                {
                    if (i % 3 == 0)
                    {
                        return now.AddDays(-30);
                    }
                    else if (i % 3 == 1)
                    {
                        return now.AddDays(-10);
                    }
                    else if (i % 3 == 2)
                    {
                        return now.AddHours(-13);
                    }
                    else
                    {
                        throw new InvalidOperationException("Loop count must be a multiple of 3.");
                    }
                };

                Func<int, HistoryStatus> getStatus = (int i) =>
                {
                    if (i % 5 == 0)
                    {
                        return HistoryStatus.Succeeded;
                    }
                    else if (i % 5 == 1)
                    {
                        return HistoryStatus.Failed;
                    }
                    else if (i % 5 == 2)
                    {
                        return HistoryStatus.Canceled;
                    }
                    else if (i % 5 == 3)
                    {
                        return HistoryStatus.TimedOut;
                    }
                    else if (i % 5 == 4)
                    {
                        return HistoryStatus.Interrupted;
                    }
                    else
                    {
                        throw new InvalidOperationException("Loop count must be a multiple of 5.");
                    }
                };

                for (int i = 0; i < 150; i++)
                {
                    DateTime indexDate = getDate(i);

                    historyRecord = new HistoryRecord()
                    {
                        ApplicationName = workerRecord.ApplicationName,
                        Data = jobData,
                        FinishedOn = indexDate,
                        JobName = job.Name,
                        JobType = typeName,
                        QueuedOn = date.AddSeconds(-2),
                        QueueName = "*",
                        StartedOn = date.AddSeconds(-1),
                        Status = getStatus(i),
                        TryNumber = 1,
                        WorkerId = workerRecord.Id.Value
                    };

                    this.Repository.CreateHistory(historyRecord, null);
                }

                stats = this.Repository.GetStatistics(workerRecord.ApplicationName, now.AddHours(-24), now.AddDays(-14), now, null);
                Assert.IsNotNull(stats.HistoryStatusRecent);
                Assert.AreEqual(10, stats.HistoryStatusRecent.SucceededCount);
                Assert.AreEqual(10, stats.HistoryStatusRecent.FailedCount);
                Assert.AreEqual(10, stats.HistoryStatusRecent.CanceledCount);
                Assert.AreEqual(10, stats.HistoryStatusRecent.TimedOutCount);
                Assert.AreEqual(10, stats.HistoryStatusRecent.InterruptedCount);
                Assert.AreEqual(50, stats.HistoryStatusRecent.TotalCount);

                Assert.IsNotNull(stats.HistoryStatusDistant);
                Assert.AreEqual(20, stats.HistoryStatusDistant.SucceededCount);
                Assert.AreEqual(20, stats.HistoryStatusDistant.FailedCount);
                Assert.AreEqual(20, stats.HistoryStatusDistant.CanceledCount);
                Assert.AreEqual(20, stats.HistoryStatusDistant.TimedOutCount);
                Assert.AreEqual(20, stats.HistoryStatusDistant.InterruptedCount);
                Assert.AreEqual(100, stats.HistoryStatusDistant.TotalCount);

                stats = this.Repository.GetStatistics(workerRecord.ApplicationName, now.AddDays(-31), now.AddDays(-60), now.AddDays(-30), null);
                Assert.AreEqual(10, stats.HistoryStatusDistant.SucceededCount);
                Assert.AreEqual(10, stats.HistoryStatusDistant.FailedCount);
                Assert.AreEqual(10, stats.HistoryStatusDistant.CanceledCount);
                Assert.AreEqual(10, stats.HistoryStatusDistant.TimedOutCount);
                Assert.AreEqual(10, stats.HistoryStatusDistant.InterruptedCount);
                Assert.AreEqual(50, stats.HistoryStatusDistant.TotalCount);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private void AddToHistory(Vector3 pWorldPosition)
        {
            var current = new HistoryRecord {
                Time = DateTime.UtcNow,
                WorldPosition = pWorldPosition
            };

            vHistory.Add(current);
        }
示例#36
0
        /// <summary>
        /// Delete all tests.
        /// </summary>
        protected void DeleteAll()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = DateTime.UtcNow
                };

                this.Repository.CreateWorker(workerRecord, null);

                QueueRecord queueRecord = new QueueRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JsonConvert.SerializeObject(job),
                    JobName = job.Name,
                    JobType = job.GetType().FullName + ", " + job.GetType().Assembly.GetName().Name,
                    QueuedOn = DateTime.UtcNow,
                    QueueName = "*",
                    TryNumber = 1
                };

                this.Repository.CreateQueued(queueRecord, null);

                ScheduleRecord scheduleRecord = new ScheduleRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Name = "Test",
                    RepeatType = ScheduleRepeatType.Days,
                    RepeatValue = 1,
                    StartOn = DateTime.UtcNow
                };

                this.Repository.CreateSchedule(scheduleRecord, null);

                ScheduledJobRecord scheduledJobRecord = new ScheduledJobRecord()
                {
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    ScheduleId = scheduleRecord.Id.Value
                };

                this.Repository.CreateScheduledJob(scheduledJobRecord, null);

                WorkingRecord workingRecord = new WorkingRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    QueuedOn = DateTime.UtcNow,
                    QueueName = null,
                    ScheduleId = scheduleRecord.Id,
                    StartedOn = DateTime.UtcNow,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateWorking(workingRecord, null);

                HistoryRecord historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    FinishedOn = DateTime.UtcNow,
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    QueuedOn = DateTime.UtcNow,
                    ScheduleId = scheduleRecord.Id,
                    StartedOn = DateTime.UtcNow,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                this.Repository.DeleteAll(BlueCollarSection.Section.ApplicationName, null);

                Assert.AreEqual(0, this.Repository.GetHistoryList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount);
                Assert.AreEqual(0, this.Repository.GetWorkingList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount);
                Assert.AreEqual(0, this.Repository.GetWorkerList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount);
                Assert.AreEqual(0, this.Repository.GetQueuedList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount);
                Assert.AreEqual(0, this.Repository.GetScheduledJobList(workerRecord.ApplicationName, scheduleRecord.Id.Value, null, 0, 100, null).TotalCount);
                Assert.AreEqual(0, this.Repository.GetScheduleList(workerRecord.ApplicationName, null, 100, 0, null).TotalCount);
            }
        }
示例#37
0
 private void LogJobEnd()
 {
     HistoryRecord old = Globals.History.FirstOrDefault(p => p == _currentRecord);
     if (old != null)
     {
         old.End = DateTime.Now;
         old.ChangedFilesCount = ChangedFiles.Count;
     }
     _currentRecord = null;
     SetTemporaryStatusMessage("Job ended.");
 }
        private void ReadXml(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                Records = new List<HistoryRecord>();
                SelectedRecord = new HistoryRecord();
                return;
            }

            FileInfo file = XmlFiles[fileName];
            var temp = new List<HistoryRecord>();
            Globals.XmlToHistory(file.FullName, out temp);

            Records = temp;
            SelectedRecord = Records.FirstOrDefault();
        }
示例#39
0
        protected override void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (_currentRecord != null)
                        LogJobEnd();

                    _cmdSelectFolder = null;
                    _cmdSaveList = null;
                    _cmdCopyFiles = null;
                    _cmdLaunchEditor = null;
                    _currentRecord = null;

                    if (watcher != null)
                        watcher.Dispose();
                    if (fileHelper != null)
                        fileHelper.Dispose();
                }

                _changedFiles = null;
                _customFilters = null;
                _scanModes = null;
                _subFolders = null;

                base.Dispose(disposing);
            }
        }
示例#40
0
        /// <summary>
        /// Delete history tests.
        /// </summary>
        protected void DeleteHistory()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };
                DateTime now = DateTime.UtcNow.FloorWithSeconds();

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = now
                };

                this.Repository.CreateWorker(workerRecord, null);

                HistoryRecord historyRecord = new HistoryRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    FinishedOn = now,
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job),
                    QueuedOn = now,
                    QueueName = QueueNameFilters.Any().ToString(),
                    StartedOn = now,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                historyRecord = new HistoryRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    FinishedOn = now.AddDays(-2),
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job),
                    QueuedOn = now.AddDays(-2),
                    QueueName = QueueNameFilters.Any().ToString(),
                    StartedOn = now.AddDays(-2),
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);
                Assert.AreEqual(2, this.Repository.GetHistoryList(BlueCollarSection.Section.ApplicationName, null, 100, 0, null).Records.Count);

                this.Repository.DeleteHistory(BlueCollarSection.Section.ApplicationName, now.AddDays(-1), null);
                Assert.AreEqual(1, this.Repository.GetHistoryList(BlueCollarSection.Section.ApplicationName, null, 100, 0, null).Records.Count);
            }
        }
示例#41
0
        /// <summary>
        /// Get counts tests.
        /// </summary>
        protected void GetCounts()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };
                string jobData = JobSerializer.Serialize(job);
                string typeName = JobSerializer.GetTypeName(job.GetType());

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = DateTime.UtcNow
                };

                this.Repository.CreateWorker(workerRecord, null);

                QueueRecord queueRecord = new QueueRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = jobData,
                    JobName = job.Name,
                    JobType = typeName,
                    QueuedOn = DateTime.UtcNow,
                    QueueName = "*",
                    TryNumber = 1
                };

                this.Repository.CreateQueued(queueRecord, null);

                for (int i = 0; i < 10; i++)
                {
                    HistoryRecord historyRecord = new HistoryRecord()
                    {
                        ApplicationName = workerRecord.ApplicationName,
                        Data = jobData,
                        FinishedOn = DateTime.UtcNow,
                        JobName = job.Name,
                        JobType = typeName,
                        QueuedOn = DateTime.UtcNow,
                        QueueName = "*",
                        StartedOn = DateTime.UtcNow,
                        Status = HistoryStatus.Succeeded,
                        TryNumber = 1,
                        WorkerId = workerRecord.Id.Value
                    };

                    this.Repository.CreateHistory(historyRecord, null);
                }

                ScheduleRecord scheduleRecord = new ScheduleRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Name = "Test Schedule 1",
                    RepeatType = ScheduleRepeatType.Days,
                    RepeatValue = 1,
                    StartOn = DateTime.UtcNow
                };

                this.Repository.CreateSchedule(scheduleRecord, null);

                scheduleRecord.Id = null;
                scheduleRecord.Name = "Test Schedule 2";
                this.Repository.CreateSchedule(scheduleRecord, null);

                CountsRecord counts = this.Repository.GetCounts(workerRecord.ApplicationName, null);
                Assert.IsNotNull(counts);
                Assert.AreEqual(10, counts.HistoryCount);
                Assert.AreEqual(1, counts.QueueCount);
                Assert.AreEqual(2, counts.ScheduleCount);
                Assert.AreEqual(1, counts.WorkerCount);
                Assert.AreEqual(0, counts.WorkingCount);
            }
        }
示例#42
0
        /// <summary>
        /// Get history tests.
        /// </summary>
        protected void GetHistoryList()
        {
            if (this.Repository != null)
            {
                IJob job = new TestJob() { Id = Guid.NewGuid() };
                DateTime now = DateTime.UtcNow.FloorWithSeconds();

                WorkerRecord workerRecord = new WorkerRecord()
                {
                    ApplicationName = BlueCollarSection.Section.ApplicationName,
                    MachineAddress = Machine.Address,
                    MachineName = Machine.Name,
                    Name = "Test Worker",
                    QueueNames = "*",
                    Signal = WorkerSignal.Stop,
                    Status = WorkerStatus.Working,
                    Startup = WorkerStartupType.Automatic,
                    UpdatedOn = now
                };

                this.Repository.CreateWorker(workerRecord, null);

                HistoryRecord historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    FinishedOn = now,
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    QueuedOn = now,
                    StartedOn = now,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                var list = this.Repository.GetHistoryList(workerRecord.ApplicationName, null, 100, 0, null);
                Assert.IsNotNull(list);
                Assert.AreEqual(1, list.TotalCount);
                Assert.AreEqual(1, list.Records.Count);

                list = this.Repository.GetHistoryList(workerRecord.ApplicationName, "boo", 100, 0, null);
                Assert.IsNotNull(list);
                Assert.AreEqual(0, list.TotalCount);
                Assert.AreEqual(0, list.Records.Count);

                ScheduleRecord scheduleRecord = new ScheduleRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Enabled = true,
                    Name = "Test",
                    QueueName = "scheduled",
                    RepeatType = ScheduleRepeatType.None,
                    StartOn = now
                };

                this.Repository.CreateSchedule(scheduleRecord, null);

                historyRecord = new HistoryRecord()
                {
                    ApplicationName = workerRecord.ApplicationName,
                    Data = JobSerializer.Serialize(job),
                    FinishedOn = now,
                    JobName = job.Name,
                    JobType = JobSerializer.GetTypeName(job.GetType()),
                    QueuedOn = now,
                    ScheduleId = scheduleRecord.Id.Value,
                    StartedOn = now,
                    Status = HistoryStatus.Succeeded,
                    TryNumber = 1,
                    WorkerId = workerRecord.Id.Value
                };

                this.Repository.CreateHistory(historyRecord, null);

                list = this.Repository.GetHistoryList(workerRecord.ApplicationName, null, 100, 0, null);
                Assert.IsNotNull(list);
                Assert.AreEqual(2, list.TotalCount);
                Assert.AreEqual(2, list.Records.Count);
                Assert.IsTrue(list.Records.Where(h => h.ScheduleName == "Test").Count() == 1);
            }
        }
 /// <summary>
 /// Creates a history record.
 /// </summary>
 /// <param name="record">The record to create.</param>
 /// <param name="transaction">The transaction to use, if applicable.</param>
 /// <returns>The created record.</returns>
 public HistoryRecord CreateHistory(HistoryRecord record, IDbTransaction transaction)
 {
     throw new NotImplementedException();
 }