예제 #1
0
        /// <summary>
        /// 将Exception打印为字符串
        /// </summary>
        /// <typeparam name="TException"></typeparam>
        /// <param name="ex"></param>
        /// <param name="options"></param>
        /// <returns></returns>

        public static string ToRecord <TException>(this TException ex, RecordOptions options = RecordOptions.Default)
            where TException : Exception
        {
            StringBuilder sb = new StringBuilder(1024);

            if (options.HasFlag(RecordOptions.Type))
            {
                sb.AppendLine($"Type: {ex.GetType().FullName}");
            }
            if (options.HasFlag(RecordOptions.TargetSite))
            {
                sb.AppendLine($"TargetSite: {ex.TargetSite}");
            }
            if (options.HasFlag(RecordOptions.Message))
            {
                sb.AppendLine($"Message: {ex.Message}");
            }
            if (options.HasFlag(RecordOptions.StackTrace))
            {
                sb.AppendLine($"StackTrace: {ex.StackTrace}");
            }
            if (options.HasFlag(RecordOptions.Source))
            {
                sb.AppendLine($"Source: {ex.Source}");
            }
            if (options.HasFlag(RecordOptions.InnerException))
            {
                if (ex.InnerException != null)
                {
                    sb.AppendLine($"---------------InnerExceptions---------------");
                    sb.AppendLine(ex.InnerException.ToRecord(options));
                }
            }
            return(sb.ToString());
        }
예제 #2
0
파일: Program.cs 프로젝트: jeffman/Displays
        private int Record(RecordOptions options)
        {
            var    currentConfig = Api.QueryDisplayConfig(QueryDisplayConfigFlags.OnlyActivePaths);
            string json          = JsonConvert.SerializeObject(currentConfig, CreateJsonSettings());
            string fullPath      = Path.GetFullPath(options.OutputFile);

            File.WriteAllText(fullPath, json);
            Console.WriteLine($"Recorded current display configuration to {fullPath}");
            return(ExitCodeOk);
        }
예제 #3
0
        /** @params id, if null, select all
         * @parmas from, begining time
         * @params to, ending selected time
         * @params options,
         */

        public async Task <List <ReportModel> > GetRecordsAsync(string id, DateTime fromT, DateTime toT,
                                                                RecordOptions option = RecordOptions.SelectAll,
                                                                bool includePending  = false)
        {
            using (var dbContext = new AppDbContext(builder.Options))
            {
                IQueryable <ReportModel> records = from record in dbContext.CheckRecord
                                                   join user in dbContext.UserInfo on
                                                   record.UserId equals user.Id
                                                   where record.CheckedDate >= fromT.Date && record.CheckedDate <= toT.Date
                                                   select new ReportModel
                {
                    UserId       = user.Id,
                    UserName     = user.UserName,
                    RecordId     = record.Id,
                    CheckedDate  = record.CheckedDate.ToString("yyyy-MM-dd"),
                    CheckInTime  = record.CheckInTime.ToString(),
                    CheckOutTime = record.CheckOutTime.ToString(),
                    GeoLocation1 = record.GeoLocation1,
                    GeoLocation2 = record.GeoLocation2,
                    OffApplyDate = record.OffApplyDate.Value == null
                            ? ""
                            : record.OffApplyDate.Value.ToString("yyyy-MM-dd"),
                    OffReason                   = record.OffReason,
                    OffTimeStart                = record.OffTimeStart.ToString(),
                    OffTimeEnd                  = record.OffTimeEnd.ToString(),
                    OffType                     = string.IsNullOrWhiteSpace(record.OffType) ? "" : record.OffType,
                    OvertimeEndTime             = record.OvertimeEndTime,
                    StatusOfApprovalForOvertime = record.StatusOfApprovalForOvertime,
                    StatusOfApproval            = record.StatusOfApproval
                };
                if (!string.IsNullOrWhiteSpace(id))
                {
                    records = records.Where(s => s.UserId == id);
                }
                switch (option)
                {
                case RecordOptions.SelectAll:
                    return(await records.ToListAsync());

                case RecordOptions.SelectLeave:
                    return(await records.Where(s => !string.IsNullOrWhiteSpace(s.OffType)).ToListAsync());

                case RecordOptions.SelectNormal:
                    return(await records.Where(s => !string.IsNullOrWhiteSpace(s.CheckInTime)).ToListAsync());

                case RecordOptions.SelectOT:
                    return(await records.Where(s => !string.IsNullOrWhiteSpace(s.OvertimeEndTime)).ToListAsync());

                default:
                    throw new Exception("Invalid Option");
                }
            }
        }
