コード例 #1
0
        private IndiagramForDevice ToIndiagramForDevice(Device device, Indiagram indiagram, IndiagramInfo info)
        {
            IndiagramState state = info.States.FirstOrDefault(s => s.DeviceId == device.Id);

            return ToIndiagramForDevice(indiagram, info, state);
        }
コード例 #2
0
 private IndiagramForDevice ToIndiagramForDevice(Indiagram indiagram, IndiagramInfo info, IndiagramState state)
 {
     return new IndiagramForDevice
     {
         Id = indiagram.Id,
         Version = info.Version,
         ImageHash = info.ImageHash,
         IsCategory = info.IsCategory,
         ParentId = info.ParentId,
         SoundHash = info.SoundHash,
         Text = info.Text,
         Position = info.Position,
         IsEnabled = state == null || state.IsEnabled,
         ImageFile = info.ImagePath,
         SoundFile = info.SoundPath
     };
 }
コード例 #3
0
        private IndiagramInfo CreateIndiagramInfo(Indiagram indiagram, IndiagramInfo old, long version)
        {
            IndiagramInfo info = _context.Set<IndiagramInfo>().Add(new IndiagramInfo
            {
                IndiagramId = indiagram.Id,
                Version = version,
                ParentId = old.ParentId,
                Position = old.Position,
                Text = old.Text,
                SoundPath = old.SoundPath,
                SoundHash = old.SoundHash,
                ImagePath = old.ImagePath,
                ImageHash = old.ImageHash,
                IsCategory = old.IsCategory,
            });
            DbSet<IndiagramState> stateSet = _context.Set<IndiagramState>();

            info.States = old.States.Select(x => stateSet.Add(
                new IndiagramState
                {
                    DeviceId = x.DeviceId,
                    IndiagramInfoId = info.Id,
                    IsEnabled = x.IsEnabled
                })).ToList();

            if (indiagram.LastIndiagramInfoId == null || indiagram.LastIndiagramInfo.Version < version)
            {
                indiagram.LastIndiagramInfoId = info.Id;
            }

            _context.SaveChanges();
            return info;
        }
コード例 #4
0
 public void SetIndiagramSound(IndiagramInfo indiagramInfo, string filename, byte[] fileContent)
 {
     indiagramInfo.SoundPath = filename;
     indiagramInfo.SoundHash = ComputeFileHash(fileContent);
     _context.SaveChanges();
 }
コード例 #5
0
        private bool UploadFile(IndiagramInfo indiagram, byte[] fileBuffer, string containerName)
        {
            if (fileBuffer == null || string.IsNullOrEmpty(containerName) || indiagram == null)
            {
                return false;
            }

            try
            {
                CloudBlobContainer container = _blobClient.GetContainerReference(containerName);
                container.CreateIfNotExists(BlobContainerPublicAccessType.Container);

                string filename = string.Format("{0}_{1}", indiagram.IndiagramId, indiagram.Version);

                if (container.ListBlobs(filename).Any())
                {
                    return false;
                }
                CloudBlockBlob blob = container.GetBlockBlobReference(filename);
                blob.UploadFromByteArray(fileBuffer, 0, fileBuffer.Length);
            }
            catch (Exception e)
            {
                Trace.TraceError("Exception while uploading file to container {0} : {1}\n{2}", containerName, e.Message, e.StackTrace);
                return false;
            }
            return true;
        }
コード例 #6
0
 public bool UploadSound(IndiagramInfo indiagram, byte[] fileBuffer)
 {
     return UploadFile(indiagram, fileBuffer, SOUNDS_CONTAINER);
 }
コード例 #7
0
 public bool UploadImage(IndiagramInfo indiagram, byte[] fileBuffer)
 {
     return UploadFile(indiagram, fileBuffer, IMAGES_CONTAINER);
 }