private static void getContentMD5List(DeviceOperationData deviceOperationData)
 {
     var folders = deviceOperationData.OperationParameters;
     bool hasInvalidFolderNames = folders.Any(folder => SystemSupport.ReservedDomainNames.Any(folder.StartsWith));
     if(hasInvalidFolderNames)
         throw new InvalidDataException("Invalid parameter for remote folder name");
     var owner = InformationContext.CurrentOwner;
     var md5List = folders.SelectMany(folder =>
         {
             if(String.IsNullOrEmpty(folder))
                 throw new InvalidDataException("Empty folder not supported as prefix");
             if (folder.EndsWith("/") == false)
                 folder += "/";
             var result = owner.GetOwnerBlobListing(folder, true)
                               .Cast<CloudBlockBlob>()
                               .Select(blob => new ContentItemLocationWithMD5
                                   {
                                       ContentLocation = StorageSupport.RemoveOwnerPrefixIfExists(blob.Name),
                                       ContentMD5 = blob.Properties.ContentMD5
                                   });
             return result;
         }).ToArray();
     deviceOperationData.OperationSpecificContentData = md5List;
     deviceOperationData.OperationResult = true;
 }
 public static SyncCopyContentToDeviceTarget.CallPrepareTargetAndListItemsToCopyReturnValue ExecuteMethod_CallPrepareTargetAndListItemsToCopy(AuthenticatedAsActiveDevice authenticatedAsActiveDevice, ContentItemLocationWithMD5[] thisSideContentMd5List)
 {
     DeviceOperationData deviceOperationData = new DeviceOperationData
         {
             OperationRequestString = "SYNCCOPYCONTENT",
             OperationSpecificContentData = thisSideContentMd5List,
             OperationParameters = new string[] { SyncSupport.RelativeRootFolderValue}
         };
     deviceOperationData = DeviceSupport.ExecuteRemoteOperation<DeviceOperationData>(authenticatedAsActiveDevice.ID,
                                                                                     "TheBall.CORE.RemoteDeviceCoreOperation", deviceOperationData);
     var returnValue = new SyncCopyContentToDeviceTarget.CallPrepareTargetAndListItemsToCopyReturnValue
         {
             ItemsToCopy = deviceOperationData.OperationSpecificContentData.Where(item => item.ItemDatas.Any(iData => iData.DataName == "OPTODO" && iData.ItemTextData == "COPY")).ToArray(),
             ItemsDeleted = deviceOperationData.OperationSpecificContentData.Where(item => item.ItemDatas.Any(iData => iData.DataName == "OPDONE" && iData.ItemTextData == "DELETED")).ToArray()
         };
     return returnValue;
 }
 private static void copySyncedContentToOwner(DeviceOperationData deviceOperationData)
 {
     string folderPrefix = deviceOperationData.OperationParameters[0];
     if (!isValidFolderName(folderPrefix))
         throw new InvalidDataException("Invalid data for remote folder name");
     var currentDevice = InformationContext.CurrentExecutingForDevice;
     string deviceInputRoot = getDeviceInputRoot(currentDevice.ID);
     string syncSourceRootFolder = deviceInputRoot + folderPrefix;
     var owner = InformationContext.CurrentOwner;
     ContentItemLocationWithMD5[] syncContentList = owner.GetOwnerBlobListing(syncSourceRootFolder, true)
                                                         .Cast<CloudBlockBlob>()
                                                         .Select(blob => new ContentItemLocationWithMD5
                                                             {
                                                                 ContentLocation = StorageSupport.RemoveOwnerPrefixIfExists(blob.Name)
                                                                     .Substring(syncSourceRootFolder.Length),
                                                                 ContentMD5 = blob.Properties.ContentMD5
                                                             }).ToArray();
     string syncTargetRootFolder = folderPrefix;
     SyncSupport.SynchronizeSourceListToTargetFolder(syncSourceRootFolder, syncContentList, syncTargetRootFolder);
 }
 public static void ExecuteMethod_PerformOperation(DeviceMembership currentDevice, DeviceOperationData deviceOperationData)
 {
     switch (deviceOperationData.OperationRequestString)
     {
         case "SYNCCOPYCONTENT":
             performSyncQueryForCopyContent(currentDevice, deviceOperationData);
             break;
         case "DELETEREMOTEDEVICE":
             currentDevice.DeleteInformationObject();
             break;
         case "GETCONTENTMD5LIST":
             getContentMD5List(deviceOperationData);
             break;
         case "COPYSYNCEDCONTENTTOOWNER":
             copySyncedContentToOwner(deviceOperationData);
             break;
         default:
             throw new NotImplementedException("Not implemented RemoteDevice operation for request string: " + deviceOperationData.OperationRequestString);
     }
     deviceOperationData.OperationResult = true;
 }
 public static void ExecuteMethod_SerializeDeviceOperationDataToOutput(Stream outputStream, DeviceOperationData deviceOperationData)
 {
     JSONSupport.SerializeToJSONStream(deviceOperationData, outputStream);
 }
        private static void performSyncQueryForCopyContent(DeviceMembership currentDevice, DeviceOperationData deviceOperationData)
        {
            string targetNamedFolder = deviceOperationData.OperationParameters != null && deviceOperationData.OperationParameters.Length > 0 ?
                deviceOperationData.OperationParameters[0] : SyncSupport.RelativeRootFolderValue;
            List<ContentItemLocationWithMD5> itemsToCopy = new List<ContentItemLocationWithMD5>();
            List<ContentItemLocationWithMD5> itemsDeleted = new List<ContentItemLocationWithMD5>();
            SyncSupport.CopySourceToTargetMethod copySourceToTarget = (location, blobLocation) => itemsToCopy.Add(new ContentItemLocationWithMD5
                {
                    ContentLocation = StorageSupport.RemoveOwnerPrefixIfExists(location),
                    ItemDatas = new ItemData[] {new ItemData {DataName = "OPTODO", ItemTextData = "COPY"}}
                });
            SyncSupport.DeleteObsoleteTargetMethod deleteObsoleteTarget = (location) =>
                {
                    itemsDeleted.Add(new ContentItemLocationWithMD5
                        {
                            ContentLocation = location,
                            ItemDatas = new ItemData[] { new ItemData { DataName = "OPDONE", ItemTextData = "DELETED"}}
                        });
                    SyncSupport.DeleteObsoleteTarget(location);
                };

            string syncTargetRootFolder = getDeviceInputRoot(currentDevice.ID) + targetNamedFolder;
            if (syncTargetRootFolder.EndsWith("/") == false)
                syncTargetRootFolder += "/";
            SyncSupport.SynchronizeSourceListToTargetFolder(SyncSupport.RelativeRootFolderValue, deviceOperationData.OperationSpecificContentData, syncTargetRootFolder,
                                                            copySourceToTarget, deleteObsoleteTarget);
            deviceOperationData.OperationSpecificContentData = itemsToCopy.Union(itemsDeleted).ToArray();
        }