Example #1
0
        private async Task GetDictionaryElementAsync <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var result = await service.GetDictionaryElementAsync(2137);

            Assert.True(result.IsLeft);
        }
Example #2
0
        public async Task EditActivityAsync_WhenActivityDTOIsNull_CheckErrorOccured()
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var value = await service.EditActivityAsync(1, null);

            Assert.True(value.IsLeft);
        }
Example #3
0
        public async Task EditActivityAsync_CorrectUpdateOnContext(
            string teacher, string room, string subject, string classGroup)
        {
            using var context = PrepareData.GetDbContext(); var activity = context.Activities.Include(a => a.Slot).FirstOrDefault();
            int id          = activity.Id;
            int slot        = activity.Slot.Index;
            var activityDTO = new ActivityEditDTO()
            {
                Id         = id,
                ClassGroup = classGroup,
                Room       = room,
                Slot       = slot,
                Subject    = subject,
                Teacher    = teacher
            };
            var service = new ActivitiesService(context);
            var value   = await service.EditActivityAsync(activity.Id, activityDTO);

            var activityToCheck = GetActivities(context).FirstOrDefault(
                a =>
                a.Id == id &&
                a.Teacher.Name == teacher &&
                a.Room.Name == room &&
                a.Subject.Name == subject &&
                a.ClassGroup.Name == classGroup
                );

            Assert.True(value.IsRight);
            Assert.NotNull(activityToCheck);
        }
Example #4
0
        public async Task GetActivityByGroupAsync_GiveIncorrectId_GetError(int id)
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var test = await service.GetActivity(id);

            Assert.True(test.IsLeft);
        }
Example #5
0
        public async Task CreateActivityAsync_CorrectUpdateOnContext(
            string teacher, string room, string subject, string classGroup, int slot)
        {
            using var context = PrepareData.GetDbContext(); var activityDTO = new ActivityCreateDTO()
            {
                ClassGroup = classGroup,
                Room       = room,
                Slot       = slot,
                Subject    = subject,
                Teacher    = teacher
            };
            var service = new ActivitiesService(context);
            var value   = await service.CreateActivityAsync(activityDTO);

            var activity = GetActivities(context).FirstOrDefault(
                a => a.Teacher.Name == teacher &&
                a.Subject.Name == subject &&
                a.Slot.Index == slot &&
                a.Room.Name == room &&
                a.ClassGroup.Name == classGroup
                );

            Assert.True(value.IsRight);
            Assert.NotNull(activity);
        }
Example #6
0
        public async Task DeleteActivityAsync_CheckErrorOccured(int id)
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var value = await service.DeleteActivityAsync(id, null);

            Assert.True(value.IsLeft);
        }
Example #7
0
        private async Task DeleteElement <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var result = await service.RemoveKey(10000, null);

            Assert.True(result.IsLeft);
        }
Example #8
0
        public async Task CreateActivityAsync_WhenOneOfValuesIsOccupied_CheckErrorOccured(
            string teacher, string room, string subject, string classGroup, int slot)
        {
            using var context = PrepareData.GetDbContext(); var service = new ActivitiesService(context);
            var value = await service.CreateActivityAsync(GetDTOToCreate(teacher, room, subject, classGroup, slot));

            Assert.True(value.IsLeft);
        }
Example #9
0
        public async Task EditActivityAsync_WhenOneOfValuesIsOccupied_CheckErrorOccured(
            string teacher, string room, string subject, string classGroup)
        {
            using var context = PrepareData.GetDbContext(); var activityDTO = GetDTOToEdit(teacher, room, subject, classGroup, context);
            var service = new ActivitiesService(context);
            var value   = await service.EditActivityAsync(activityDTO.Id, activityDTO);

            Assert.True(value.IsLeft);
        }
