示例#1
0
        // Request
        public RequestIndex BuildRequestIndexViewModel(string username, string[] userRoles, string title, IEnumerable <Request> requests, List <int> itemsPerPage)
        {
            var contactRequests  = requests.Where(c => c.RequestType == 2);
            var allOtherRequests = requests.Where(c => c.RequestType != 2);

            var viewModel = new RequestIndex
            {
                Title                = title,
                SubTitle             = GeneralConstants.PortalTitle,
                PortalTitle          = GeneralConstants.PortalTitle,
                Icon                 = "Icon",
                Breadcrumb           = _breadcrumbFactory.BuildBreadcrumb(),
                LeftNav              = _leftNavFactory.BuildLeftNav(LeftNavigationItems.Requests, userRoles),
                TopNav               = _topNavFactory.BuildTopNav(GeneralConstants.PortalTitle, username),
                ContactRequestTable  = contactRequests != null && contactRequests.Any() ? _tableFactory.BuildRequestsTable(contactRequests, itemsPerPage, string.Concat("Contact ", title), 0) : null,
                NewRequestTable      = allOtherRequests != null && allOtherRequests.Any() ? _tableFactory.BuildRequestsTable(allOtherRequests, itemsPerPage, string.Concat("New ", title), 0) : null,
                RejectedRequestTable = allOtherRequests != null && allOtherRequests.Any() ? _tableFactory.BuildRequestsTable(allOtherRequests, itemsPerPage, string.Concat("Rejected ", title), -1) : null,
                AcceptedRequestTable = allOtherRequests != null && allOtherRequests.Any() ? _tableFactory.BuildRequestsTable(allOtherRequests, itemsPerPage, string.Concat("Accepted ", title), 3) : null
            };

            return(viewModel);
        }
