DeviceUniqueId,Azure移动服务
本文关键字:服务 移动 Azure DeviceUniqueId | 更新日期: 2023-09-27 18:05:44
问题
我有Windows Phone 8应用程序。从应用程序用户可以上传照片,然后添加条目到表中使用Azure移动服务进行处理。表中的一列是DeviceId。
在另一个视图中,人们可以加载他们已经添加的条目列表。不幸的是,对于一些用户来说,这似乎不起作用,因为它没有返回任何条目(我可以在数据库中找到它们的条目)。
请帮忙,因为我不明白为什么它适用于某些用户而不是其他人。
这是我如何得到DeviceUniqueId:
byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);
下面是我添加新条目的方法:TimelapseBatch。DeviceId(构造函数的第一个参数是字符串)
var item = new TimelapseBatch(DeviceInfo.DeviceUniqueId, /*other properties go here*/);
await App.MobileService.GetTable<TimelapseBatch>().InsertAsync(item);
如何查询服务
private readonly IMobileServiceTable<TimelapseBatch> batchesTable = App.MobileService.GetTable<TimelapseBatch>();
...
batches = await batchesTable.Where(t => t.DeviceId == DeviceInfo.DeviceUniqueId).ToListAsync();
var processed = batches.Where(t => t.StatusCode == (int)BatchStatus.Processed).OrderByDescending(t => t.Processed).Select(t => new Timelapse()
{
Page = new Uri(t.PlayerUrl),
Thumbnail = new Uri(t.ThumbnailUrl)
}).ToList();
显然,所有这些处理后不包含任何条目,即使根据数据库它应该。
我确实验证过,当相同的用户(即使是那些遇到问题的用户)创建多个条目时,数据库中的DeviceId似乎是相同的。
请帮忙,为什么它可以为一些用户工作,而不是其他人?
因此,当我使用遇到问题的客户的DeviceUniqueId时,我可以重现问题。
同样,如果我这样做:
batches = await batchesTable.Take(200).ToListAsync();
batches = batches.Where(t => t.DeviceId == DeviceInfo.DeviceUniqueId).ToList();
按预期填充批。然而,如果我这样做(下面),批次是空的(我指定200个用于测试目的,因为条目较少)。
batches = await batchesTable.Take(200).Where(t => t.DeviceId == DeviceInfo.DeviceUniqueId).ToListAsync();
更新2
如果DeviceId包含"+"号,比较似乎失败。如果我做
t.DeviceId.Substring(0,X) == DeviceInfo.DeviceUniqueId.Substring(0,X)
其中X是+号的位置,则按预期工作。我的天啊现在我正拼命地想找到一个解决办法。
更新3
类型定义:
public enum BatchStatus
{
QueuedUp = 0,
Processed = 1,
Error = 2,
}
public class TimelapseBatch
{
public TimelapseBatch()
{
TimelapseId = String.Empty;
DeviceId = String.Empty;
ContainerUrl = String.Empty;
VideoMp4Url = String.Empty;
VideoWebmUrl = String.Empty;
ThumbnailUrl = String.Empty;
Uploaded = new DateTime(2000, 1, 1);
Processed = new DateTime(2000, 1, 1);
PlayerUrl = String.Empty;
}
public TimelapseBatch(string deviceId, string timelapseId, string containerUrl, int photosCount, int fps):this()
{
DeviceId = deviceId;
ContainerUrl = containerUrl;
TimelapseId = timelapseId;
PhotosCount = photosCount;
Fps = fps;
StatusCode = (int) BatchStatus.QueuedUp;
Uploaded = DateTime.Now;
}
public int Id { get; set; }
public int StatusCode { get; set; }
public string TimelapseId { get; set; }
public string DeviceId { get; set; }
public string ContainerUrl { get; set; }
public int PhotosCount { get; set; }
public int Fps { get; set; }
public DateTime Uploaded { get; set; }
public string VideoMp4Url { get; set; }
public string VideoWebmUrl { get; set; }
public string ThumbnailUrl { get; set; }
public double VideoSize { get; set; }
public DateTime Processed { get; set; }
public string PlayerUrl { get; set; }
}
现在解决方案:
batches = await batchesTable.Where(t => t.DeviceId == DeviceInfo.DeviceUniqueId.Replace("+", "%2B") || t.DeviceId == DeviceInfo.DeviceUniqueId).ToListAsync();
我必须手动转义+符号为%2B。添加了额外的条件,以防Azure团队修复这个错误。