public FlowSample(byte[] buffer) : base(buffer)
        {
            SamplingRate    = buffer.ToUInt(16, 4);
            SamplingPool    = buffer.ToUInt(20, 4);
            DroppedPackets  = buffer.ToUInt(24, 4);
            InputInterface  = buffer.ToUInt(28, 4).ToSflowInterface();
            OutputInterface = buffer.ToUInt(32, 4).ToSflowInterface();
            uint records = buffer.ToUInt(36, 4);

            Records = new FlowRecord[records];
            uint recordStartIndex = 40;

            for (uint i = 0; i < Records.Length; i++)
            {
                FlowRecord record       = new FlowRecord(buffer.AsSpan((int)recordStartIndex, (int)Record.HeaderLengthBytes).ToArray());
                int        recordLength = (int)(record.Length + Record.HeaderLengthBytes);
                if (record.Type == RecordType.RawPacketHeader)
                {
                    record = new RawPacketHeader(buffer.AsSpan((int)recordStartIndex, recordLength).ToArray());
                }
                else if (record.Type == RecordType.ExtSwitchData)
                {
                    record = new SwitchData(buffer.AsSpan((int)recordStartIndex, recordLength).ToArray());
                }
                recordStartIndex += (uint)recordLength;
                Records[i]        = record;
            }
        }
        /// <summary>
        /// Faz um novo registro de fluxo no sistema por Placa ou Número do Ônibus.
        /// </summary>
        /// <param name="identifier">Placa ou Número do Ônibus</param>
        /// <param name="user">Usuário que está efetuando o registro</param>
        /// <returns>Retorna o Id do registro cadastrado no banco, ou zero caso não for registrado.</returns>
        public int Register(string identifier, User user)
        {
            Bus busRegistered = null;

            using (BusDAO busDAO = new BusDAO())
            {
                busRegistered = busDAO.GetByIdentifier(identifier);

                if (busRegistered != null)
                {
                    var register = new FlowRecord()
                    {
                        RegistryClerk = user,
                        BusRegistered = busRegistered
                    };

                    if (busDAO.IsOnPlatform(busRegistered))
                    {
                        register.Departure = DateTime.Now;
                    }

                    else
                    {
                        register.Arrival = DateTime.Now;
                    }

                    return(this.Add(register));
                }
            }

            return(0);
        }
Example #3
0
        public ActionResult Save()
        {
            //当前登录人员信息
            var userInfo = Session[CommonSession.CurrentUser] as SysUser;

            if (userInfo != null)
            {
                //request.CreateTime = DateTime.Now;
                //1.保存请假单
                //context.LeaveRequests.AddOrUpdate(request);

                var Bid = Guid.NewGuid(); //业务Id

                //2.创建工作流
                var flowInstance = new FlowInstance
                {
                    //工作流当前节点
                    NodeNumber = _flowNodeService.GetFlowNodeByNodeName("发起申请").Result.NodeNumber,
                    NodeName   = "发起申请",
                    //申请处理状态
                    StatusName = "已申请",
                    //申请人(流程发起人)
                    StartUserId = userInfo.Id,
                    StartUser   = userInfo.RealName,
                    //当前操作者
                    OperatingUserId = userInfo.Id,
                    OperatingUser   = userInfo.RealName,
                    //下一个节点处理人
                    ToDoUserId = _flowNodeService.GetFlowNodeByNodeName("部门经理审批").Result.OperateUserId,
                    ToDoUser   = _flowNodeService.GetFlowNodeByNodeName("部门经理审批").Result.OperateUser,
                    ////申请单ID
                    RequisitionId = Bid,
                    UpdateTime    = DateTime.Now,
                    CreateTime    = DateTime.Now,
                    //已操作过的人
                    OperatedUserId = userInfo.Id,
                    OperatedUser   = userInfo.RealName
                };

                //添加
                _flowInstanceSvc.CreateFlowInstance(flowInstance);

                ////3.新建流操作记录
                var flowRecord = new FlowRecord
                {
                    WorkId            = flowInstance.Id,         //流程实例Id
                    OperateUser       = userInfo.RealName,       //当前处理人
                    OperateUserId     = userInfo.Id,
                    CurrentNodeNumber = flowInstance.NodeNumber, ////当前节点
                    CurrentNode       = flowInstance.NodeName,
                    IsRead            = true,                    ////是否已读
                    IsPass            = true,                    ////是否通过
                    UpdateTime        = DateTime.Now
                };
            }
            return(View());
        }
