コード例 #1
0
        /// <summary>
        /// Initialize
        /// </summary>
        public FileNotificationTemplateRepository()
        {
            ApplicationServiceContext.Current.Started += (o, e) =>
            {
                try
                {
                    this.m_tracer.TraceInfo("Scanning {0}", this.m_configuration.RepositoryRoot);
                    if (!Directory.Exists(this.m_configuration.RepositoryRoot))
                    {
                        Directory.CreateDirectory(this.m_configuration.RepositoryRoot);
                    }

                    Directory.GetFiles(this.m_configuration.RepositoryRoot, "*.xml", SearchOption.AllDirectories)
                    .ToList().ForEach(f =>
                    {
                        try
                        {
                            lock (this.m_lock)
                                using (var fs = File.OpenRead(f))
                                    this.m_repository.Add(NotificationTemplate.Load(fs));
                        }
                        catch (Exception ex)
                        {
                            this.m_tracer.TraceWarning("Skipping {0} - {1}", f, ex.Message);
                        }
                    });
                }
                catch (Exception ex)
                {
                    this.m_tracer.TraceError("Error loading templates - {0}", ex);
                }
            };
        }