예제 #4
0
 public Record(IConnectionFactory connectionFactory, Limits limits, string?exchange, string queue,
               string folderPath, RecordOptions options, JsonSerializerSettings serializerSettings,
               TimeSpan updateInterval)
 {
     _connectionFactory  = connectionFactory;
     _limits             = limits;
     _exchange           = exchange;
     _queue              = queue;
     _options            = options;
     _folderPath         = folderPath;
     _serializerSettings = serializerSettings;
     _updateInterval     = updateInterval;
 }
예제 #5
0
        public Form2(Order currentDemandItem)
        //: this()
        {
            //replace : this() by real code and fix modify issues

            actionToTake    = RecordOptions.ModifyRecord;
            button1.Enabled = false;
            button3.Enabled = false;

            this.Text    = RecordOptions.ModifyRecord.ToString();
            currentIndex = currentDemandItem.Id;

            ShowDBRecordInGridView(currentDemandItem);
            ShowStatusForm2(actionToTake.ToString());

            this.Activated += Form2_Activated;
            this.dataGridView2.DataError += this.DataGridView2_DataError;
        }
예제 #6
0
        public Recorder(RecordOptions options, IFileSystem fileSystem)
        {
            _options = options;
            var factory = new ConnectionFactory
            {
                Uri = options.RabbitUri,
                AutomaticRecoveryEnabled = false
            };

            _file       = options.OutputFile;
            _routingKey = options.RoutingKey;

            // disposables! clean them up!
            _connection = factory.CreateConnection();
            _channel    = _connection.CreateModel();
            _textWriter = new StreamWriter(fileSystem.File.Open(_file, FileMode.OpenOrCreate));
            _jsonWriter = new JsonTextWriter(_textWriter);
        }
예제 #7
0
        private void LoadPlaylist(string fileName)
        {
            _lastRecord = _viewModel.Playback.Records.SingleOrDefault(r => r.Playlist == fileName);
            if (_lastRecord.IsNull())
            {
                _lastRecord = new RecordOptions();
                _viewModel.Playback.Records.Add(_lastRecord);
            }

            if (_lastRecord.Playlist != fileName)
            {
                _lastRecord.Playlist = fileName;
            }

            _viewModel.Playlist = PlaylistHelper.LoadOptions(fileName);
            _viewModel.ClearPlayback();

            EnableControls();
        }
예제 #8
0
        public void TestRecordCommand_Successful()
        {
            // Preconditions
            Debug.Assert(managerMock != null);
            Debug.Assert(outputMock != null);
            Debug.Assert(commandLineMock != null);
            Debug.Assert(messageLoopMock != null);

            /* GIVEN */
            var mockSequence = new MockSequence();

            managerMock.InSequence(mockSequence)?.Setup(manager => manager.StartRecording());
            managerMock.InSequence(mockSequence)?.Setup(manager => manager.StopRecording());

            commandLineMock
            .Setup(cli => cli.Launch(It.IsAny <Action>()))?
            .Callback((Action action) => action?.Invoke())?
            .Verifiable();

            var command = new RecordCommand(managerMock.Object, outputMock.Object, commandLineMock.Object, messageLoopMock.Object);
            var options = new RecordOptions
            {
                IsVerbose  = false,
                ConfigPath = Assembly.GetExecutingAssembly().Location
            };

            /* WHEN */
            var returnCode = command.Execute(options);

            /* THEN */

            // We test if the command was successful and returned code 0.
            Assert.AreEqual(successCode, returnCode);

            managerMock.VerifyAll();
            managerMock.Verify(manager => manager.StartRecording(), Times.Once);
            managerMock.Verify(manager => manager.StopRecording(), Times.Once);

            messageLoopMock.Verify(loop => loop.Start(), Times.Once);
            messageLoopMock.Verify(loop => loop.Stop(), Times.Once);
        }
