예제 #1
0
        public static bool TryUpdateFacetFactoryIndex(LoaderFacetFactory info)
        {
            var ffwi = info.Factory as IFacetFactoryWithIndex;

            if (ffwi == null)
            {
                throw new ArgumentException("factory is not indexed");
            }

            var lastUpdatedAt = DatabaseUtil.ExecuteNullableScalar <DateTime>(
                "SELECT LastIndexUpdate FROM FacetFactories WHERE Id = @Id",
                "@Id", info.DatabaseId);

            if (!ffwi.ShouldUpdateIndex(FacetIndexReason.Startup, lastUpdatedAt))
            {
                return(false);
            }

            ThreadPool.QueueUserWorkItem(notused =>
            {
                // what is this for?
                // Thread.Sleep(2000);
                UpdateFromFactory(info);
            });

            return(true);
        }
예제 #2
0
        public static ParseInput RewriteInput(this ParseInput input, LoaderFacetFactory forFactory, bool fromHistory)
        {
            if (!input.Any(x => x.Mode != TermParseMode.Normal))
            {
                return(input);
            }

            return(new ParseInput(input.Where(x =>
                                              (x.Mode == TermParseMode.Normal ||
                                               (x.Mode == TermParseMode.History && fromHistory)) &&
                                              x.IsFactorySourceValid(forFactory))));
        }
예제 #3
0
 static IEnumerable <ParseResult> TryParse(CommandGeneratorResult result, LoaderFacetFactory lff, ParseInput input, ParseMode mode,
                                           IList <TypeMoniker> facetTypes)
 {
     try
     {
         return(lff.Factory.Parse(input.RewriteInput(lff, false), mode, facetTypes));
     }
     catch (RequiresConfigurationException ex)
     {
         result.AddRCException(ex);
         return(null);
     }
     catch (OutOfMemoryException)
     {
         throw;
     }
     catch
     {
         return(null);
     }
 }
예제 #4
0
 public static void InitFacetFactory(LoaderFacetFactory info)
 {
     InitExtensionItem("FacetFactories", info);
 }
예제 #5
0
        static void UpdateFromFactory(LoaderFacetFactory factory)
        {
            var ffwi = factory.Factory as IFacetFactoryWithIndex;
            List <FacetMoniker> index;

            try
            {
                index = ffwi.EnumerateIndex().ToList();
            }
            catch (RequiresConfigurationException rce)
            {
                factory.AddIndexingException(rce);
                return;
            }
            catch (Exception ex)
            {
                // TODO: failure log?
                Debug.WriteLine("Could not enumerate indexed factory {0}: {1}", factory.Name, ex.Message);
                return;
            }

            using (var connection = DatabaseUtil.GetConnection())
            {
                const string cmdText =
                    @"SELECT FacetTypeId, FactoryDataHash, DisplayName
                      FROM FacetMonikers
                      WHERE FactoryTypeId = @FactoryTypeId";

                // load the existing index
                using (var cmd = new SqlCeCommand(cmdText, connection))
                {
                    cmd.Parameters.AddWithValue("@FactoryTypeId", factory.DatabaseId);

                    using (var reader = cmd.ExecuteResultSet(ResultSetOptions.Updatable))
                    {
                        while (reader.Read())
                        {
                            var facetType = Loader.GetFacetInfo((int)reader["FacetTypeId"]);

                            if (facetType == null)
                            {
                                // this would be unusual, since the factory is loaded
                                continue;
                            }

                            var factoryDataHash = (string)reader["FactoryDataHash"];
                            var displayName     = (string)reader["DisplayName"];
                            var indexIndex      = index.FindIndex(x => x.FacetType == facetType.Type &&
                                                                  x.HashString == factoryDataHash &&
                                                                  x.DisplayName == displayName);

                            if (indexIndex == -1)
                            {
                                reader.Delete();
                            }
                            else
                            {
                                index.RemoveAt(indexIndex);
                            }
                        }
                    }
                }

                foreach (var moniker in index)
                {
                    SaveFacetMoniker(moniker, connection: connection);
                }
            }
        }
예제 #6
0
 public static bool IsFactorySourceValid(this ParseInputTerm term, LoaderFacetFactory f)
 {
     return(term.Mode != TermParseMode.SpecificFactory ||
            (term.Mode == TermParseMode.SpecificFactory &&
             f.Aliases.Contains(term.FactoryAlias, StringComparer.CurrentCultureIgnoreCase)));
 }