internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update) { if (this.SyncFromAllServersCallback != null) { DS_REPSYNCALL_UPDATE dSREPSYNCALLUPDATE = new DS_REPSYNCALL_UPDATE(); Marshal.PtrToStructure(update, dSREPSYNCALLUPDATE); SyncFromAllServersEvent syncFromAllServersEvent = dSREPSYNCALLUPDATE.eventType; IntPtr intPtr = dSREPSYNCALLUPDATE.pErrInfo; SyncFromAllServersOperationException syncFromAllServersOperationException = null; if (intPtr != (IntPtr)0) { syncFromAllServersOperationException = ExceptionHelper.CreateSyncAllException(intPtr, true); if (syncFromAllServersOperationException == null) { return(true); } } string stringUni = null; string str = null; intPtr = dSREPSYNCALLUPDATE.pSync; if (intPtr != (IntPtr)0) { DS_REPSYNCALL_SYNC dSREPSYNCALLSYNC = new DS_REPSYNCALL_SYNC(); Marshal.PtrToStructure(intPtr, dSREPSYNCALLSYNC); stringUni = Marshal.PtrToStringUni(dSREPSYNCALLSYNC.pszDstId); str = Marshal.PtrToStringUni(dSREPSYNCALLSYNC.pszSrcId); } SyncUpdateCallback syncFromAllServersCallback = this.SyncFromAllServersCallback; return(syncFromAllServersCallback(syncFromAllServersEvent, stringUni, str, syncFromAllServersOperationException)); } else { return(true); } }
public Attempt <int> Deploy(string folder, XElement configNode, SyncUpdateCallback callback) { var config = LoadSettings(configNode); try { var cleanFolder = $"{folder.Replace("/", "\\")}\\".Replace("\\\\", "\\"); var connectionInfo = new ConnectionInfo(config.Server, config.Username, new PasswordAuthenticationMethod(config.Username, config.Password), new PrivateKeyAuthenticationMethod("rsa.key")); int count = 0; using (var client = new SftpClient(connectionInfo)) { callback?.Invoke("Connecting to Server", 1, 100); client.Connect(); count = UploadFolder(config.Folder, cleanFolder, "", client, callback); callback?.Invoke("Complete", 100, 100); client.Disconnect(); } return(Attempt.Succeed(count)); } catch (Exception ex) { return(Attempt.Fail(0, ex)); } }
public Attempt <int> Publish(Guid id, string server, SyncUpdateCallback updateCallback) { var source = $"{syncRoot}\\{id}"; var deployConfig = LoadDeployerConfig(server); if (deployConfig == null) { throw new ArgumentException("No deploy config for server", nameof(server)); } var deployerAlias = deployConfig.Attribute("alias").ValueOrDefault(string.Empty); if (string.IsNullOrWhiteSpace(deployerAlias)) { throw new ArgumentException("No deployer alias in config", nameof(server)); } var deployer = deployers.GetDeployer(deployerAlias); if (deployer != null) { return(deployer.Deploy(source, deployConfig, updateCallback)); } return(Attempt.Fail(0)); }
public void SyncFromAllServersCallback_Set_GetReturnsExpected() { SyncUpdateCallback callback = SyncUpdateCallback; var controller = new SubController { SyncFromAllServersCallback = callback }; Assert.Equal(callback, controller.SyncFromAllServersCallback); }
public Attempt <int> Deploy(string folder, XElement config, SyncUpdateCallback update) { var settings = LoadSettings(config); update?.Invoke($"Copying site to {Path.GetFileName(folder)}", 1, 2); Directory.CreateDirectory(settings.Folder); templateFileService.CopyFolder(folder, settings.Folder); return(Attempt.Succeed(1)); }
internal bool SyncAllCallbackRoutine(IntPtr data, IntPtr update) { if (SyncFromAllServersCallback == null) { // user does not specify callback, resume the DsReplicaSyncAll execution return(true); } else { // user specifies callback // our callback is invoked, update should not be NULL, do assertion here Debug.Assert(update != (IntPtr)0); DS_REPSYNCALL_UPDATE syncAllUpdate = new DS_REPSYNCALL_UPDATE(); Marshal.PtrToStructure(update, syncAllUpdate); // get the event type SyncFromAllServersEvent eventType = syncAllUpdate.eventType; // get the error information IntPtr temp = syncAllUpdate.pErrInfo; SyncFromAllServersOperationException exception = null; if (temp != (IntPtr)0) { // error information is available exception = ExceptionHelper.CreateSyncAllException(temp, true); if (exception == null) { // this is the special case that we ingore the failure when SyncAllOptions.CheckServerAlivenessOnly is specified return(true); } } string targetName = null; string sourceName = null; temp = syncAllUpdate.pSync; if (temp != (IntPtr)0) { DS_REPSYNCALL_SYNC sync = new DS_REPSYNCALL_SYNC(); Marshal.PtrToStructure(temp, sync); targetName = Marshal.PtrToStringUni(sync.pszDstId); sourceName = Marshal.PtrToStringUni(sync.pszSrcId); } // invoke the client callback SyncUpdateCallback clientCallback = SyncFromAllServersCallback; return(clientCallback(eventType, targetName, sourceName, exception)); } }
public Attempt <int> Deploy(string folder, XElement config, SyncUpdateCallback update) { var settings = LoadSettings(config); var client = new FtpClient(settings.Server); client.Credentials = new NetworkCredential(settings.Username, settings.Password); client.EncryptionMode = FtpEncryptionMode.Explicit; client.SslProtocols = SslProtocols.Default | SslProtocols.Tls11 | SslProtocols.Tls12; client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate); update?.Invoke("connecting to server", 1, 100); client.Connect(); var count = UploadFolder(settings.Folder, folder, "", client, update); client.Disconnect(); return(Attempt.Succeed(count)); }
/// <summary> /// don't think you can get dictionary items via the entity service :( /// </summary> public IEnumerable <uSyncAction> ExportAll(Guid parent, string folder, HandlerSettings config, SyncUpdateCallback callback) { var actions = new List <uSyncAction>(); var items = new List <IDictionaryItem>(); if (parent == Guid.Empty) { items = localizationService.GetRootDictionaryItems().ToList(); } else { items = localizationService.GetDictionaryItemChildren(parent).ToList(); } int count = 0; foreach (var item in items) { count++; callback?.Invoke(item.ItemKey, count, items.Count); actions.AddRange(Export(item, folder, config)); actions.AddRange(ExportAll(item.Key, folder, config, callback)); } return(actions); }
public override IEnumerable <uSyncAction> ExportAll(string folder, HandlerSettings config, SyncUpdateCallback callback) { syncFileService.CleanFolder(folder); return(ExportAll(Guid.Empty, folder, config, callback)); }
public IEnumerable <uSyncAction> Export(string folder, SyncEventCallback callback = null, SyncUpdateCallback update = null) => Export(folder, default(SyncHandlerOptions), new uSyncCallbacks(callback, update));
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr zero = IntPtr.Zero; if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)); int errorCode = delegateForFunctionPointer(handle, partition, ((int)option) | 4, syncAllFunctionPointer, IntPtr.Zero, ref zero); try { if (zero != IntPtr.Zero) { SyncFromAllServersOperationException exception = ExceptionHelper.CreateSyncAllException(zero, false); if (exception != null) { throw exception; } } else if (errorCode != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(errorCode, false)); } } finally { if (zero != IntPtr.Zero) { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LocalFree(zero); } } }
public uSyncCallbacks(SyncEventCallback callback, SyncUpdateCallback update) { this.Callback = callback; this.Update = update; }
/// <summary> /// this is the simple interface, based purely on level, /// we could get clever (like dependency trees for content types) /// /// but that would have to be implimented lower down (and it doesn't /// really matter for things in containers only things that parent others). /// </summary> /// <param name="folder"></param> /// <param name="force"></param> /// <param name="updates"></param> /// <returns></returns> protected override IEnumerable <uSyncAction> ImportFolder(string folder, HandlerSettings config, Dictionary <string, TObject> updates, bool force, SyncUpdateCallback callback) { // if not using flat, then directory structure is doing // this for us. if (config.UseFlatStructure == false) { return(base.ImportFolder(folder, config, updates, force, callback)); } List <uSyncAction> actions = new List <uSyncAction>(); var files = syncFileService.GetFiles(folder, "*.config"); List <LeveledFile> nodes = new List <LeveledFile>(); callback?.Invoke("Calculating import order", 0, 1); logger.Verbose(handlerType, "Calculating import order"); foreach (var file in files) { try { var node = LoadNode(file); if (node != null) { nodes.Add(new LeveledFile { Level = node.GetLevel(), File = file }); } } catch (XmlException ex) { // one of the files is wrong. (do we stop or carry on) logger.Warn(handlerType, $"Error loading file: {file} [{ex.Message}]"); actions.Add(uSyncActionHelper <TObject> .SetAction( SyncAttempt <TObject> .Fail(Path.GetFileName(file), ChangeType.Fail, $"Failed to Load: {ex.Message}"), file, false)); } } // loaded - now process. var flags = SerializerFlags.None; if (force) { flags |= SerializerFlags.Force; } if (config.BatchSave) { flags |= SerializerFlags.DoNotSave; } var cleanMarkers = new List <string>(); foreach (var item in nodes.OrderBy(x => x.Level).Select((Node, Index) => new { Node, Index })) { var filename = Path.GetFileNameWithoutExtension(item.Node.File); callback?.Invoke($"{filename}", item.Index, nodes.Count); logger.Verbose(handlerType, "{Index} Importing: {File}, [Level {Level}]", item.Index, filename, item.Node.Level); var attempt = Import(item.Node.File, config, flags); if (attempt.Success) { if (attempt.Change == ChangeType.Clean) { cleanMarkers.Add(item.Node.File); } else if (attempt.Item != null) { updates.Add(item.Node.File, attempt.Item); } } actions.Add(uSyncActionHelper <TObject> .SetAction(attempt, item.Node.File, IsTwoPass)); } if (flags.HasFlag(SerializerFlags.DoNotSave) && updates.Any()) { // bulk save - should be the fastest way to do this callback?.Invoke($"Saving {updates.Count()} changes", 1, 1); serializer.Save(updates.Select(x => x.Value)); } var folders = syncFileService.GetDirectories(folder); foreach (var children in folders) { actions.AddRange(ImportFolder(children, config, updates, force, callback)); } if (actions.All(x => x.Success)) { // LINQ // actions.AddRange(cleanMarkers.Select(x => CleanFolder(x)).SelectMany(a => a)); // only if there are no fails. // then we consider the folder safe to clean foreach (var cleanfile in cleanMarkers) { actions.AddRange(CleanFolder(cleanfile, false, config.UseFlatStructure)); } // remove the actual cleans (they will have been replaced by the deletes actions.RemoveAll(x => x.Change == ChangeType.Clean); } callback?.Invoke("", 1, 1); return(actions); }
private void ProcessSecondPasses(IDictionary <string, TObject> updates, List <uSyncAction> actions, HandlerSettings config, SyncUpdateCallback callback = null) { List <TObject> updatedItems = new List <TObject>(); foreach (var item in updates.Select((update, Index) => new { update, Index })) { callback?.Invoke($"Second Pass {Path.GetFileName(item.update.Key)}", item.Index, updates.Count); var attempt = ImportSecondPass(item.update.Key, item.update.Value, config, callback); if (attempt.Success) { // if the second attempt has a message on it, add it to the first attempt. if (!string.IsNullOrWhiteSpace(attempt.Message)) { if (actions.Any(x => x.FileName == item.update.Key)) { var action = actions.FirstOrDefault(x => x.FileName == item.update.Key); actions.Remove(action); action.Message += attempt.Message; actions.Add(action); } } if (attempt.Change > ChangeType.NoChange) { updatedItems.Add(attempt.Item); } } else { // the second attempt failed - update the action. if (actions.Any(x => x.FileName == item.update.Key)) { var action = actions.FirstOrDefault(x => x.FileName == item.update.Key); actions.Remove(action); action.Success = attempt.Success; action.Message = $"Second Pass Fail: {attempt.Message}"; action.Exception = attempt.Exception; actions.Add(action); } } } if (config.BatchSave) { callback?.Invoke($"Saving {updatedItems.Count} Second Pass Items", 2, 3); serializer.Save(updatedItems); } }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr errorInfo = (IntPtr)0; if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, "partition"); } // we want to return the dn instead of DNS guid // call DsReplicaSyncAllW IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaSyncAllW dsReplicaSyncAllW = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int result = dsReplicaSyncAllW(handle, partition, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, ref errorInfo); try { // error happens during the synchronization if (errorInfo != (IntPtr)0) { SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) { return; } else { throw e; } } else { // API does not return error infor occurred during synchronization, but result is not success. if (result != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false)); } } } finally { // release the memory if (errorInfo != (IntPtr)0) { UnsafeNativeMethods.LocalFree(errorInfo); } } }
virtual public void ImportSecondPass(string file, TObject item, HandlerSettings config, SyncUpdateCallback callback) { if (IsTwoPass) { try { syncFileService.EnsureFileExists(file); var flags = SerializerFlags.None; if (config.BatchSave) { flags |= SerializerFlags.DoNotSave; } using (var stream = syncFileService.OpenRead(file)) { var node = XElement.Load(stream); serializer.DeserializeSecondPass(item, node, flags); stream.Dispose(); } } catch (Exception ex) { logger.Warn <TObject>($"Second Import Failed: {ex.Message}"); } } }
protected virtual IEnumerable <uSyncAction> ImportFolder(string folder, HandlerSettings config, Dictionary <string, TObject> updates, bool force, SyncUpdateCallback callback) { List <uSyncAction> actions = new List <uSyncAction>(); var files = syncFileService.GetFiles(folder, "*.config"); var flags = SerializerFlags.None; if (force) { flags |= SerializerFlags.Force; } if (config.BatchSave) { flags |= SerializerFlags.DoNotSave; } int count = 0; int total = files.Count(); foreach (string file in files) { count++; callback?.Invoke($"Importing {Path.GetFileNameWithoutExtension(file)}", count, total); var attempt = Import(file, config, flags); if (attempt.Success && attempt.Item != null) { updates.Add(file, attempt.Item); } var action = uSyncActionHelper <TObject> .SetAction(attempt, file, IsTwoPass); if (attempt.Details != null && attempt.Details.Any()) { action.Details = attempt.Details; } actions.Add(action); } // bulk save .. if (flags.HasFlag(SerializerFlags.DoNotSave) && updates.Any()) { callback?.Invoke($"Saving {updates.Count()} changes", 1, 1); serializer.Save(updates.Select(x => x.Value)); } var folders = syncFileService.GetDirectories(folder); foreach (var children in folders) { actions.AddRange(ImportFolder(children, config, updates, force, callback)); } callback?.Invoke("", 1, 1); return(actions); }
public IEnumerable <uSyncAction> ImportAll(string folder, HandlerSettings config, bool force, SyncUpdateCallback callback = null) { logger.Info <uSync8BackOffice>("Running Import: {0}", Path.GetFileName(folder)); var actions = new List <uSyncAction>(); var updates = new Dictionary <string, TObject>(); actions.AddRange(ImportFolder(folder, config, updates, force, callback)); if (updates.Any()) { int count = 0; foreach (var update in updates) { count++; callback?.Invoke($"Second Pass {Path.GetFileName(update.Key)}", count, updates.Count); ImportSecondPass(update.Key, update.Value, config, callback); } } callback?.Invoke("Done", 1, 1); return(actions); }
public override IEnumerable <uSyncAction> ExportAll(string folder, HandlerSettings config, SyncUpdateCallback callback) { var items = syncFormService.GetAllForms(); var actions = new List <uSyncAction>(); foreach (var item in items) { callback?.Invoke(GetItemName(item), 2, 4); actions.AddRange(Export(item, folder, config)); } return(actions); }
/// <inheritdoc/> protected override IEnumerable <uSyncAction> ImportFolder(string folder, HandlerSettings config, Dictionary <string, TObject> updates, bool force, SyncUpdateCallback callback) { // if not using flat then directory structure is sorting them for us. if (config.UseFlatStructure == false) { return(base.ImportFolder(folder, config, updates, force, callback)); } List <uSyncAction> actions = new List <uSyncAction>(); callback?.Invoke("Calculating import order", 0, 1); logger.LogDebug("Calculating import order"); var orderedFiles = GetLevelOrderedFiles(folder, actions); // process. var flags = SerializerFlags.None; if (force) { flags |= SerializerFlags.Force; } var cleanMarkers = new List <string>(); foreach (var item in orderedFiles.Select((Node, Index) => new { Node, Index })) { var filename = Path.GetFileNameWithoutExtension(item.Node.File); callback?.Invoke($"{filename}", item.Index, orderedFiles.Count); logger.LogTrace("{Index} Importing: {File}, [Level {Level}]", item.Index, filename, item.Node.Level); var result = Import(item.Node.File, config, flags); foreach (var attempt in result) { if (attempt.Success) { if (attempt.Change == ChangeType.Clean) { cleanMarkers.Add(item.Node.File); } else if (attempt.Item != null && attempt.Item is TObject attemptItem) { updates.Add(item.Node.File, attemptItem); } } if (attempt.Change != ChangeType.Clean) { actions.Add(attempt); } } } if (flags.HasFlag(SerializerFlags.DoNotSave) && updates.Any()) { // bulk save - should be the fastest way to do this callback?.Invoke($"Saving {updates.Count()} changes", 1, 1); serializer.Save(updates.Select(x => x.Value)); } var folders = syncFileService.GetDirectories(folder); foreach (var children in folders) { actions.AddRange(ImportFolder(children, config, updates, force, callback)); } if (actions.All(x => x.Success)) { // LINQ // actions.AddRange(cleanMarkers.Select(x => CleanFolder(x)).SelectMany(a => a)); // only if there are no fails. // then we consider the folder safe to clean foreach (var cleanfile in cleanMarkers) { actions.AddRange(CleanFolder(cleanfile, false, config.UseFlatStructure)); } // remove the actual cleans (they will have been replaced by the deletes actions.RemoveAll(x => x.Change == ChangeType.Clean); } callback?.Invoke("", 1, 1); return(actions); }
/// <inheritdoc/> public override IEnumerable <uSyncAction> ExportAll(string folder, HandlerSettings config, SyncUpdateCallback callback) { var actions = new List <uSyncAction>(); var domains = domainService.GetAll(true).ToList(); int count = 0; foreach (var domain in domains) { count++; if (domain != null) { callback?.Invoke(domain.DomainName, count, domains.Count); actions.AddRange(Export(domain, folder, config)); } } callback?.Invoke("done", 1, 1); return(actions); }
public IEnumerable <uSyncAction> ImportAll(string folder, HandlerSettings config, bool force, SyncUpdateCallback callback = null) { var sw = Stopwatch.StartNew(); logger.Debug(handlerType, "{alias} ImportAll: {fileName}", this.Alias, Path.GetFileName(folder)); var actions = new List <uSyncAction>(); var updates = new Dictionary <string, TObject>(); runtimeCache.ClearByKey($"keycache_{this.Alias}"); actions.AddRange(ImportFolder(folder, config, updates, force, callback)); if (updates.Any()) { ProcessSecondPasses(updates, actions, config, callback); } runtimeCache.ClearByKey($"keycache_{this.Alias}"); callback?.Invoke("Done", 3, 3); sw.Stop(); logger.Debug(handlerType, "{alias} Import Complete {elapsedMilliseconds}ms", this.Alias, sw.ElapsedMilliseconds); return(actions); }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr intPtr = (IntPtr)0; if (this.Partitions.Contains(partition)) { IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int num = delegateForFunctionPointer(handle, partition, (int)option | 4, syncAllFunctionPointer, (IntPtr)0, ref intPtr); try { if (intPtr == (IntPtr)0) { if (num != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(num, false)); } } else { SyncFromAllServersOperationException syncFromAllServersOperationException = ExceptionHelper.CreateSyncAllException(intPtr, false); if (syncFromAllServersOperationException != null) { throw syncFromAllServersOperationException; } } } finally { if (intPtr != (IntPtr)0) { UnsafeNativeMethods.LocalFree(intPtr); } } return; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } else { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } }
protected virtual IEnumerable <uSyncAction> ImportFolder(string folder, HandlerSettings config, Dictionary <string, TObject> updates, bool force, SyncUpdateCallback callback) { List <uSyncAction> actions = new List <uSyncAction>(); var files = GetImportFiles(folder); var flags = SerializerFlags.None; if (force) { flags |= SerializerFlags.Force; } if (config.BatchSave) { flags |= SerializerFlags.DoNotSave; } var cleanMarkers = new List <string>(); int count = 0; int total = files.Count(); foreach (string file in files) { count++; callback?.Invoke($"Importing {Path.GetFileNameWithoutExtension(file)}", count, total); var attempt = Import(file, config, flags); if (attempt.Success) { if (attempt.Change == ChangeType.Clean) { cleanMarkers.Add(file); } else if (attempt.Item != null) { updates.Add(file, attempt.Item); } } var action = uSyncActionHelper <TObject> .SetAction(attempt, file, this.Alias, IsTwoPass); if (attempt.Details != null && attempt.Details.Any()) { action.Details = attempt.Details; } if (attempt.Change != ChangeType.Clean) { actions.Add(action); } } // bulk save .. if (flags.HasFlag(SerializerFlags.DoNotSave) && updates.Any()) { // callback?.Invoke($"Saving {updates.Count()} changes", 1, 1); serializer.Save(updates.Select(x => x.Value)); } var folders = syncFileService.GetDirectories(folder); foreach (var children in folders) { actions.AddRange(ImportFolder(children, config, updates, force, callback)); } if (actions.All(x => x.Success) && cleanMarkers.Count > 0) { // this is just extra messaging, given how quickly the next message will be sent. // callback?.Invoke("Cleaning Folders", 1, cleanMarkers.Count); foreach (var item in cleanMarkers.Select((filePath, Index) => new { filePath, Index })) { var folderName = Path.GetFileName(item.filePath); callback?.Invoke($"Cleaning {folderName}", item.Index, cleanMarkers.Count); var cleanActions = CleanFolder(item.filePath, false, config.UseFlatStructure); if (cleanActions.Any()) { actions.AddRange(cleanActions); } else { // nothing to delete, we report this as a no change actions.Add(uSyncAction.SetAction(true, $"Folder {Path.GetFileName(item.filePath)}", change: ChangeType.NoChange, filename: item.filePath)); } } // remove the actual cleans (they will have been replaced by the deletes actions.RemoveAll(x => x.Change == ChangeType.Clean); } return(actions); }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr zero = IntPtr.Zero; if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)); int errorCode = delegateForFunctionPointer(handle, partition, ((int) option) | 4, syncAllFunctionPointer, IntPtr.Zero, ref zero); try { if (zero != IntPtr.Zero) { SyncFromAllServersOperationException exception = ExceptionHelper.CreateSyncAllException(zero, false); if (exception != null) { throw exception; } } else if (errorCode != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(errorCode, false)); } } finally { if (zero != IntPtr.Zero) { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LocalFree(zero); } } }
virtual public IEnumerable <uSyncAction> ExportAll(string folder, HandlerSettings config, SyncUpdateCallback callback) { // we dont clean the folder out on an export all. // because the actions (renames/deletes) live in the folder // // there will have to be a diffrent clean option /// // syncFileService.CleanFolder(folder); return(ExportAll(-1, folder, config, callback)); }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr errorInfo = (IntPtr)0; if (!Partitions.Contains(partition)) throw new ArgumentException(Res.GetString(Res.ServerNotAReplica), "partition"); // we want to return the dn instead of DNS guid // call DsReplicaSyncAllW IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaSyncAllW dsReplicaSyncAllW = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int result = dsReplicaSyncAllW(handle, partition, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, ref errorInfo); try { // error happens during the synchronization if (errorInfo != (IntPtr)0) { SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) return; else throw e; } else { // API does not return error infor occurred during synchronization, but result is not success. if (result != 0) throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false)); } } finally { // release the memory if (errorInfo != (IntPtr)0) UnsafeNativeMethods.LocalFree(errorInfo); } }
/// <summary> /// Export all items under a suppled parent id /// </summary> virtual public IEnumerable <uSyncAction> ExportAll(int parentId, string folder, HandlerSettings config, SyncUpdateCallback callback) { var parent = GetFromService(parentId); return(ExportAll(parent, folder, config, callback)); }
virtual public IEnumerable <uSyncAction> ExportAll(int parent, string folder, HandlerSettings config, SyncUpdateCallback callback) { int count = 0; var actions = new List <uSyncAction>(); if (itemContainerType != UmbracoObjectTypes.Unknown) { var containers = entityService.GetChildren(parent, this.itemContainerType); foreach (var container in containers) { actions.AddRange(ExportAll(container.Id, folder, config, callback)); } } var items = GetExportItems(parent, itemObjectType).ToList(); foreach (var item in items) { count++; var concreateType = GetFromService(item.Id); callback?.Invoke(GetItemName(concreateType), count, items.Count); actions.Add(Export(concreateType, folder, config)); actions.AddRange(ExportAll(item.Id, folder, config, callback)); } callback?.Invoke("Done", 1, 1); return(actions); }
private int UploadFolder(string siteRoot, string localRoot, string folder, SftpClient client, SyncUpdateCallback callback) { if (!client.IsConnected) { throw new FtpException("Not connected"); } var path = Path.Combine(localRoot, folder); if (!Directory.Exists(path)) { throw new DirectoryNotFoundException("Path not found: " + path); } var dest = $"/{siteRoot}/{folder}"; try { client.CreateDirectory(dest); } catch { } callback?.Invoke($"Syncing {folder}", 5, 10); var files = client.SynchronizeDirectories(path, dest, "*.*"); var total = files.Count(); foreach (var child in Directory.GetDirectories(path)) { var childFolder = child.Substring(localRoot.Length) .Replace("\\", "/"); total += UploadFolder(siteRoot, localRoot, childFolder, client, callback); } return(total); }
public IEnumerable <uSyncAction> Report(string folder, HandlerSettings config, SyncUpdateCallback callback) { var actions = new List <uSyncAction>(); callback?.Invoke("Checking Actions", 0, 1); actions.AddRange(ReportFolder(folder, config, callback)); callback?.Invoke("Done", 1, 1); return(actions); }
/// <summary> /// overrider the default export, because macros, don't exist as an object type??? /// </summary> public override IEnumerable <uSyncAction> ExportAll(int parent, string folder, HandlerSettings config, SyncUpdateCallback callback) { // we clean the folder out on an export all. syncFileService.CleanFolder(folder); var actions = new List <uSyncAction>(); var items = macroService.GetAll().ToList(); int count = 0; foreach (var item in items) { count++; callback?.Invoke(item.Name, count, items.Count); actions.AddRange(Export(item, folder, config)); } return(actions); }
public IEnumerable <uSyncAction> ReportFolder(string folder, HandlerSettings config, SyncUpdateCallback callback) { List <uSyncAction> actions = new List <uSyncAction>(); var files = syncFileService.GetFiles(folder, "*.config"); int count = 0; int total = files.Count(); foreach (string file in files) { count++; callback?.Invoke(Path.GetFileNameWithoutExtension(file), count, total); actions.Add(ReportItem(file)); } foreach (var children in syncFileService.GetDirectories(folder)) { actions.AddRange(ReportFolder(children, config, callback)); } return(actions); }