コード例 #1
0
        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="host">Reference to the <see cref="IPluginHost"/> object.</param>
        /// <returns>True if the plugin is initialized properly, false otherwise.</returns>
        public override bool Initialize(IPluginHost host)
        {
            _host = host;

            // Add handler to detect when a new window has been opened.
            GlobalWindowManager.WindowAdded += GlobalWindowManager_WindowAdded;

            string configFilePath = GetConfigFilePath();

            if (!File.Exists(configFilePath))
            {
                // Create sample dates.
                CustomDateOptions = new List <CustomDateOption>
                {
                    new CustomDateOption {
                        Days = 31
                    },
                    new CustomDateOption {
                        Days = 45
                    },
                    new CustomDateOption {
                        Days = 180
                    }
                };
            }
            else
            {
                // Read config file.
                using (FileStream fileStream = new FileStream(configFilePath, FileMode.OpenOrCreate))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(List <CustomDateOption>), new XmlRootAttribute("CustomDateOptions"));
                    CustomDateOptions = serializer.Deserialize(fileStream) as List <CustomDateOption>;
                }
            }

            // Sort custom options
            CustomDateOptions.Sort((x, y) => string.Compare(x.ToString(), y.ToString()));

            return(true);
        }