Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves or creates a container catalog based on container name.
        /// </summary>
        private CollectionData GetCollection(string container)
        {
            CollectionData returnData = null;

            if (!String.IsNullOrEmpty(container))
            {
                if (!this.CollectionMap.ContainsKey(container))
                {
                    String fileName = String.Format("{0}.csv", Guid.NewGuid().ToString("N"));
                    fileName = System.IO.Path.Combine(this.Directory, fileName);

                    // Add to the collection and record it
                    this.CollectionMap.Add(container, fileName);
                    this.Record(new string[] { container, fileName });
                }

                if (!this.Collections.ContainsKey(container))
                {
                    this.Collections.Add(container, new CollectionData());

                    this.Collections[container].Logger = new GenericCsvLogger(
                        System.IO.Path.GetDirectoryName(this.CollectionMap[container]),
                        System.IO.Path.GetFileName(this.CollectionMap[container]),
                        CatalogSink.CATALOG_HEADERS);
                }

                returnData = this.Collections[container];
            }
            return(returnData);
        }
Ejemplo n.º 2
0
        public bool ItemHasBeenScored(string container, string name)
        {
            bool returnValue = false;
            // Get or create the collection
            CollectionData collection = GetCollection(container);

            if (collection != null)
            {
                //Is this a duplicate? Are we updating something?
                returnValue = (collection.Items.FirstOrDefault(x => String.Compare(x.Name, name) == 0) != null);
            }
            return(returnValue);
        }
Ejemplo n.º 3
0
        public ScoredItem Find(string container, string name)
        {
            ScoredItem returnItem = null;

            if (this.CollectionMap.ContainsKey(container))
            {
                CollectionData collection = GetCollection(container);

                if (collection != null)
                {
                    //Is this a duplicate? Are we updating something?
                    returnItem = collection.Items.FirstOrDefault(x => String.Compare(x.Name, name) == 0);
                }
            }
            return(returnItem);
        }
Ejemplo n.º 4
0
        private void UpdateLog(object obj)
        {
            lock (this.ThreadLock)
            {
                CollectionData data = obj as CollectionData;
                if (data != null)
                {
                    data.Logger.ClearLog();
                    List <String> newEntries = new List <string>();

                    foreach (ScoredItem colitem in data.Items)
                    {
                        newEntries.Add(this.FormatItem(colitem));
                        //data.Logger.Record(this.FormatItem(colitem));
                    }

                    data.Logger.Rewrite(newEntries);
                }
            }
        }
Ejemplo n.º 5
0
        public void Record(IEnumerable <ScoredItem> itemBatch)
        {
            CollectionData collection     = null;
            String         collectionName = String.Empty;

            // Restriction is they all have to belong to the same collection
            foreach (ScoredItem item in itemBatch)
            {
                collection = GetCollection(item.Container);
                if (collection == null)
                {
                    throw new Exception("Invalid collection");
                }

                if (!String.IsNullOrEmpty(collectionName) &&
                    String.Compare(collectionName, collection.Logger.FileName) != 0)
                {
                    throw new Exception("Collections do not match on batch");
                }

                collectionName = collection.Logger.FileName;
            }

            // Now we know we have the same collection, update each one.
            foreach (ScoredItem item in itemBatch)
            {
                ScoredItem existing = collection.Items.FirstOrDefault(x => String.Compare(x.Name, item.Name) == 0);
                if (existing != null)
                {
                    existing.Classifications = item.Classifications;
                }
                else
                {
                    collection.Items.Add(item);
                }
            }

            // Update the entire thing in one go
            System.Threading.ThreadPool.QueueUserWorkItem(this.UpdateLog, collection);
        }
Ejemplo n.º 6
0
        public void Record(ScoredItem item)
        {
            // Get or create the collection
            CollectionData collection = GetCollection(item.Container);

            if (collection != null)
            {
                //Is this a duplicate? Are we updating something?
                ScoredItem existing = collection.Items.FirstOrDefault(x => String.Compare(x.Name, item.Name) == 0);
                if (existing != null)
                {
                    existing.Classifications = item.Classifications;

                    System.Threading.ThreadPool.QueueUserWorkItem(this.UpdateLog, collection);
                }
                else
                {
                    collection.Items.Add(item);
                    collection.Logger.Record(this.FormatItem(item));
                }
            }
        }