public async Task <LocationDevices> GetLocationDevices(string token)
        {
            LocationDevices locationDevices = new LocationDevices();

            using (RelayDJDevEntities db = new RelayDJDevEntities())
            {
                string userId = User.Identity.GetUserId();
                locationDevices.LocationId = db.Locations.Where(x => x.LocationOwnerId == userId).SingleOrDefault().LocationId;
            }
            List <Devices> devices = new List <Devices>();
            HttpClient     client  = new HttpClient();

            client.BaseAddress = new Uri("https://api.spotify.com/v1/me/player/devices");
            string phantomPram = "";

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpResponseMessage response = client.GetAsync(phantomPram).Result;

            if (response.IsSuccessStatusCode)
            {
                var     result      = response.Content.ReadAsStringAsync().Result;
                string  replacement = System.Text.RegularExpressions.Regex.Replace(result, @"\t|\n|\r|\\\\", "");
                JObject s           = JObject.Parse(replacement);

                JArray sentDevices = (JArray)s["devices"];
                locationDevices.devices = sentDevices.ToObject <List <Devices> >();
            }
            return(locationDevices);
        }
示例#2
0
        private void SaveArchorInfoToXml(List <TModel.Location.AreaAndDev.Archor> archorList, LocationService service)
        {
            LocationDeviceList backUpList = new LocationDeviceList();

            backUpList.DepList = new List <LocationDevices>();

            foreach (var item in archorList)
            {
                if (item.DevInfo == null)
                {
                    continue;
                }
                Area area = service.GetAreaById(item.ParentId);
                if (area == null)
                {
                    Log.Info(string.Format("Error: Dev {0} area not find...", item.DevInfo.Id));
                    continue;
                }
                LocationDevices areaList = backUpList.DepList.Find(i => i.Name == area.Name);
                if (areaList == null)
                {
                    areaList         = new LocationDevices();
                    areaList.Name    = area.Name;
                    areaList.DevList = new List <LocationDevice>();
                    backUpList.DepList.Add(areaList);
                }
                if (areaList.DevList == null)
                {
                    areaList.DevList = new List <LocationDevice>();
                }
                LocationDevice dev = new LocationDevice();
                dev.Name           = item.Name;
                dev.Abutment_DevID = item.DevInfo.Abutment_DevID;
                dev.AnchorId       = item.Code;
                dev.IP             = item.Ip;
                dev.AbsolutePosX   = item.X.ToString("f2");
                dev.AbsolutePosY   = item.Y.ToString("f2");
                dev.AbsolutePosZ   = item.Z.ToString("f2");

                DevPos pos = item.DevInfo.Pos;
                if (pos != null)
                {
                    dev.XPos = pos.PosX.ToString("f2");
                    dev.YPos = pos.PosY.ToString("f2");
                    dev.ZPos = pos.PosZ.ToString("f2");
                }
                else
                {
                    Log.Info("Error: dev.pos is null->" + item.DevInfo.Id);
                }
                areaList.DevList.Add(dev);
            }
            //string initFile = GetSaveDevDirectory() + "基站信息.xml";
            //XmlSerializeHelper.Save(backUpList, initFile, Encoding.UTF8);
            SaveArchorDevXml("基站信息.xml", backUpList);
        }
        private void MenuExportArchorData_Click(object sender, RoutedEventArgs e)
        {
            LocationDeviceList list = new LocationDeviceList();

            list.DepList = new List <LocationDevices>();

            Dictionary <int, List <Archor> > dict = new Dictionary <int, List <Archor> >();

            Bll bll        = new Bll();
            var archorList = bll.Archors.ToList();

            foreach (var item in archorList)
            {
                int pId = (int)item.ParentId;
                if (!dict.ContainsKey(pId))
                {
                    dict[pId] = new List <Archor>();
                }
                dict[pId].Add(item);
            }

            foreach (var item in dict.Keys)
            {
                var             area    = bll.Areas.Find(item);
                var             archors = dict[item];
                LocationDevices devs    = new LocationDevices();
                devs.DevList = new List <LocationDevice>();
                devs.Name    = area.Name;

                list.DepList.Add(devs);
                foreach (var archor in archors)
                {
                    var dev = new LocationDevice();
                    dev.AbsolutePosX = archor.X.ToString();
                    dev.AbsolutePosY = archor.Y.ToString();
                    dev.AbsolutePosZ = archor.Z.ToString();
                    dev.AnchorId     = archor.Code;
                    dev.IP           = archor.Ip;
                    dev.Name         = archor.Name;
                    dev.XPos         = archor.DevInfo.PosX.ToString();
                    dev.YPos         = archor.DevInfo.PosY.ToString();
                    dev.ZPos         = archor.DevInfo.PosZ.ToString();
                    devs.DevList.Add(dev);
                }
            }

            string basePath = AppDomain.CurrentDomain.BaseDirectory;
            string filePath = basePath + "Data\\基站信息\\基站信息.xml";

            XmlSerializeHelper.Save(list, filePath);

            FileInfo fi = new FileInfo(filePath);

            Process.Start(fi.Directory.FullName);
        }