Esempio n. 1
0
 public static FolderSyncItem CreateFromStagingRemoteDataFolder(string stagingRootFolder, string dataFolder)
 {
     if (string.IsNullOrEmpty(dataFolder))
         return null;
     if (dataFolder.EndsWith("/") == false)
         dataFolder += "/";
     var folderSyncItem = new FolderSyncItem
         {
             LocalFullPath = Path.Combine(stagingRootFolder, dataFolder),
             RemoteFolder = dataFolder,
             SyncDirection = "DOWN",
             SyncItemName = "DYNAMIC",
             SyncType = "DEV",
         };
     return folderSyncItem;
 }
Esempio n. 2
0
 public static FolderSyncItem AddSyncFolder(string connectionName, string syncName, string syncType, string syncDirection, string localFullPath, string remoteFolder)
 {
     localFullPath = Path.GetFullPath(localFullPath);
     var connection = GetConnection(connectionName);
     if(connection.FolderSyncItems.Any(item => item.SyncItemName == syncName))
         throw new ArgumentException("Sync folder already exists: " + syncName);
     var syncFolderItem = new FolderSyncItem
         {
             SyncItemName = syncName,
             SyncDirection = syncDirection,
             SyncType = syncType,
             LocalFullPath = localFullPath,
             RemoteFolder = remoteFolder
         };
     syncFolderItem.Validate();
     connection.FolderSyncItems.Add(syncFolderItem);
     return syncFolderItem;
 }
Esempio n. 3
0
 public static FolderSyncItem CreateFromStagingFolderDirectory(string stagingRootFolder, string stagingSubfolder)
 {
     if (stagingSubfolder.StartsWith("DEV_") == false && stagingSubfolder.StartsWith("LIVE_") == false)
         return null;
     string remoteFolder;
     string syncType = null;
     if (stagingSubfolder.StartsWith("DEV_"))
     {
         remoteFolder = stagingSubfolder.Substring(4);
         syncType = "DEV";
     }
     else
     {
         if (stagingSubfolder == "LIVE_wwwsite")
         {
             remoteFolder = "wwwsite";
             syncType = "wwwsite";
         }
         else
         {
             remoteFolder = stagingSubfolder;
             syncType = "LIVE";
         }
     }
     if(string.IsNullOrEmpty(remoteFolder))
         throw new InvalidDataException("Invalid remote staging subfolder: " + stagingSubfolder);
     var folderSyncItem = new FolderSyncItem
         {
             LocalFullPath = Path.Combine(stagingRootFolder, stagingSubfolder),
             RemoteFolder = remoteFolder,
             SyncDirection = "UP",
             SyncItemName = "DYNAMIC",
             SyncType = syncType
         };
     return folderSyncItem;
 }
Esempio n. 4
0
        public static void DownSync(Connection connection, FolderSyncItem downSyncItem)
        {
            var rootFolder = downSyncItem.LocalFullPath;
            var myDataContents = FileSystemSupport.GetContentRelativeFromRoot(rootFolder);
            foreach (var myDataItem in myDataContents)
            {
                myDataItem.ContentLocation = downSyncItem.RemoteFolder + myDataItem.ContentLocation;
            }
            ContentItemLocationWithMD5[] remoteContentSourceList = getConnectionContentMD5s(connection, new string[] { downSyncItem.RemoteFolder });
            var device = connection.Device;
            int stripRemoteFolderIndex = downSyncItem.RemoteFolder.Length;
            SyncSupport.SynchronizeSourceListToTargetFolder(
                remoteContentSourceList, myDataContents,
                delegate(ContentItemLocationWithMD5 source, ContentItemLocationWithMD5 target)
                    {
                        string targetFullName = Path.Combine(rootFolder, target.ContentLocation.Substring(stripRemoteFolderIndex));
                        string targetDirectoryName = Path.GetDirectoryName(targetFullName);
                        try
                        {
                            if (Directory.Exists(targetDirectoryName) == false)
                                Directory.CreateDirectory(targetDirectoryName);
                        }
                        catch
                        {

                        }
                        //Console.Write("Copying: " + source.ContentLocation);
                        DeviceSupport.FetchContentFromDevice(device, source.ContentLocation,
                                                             targetFullName);
                        //Console.WriteLine(" ... done");
                        Console.WriteLine("Copied: " + source.ContentLocation);
                    }, delegate(ContentItemLocationWithMD5 target)
                        {
                            string targetContentLocation = target.ContentLocation.Substring(stripRemoteFolderIndex);
                            string targetFullName = Path.Combine(rootFolder, targetContentLocation);
                            File.Delete(targetFullName);
                            Console.WriteLine("Deleted: " + targetContentLocation);
                        }, 10);
        }
Esempio n. 5
0
        public static void UpSync(Connection connection, FolderSyncItem upSyncItem)
        {
            var rootFolder = upSyncItem.LocalFullPath;
            var sourceList = FileSystemSupport.GetContentRelativeFromRoot(rootFolder);
            string destinationPrefix = upSyncItem.SyncType == "DEV" ? "DEV_" : "";
            string destinationCopyRoot = destinationPrefix + upSyncItem.RemoteFolder;
            if (destinationCopyRoot.EndsWith("/") == false)
                destinationCopyRoot += "/";
            ContentItemLocationWithMD5[] remoteContentBasedActionList = getConnectionToCopyMD5s(connection, sourceList, destinationCopyRoot);

            var itemsToCopy = remoteContentBasedActionList.Where(item => item.ItemDatas.Any(iData => iData.DataName == "OPTODO" && iData.ItemTextData == "COPY")).ToArray();
            var itemsDeleted = remoteContentBasedActionList.Where(item => item.ItemDatas.Any(iData => iData.DataName == "OPDONE" && iData.ItemTextData == "DELETED")).ToArray();
            var device = connection.Device;
            SyncSupport.SynchronizeSourceListToTargetFolder(
                itemsToCopy, new ContentItemLocationWithMD5[0],
                delegate(ContentItemLocationWithMD5 source, ContentItemLocationWithMD5 target)
                    {
                        string fullLocalName = Path.Combine(rootFolder, source.ContentLocation);
                        string destinationContentName = destinationCopyRoot + source.ContentLocation;
                        DeviceSupport.PushContentToDevice(device, fullLocalName, destinationContentName);
                        Console.WriteLine("Uploaded: " + source.ContentLocation);
                    },
                target =>
                    {

                    }, 10);
            var dod = device.ExecuteDeviceOperation(new DeviceOperationData
                {
                    OperationParameters = new[] {destinationCopyRoot},
                    OperationRequestString = "COPYSYNCEDCONTENTTOOWNER"
                });
            if(dod.OperationResult == false)
                throw new OperationCanceledException("Error on remote call operation");
            Console.WriteLine("Finished copying data to owner location: " + destinationCopyRoot);
        }