Exemplo n.º 1
0
        /// <summary>
        /// Backup and replace a file
        /// </summary>
        /// <param name="destFile">Where the new file should go</param>
        /// <param name="backupFile">Backup file to move existing dest file to</param>
        /// <param name="newFile">New file to move to dest file</param>

        public static bool BackupAndReplaceFile(
            string destFile,
            string backupFile,
            string newFile,
            bool logErrors)
        {
            if (File.Exists(backupFile))             // remove any old backup file
            {
                try { File.Delete(backupFile); }
                catch (Exception ex)
                { if (logErrors)
                  {
                      DebugLog.Message("Can't delete file: " + backupFile);
                  }
                }
            }

            if (File.Exists(destFile))
            {
                try { File.Move(destFile, backupFile); } // move any existing dest to bak
                catch (Exception ex)
                {                                        // try deleting existing dest file if it can't be moved
                    if (logErrors)
                    {
                        DebugLog.Message("Can't move file: " + destFile + " to file: " + backupFile);
                    }

                    try { File.Delete(destFile); }
                    catch (Exception ex2)
                    { if (logErrors)
                      {
                          DebugLog.Message("Can't delete file: " + destFile);
                      }
                    }
                }
            }

            try { File.Move(newFile, destFile); }             // move new to dest
            catch (Exception ex)
            {
                { if (logErrors)
                  {
                      DebugLog.Message(DebugLog.FormatExceptionMessage(ex, "Can't move file: " + newFile + " to file: " + destFile, true));
                  }
                }
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
/// <summary>
/// Add a new connection
/// </summary>
/// <param name="connectionString"></param>
/// <param name="accountName"></param>
/// <param name="accountPw"></param>
/// <param name="interactive"></param>

        public static void AddConnection(
            string connectionString,
            string accountName,
            string accountPw,
            bool interactive)
        {
            try
            {
                int t0 = TimeOfDay.Milliseconds();
                connectionString = NormalizeConnectionStringToUncShareName(connectionString);

                CancelConnection(connectionString);                 // try to cancel first (seems to make reconnect faster)

                NetworkConnectionWorker worker = new NetworkConnectionWorker();
                worker.connectionString = connectionString;
                worker.directoryExists  = false;

                worker.accountName = accountName;
                worker.accountPw   = accountPw;
                worker.interactive = interactive;

                Thread workerThread = new Thread(new ThreadStart(worker.AddConnection));
                workerThread.Name = "AddConnection";
                workerThread.Start();
                while (!workerThread.IsAlive)
                {
                    ;                                           // loop until worker thread activates.
                }
                while (workerThread.IsAlive)
                {
                    Thread.Sleep(10);
                    Application.DoEvents();
                }

                //workerThread.Join();
                if (worker.ex != null)
                {
                    throw worker.ex;
                }
            }
            catch (Exception ex)
            {
                DebugLog.Message("AddConnection exception: " + DebugLog.FormatExceptionMessage(ex));
            }
            return;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Register bonus skins
        /// </summary>
        /// <returns></returns>

        public static bool BonusSkinsRegister()
        {
            try
            {             // load bonus skins assembly if needed, i.e. call DevExpress.UserSkins.BonusSkins.Register();
                DevExpress.UserSkins.BonusSkins.Register();

                //string dxSkins = GetSkinManagerDefaultSkins(); // debug

                BonusSkinsRegistered = true;
                return(true);
            }
            catch (Exception ex)
            {
                DebugLog.Message("Error registering BonusSkins:\n" + DebugLog.FormatExceptionMessage(ex));
                return(false);

                //DebugLog.Message("Error loading skin: " + lookAndFeelName + "\n" + DebugLog.FormatExceptionMessage(ex));
                //lookAndFeelName = "Blue"; // default to blue
                //si = GetSkinFromInternalName(lookAndFeelName);
            }
        }