Example #4
0
        public ActionResult FlowSubmit(int flowType, int flowInstanceId)
        {
            switch (flowType)
            {
            case 1: break;

            case 2: break;

            case 3: break;

            case 4: break;
            }

            //当前登录人员信息
            var userInfo = Session[CommonSession.CurrentUser] as SysUser;

            if (userInfo != null)
            {
                //2.创建工作流
                var flowInstance = new FlowInstance
                {
                    //工作流当前节点
                    NodeNumber = _flowNodeService.GetFlowNodeByNodeName("工程申请计划").Result.Id,
                    //申请处理状态
                    StatusName = "已申请",
                    //申请人(流程发起人)
                    StartUserId = userInfo.Id,
                    //当前操作者
                    OperatingUserId = userInfo.Id,
                    //下一个节点处理人
                    ToDoUserId = _flowNodeService.GetFlowNodeByNodeName("工程审核计划").Result.SysRoleId,
                    UpdateTime = DateTime.Now,
                    CreateTime = DateTime.Now,
                    //已操作过的人
                    OperatedUserId = userInfo.Id
                };

                //添加
                _flowInstanceSvc.CreateFlowInstance(flowInstance);

                ////3.新建流操作记录
                var flowRecord = new FlowRecord
                {
                    FlowInstanceId = flowInstance.Id, //流程实例Id
                    IsRead         = true,            ////是否已读
                    IsPass         = true,            ////是否通过
                    UpdateTime     = DateTime.Now
                };
            }
            return(View());
        }
Example #5
0
        private void WriteOtherValueToWriter(Utf8JsonWriter writer, FlowRecord record, VariantValue value)
        {
            var utf8Length = _valuePresenter.GetMaxOutputByteCount(Limits.Value);

            if (utf8Length > 100)   // just in case, don't want a StackOverflow if here is a bug somewhere
            {
                writer.WriteStringValue("(#error#)");
                return;
            }

            var utf8Bytes = (Span <byte>) stackalloc byte[utf8Length];

            _valuePresenter.Present(utf8Bytes, value, Limits.Value, out var byteCount);
            writer.WriteStringValue(utf8Bytes.Slice(0, byteCount));
        }
        public bool Change(int id, FlowRecord model)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = connection;
            cmd.CommandText = @"UPDATE FlowRecords 
                                SET 
                                WHERE ";

            cmd.Parameters.AddWithValue("", id);
            cmd.Parameters.AddWithValue("", model.RegistryClerk);
            cmd.Parameters.AddWithValue("", model.BusRegistered);

            return(cmd.ExecuteNonQuery() > 0);
        }
Example #7
0
        private static void Main(string[] args)
        {
            try
            {
                var filename = @"s:\RJFAF614.FFL";

                var hexNlcSet = new HashSet <string> {
                    "H584", "7090", "7091", "9846"
                };
                var hexFlowList = new List <FlowRecord>();
                foreach (var line in File.ReadLines(filename))
                {
                    if (line.Length > 0 && line[0] == '/')
                    {
                        continue;
                    }
                    if (line.Length == 49 && line[0] == 'R' && line[1] == 'F')
                    {
                        var orig  = line.Substring(2, 4);
                        var dest  = line.Substring(6, 4);
                        var route = line.Substring(10, 5);

                        if ((hexNlcSet.Contains(orig) || hexNlcSet.Contains(dest)) && route != "00128")
                        {
                            var flow = new FlowRecord
                            {
                                Origin      = orig,
                                Destination = dest,
                                Route       = line.Substring(10, 5),
                                Toc         = line.Substring(36, 3),
                                Flowid      = Convert.ToInt32(line.Substring(42, 7))
                            };
                            hexFlowList.Add(flow);
                        }
                    }
                }
                var tocdic   = hexFlowList.GroupBy(x => x.Toc).ToDictionary(y => y.Key, y => y.ToList());
                var destdic  = hexFlowList.GroupBy(x => hexNlcSet.Contains(x.Origin) ? x.Destination : x.Origin).ToDictionary(y => y.Key, y => y.ToList());
                var routedic = hexFlowList.GroupBy(x => x.Route).ToDictionary(y => y.Key, y => y.ToList());
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                var codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                var progname = Path.GetFileNameWithoutExtension(codeBase);
                Console.Error.WriteLine(progname + ": Error: " + ex.Message);
            }
        }