Example #10
0
        private async Task GetDictionaryGenericAsync <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            int size = context.Set <T>().Count();
            var dictionaryIndexDTO = await service.GetDictionaryAsync();

            Assert.True(dictionaryIndexDTO.IsRight);
            dictionaryIndexDTO.IfRight(r => {
                Assert.Equal(size, r.Count());
            });
        }
Example #11
0
        private async Task RemoveKey <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var element = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Name == name);
            var result  = await service.RemoveKey(element.Id, element.Timestamp);

            Assert.True(result.IsRight);
            var value = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Id == element.Id);

            Assert.Null(value);
        }
Example #12
0
        private async Task UpdateKey <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement = new DictionaryElementEditDTO()
            {
                Id = 1000
            };
            var result = await service.UpdateKey(dictionaryElement);

            Assert.True(result.IsLeft);
        }
Example #13
0
        private async Task AddKey <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement = new DictionaryElementCreateDTO()
            {
                Name = name
            };
            var result = await service.AddKey(dictionaryElement);

            Assert.True(result.IsLeft);
        }
        public void GetScheduleByTeacher_ReturnCorrectDTO(string teacher, string title, int index)
        {
            using var context = PrepareData.GetDbContext(); var service = new ScheduleService(context);
            var scheduleDTO = service.GetScheduleByTeacher(teacher);

            Assert.True(scheduleDTO.IsRight);
            scheduleDTO.IfRight(r => {
                Assert.Equal(title, r.Slots[index].Title);
                Assert.Equal("teachers", r.Type);
                Assert.Equal(teacher, r.Name);
            });
        }
Example #15
0
        private async Task GetDictionaryElementGenericAsync <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement    = context.Set <T>().FirstOrDefault(e => e.Name == name);
            var dictionaryElementDTO = await service.GetDictionaryElementAsync(dictionaryElement.Id);

            Assert.True(dictionaryElementDTO.IsRight);
            dictionaryElementDTO.IfRight(r => {
                Assert.Equal(dictionaryElement.Id, r.Id);
                Assert.Equal(dictionaryElement.Name, r.Name);
            });
        }
Example #16
0
        private async Task UpdateKey <T>(string name, string newName) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var element           = context.Set <T>().FirstOrDefault(e => e.Name == name);
            var dictionaryElement = new DictionaryElementEditDTO()
            {
                Id   = element.Id,
                Name = newName
            };
            var result = await service.UpdateKey(dictionaryElement);

            Assert.True(result.IsLeft);
        }
        public LinkedList <KeyValuePair <decimal, string[]> > DownloadData(string title, float minLat, float minLon, float maxLat, float maxLon)
        {
            Models.Data data;
            using (GraphContext dopravnaSietContext = new GraphContext())
            {
                decimal id = dopravnaSietContext.Data.Max(d => d.IdData);
                dopravnaSietContext.Data.Where(d => d.Active == true).FirstOrDefault().Active = false;
                dopravnaSietContext.SaveChanges();
                SpracovanieOSMDat spracovanieOSMDat = new SpracovanieOSMDat();
                spracovanieOSMDat.SpracovanieXMLDat(dopravnaSietContext, new Models.Data()
                {
                    IdData = ++id,
                    Title  = title,
                    MinLat = minLat,
                    MinLon = minLon,
                    MaxLat = maxLat,
                    MaxLon = maxLon,
                    Active = true
                });
                data = dopravnaSietContext.Data.Where(d => d.Active == true).FirstOrDefault();
            }

            PrepareData.PrepareNodesGraph(data);
            PrepareData.PrepareDisabledMovementGraph();

            LinkedList <KeyValuePair <decimal, string[]> > array = new LinkedList <KeyValuePair <decimal, string[]> >();

            using (GraphContext dopravnaSietContext = new GraphContext())
            {
                foreach (Models.Data d in dopravnaSietContext.Data)
                {
                    string[] field = new string[5] {
                        d.Title,
                        d.MinLat.ToString(CultureInfo.InvariantCulture),
                        d.MinLon.ToString(CultureInfo.InvariantCulture),
                        d.MaxLat.ToString(CultureInfo.InvariantCulture),
                        d.MaxLon.ToString(CultureInfo.InvariantCulture)
                    };
                    if (d.Active)
                    {
                        array.AddFirst(new KeyValuePair <decimal, string[]>(d.IdData, field));
                    }
                    else
                    {
                        array.AddLast(new KeyValuePair <decimal, string[]>(d.IdData, field));
                    }
                }
            }

            return(array);
        }
