Example #1
0
        /// <summary>
        /// Gets a reference to the class in the <see cref="AssemblyName"/> that matches <see cref="StorerClassName"/>.
        /// </summary>
        /// <returns>Returns the <see cref="IStorer"/> class reference.</returns>
        public IStorer GetStorer()
        {
            if (storer == null)
            {
                if (storerType == null)
                {
                    if (AssemblyName != null && StorerClassName != null)
                    {
                        if (assemblyRef == null)
                        {
                            GetAssembly();
                        }

                        if (assemblyRef != null)
                        {
                            storerType = assemblyRef.GetType(AssemblyName + "." + StorerClassName);
                        }
                    }
                }

                if (storerType != null && storer == null)
                {
                    if (storerType.BaseType == typeof(DatabaseStorer))
                    {
                        storer = (IStorer)Activator.CreateInstance(storerType, this.ConnectionString);
                    }
                    else
                    {
                        storer = (IStorer)Activator.CreateInstance(storerType);
                    }
                }
            }
            return(storer);
        }
Example #2
0
 public BaseStorer(string name, ConcurrentQueue <MetaDataItem> storeQueue, IStorer storer)
 {
     _name        = name;
     _storeQueue  = storeQueue;
     _storer      = storer;
     _thread      = new Thread(Start);
     _thread.Name = string.Format("conthr{0}", _name);
 }
Example #3
0
 public Consumer(string name, ConcurrentQueue <IPMetaDataItem> storeQueue, IStorer storer)
     : base(name, storeQueue)
 {
     _storer = storer;
 }
Example #4
0
 /// <summary>
 ///  排序实例,存储器实例,数据实例,关系词实例,拼音实例
 /// </summary>
 /// <param name="storer"></param>
 public Worder(IStorer storer)
 {
     Storer = storer;
 }
Example #5
0
 /// <summary>
 /// 排序实例,存储器实例,词库实例
 /// </summary>
 /// <param name="storer"></param>
 public Documentor(IStorer storer)
 {
     Storer = storer;
 }
        /// <summary>
        /// Gets a reference to the class in the <see cref="AssemblyName"/> that matches <see cref="StorerClassName"/>.
        /// </summary>
        /// <returns>Returns the <see cref="IStorer"/> class reference.</returns>
        public IStorer GetStorer()
        {
            if (storer == null)
            {
                if (storerType == null)
                {
                    if (AssemblyName != null && StorerClassName != null)
                    {
                        if (assemblyRef == null)
                        {
                            GetAssembly();
                        }

                        if (assemblyRef != null)
                        {
                            storerType = assemblyRef.GetType(AssemblyName + "." + StorerClassName);
                        }
                    }
                }

                if (storerType != null && storer == null)
                {
                    if (storerType.BaseType == typeof(DatabaseStorer))
                    {
                        storer = (IStorer)Activator.CreateInstance(storerType, this.ConnectionString);
                    }
                    else
                    {
                        storer = (IStorer)Activator.CreateInstance(storerType);
                    }
                }
            }
            return storer;
        }
Example #7
0
        /// <summary>
        /// Flushes all buffers that contain data by calling each buffer handler's StoreMessages method.
        /// </summary>
        public void Flush()
        {
            // Get a fast, one-way, read-only enumer of the buffers' keys
            Dictionary <string, List <string[]> > .KeyCollection.Enumerator enumer = buffers.Keys.GetEnumerator();
            List <string[]> currentVal, copiedList = null;

            // Ensure that a buffer is defined
            if (enumer.Current == null)
            {
                enumer.MoveNext();
            }

            while (enumer.Current != null)
            {
                currentVal = buffers[enumer.Current];

                // Lock the buffer while a copy is made so that new entries being added do not block or fail the copy.
                lock (currentVal)
                {
                    try
                    {
                        if (currentVal.Count > 0)
                        {
                            copiedList = DeepCopy <List <string[]> >(currentVal);

                            // Ensure that the copied object contains the same number of messages.
                            if (copiedList.Count != currentVal.Count)
                            {
                                EventLogger.LogEvent("An error occured while storing messages for " + enumer.Current,
                                                     System.Diagnostics.EventLogEntryType.Error);
                            }

                            // Clear the buffer.
                            currentVal.Clear();
                        }
                    }
                    catch (Exception ex)
                    {
                        EventLogger.LogEvent("Could not store messages from " + enumer.Current + " because: " + ex.Message,
                                             System.Diagnostics.EventLogEntryType.Error);
                    }
                    finally
                    {
                        Monitor.Pulse(currentVal);
                    }
                }

                if (copiedList != null && copiedList.Count > 0)
                {
                    try
                    {
                        // Get a refence to the storer interface of the handler
                        IStorer storer = handlers[enumer.Current].GetStorer() as IStorer;

                        if (storer != null)
                        {
                            //Process the list of messages
                            if (!storer.StoreMessages(copiedList))
                            {
                                EventLogger.LogEvent("An error occured while storing messages for " + enumer.Current,
                                                     System.Diagnostics.EventLogEntryType.Warning);
                            }
                            else
                            {
                                copiedList.Clear();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        EventLogger.LogEvent("Could not store message from " + enumer.Current + " because: " + ex.Message,
                                             System.Diagnostics.EventLogEntryType.Warning);
                    }
                }

                enumer.MoveNext();
            }
        }