/// <summary>
        ///     Provide the property page with an array of pointers to objects associated
        ///     with this property page.
        ///     When the property page receives a call to IPropertyPage::Apply, it must send
        ///     value changes to these objects through whatever interfaces are appropriate.
        ///     The property page must query for those interfaces. This method can fail if
        ///     the objects do not support the interfaces expected by the property page.
        /// </summary>
        /// <param name="cObjects">
        ///     The number of pointers in the array pointed to by ppUnk.
        ///     If this parameter is 0, the property page must release any pointers previously
        ///     passed to this method.
        /// </param>
        /// <param name="ppunk"></param>
        public void SetObjects(uint cObjects, object[] ppunk)
        {
            // If cObjects ==0 or ppunk == null, release the PropertyStore.
            if ((ppunk == null) || (cObjects == 0))
            {
                if (PropertyStore != null)
                {
                    PropertyStore.Dispose();
                    PropertyStore = null;
                }
            }
            else
            {
                // Initialize the PropertyStore using the provided objects.
                PropertyStore = GetNewPropertyStore();
                PropertyStore.Initialize(ppunk);

                // If PropertyStore is not null, which means that the PageView UI has been
                // initialized, then it needs to be refreshed.
                if (PropertyStore != null)
                {
                    MyPageView.RefreshPropertyValues();
                }
            }
        }
Esempio n. 2
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (_propertyStore != null)
     {
         _propertyStore.Dispose();
         _propertyStore = null;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Disposes the <see cref="MMDevice"/> and its default property store (see <see cref="PropertyStore"/> property).
        /// </summary>
        /// <param name="disposing">True to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (_propertyStore != null)
            {
                _propertyStore.Dispose();
                _propertyStore = null;
            }
            _disposed = true;
            base.Dispose(disposing);
        }
        /// <summary>
        /// Called to complete disposing.
        /// </summary>
        /// <param name="disposing">Whether or not managed resources are released.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    foreach (var item in _errors)
                    {
                        item.Value.Clear();
                    }
                    _errors.Clear();
                    _publicErrors.Clear();

                    ErrorsChanged        = null;
                    Notify               = null;
                    PropertyChanged      = null;
                    FocusChangeRequested = null;
                    PropertyStore.Dispose();
                }
                disposedValue = true;
                Disposed?.Invoke(this, EventArgs.Empty);
            }
            Disposed = null;
        }
