Exemple #1
0
        public XMLAccess(bool p_IgnoreTest)
        {
            string PlatformVersion;

            TL         = new TraceLogger("", "XMLAccess");                  // Create a new trace logger
            TL.Enabled = GetBool(TRACE_XMLACCESS, TRACE_XMLACCESS_DEFAULT); // Get enabled / disabled state from the user registry
            RunningVersions(TL);                                            // Include version information

            sw        = new Stopwatch();                                    // Create the stowatch instances
            swSupport = new Stopwatch();

            FileStore = new AllUsersFileSystemProvider();
            // FileStore = New IsolatedStorageFileStoreProvider

            ProfileMutex = new System.Threading.Mutex(false, PROFILE_MUTEX_NAME);

            // Bypass test for initial setup by MigrateProfile because the profile isn't yet set up
            if (!p_IgnoreTest)
            {
                try
                {
                    if (!FileStore.Exists(@"\" + VALUES_FILENAME))
                    {
                        throw new Exceptions.ProfileNotFoundException("Utilities Error Base key does not exist");
                    }
                    PlatformVersion = GetProfile(@"\", "PlatformVersion");
                }
                // OK, no exception so assume that we are initialised
                catch (Exception ex)
                {
                    TL.LogMessageCrLf("XMLAccess.New Unexpected exception:", ex.ToString());
                    throw;
                }
            }
        }
Exemple #2
0
        internal void CreateKey(string p_SubKeyName)
        {
            // Create a key
            Generic.SortedList <string, string> InitalValues = new Generic.SortedList <string, string>();
            string[] SubKeys;
            string   SubKey;
            int      i, j;

            try
            {
                GetProfileMutex("CreateKey", p_SubKeyName);
                sw.Reset(); sw.Start(); // Start timing this call
                TL.LogMessage("CreateKey", "SubKey: \"" + p_SubKeyName + "\"");

                p_SubKeyName = Strings.Trim(p_SubKeyName);                                                           // Normalise the string:
                SubKeys      = Strings.Split(p_SubKeyName, @"\", Compare: Microsoft.VisualBasic.CompareMethod.Text); // Parse p_SubKeyName into its elements
                switch (p_SubKeyName)
                {
                case ""      // Null path so do nothing
                    :
                {
                    break;
                }

                case @"\"     // Root node so just create this
                    :
                {
                    if (!FileStore.Exists(@"\" + VALUES_FILENAME))
                    {
                        TL.LogMessage("  CreateKey", @"  Creating root key ""\""");
                        InitalValues.Clear();                       // Now add the file containing the contents of the key
                        InitalValues.Add(COLLECTION_DEFAULT_VALUE_NAME, COLLECTION_DEFAULT_UNSET_VALUE);
                        WriteValues(@"\", ref InitalValues, false); // Write the profile file, don't check if it already exists
                    }
                    else
                    {
                        TL.LogMessage("  CreateKey", "  Root key alread exists");
                    }
                    break;
                }

                default:
                {
                    for (i = 0; i <= SubKeys.Length - 1; i++)
                    {
                        SubKey = "";
                        for (j = 0; j <= i; j++)
                        {
                            SubKey = SubKey + @"\" + SubKeys[j];
                        }
                        if (!FileStore.Exists(SubKey + @"\" + VALUES_FILENAME))
                        {
                            FileStore.CreateDirectory(SubKey, TL);        // It doesn't exist so create it
                            InitalValues.Clear();                         // Now add the file containing the contents of the key
                            InitalValues.Add(COLLECTION_DEFAULT_VALUE_NAME, COLLECTION_DEFAULT_UNSET_VALUE);
                            WriteValues(SubKey, ref InitalValues, false); // Write the profile file
                        }
                    }

                    break;
                }
                }
                sw.Stop(); TL.LogMessage("  ElapsedTime", "  " + sw.ElapsedMilliseconds + " milliseconds");
            }
            finally
            {
                ProfileMutex.ReleaseMutex();
            }
        }