none
SF 2.1 - PathTooLong not thrown

    Question

  • Hi,

    I'm using the SF 2.1 , FileSyncProvider (out-of-the-box). When the path is too long I'd expect it skips the change and raise an event so I can handle it and display some message to the user, however it doesn't. I simply creates the folder until the path is valid and ignores the content (files and subfolder) when the path it too long. I've seen somewhere that to somebody else it went to the skipped change, but I can not do it.

    My code

    private SyncResult Start()
            {
                SyncResult result = new SyncResult();
                FileSyncProvider localProvider = null;
                FileSyncProvider serverProvider = null;

                try
                {
                    ReportProgress(0, "");

                    IsWorking = true;

                    //check the paths validity
                    StringBuilder errors = new StringBuilder();
                    if (!Directory.Exists(LocalPath))
                    {
                        //local directory doesn't exist, try to create it
                        try
                        {
                            Directory.CreateDirectory(LocalPath);
                            LogInfo(String.Format("Directory '{0}' didn't exist so has been created."));
                        }
                        catch (Exception ex)
                        {
                            //unable to create it - log it
                            errors.AppendLine(String.Format("Local directory '{0}' doesn't exists and the trial to create it has ended with exception '{1}'.", LocalPath, ex.ToString()));
                        }
                    }

                    //check the server directory
                    if (!Directory.Exists(ServerPath))
                    {
                        //server directory doesn't exist, log it
                        errors.AppendLine(String.Format("Datastore directory '{0}' doesn't exists.", ServerPath));
                    }
                    //if some errors appeared, exit (call fail callback)
                    if (errors.Length > 0)
                    {
                        return new SyncResult()
                        {
                            ResultingState = SyncResultEnum.Fail,
                            Log = this.Log
                        };
                    }

                    //otherwise run the sync asynchronously
                    //
                    FileSyncScopeFilter serverFilter = GetFileFilter();
                    FileSyncScopeFilter localFilter = serverFilter;

                    if (LocalUnselectedFolders.Count > 0)
                    {
                        foreach (var unselectedFolder in LocalUnselectedFolders)
                            localFilter.SubdirectoryExcludes.Add(unselectedFolder);
                    }

                    if (ServerUnselectedFolders.Count > 0)
                    {
                        foreach (var unselectedFolder in ServerUnselectedFolders)
                            serverFilter.SubdirectoryExcludes.Add(unselectedFolder);
                    }

                    //recycle settings
                    FileSyncOptions options =FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecycleConflictLoserFiles | FileSyncOptions.RecyclePreviousFileOnUpdates;
                    SyncOperationStatistics syncStat;

                    result.ProcessName = string.Format("File sync of {0}", ProjectSiteNr);

                    LogInfo(String.Format("Initializing local provider at '{0}'", LocalPath));
                    localProvider = new FileSyncProvider(LocalPath, localFilter, options);
                    LogInfo("Local provider initalized succesfully.");

                    LogInfo(String.Format("Initializing server provider at '{0}'", ServerPath));
                    serverProvider = new FileSyncProvider(ServerPath, serverFilter, options);
                    LogInfo("Server provider initalized succesfully.");


                    //attach event hadler to the providers
                    localProvider.AppliedChange += localProvider_AppliedChange;
                    localProvider.SkippedChange += localProvider_SkippedChange;
                    serverProvider.AppliedChange += serverProvider_AppliedChange;
                    serverProvider.SkippedChange += serverProvider_SkippedChange;

                    _syncAgent = new SyncOrchestrator();
                    _syncAgent.LocalProvider = localProvider;
                    _syncAgent.RemoteProvider = serverProvider;
                    _syncAgent.Direction = SyncDirectionOrder.UploadAndDownload;

                    LogEmptyRow();
                    LogHeaderRow("Synchronization");
                    LogEmptyRow();
                    LogInfo(string.Format("Sync order: '{0}'", SyncDirection.ToString()));

                    LogEmptyRow();

                    _futureChanges = 0;
                    localProvider.ApplyingChange += provider_CountFutureChanges;
                    serverProvider.ApplyingChange += provider_CountFutureChanges;
                    localProvider.PreviewMode = true;
                    serverProvider.PreviewMode = true;
                    //==========================================
                    //      CALCULATE CHANGES
                    ReportProgress(0, string.Format("Calculating changes...", LocalPath, ServerPath));
                    _syncAgent.Synchronize();
                    //===========================================

                    localProvider.PreviewMode = false;
                    serverProvider.PreviewMode = false;
                    _currentChangeNr = 0;
                    localProvider.ApplyingChange -= provider_CountFutureChanges;
                    serverProvider.ApplyingChange -= provider_CountFutureChanges;

                    localProvider.ApplyingChange += provider_ApplyingChange;
                    serverProvider.ApplyingChange += provider_ApplyingChange;
                    //==========================================
                    //      RUN SYNC
                    syncStat = _syncAgent.Synchronize();
                    //===========================================
                    if (Log.Count(LogRecordTypeEnum.Error) + Log.Count(LogRecordTypeEnum.Warning) > 0)
                    {
                        Log.WriteError (String.Format("Synchronization finished with {0} errors and {1} warnings.",
                            Log.Count(LogRecordTypeEnum.Error),
                            Log.Count(LogRecordTypeEnum.Warning)));
                        result.ResultingState = SyncResultEnum.Fail;
                    }
                    else
                    {
                        Log.WriteInfo("Synchronization finished succesfully.");
                        Log.WriteEmptyRow();
                        Log.WriteHeaderRow("Statistics:");
                        //Display the statistics from the SyncOperationStatistics object that is returned 
                        //by Synchronize().
                        Log.WriteInfo(String.Format("Download Applied:\t\t {0}", syncStat.DownloadChangesApplied));
                        Log.WriteInfo(String.Format("Download Failed:\t\t {0}", syncStat.DownloadChangesFailed));
                        Log.WriteInfo(String.Format("Download Total:\t\t {0}", syncStat.DownloadChangesTotal));
                        Log.WriteInfo(String.Format("Upload Total:\t\t {0}", syncStat.UploadChangesApplied));
                        Log.WriteInfo(String.Format("Upload Total:\t\t {0}", syncStat.UploadChangesFailed));
                        Log.WriteInfo(String.Format("Upload Total:\t\t {0}", syncStat.UploadChangesTotal));
                        result.ResultingState = SyncResultEnum.Success;
                    }
                }
                catch (Exception ex)
                {
                    LogEmptyRow();
                    LogError("Error in synchronization", LogRecordCategoryEnum.NotDefined, ex);
                    result.ResultingState = SyncResultEnum.Fail;
                    result.ResultMessage = ex.Message;
                    if (ex.Message.Contains("Access is denied"))
                    {
                        ReportProgress(100, "Access is denied");
                    }
                    else
                    {
                        ReportProgress(100, "Synchronization error");
                    }

                    LastSyncTime = DateTime.Now;
                    result.Log = this.Log;
                    LastSyncResult = result;
                }
                finally
                {
                    // Release resources
                    if (localProvider != null) localProvider.Dispose();
                    if (serverProvider != null) serverProvider.Dispose();
                    if (_syncAgent != null)
                    {
                        string state = _syncAgent.State.ToString();
                        if (state == "Ready") state = "";
                        ReportProgress(100, state);

                        if (_syncAgent.State != SyncOrchestratorState.Canceled)
                        {
                            LastSyncTime = DateTime.Now;
                            result.Log = this.Log;
                            LastSyncResult = result;
                        }
                    }
                    IsWorking = false;
                }

                SaveAndResetLog();
                return result;


            }

            void localProvider_SkippedChange(object sender, SkippedChangeEventArgs e)
            {
                //it never goes here, why ??
                LogSkippedChange("Local: ", e);
            }

    ApplyingChange event is handled normally.

    Thanks

    Filip


    Tuesday, August 20, 2013 6:03 PM

All replies

  • hmm, one more aditional observation - when I have path too long on server and sychnronizing to local, the skippedChange event is fired with message

     [The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.] which is what I'd like to get also for the upload. How can I achieve it? For upload it'S more important, since I can say the user "hey, your files can not be uploaded, change the structure" - when he get this error whne downloading, what can he does?

    Thanks a lot

    Filip

    Tuesday, August 20, 2013 6:12 PM