Example #1
0
 /// <summary>
 /// Attempts to authenticate to the file share.
 /// </summary>
 public void Authenticate()
 {
     try
     {
         FilePath.ConnectToNetworkShare(m_name, m_username, Password, m_domain);
         m_authenticationException = null;
     }
     catch (Exception ex)
     {
         m_authenticationException = ex;
         throw;
     }
 }
Example #2
0
        /// <summary>
        /// Replicates the <see cref="TVA.Historian.IArchive"/>.
        /// </summary>
        protected override void ReplicateArchive()
        {
            // Connect to remote share if specified.
            string archiveLocation = ArchiveLocation;
            string replicaLocation = ReplicaLocation;

            if (replicaLocation.StartsWith(@"\\") && replicaLocation.Contains(':') && replicaLocation.Contains('@'))
            {
                // Format: \\[<domain>\]<username>:<password>@<network share>
                string share    = @"\\" + replicaLocation.Substring(replicaLocation.IndexOf('@') + 1);
                string login    = replicaLocation.Substring(2, replicaLocation.IndexOf(':') - 2);
                string password = replicaLocation.Substring(replicaLocation.IndexOf(':') + 1, replicaLocation.IndexOf('@') - replicaLocation.IndexOf(':') - 1);

                replicaLocation = share;
                string[] loginParts = login.Split('\\');
                if (loginParts.Length == 2)
                {
                    FilePath.ConnectToNetworkShare(replicaLocation, loginParts[0], password, loginParts[1]);
                }
                else
                {
                    FilePath.ConnectToNetworkShare(replicaLocation, login, password, Environment.UserDomainName);
                }
            }

            FileSyncProvider syncSource      = null;
            FileSyncProvider syncDestination = null;

            try
            {
                // Setup file synchronization filter.
                FileSyncScopeFilter synchFilter = new FileSyncScopeFilter();
                synchFilter.FileNameIncludes.Add("*_to_*.d");

                // Setup file synchronization providers.
                syncSource      = new FileSyncProvider(archiveLocation, synchFilter, FileSyncOptions.CompareFileStreams);
                syncDestination = new FileSyncProvider(replicaLocation, synchFilter, FileSyncOptions.CompareFileStreams);
                syncDestination.ApplyingChange += SyncDestination_ApplyingChange;
                syncDestination.AppliedChange  += SyncDestination_AppliedChange;

                // Setup and start file synchronization agent.
                SyncOrchestrator syncAgent = new SyncOrchestrator();
                syncAgent.LocalProvider  = syncSource;
                syncAgent.RemoteProvider = syncDestination;
                syncAgent.Direction      = SyncDirectionOrder.Upload;
                syncAgent.Synchronize();
            }
            finally
            {
                // Release resource used by synchronization providers.
                if (syncSource != null)
                {
                    syncSource.Dispose();
                }

                if (syncDestination != null)
                {
                    syncDestination.Dispose();
                }
            }
        }