예제 #9
0
        public void TestRecordCommand_OnStartError()
        {
            // Preconditions
            Debug.Assert(managerMock != null);
            Debug.Assert(outputMock != null);
            Debug.Assert(commandLineMock != null);
            Debug.Assert(messageLoopMock != null);

            /* GIVEN */
            managerMock
            .Setup(manager => manager.StartRecording())?
            .Throws(new InvalidOperationException());

            var command = new RecordCommand(managerMock.Object, outputMock.Object, commandLineMock.Object, messageLoopMock.Object);
            var options = new RecordOptions
            {
                IsVerbose  = false,
                ConfigPath = Assembly.GetExecutingAssembly().Location
            };

            /* WHEN */
            var returnCode = command.Execute(options);

            /* THEN */

            // We test if the command failed and returned code -1.
            Assert.AreEqual(failCode, returnCode);

            managerMock.Verify(manager => manager.StartRecording(), Times.Once);
            managerMock.Verify(manager => manager.StopRecording(), Times.Never);

            outputMock.Verify(output => output.PrintError(It.IsAny <InvalidOperationException>()), Times.Once);

            messageLoopMock.Verify(loop => loop.Start(), Times.Never);
            messageLoopMock.Verify(loop => loop.Stop(), Times.Never);
        }
예제 #10
0
        public void TestRecordCommand_IsVerbosePropagation()
        {
            // Preconditions
            Debug.Assert(managerMock != null);
            Debug.Assert(outputMock != null);
            Debug.Assert(commandLineMock != null);
            Debug.Assert(messageLoopMock != null);

            /* GIVEN */
            outputMock.SetupSet(output => output.IsVerbose = true);

            var command = new RecordCommand(managerMock.Object, outputMock.Object, commandLineMock.Object, messageLoopMock.Object);
            var options = new RecordOptions
            {
                IsVerbose  = true,
                ConfigPath = ""
            };

            /* WHEN */
            command.Execute(options);

            /* THEN */
            outputMock.VerifySet(output => output.IsVerbose = true);
        }
예제 #11
0
        public Form2()
        {
            InitializeComponent();
            var createdOn = DateTime.Now;

            actionToTake = RecordOptions.AddRecord;

            button1.Enabled = false;
            button3.Enabled = false;
            this.ControlBox = false;

            DataGridViewCellStyle headerStyle = dataGridView2.ColumnHeadersDefaultCellStyle;

            headerStyle.BackColor = Color.Navy;
            headerStyle.ForeColor = Color.White;
            headerStyle.Font      = new Font(dataGridView2.Font, FontStyle.Bold);

            this.Text = RecordOptions.AddRecord.ToString();

            //read header from SQL

            string[] gridHeader   = readGridHeader();
            string[] statusCBCell = readstatusCBCell();

            //dataGridView2.RowCount = 1;
            dataGridView2.ColumnCount = gridHeader.Length;
            dataGridView2.ReadOnly    = false;

            DataGridViewRow sampleRow = new DataGridViewRow();

            for (int i = 0; i < gridHeader.Length; i++)
            {
                dataGridView2.Columns[i].Name = gridHeader[i];
                if (i == 0)
                {
                    DataGridViewTextBoxCell textCell = new DataGridViewTextBoxCell();
                    textCell.Value = null;
                    sampleRow.Cells.Add(textCell);
                }
                else
                {
                    if (i == 4 || i == 8)
                    {
                        DataGridViewTextBoxCell textCell = new DataGridViewTextBoxCell();
                        textCell.Value = null;
                        sampleRow.Cells.Add(textCell);
                    }
                    else
                    {
                        if (i == 6)
                        {
                            DataGridViewComboBoxCell cbCell = new DataGridViewComboBoxCell();
                            cbCell.Items.AddRange(statusCBCell);
                            cbCell.Value = statusCBCell[0];
                            sampleRow.Cells.Add(cbCell);
                        }
                        else
                        {
                            DataGridViewTextBoxCell textCell = new DataGridViewTextBoxCell();
                            textCell.Value = null;
                            sampleRow.Cells.Add(textCell);
                        }
                    }
                }
            }
            dataGridView2.Rows.Add(sampleRow);
            //TODO ComboBox as GridCell

            dataGridView2.Rows[0].Cells[4].Value    = createdOn;
            dataGridView2.Rows[0].Cells[8].Value    = false;
            dataGridView2.Rows[0].Cells[4].ReadOnly = true;
            dataGridView2.Rows[0].Cells[8].ReadOnly = true;
            dataGridView2.Rows[0].Cells[0].ReadOnly = true;

            ShowStatusForm2(actionToTake.ToString());
            this.Activated += Form2_Activated;
            this.dataGridView2.DataError += this.DataGridView2_DataError;
        }