Example #18
0
        private async Task AddKeyGeneric <T>() where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var dictionaryElement = new DictionaryElementCreateDTO()
            {
                Name = "elo"
            };
            var result = await service.AddKey(dictionaryElement);

            Assert.True(result.IsRight);
            var value = context.Set <T>().FirstOrDefault(e => e.Name == dictionaryElement.Name);

            Assert.NotNull(value);
        }
        private KeyValuePair <NodeGraphDTO, NodeGraphDTO> BeforeCalculateDisabledShortestPath(string startLatLon, string endLatLon)
        {
            PrepareData.PrepareNodesGraph();

            var startLat  = double.Parse(startLatLon.Split(',')[0], CultureInfo.InvariantCulture);
            var startLon  = double.Parse(startLatLon.Split(',')[1], CultureInfo.InvariantCulture);
            var startNode = PrepareData.NodesGraph.OrderBy(n1 => (Utils.Distance(n1.Key.Lat, n1.Key.Lon, startLat, startLon))).First();

            var endLat  = double.Parse(endLatLon.Split(',')[0], CultureInfo.InvariantCulture);
            var endLon  = double.Parse(endLatLon.Split(',')[1], CultureInfo.InvariantCulture);
            var endNode = PrepareData.NodesGraph.OrderBy(n1 => (Utils.Distance(n1.Key.Lat, n1.Key.Lon, endLat, endLon))).First();

            return(new KeyValuePair <NodeGraphDTO, NodeGraphDTO>(startNode.Value, endNode.Value));
        }
        public RoutesDTO DuplexDijksterDisabled(string startLatLon, string endLatLon)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateDisabledShortestPath(startLatLon, endLatLon);

            PrepareData.PutStartEnd(nodes.Key, nodes.Value);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = duplexDijkster.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            RoutesDTO routes = AfterCalculateShortestPathDuplex(node);

            PrepareData.RemoveStartEnd(nodes.Key, nodes.Value);
            return(routes);
        }
Example #21
0
 /// <summary>
 /// LoopBack测试一般只会用在文件传输上,指定的文件的内容通过CRC校验可以确保是否一样
 /// 无须按字节对比,或者equal  还是字节对比快
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="testlen"></param>
 /// <returns></returns>
 public static byte[] LoopTest(byte destid, ushort testlen)
 {
     byte[] donedata;
     byte[] data = GetData(testlen);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.ReadBuffer;
     _frame.msgSubType = (byte)MSGEncoding.ReadBuffer.ReadCO2Cache;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Example #22
0
 /// <summary>
 /// 上传升级文件到设备
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] UpGradeFile(byte destid, WriteFile.Parameter para)
 {
     byte[] donedata;
     byte[] tempdata            = GetData(para, (int)FileType.UpGradeFile);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.WriteFile;
     _frame.msgSubType = (byte)MSGEncoding.WriteFile.UpGradeFile;
     _frame.dataLen    = (ushort)tempdata.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, tempdata);
     return(donedata);
 }
