コード例 #1
0
        public static DataFolderState MakeNewStaticDataForTesting()
        {
            DataFolderState state = new DataFolderState();

            state.userDataPath        = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
            state.renamedUserDataPath = Path.Combine(Path.GetDirectoryName(state.userDataPath), "-MatterControl");
            int testCount = 0;

            while (Directory.Exists(state.renamedUserDataPath + testCount.ToString()))
            {
                testCount++;
            }
            state.renamedUserDataPath = state.renamedUserDataPath + testCount.ToString();

            state.undoDataRename = false;
            if (Directory.Exists(state.userDataPath))
            {
                Directory.Move(state.userDataPath, state.renamedUserDataPath);
                state.undoDataRename = true;
            }

            Datastore.Instance.Initialize();

            return(state);
        }
コード例 #2
0
        public static DataFolderState MakeNewStaticDataForTesting(string testDBFolderName = null)
        {
            DataFolderState state = new DataFolderState();

            state.userDataPath        = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
            state.renamedUserDataPath = Path.Combine(Path.GetDirectoryName(state.userDataPath), "-MatterControl");

            int testCount = 0;

            while (Directory.Exists(state.renamedUserDataPath + testCount.ToString()))
            {
                testCount++;
            }

            state.renamedUserDataPath = state.renamedUserDataPath + testCount.ToString();

            state.undoDataRename = false;
            if (Directory.Exists(state.userDataPath))
            {
                Directory.Move(state.userDataPath, state.renamedUserDataPath);
                state.undoDataRename = true;
            }

            if (testDBFolderName != null)
            {
                string fullPathToDataContents = Path.Combine("..", "..", "..", "TestData", "TestDatabaseStates", testDBFolderName);
                CopyTestDataDBFolderToTemporaryMCAppDataDirectory(fullPathToDataContents);
                state.undoDataRename = true;
                return(state);
            }

            Datastore.Instance.Initialize();

            return(state);
        }
コード例 #3
0
        public static DataFolderState MakeNewStaticDataForTesting2(string testDBFolderName = null)
        {
            DataFolderState state = new DataFolderState();

            state.userDataPath        = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
            state.renamedUserDataPath = Path.Combine(Path.GetDirectoryName(state.userDataPath), "-MatterControl");

            int testCount = 0;

            while (Directory.Exists(state.renamedUserDataPath + testCount.ToString()))
            {
                testCount++;
            }

            state.renamedUserDataPath = state.renamedUserDataPath + testCount.ToString();

            state.undoDataRename = false;
            if (Directory.Exists(state.userDataPath))
            {
                Directory.Move(state.userDataPath, state.renamedUserDataPath);
                state.undoDataRename = true;
            }

            Stopwatch time = Stopwatch.StartNew();

            // Wait for up to some amount of time for the directory to be moved.
            while (!Directory.Exists(state.renamedUserDataPath) &&
                   time.ElapsedMilliseconds < 1000)
            {
                Thread.Sleep(1);                 // make sure we are not eating all the cpu time.
            }

            if (testDBFolderName != null)
            {
                string fullPathToDataContents = Path.Combine("..", "..", "..", "TestData", "TestDatabaseStates", testDBFolderName);
                CopyTestDataDBFolderToTemporaryMCAppDataDirectory(fullPathToDataContents);

                if (Directory.Exists(state.renamedUserDataPath))
                {
                    state.undoDataRename = true;
                }
                return(state);
            }

            Datastore.Instance.Initialize();

            return(state);
        }
コード例 #4
0
 public static void RestoreStaticDataAfterTesting(DataFolderState state, bool closeDataBase)
 {
     if (state.undoDataRename)
     {
         Thread.Sleep(500);
         if (closeDataBase)
         {
             Datastore.Instance.Exit();
         }
         Directory.Delete(state.userDataPath, true);
         Stopwatch time = Stopwatch.StartNew();
         // Wait for up to some amount of time for the directory to be gone.
         while (Directory.Exists(state.userDataPath) &&
                time.ElapsedMilliseconds < 100)
         {
             Thread.Sleep(1);                     // make sure we are not eating all the cpu time.
         }
         Directory.Move(state.renamedUserDataPath, state.userDataPath);
     }
 }
コード例 #5
0
 public static void RestoreStaticDataAfterTesting(DataFolderState state, bool closeDataBase)
 {
     if (state.undoDataRename)
     {
         Thread.Sleep(500);
         if (closeDataBase)
         {
             Datastore.Instance.Exit();
         }
         Stopwatch timeTryingToDelete = Stopwatch.StartNew();
         while (Directory.Exists(state.userDataPath) &&
                timeTryingToDelete.Elapsed.TotalSeconds < 10)
         {
             try
             {
                 Directory.Delete(state.userDataPath, true);
             }
             catch (Exception e)
             {
                 Debug.Print(e.Message);
                 GuiWidget.BreakInDebugger();
             }
         }
         Stopwatch time = Stopwatch.StartNew();
         // Wait for up to some amount of time for the directory to be gone.
         while (Directory.Exists(state.userDataPath) &&
                time.ElapsedMilliseconds < 100)
         {
             Thread.Sleep(1);                     // make sure we are not eating all the cpu time.
         }
         if (!Directory.Exists(state.userDataPath))
         {
             Directory.Move(state.renamedUserDataPath, state.userDataPath);
         }
     }
 }