Example #8
0
        // Must be thread safe
        private bool TryAddRecord(FlowRecord record)
        {
            if (_currentRecordIndex > Limits.MaxRecords)
            {
                return(false);
            }

            var nextRecordIndex = Interlocked.Increment(ref _currentRecordIndex);

            if (nextRecordIndex >= Limits.MaxRecords)
            {
                return(false);
            }

            _records[nextRecordIndex] = record;
            return(true);
        }
Example #9
0
        // Does NOT have to be thread-safe
        private void WriteRecordToWriter(Utf8JsonWriter writer, FlowRecord record)
        {
            if (record.Value is {} value)
            {
                WriteRecordWithValueToWriter(writer, record, value);
                return;
            }

            if (record.Exception is {} exception)
            {
                writer.WriteStartObject();
                writer.WriteString(Exception, record.Exception.GetType().Name);
                writer.WriteEndObject();
                return;
            }

            writer.WriteNumberValue(record.LineNumber);
        }
Example #10
0
        // Does NOT have to be thread-safe
        private void WriteRecordWithValueToWriter(Utf8JsonWriter writer, FlowRecord record, VariantValue value)
        {
            writer.WriteStartArray();
            writer.WriteNumberValue(record.LineNumber);
            switch (value.Kind)
            {
            case VariantKind.Int32:
                writer.WriteNumberValue(value.AsInt32Unchecked());
                break;

            default:
                WriteOtherValueToWriter(writer, record, value);
                break;
            }
            if (record.Name != null)
            {
                WriteNameToWriter(writer, record.Name);
            }
            writer.WriteEndArray();
        }
        public int Add(FlowRecord model)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = connection;
            cmd.CommandText = @"INSERT INTO FlowRecords (User_Id, Bus_Id, Arrival, Departure)
                                VALUES (@UserId, @BusId, @Arrival, @Departure)
                                SELECT CAST(@@IDENTITY AS INT)";

            cmd.Parameters.AddWithValue("@UserId", model.RegistryClerk);
            cmd.Parameters.AddWithValue("@BusId", model.BusRegistered);
            cmd.Parameters.AddWithValue("@Arrival", model.Arrival);
            cmd.Parameters.AddWithValue("@Departure", model.Departure);

            using (var reader = cmd.ExecuteReader())
                if (reader.Read())
                {
                    return(reader.GetInt32(0));
                }

            return(0);
        }
        public ActionResult ProcessImageBytes()
        {
            try
            {
                if (Response.Body != null || Response.ContentLength > 0)
                {
                    using (StreamReader targetStream = new StreamReader(Request.Body))
                    {
                        byte[] bytes;
                        using (var memoryStream = new MemoryStream())
                        {
                            Request.Body.CopyTo(memoryStream);
                            bytes = memoryStream.ToArray();
                        }

                        Task <string> recognizeTask = Task.Run(() => new OpenALPR(_secretKey).ProcessImage(bytes));
                        recognizeTask.Wait();

                        var response = JsonConvert.DeserializeObject <OpenALPRResponse>(recognizeTask.Result);

                        if (!response.Error && response.Results.Length > 0)
                        {
                            FlowRecord record = null;

                            using (var recordFlowDAO = new FlowRecordDAO())
                                record = recordFlowDAO.Register(response.Results[0].Plate, null);

                            if (record != null)
                            {
                                SystemNotifier.VehicleActionAsync(record);
                                return(StatusCode(200));
                            }

                            else
                            {
                                SystemNotifier.WarningAsync(new SystemWarning()
                                {
                                    Moment       = DateTime.Now,
                                    Type         = SystemWarning.WarningType.NotRegistered,
                                    LicensePlate = response.Results[0].Plate,
                                    Message      = "A placa não foi reconhecida para nenhuma empresa no banco de dados"
                                });

                                return(StatusCode(404));
                            }
                        }
                    }
                }

                SystemNotifier.WarningAsync(new SystemWarning()
                {
                    Moment  = DateTime.Now,
                    Type    = SystemWarning.WarningType.NotRecognized,
                    Message = "Falha ao identificar a placa"
                });

                return(StatusCode(406));
            }

            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }
Example #13
0
 public void VehicleActionAsync(FlowRecord record)
 {
     _hub.Clients.All.SendAsync("VehicleAction", record);
 }
Example #14
0
 public async Task VehicleAction(FlowRecord record)
 {
     await Clients.All.SendAsync("VehicleAction", record);
 }