Example #23
0
 //写数据
 public static byte[] WriteData(byte destid, Dictionary <string, string> datadict)
 {
     byte[] donedata;
     byte[] data = GetData(datadict);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.WriteUnit;
     _frame.msgSubType = (byte)MSGEncoding.WriteUint.WriteData;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Example #24
0
 /// <summary>
 /// 查询设备状态
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] GetDevStatus(byte destid, ushort[] unit)
 {
     byte[] donedata;
     byte[] data = GetData(unit);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.ReadUnit;
     _frame.msgSubType = (byte)MSGEncoding.ReadUint.GetDevStatus;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Example #25
0
        private async Task UpdateKey <T>(string name) where T : DictionaryElementBase, new()
        {
            using var context = PrepareData.GetDbContext(); var service = new GenericDictionaryService <T>(context);
            var element           = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Name == name);
            var dictionaryElement = new DictionaryElementEditDTO()
            {
                Id   = element.Id,
                Name = "elo"
            };
            var result = await service.UpdateKey(dictionaryElement);

            Assert.True(result.IsRight);
            var value = context.Set <T>().AsNoTracking().FirstOrDefault(e => e.Id == element.Id);

            Assert.Equal("elo", value.Name);
        }
Example #26
0
 public static void Run([CosmosDBTrigger(
                             databaseName: "FlightDataAnalyticsCosmosDB",
                             collectionName: "TestSource",
                             ConnectionStringSetting = "azurecosmosdbwn_DOCUMENTDB",
                             LeaseCollectionName = "TestSource_leases", CreateLeaseCollectionIfNotExists = true, MaxItemsPerInvocation = 2)] IReadOnlyList <Document> input, ILogger log)
 {
     if (input != null && input.Count > 0)
     {
         //var departureAirport = CosmosDBHelper.GetItemsByQuery(client, "FlightDataAnalyticsCosmosDB", "Airports", "select TOP 1 * from c where DepAptIATACode = " +input.);
         IPrepareData             prepareData = new PrepareData();
         IReadOnlyList <Document> documents   = prepareData.PrepareData(input, log);
         log.LogInformation("Documents modified " + documents);
         log.LogInformation("Documents modified " + input.Count);
         log.LogInformation("First document Id " + input[0].Id);
     }
 }
        public RoutesDTO MultiLabelDIsabled(string startLatLon, string endLatLon, string k)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateDisabledShortestPath(startLatLon, endLatLon);

            PrepareData.PutStartEnd(nodes.Key, nodes.Value);
            multiLabel.K = Int32.Parse(k);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = multiLabel.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            RoutesDTO routes = AfterCalculateShortestPathMultiLabel(node);

            PrepareData.RemoveStartEnd(nodes.Key, nodes.Value);
            return(routes);
        }
Example #28
0
 /// <summary>
 /// 向设备查询Error Code的详细解释
 /// 通过该功能,主机可向设备查询每个Error Code的详细英文解释。
 /// !!!注意:一次请求只能查询一个error code的解释。
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] ExplainError(byte destid, ushort error)
 {
     byte []             donedata;
     byte[]              data   = GetData(error);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.GetErrorInfo;
     _frame.msgSubType = (byte)MSGEncoding.Other.GetErrorInfo;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Example #29
0
 /// <summary>
 /// 读取指定配置文件,从x位置开始的n个字节数据
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] ReadDataFile(byte destid, ReadFile.Parameter para)
 {
     byte[] donedata;
     byte[] data = GetData(para);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.ReadFile;
     _frame.msgSubType = (byte)MSGEncoding.ReadFile.ReadDataFile;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Example #30
0
        public async Task DeleteActivityAsync_CorrectUpdateOnContext(
            int slot, string classgroup, string teacher, string room)
        {
            using var context = PrepareData.GetDbContext(); var activityToDelete = GetActivities(context).FirstOrDefault(
                a => a.Slot.Index == slot &&
                a.Room.Name == room &&
                a.Teacher.Name == teacher &&
                a.ClassGroup.Name == classgroup
                );
            var service = new ActivitiesService(context);
            var value   = await service.DeleteActivityAsync(activityToDelete.Id, activityToDelete.Timestamp);

            var activity = context.Activities.FirstOrDefault(a => a.Id == activityToDelete.Id);

            Assert.Null(activity);
            Assert.True(value.IsRight);
        }