Esempio n. 5
0
        public void RetrieveAll(string path)
        {
            try
            {
                Console.WriteLine(path);
                foreach (string filePath in Directory.GetFiles(path))
                {
                    PropertyStore propStore = null;
                    try
                    {
                        bool hasError = false;
                        try
                        {
                            propStore = PropertyStore.Open(filePath);
                        }
                        catch (Exception err)
                        {
                            Console.WriteLine("Failed to open property store on: {0}\r\n{1}\r\n", filePath, err.ToString());
                            // m_log.WriteLine("Failed to open property store on: {0}\r\n{1}\r\n", filePath, err.ToString());
                            hasError = true;
                        }

                        if (!hasError)
                        {
                            int count = propStore.Count;
                            for (int i = 0; i < propStore.Count; ++i)
                            {
                                PropertyKey propKey;
                                try
                                {
                                    // Get the key for the enumerated property
                                    propKey = propStore.GetAt(i);
                                }
                                catch (Exception err)
                                {
                                    Console.WriteLine("Failed to retrieve property key on '{0}' index='{1}'\r\n{2}\r\n", filePath, i, err.ToString());
                                    m_log.WriteLine("Failed to retrieve property key on '{0}' index='{1}'\r\n{2}\r\n", filePath, i, err.ToString());
                                    continue;
                                }

                                object value = null;
                                try
                                {
                                    // Get the value
                                    value = propStore.GetValue(propKey);
                                }
                                catch (Exception err)
                                {
                                    if (m_errorKeys.Add(propKey))
                                    {
                                        string message = (err.InnerException != null) ? err.InnerException.Message : err.Message;

                                        // Attempt to get the canonical name
                                        string name = string.Empty;
                                        try
                                        {
                                            name = m_ps.GetPropertyDescription(propKey).CanonicalName;
                                        }
                                        catch
                                        {
                                            name = string.Empty;
                                        }

                                        Console.WriteLine("Failed to retrieve value. file='{0}' propkey='{1}' canonicalName='{2}'\r\n{3}\r\n", filePath, propKey, name, message);
                                        m_log.WriteLine("Failed to retrieve value. file='{0}' propkey='{1}' canonicalName='{2}'\r\n{3}\r\n", filePath, propKey, name, message);
                                    }
                                }

                                if (m_foundKeys.Add(propKey))
                                {
                                    PropertyDescription desc = null;
                                    try
                                    {
                                        // Get the description from the property store (if available)
                                        desc = m_ps.GetPropertyDescription(propKey);
                                    }
                                    catch (Exception err)
                                    {
                                        Console.WriteLine("Error retrieving property description. propkey='{0}'\r\n{1}\r\n", propKey, err.ToString());
                                        m_log.WriteLine("Error retrieving property description. propkey='{0}'\r\n{1}\r\n", propKey, err.ToString());
                                    }
                                    if (desc != null)
                                    {
                                        if (string.IsNullOrEmpty(desc.CanonicalName))
                                        {
                                            Console.WriteLine("No canonical name provided. propkey='{0}'\r\n", propKey);
                                            m_log.WriteLine("No canonical name provided. propkey='{0}'\r\n", propKey);
                                        }
                                        else if (string.IsNullOrEmpty(desc.DisplayName))
                                        {
                                            Console.WriteLine("No display name provided. propkey='{0}' canonical='{1}'\r\n", propKey, desc.CanonicalName);
                                            m_log.WriteLine("No display name provided. propkey='{0}' canonical='{1}'\r\n", propKey, desc.CanonicalName);
                                        }
                                    }
                                } // if not in foundkeys

                                if (value != null && !m_typematchKeys.Contains(propKey))
                                {
                                    m_typematchKeys.Add(propKey);

                                    PropertyDescription desc = null;
                                    try
                                    {
                                        // Get the description from the property store (if available)
                                        desc = m_ps.GetPropertyDescription(propKey);
                                    }
                                    catch (Exception)
                                    {
                                        // Suppress errors here
                                    }
                                    if (desc != null)
                                    {
                                        // See if type matches
                                        Type expectedType = desc.ValueType;
                                        Type valueType    = (value != null) ? value.GetType() : null;

                                        if (expectedType == null)
                                        {
                                            Console.WriteLine($"For '{desc.CanonicalName}' expected type is null but value type is '{valueType}'.");
                                            m_log.WriteLine($"For '{desc.CanonicalName}' expected type is null but value type is '{valueType}'.");
                                        }
                                        else if (expectedType != valueType)
                                        {
                                            Console.WriteLine($"For '{desc.CanonicalName}' expected type is '{expectedType}' but value type is '{valueType}'.");
                                            m_log.WriteLine($"For '{desc.CanonicalName}' expected type is '{expectedType}' but value type is '{valueType}'.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (propStore != null)
                        {
                            propStore.Dispose();
                            propStore = null;
                        }
                    }
                } // foreach file

                // Recursively enumerate directories
                foreach (string dirPath in Directory.GetDirectories(path))
                {
                    RetrieveAll(dirPath);
                }
            }
            catch (UnauthorizedAccessException err)
            {
                Console.WriteLine("Error: " + err.ToString() + "\r\n");
            }
            catch (Exception err)
            {
                Console.WriteLine("Error: " + err.ToString() + "\r\n");
                m_log.WriteLine("Error: " + err.ToString() + "\r\n");
            }
        }