Пример #1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                IsEnabled            = false;

                Log.Info("Get the details from the page into the share object");
                csd.SharesToRestore[0].TargetMachineName = cpd.TargetMachineName;
                csd.SharesToRestore[0].Port             = (ushort)cpd.Port;
                csd.SharesToRestore[0].SecurityProtocol = cpd.SecurityProtocol;
                csd.SharesToRestore[0].UserName         = cpd.UserName;
                csd.SharesToRestore[0].Password         = cpd.Password;
                csd.SharesToRestore[0].TargetShareName  = cpd.TargetShareName;
                string oldDriveLetter = csd.SharesToRestore[0].DriveLetter;
                csd.SharesToRestore[0].DriveLetter               = cpd.DriveLetter;
                csd.SharesToRestore[0].VolumeLabel               = cpd.VolumeLabel;
                csd.SharesToRestore[0].BufferWireTransferSize    = (uint)cpd.BufferWireTransferSize;
                csd.SharesToRestore[0].CacheFileMaxSize          = (uint)cpd.CacheFileMaxSize;
                csd.SharesToRestore[0].CacheInfoExpireSeconds    = (uint)cpd.CacheInfoExpireSeconds;
                csd.SharesToRestore[0].FileNamesToIgnore         = cpd.FileNamesToIgnore;
                csd.SharesToRestore[0].DokanThreadCount          = (ushort)cpd.DokanThreadCount;
                csd.SharesToRestore[0].DokanDebugMode            = cpd.DokanDebugMode;
                csd.SharesToRestore[0].ApplicationLogLevel       = cpd.ApplicationLogLevel;
                csd.SharesToRestore[0].TargetIsReadonly          = cpd.TargetIsReadonly;
                csd.SharesToRestore[0].IgnoreSetTimeStampFailure = cpd.IgnoreSetTimeStampFailure;
                csd.SharesToRestore[0].TargetRequiresSplitDirs   = cpd.TargetRequiresSplitDirs;

                Log.Info("Write the values to the Service config file");
                WriteOutConfigDetails(csd);
                if (MessageBoxResult.Yes == Microsoft.Windows.Controls.MessageBox.Show(this, "This is about to stop then start the \"Share Enabler Service\".\nDo you want to this to happen now ?",
                                                                                       "Stop then Start the Service Now..", MessageBoxButton.YesNo, MessageBoxImage.Question))
                {
                    try
                    {
                        Log.Info("Now toggle the service");
                        if (Handlers.ClientMappings.ContainsKey(oldDriveLetter))
                        {
                            if (Handlers.ClientMappings[oldDriveLetter].Stop())
                            {
                                Handlers.ClientMappings.Remove(oldDriveLetter);
                            }
                        }
                        HandleMappingThread newMapping = new HandleMappingThread();
                        Handlers.ClientMappings[csd.SharesToRestore[0].DriveLetter] = newMapping;
                        newMapping.Start(csd.SharesToRestore[0]);
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorException("btnSend_Click:\n", ex);
                        Microsoft.Windows.Controls.MessageBox.Show(this, ex.Message, "Failed, Check the logs", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
                IsEnabled            = true;
            }
        }
 protected override void OnInitialized(EventArgs e)
 {
     base.OnInitialized(e);
     try
     {
         ClientConfigDetails csd;
         bool allowStart = Management.ReadConfigDetails(out csd);
         if (allowStart)
         {
             HandleMappingThread newMapping = new HandleMappingThread();
             Handlers.ClientMappings[csd.SharesToRestore[0].DriveLetter] = newMapping;
             newMapping.Start(csd.SharesToRestore[0]);
         }
     }
     catch (Exception ex)
     {
         Log.ErrorException("OnInitialized:\n", ex);
         Application.Current.Shutdown();
     }
 }