コード例 #6
0
		public static void RestoreStaticDataAfterTesting(DataFolderState state, bool closeDataBase)
		{
			if (state.undoDataRename)
			{
				Thread.Sleep(500);
				if (closeDataBase)
				{
					Datastore.Instance.Exit();
				}
				Directory.Delete(state.userDataPath, true);
				Stopwatch time = Stopwatch.StartNew();
				// Wait for up to some amount of time for the directory to be gone.
				while (Directory.Exists(state.userDataPath)
					&& time.ElapsedMilliseconds < 100)
				{
					Thread.Sleep(1); // make sure we are not eating all the cpu time.
				}
				Directory.Move(state.renamedUserDataPath, state.userDataPath);
			}
		}
コード例 #7
0
		public static DataFolderState MakeNewStaticDataForTesting()
		{
			DataFolderState state = new DataFolderState();
			state.userDataPath = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
			state.renamedUserDataPath = Path.Combine(Path.GetDirectoryName(state.userDataPath), "-MatterControl");
			int testCount = 0;
			while (Directory.Exists(state.renamedUserDataPath + testCount.ToString()))
			{
				testCount++;
			}
			state.renamedUserDataPath = state.renamedUserDataPath + testCount.ToString();

			state.undoDataRename = false;
			if (Directory.Exists(state.userDataPath))
			{
				Directory.Move(state.userDataPath, state.renamedUserDataPath);
				state.undoDataRename = true;
			}

			Datastore.Instance.Initialize();

			return state;
		}
コード例 #8
0
		public static DataFolderState MakeNewStaticDataForTesting(string testDBFolderName = null)
		{
			DataFolderState state = new DataFolderState();
			state.userDataPath = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
			state.renamedUserDataPath = Path.Combine(Path.GetDirectoryName(state.userDataPath), "-MatterControl");

			int testCount = 0;
			while (Directory.Exists(state.renamedUserDataPath + testCount.ToString()))
			{
				testCount++;
			}

			state.renamedUserDataPath = state.renamedUserDataPath + testCount.ToString();

			state.undoDataRename = false;
			if (Directory.Exists(state.userDataPath))
			{
				Directory.Move(state.userDataPath, state.renamedUserDataPath);
				state.undoDataRename = true;
			}

			if (testDBFolderName != null)
			{
				string fullPathToDataContents = Path.Combine("..", "..", "..", "TestData", "TestDatabaseStates", testDBFolderName);
				CopyTestDataDBFolderToTemporaryMCAppDataDirectory(fullPathToDataContents);
				state.undoDataRename = true;
				return state;
			}

			Datastore.Instance.Initialize();

			return state;
		}
コード例 #9
0
		public static void RestoreStaticDataAfterTesting(DataFolderState state, bool closeDataBase)
		{
			if (state.undoDataRename)
			{
				Thread.Sleep(500);
				if (closeDataBase)
				{
					Datastore.Instance.Exit();
				}
				Stopwatch timeTryingToDelete = Stopwatch.StartNew();
				while (Directory.Exists(state.userDataPath)
					&& timeTryingToDelete.Elapsed.TotalSeconds < 10)
				{
					try
					{
						Directory.Delete(state.userDataPath, true);
					}
					catch (Exception e)
					{
						Debug.Print(e.Message);
						GuiWidget.BreakInDebugger();
					}
				}
				Stopwatch time = Stopwatch.StartNew();
				// Wait for up to some amount of time for the directory to be gone.
				while (Directory.Exists(state.userDataPath)
					&& time.ElapsedMilliseconds < 100)
				{
					Thread.Sleep(1); // make sure we are not eating all the cpu time.
				}
				if (!Directory.Exists(state.userDataPath))
				{
					Directory.Move(state.renamedUserDataPath, state.userDataPath);
				}
			}
		}
コード例 #10
0
		public static DataFolderState MakeNewStaticDataForTesting2(string testDBFolderName = null)
		{
			DataFolderState state = new DataFolderState();
			state.userDataPath = MatterHackers.MatterControl.DataStorage.ApplicationDataStorage.ApplicationUserDataPath;
			state.renamedUserDataPath = Path.Combine(Path.GetDirectoryName(state.userDataPath), "-MatterControl");

			int testCount = 0;
			while (Directory.Exists(state.renamedUserDataPath + testCount.ToString()))
			{
				testCount++;
			}

			state.renamedUserDataPath = state.renamedUserDataPath + testCount.ToString();

			state.undoDataRename = false;
			if (Directory.Exists(state.userDataPath))
			{
				Directory.Move(state.userDataPath, state.renamedUserDataPath);
				state.undoDataRename = true;
			}

			Stopwatch time = Stopwatch.StartNew();
			// Wait for up to some amount of time for the directory to be moved.
			while (!Directory.Exists(state.renamedUserDataPath)
				&& time.ElapsedMilliseconds < 1000)
			{
				Thread.Sleep(1); // make sure we are not eating all the cpu time.
			}

			if (testDBFolderName != null)
			{
				string fullPathToDataContents = Path.Combine("..", "..", "..", "TestData", "TestDatabaseStates", testDBFolderName);
				CopyTestDataDBFolderToTemporaryMCAppDataDirectory(fullPathToDataContents);

				if (Directory.Exists(state.renamedUserDataPath))
				{
					state.undoDataRename = true;
				}
				return state;
			}

			Datastore.Instance.Initialize();

			return state;
		}