示例#2
0
        public ActionResult GetRequests()
        {
            try
            {
                IEnumerable <REF_REQUEST_TB> requests    = _uow.Repository <REF_REQUEST_TB>().GetAll();
                List <RequestIndex>          requestList = new List <RequestIndex>();

                requests = requests.ToList().OrderBy(u => u.REF_REQUEST_GROUP_TB.SZ_DESCRIPTION)
                           .ThenBy(u => u.REF_LOCATION_GROUP_TB.SZ_DESCRIPTION)
                           .ThenBy(u => u.REF_TEST_GROUP_TB.SZ_DESCRIPTION);

                foreach (var request in requests)
                {
                    RequestIndex item = new RequestIndex()
                    {
                        RequestID = request.N_REQUEST_SYSID,
                        LocationGroupDescription = request.REF_LOCATION_GROUP_TB.SZ_DESCRIPTION == null ? "" : request.REF_LOCATION_GROUP_TB.SZ_DESCRIPTION,
                        RequestGroupDescription  = request.REF_REQUEST_GROUP_TB.SZ_DESCRIPTION == null ? "" : request.REF_REQUEST_GROUP_TB.SZ_DESCRIPTION,
                        TestGroupDescription     = request.REF_TEST_GROUP_TB.SZ_DESCRIPTION == null ? "" : request.REF_TEST_GROUP_TB.SZ_DESCRIPTION
                    };
                    requestList.Add(item);
                }

                return(Json(requestList, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    ViewBag.Message = "Function: RequestController.GetRequests_GET\n\nError: " + ex.Message;
                }
                else
                {
                    ViewBag.Message = "Function: ComplainantController.GetRequests_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message);
                };
                Session["ErrorMessage"] = ViewBag.Message;
                return(RedirectToAction("InternalServerError", "Error"));
            };
        }
示例#3
0
        /*public OperationResult TryReadAvPower3min(IIODriverClient channel, string psw, DeviceCompOn deviceTime, TimeZoneMap map, RequestIndex request, DateTimeZone cutTime, out AvPowerIndex response)
         * {
         *  response = null;
         *  var result =  TryReadPower(channel, psw, request, Codes.CODE_3AVPWR_INX, out response);
         *  if (result.IsGood) if (!response.Check(cutTime)) result = new OperationResult(Quality.Bad, SR.ERROR_CUT);
         *  return result;
         * }
         *
         * OperationResult TryReadPower(IIODriverClient channel, string psw, RequestIndex request, byte action, out AvPowerIndex response)
         * {
         *  OperationResult result = OperationResult.Bad;
         *  response = null;
         *  var send = CreateRequest(request.Address, action, psw, request.Index, 0, 0);
         *  result = WriteReadCheck(channel, 1, send, out byte[] answer);
         *
         *  if (!result.IsGood) return result;
         *  var seg = new ByteArraySegment(answer, 0, answer.Length);
         *  try
         *  {
         *  response = new AvPowerIndex
         *  {
         *      Power = new AvPower
         *      {
         *      Pplus = seg.ReadSingle(0),
         *      Pminus = seg.ReadSingle(1),
         *      Qplus = seg.ReadSingle(2),
         *      Qminus = seg.ReadSingle(3),
         *      },
         *      Index = seg.ReadUInt16(0 + (4 * sizeof(Single)))
         *  };
         *  result = OperationResult.Good;
         *  }
         *  catch (Exception e)
         *  {
         *  result = OperationResult.From(e);
         *  }
         *  return result;
         * }*/
        #endregion

        #region Энергия
        /// <summary>Прочитать показание счетчиков</summary>
        public OperationResult TryReadCounter(
            IIODriverClient channel,
            string psw,
            TypeInc typeInc,
            RequestIndex request,
            ETariff tariff,
            out Energy response)
        {
            response = null;
            ushort action;

            byte[]          arr;
            OperationResult result = new OperationResult(Quality.BadNoRestore, "Превышение глубины опроса");

            if (typeInc == TypeInc.Day)
            {
                if ((request.Index > Emera3Request.DepthDayCounter) || (request.Index > 45))
                {
                    return(result);
                }
                if (tariff == ETariff.NoTariff)
                {
                    action = Codes.CODE_READ_ENERGY_DAY_SUM;
                    arr    = new byte[1];
                    arr[0] = request.Index;
                }
                else
                {
                    action = Codes.CODE_READ_ENERGY_DAY_TARIFF;
                    arr    = new byte[2];
                    arr[0] = (byte)(tariff - 1);
                    arr[1] = request.Index;
                }
            }
            else if (typeInc == TypeInc.Month)
            {
                if ((request.Index > Emera3Request.DepthMonthCounter) || (request.Index > 13))
                {
                    return(result);
                }
                if (tariff == ETariff.NoTariff)
                {
                    action = Codes.CODE_READ_ENERGY_MONTH_SUM;
                    arr    = new byte[1];
                    arr[0] = request.Index;
                }
                else
                {
                    action = Codes.CODE_READ_ENERGY_MONTH_TARIFF;
                    arr    = new byte[2];
                    arr[0] = (byte)(tariff - 1);
                    arr[1] = request.Index;
                }
            }
            else
            {
                return(OperationResult.Bad);
            }

            var send = CreateRequest(request.Address, action, psw, arr);

            result = WriteReadCheck(channel, nRepeatGlobal, send, out byte[] answer);
            if (!result.IsGood)
            {
                return(result);
            }

            var seg = new ByteArraySegment(answer, 0, answer.Length);

            try
            {
                response = new Energy(seg.ReadUInt32(0), 0, 0, 0);
                result   = OperationResult.Good;
            }
            catch (Exception e)
            {
                result = OperationResult.From(e);
            }
            return(result);
        }
示例#4
0
文件: IO.cs 项目: est-by/EmeraDrv
        /// <summary>
        /// Чтение приращений (показаний)
        /// </summary>
        /// <param name="fromTime"></param>
        /// <param name="typeQuery"></param>
        /// <param name="typeInc"></param>
        /// <param name="aplus"></param>
        /// <param name="aminus"></param>
        /// <param name="rplus"></param>
        /// <param name="rminus"></param>
        /// <param name="depth"></param>
        /// <param name="deepSyncTime"></param>
        /// <param name="tariff">
        /// Добавлена поддержка чтения тарифов для показаний, т.к. эту величину нельзя расчитать.
        /// </param>
        static internal void ReadInc(
            QueryInfo info,
            DateTimeZone fromTime,
            TypeQuery typeQuery,
            TypeInc typeInc,
            TagDef aplus,
            TagDef aminus,
            TagDef rplus,
            TagDef rminus,
            int depth,
            DateTimeUtc deepSyncTime,
            ETariff tariff = ETariff.NoTariff)
        {
            //Если в гране нет данных то дальше этой даты записываем что нельзя востонавить
            bool            fillBadNoRestore = false;
            int             itemNum          = 0;
            OperationResult oper             = new OperationResult(Quality.Bad);

            var holes         = info.GetHoles(typeInc, fromTime, depth, deepSyncTime, new[] { aplus });
            var reversedHoles = holes.Reverse();

            foreach (var item in reversedHoles)
            {
                itemNum++;
                Energy          read = null;
                OperationResult res  = OperationResult.Bad;
                if (fillBadNoRestore)
                {
                    read = new Energy(0, 0, 0, 0);
                    oper = new OperationResult(Quality.BadNoRestore);
                }
                else if (info.Session.BeginOperation())
                {
                    if (DataBusSetting.StubData) //STUBDATA->
                    {
                        read = new Energy(StubUtil.Int32(500), StubUtil.Int32(600), StubUtil.Int32(700), StubUtil.Int32(800));
                        oper = new OperationResult(Quality.Good);
                    }
                    else
                    {
                        switch (typeQuery)
                        {
                            #region (case TypeQuery.SlicesEnergy:)
                        case TypeQuery.SlicesEnergy:
                            if (!info.IsHalfHourInterval)
                            {
                                oper = new OperationResult(Quality.Bad, "HalfHour Interval is incorrect!");
                            }
                            else
                            {
                                // только для версий СЕ102 S7, R8, CE301M S31, R33
                                // версии CE102 S6, R5 не поддерживают архив получасов
                                oper = info.Request.TryReadSlicesEnergy(
                                    info.DataBus,
                                    info.Cs.Psw,
                                    info.Session.TimeDevice,
                                    SlicesQuery.From(item, info.Cs.Address),
                                    out read);
                                read.Calc(info.DeviceKoef);
                            }
                            break;

                            #endregion
                            #region (case TypeQuery.Counter:)
                        case TypeQuery.Counter:
                            oper = info.Request.TryReadCounter(
                                info.DataBus,
                                info.Cs.Psw,
                                typeInc,
                                RequestIndex.From(item, typeInc, info.Cs.Address, true),
                                tariff,
                                out read);
                            read.Calc(info.DeviceKoef);
                            break;
                            #endregion

                            /*#region (case TypeQuery.Power3min:)
                             * case TypeQuery.Power3min:
                             * AvPowerIndex pi;
                             * oper = info.Request.TryReadAvPower3min(
                             *  info.DataBus,
                             *  info.Session.TimeDevice,
                             *  info.Session.Zone,
                             *  RequestIndex.From(item, typeInc, info.Cs.Address, false),
                             *  item,
                             *  out pi);
                             * if (oper.IsGood)
                             *  read = pi.Power.ToEnergy(20);
                             * break;
                             #endregion*/
                        }
                        //Может возникать ситуация когда на компе уже наступило время опроса а на счетчике нет и будет возвращен блок поврежден
                        //TODO      if ((itemNum < 3) && (oper.Quality == Quality.BadNoRestore)) oper.Quality = Quality.Bad;
                    }

                    /*if ((!oper.IsGood) && (oper.Code == 2))
                     * {
                     *  if (info.Session.OpenData.NewDevice != ChangeDeviceInfo.None)
                     *      info.LogWarn(SR.NOT_PARAM, info.DisplayName, aplus.AccountKind, aplus.Discrete, aplus.DiscreteValue);
                     *  info.Session.EndOperation(OperationResult.Good);
                     *  break; //Неизвестная функция не подерживаемая версией устройства
                     * }*/

                    info.Session.EndOperation(oper);
                    if (!oper.IsGood)
                    {
                        read = new Energy(0, 0, 0, 0);
                        info.DataBus.DiscardInBuffer();
                    }
                    if (oper.Quality == Quality.BadNoRestore)
                    {
                        fillBadNoRestore = true;                                       //заполним все полохими не востанавливаемыми
                    }
                }
                else
                {
                    break;
                }

                info.Storage.WriteTagsValue(
                    HW(oper.Quality, read.Aplus, item, aplus),
                    HW(Quality.Bad, read.Aminus, item, aminus),
                    HW(Quality.Bad, read.Rplus, item, rplus),
                    HW(Quality.Bad, read.Rminus, item, rminus));

                if (info.Log.Trace.IsOn(2))
                {
                    var sb = new StringBuilder();
                    sb.AppendFormat("Read from [{0}] {1} {2}", item, typeInc, oper.Quality);
                    if (typeQuery != TypeQuery.SlicesEnergy)
                    {
                        sb.Append(" " + typeQuery);
                    }

                    if (!oper.IsGood)
                    {
                        sb.AppendFormat(". Error: {0}", oper.ErrorMsg);
                        info.Log.Trace.Error(2, sb.ToString());
                    }
                    else
                    {
                        sb.AppendFormat(". A+: {0}, A-: {1}, R+: {2}, R-: {3}", read.Aplus, read.Aminus, read.Rplus, read.Rminus);
                        info.Log.Trace.Info(2, sb.ToString());
                    }
                }
            }
        }
示例#5
0
        private void ProcessChanges(RequestIndex index)
        {
            // When the UI thread acquires the lock, it should update the front
            // buffer only if there has been changes. Otherwise, it would block
            // the UI for too long on each update.
            _isBackBufferDirty = index.Modifications.Count > 0 ||
                                 index.Insertions.Count > 0;

            // apply changes to the data in the back buffer
            if (index.Modifications.Count > 0)
            {
                var groupHead = 0;
                for (var i = 0; i < _backBuffer.Count; ++i)
                {
                    Trace.Assert(groupHead <= i, $"{nameof(groupHead)} <= {nameof(i)}");
                    var group = _backBuffer[i];

                    // update items in the group
                    var head = 0;
                    for (var j = 0; j < group.Items.Count; ++j)
                    {
                        Trace.Assert(head <= j, $"{nameof(head)} <= {nameof(j)}");
                        var item = group.Items[j];
                        if (!index.Modifications.TryGetValue(item.FullPath, out var req))
                        {
                            // this item has not changed
                            group.Items[head] = item;
                            ++head;
                        }
                        else if (req is RemoveRequest)
                        {
                            _removed.Add(item);
                        }
                        else if (req is MoveRequest moveReq)
                        {
                            item.Data.ChangePath(moveReq.NewPath);
                            var key  = Query.GetGroup(item.Data);
                            var list = GetOrAddList(key, index.Insertions);
                            list.Add(item);
                        }
                        else if (req is ModifyRequest modReq)
                        {
                            // replace the item but do not throw away its thumbnail
                            item = new EntityView(modReq.Value, item.Thumbnail);
                            var key  = Query.GetGroup(item.Data);
                            var list = GetOrAddList(key, index.Insertions);
                            list.Add(item);
                        }
                    }

                    group.Items.RemoveRange(head, group.Items.Count - head);

                    // remove the group if it is empty
                    if (group.Items.Count > 0)
                    {
                        _backBuffer[groupHead] = group;
                        ++groupHead;
                    }
                }

                _backBuffer.RemoveRange(groupHead, _backBuffer.Count - groupHead);
            }

            // add new groups
            if (index.Insertions.Count > 0)
            {
                // merge items of existing groups
                for (var i = 0; i < _backBuffer.Count; ++i)
                {
                    var group = _backBuffer[i];
                    if (!index.Insertions.TryGetValue(group.Key, out var list))
                    {
                        continue;
                    }

                    list.Sort(Comparer);
                    group.Items = group.Items.Merge(list, Comparer);
                    index.Insertions.Remove(group.Key);
                }

                // add brand new groups
                var addedGroups = index.Insertions
                                  .Select(pair => new Group(pair.Key)
                {
                    Items = pair.Value
                })
                                  .ToList();
                addedGroups.Sort();
                foreach (var view in addedGroups)
                {
                    view.Items.Sort(Comparer);
                }

                _backBuffer = _backBuffer.Merge(addedGroups, Comparer <Group> .Default);
            }
        }