Example #1
0
 /// <summary>
 /// Create a new AdaptorCollator providing collator it adapts, with read and write conversions for the outer
 /// and underlying types
 /// </summary>
 /// <param name="baseCollator">Collator this adaptor wraps</param>
 /// <param name="readConvert">Conversion from data read from inner collator to type of outer adaptor</param>
 /// <param name="writeConvert">Conversion for data being written from outer adaptor to inner collator</param>
 public AdaptorCollator(ICollator baseCollator, Func <TFrom, TTo> readConvert, Func <TTo, TFrom, TFrom> writeConvert) : base(baseCollator.System)
 {
     this.baseCollator = baseCollator;
     this.readConvert  = readConvert;
     this.writeConvert = writeConvert;
     IdWriteConvert    = x => x;
     PropertyMap       = new Dictionary <string, string>();
 }
        public async Task <ImageCollatorOutputs> FunctionHandler(ImageCollatorInputs input, ILambdaContext context)
        {
            this.context = context;

            Log("Collation: " + input.collation);
            Log("Accounts:  " + string.Join(",", input.accounts));
            Log("Period:    " + input.period);
            Log("Filter:    " + input.filter);
            Log("Group:     " + input.group);

            var collation = EnumHelper.EnsureArgument <Collations>(input.collation, "collation");

            var twitterApiKey            = GetEnv("TWITTER_CONSUMER_KEY");
            var twitterApiKeySecret      = GetEnv("TWITTER_CONSUMER_KEY_SECRET");
            var twitterAccessToken       = GetEnv("TWITTER_ACCESS_TOKEN");
            var twitterAccessTokenSecret = GetEnv("TWITTER_ACCESS_TOKEN_SECRET");
            var githubToken      = GetEnv("GITHUB_TOKEN", collation == Collations.github);
            var githubOwner      = GetEnv("GITHUB_OWNER", collation == Collations.github);
            var githubRepository = GetEnv("GITHUB_REPOSITORY", collation == Collations.github);
            var bucket           = GetEnv("AWS_S3_BUCKET", collation == Collations.s3);

            var filter = EnumHelper.EnsureArgument <Filters>(input.filter, "filter");

            var dates = PeriodHelper.ParsePeriod(input.period);
            var start = dates[0];
            var end   = dates[1];

            var keywords = await KeywordsHelper.FindKeywordsAsync(input.keywords_list, input.keywords_list_url);

            var inspector = new TwitterInspector(
                twitterApiKey,
                twitterApiKeySecret,
                twitterAccessToken,
                twitterAccessTokenSecret,
                filter,
                context.Logger.LogLine,
                keywords);

            ICollator collator = CollatorFactory.Create(collation, Log, input.group, bucket, githubToken, githubOwner, githubRepository);

            collator.Verbose = true;

            var outputs = new ImageCollatorOutputs();

            foreach (var account in input.accounts)
            {
                var medias = await inspector.FilterTimelineAsync(account, start, end);

                var summary = await collator.CollateAsync(medias);

                outputs.summaries += summary.Summaries;
                outputs.files     += summary.Files;
                outputs.errors.AddRange(summary.Errors);
            }

            return(outputs);
        }
Example #3
0
        /// <summary>
        /// Get the url(s) of a container or content item with option to process through
        /// processes registered to GenerateUrl event
        /// </summary>
        /// <param name="o">container or content item</param>
        /// <param name="transform">whether to process through GenerateUrl event</param>
        /// <returns>All the possible urls</returns>
        public IEnumerable <string> GetUrls(object o, bool transform)
        {
            Type type = Collator.GetContentType(o);

            ICollator collator = Collator.Instance.Registered(type);
            var       address  = collator.GetAddress(o);

            var urls = GetUrls(address);

            if (transform)
            {
                var         container = Collator.Instance.GetContainer(o);
                ItemVersion iv        = new ItemVersion(container);
                urls = urls.Select(url => transform ? UrlTransform(url, iv) : url);
            }

            return(urls);
        }
        private void Add(int indexId, int wsId, string text, T item)
        {
            SortKeyIndex   index    = GetIndex(indexId, wsId);
            IWritingSystem ws       = m_wsManager.Get(wsId);
            ICollator      collator = ws.Collator;

            switch (m_type)
            {
            case SearchType.Exact:
            case SearchType.Prefix:
                index.Add(collator.GetSortKey(text).KeyData, item);
                break;

            case SearchType.FullText:
                foreach (string token in Icu.Split(Icu.UBreakIteratorType.UBRK_WORD, ws.IcuLocale, text))
                {
                    index.Add(collator.GetSortKey(token).KeyData, item);
                }
                break;
            }
        }
Example #5
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Opens the collating engine.
			/// </summary>
			/// <param name="sWs">The s ws.</param>
			/// --------------------------------------------------------------------------------
			public void OpenCollatingEngine(string sWs)
			{
				m_collater = m_cache.ServiceLocator.WritingSystemManager.Get(sWs).Collator;
			}
Example #6
0
			private void Init()
			{
				m_collater = null;
			}
Example #7
0
        /// <summary>
        /// Get the possible route datas that could have selected a given container or content item via a route
        /// </summary>
        /// <param name="route">The route</param>
        /// <param name="o">The container or content item</param>
        /// <returns>The route datas that could have accessed the object via the route</returns>
        public List <RouteData> GetRouteDatas(Route route, Address address)
        {
            // Start list of urls which could map to this item.  Note, catchall items (starting *) are treated as normal ones
            List <RouteValueDictionary> rvds = new List <RouteValueDictionary>();

            var keyOutputs = route.KeyOutputs();

            Type type = address.Type;

            ICollator collator = Collator.Instance.Registered(type);
            var       rvd      = new RouteValueDictionary(address);

            // Action & controller

            if (!(keyOutputs.ContainsKey("controller") && keyOutputs.ContainsKey("action")))
            {
                throw new Exception("Route " + route.Url + " fails to define controller and action");
            }

            if (keyOutputs["controller"].StartsWith("?"))
            {
                throw new Exception("Route " + route.Url + " is a data route which lacks but must have a specified controller");
            }

            if (!ContentTypeHierarchy.ControllerActions.ContainsKey(keyOutputs["controller"]))
            {
                return(new List <RouteData>());  // Controller doesn't exist therefore no rvds
            }
            rvd.Add("controller", keyOutputs["controller"]);

            rvds.Add(rvd);

            // copy list so we can change 'actions'
            var actions = ContentTypeHierarchy.ControllerActions[keyOutputs["controller"]].ToList();

            if (keyOutputs["action"].StartsWith("?"))
            {
                if (keyOutputs["action"].Length > 1 && actions.Contains(keyOutputs["action"].Substring(1).ToLower()))
                {
                    actions.Add("??");
                }
                rvds = PermuteAdd(rvds, "action", actions);
            }
            else if (!actions.Contains(keyOutputs["action"]))
            {
                return(new List <RouteData>()); // Fixed action doesn't exist therefore no urls
            }
            else
            {
                rvd.Add("action", keyOutputs["action"]);
            }

            // Route vars addressing the content item

            foreach (var kvp in keyOutputs)
            {
                if (kvp.Key == "controller" || kvp.Key == "action") // already dealt with
                {
                    continue;
                }

                if (kvp.Value == "??" && address.ContainsKey(kvp.Key)) // optional variable
                {
                    address.SetMatched(kvp.Key);
                }
                else if (kvp.Value.StartsWith("?")) // variable takes any value
                {
                    // matches a path element
                    address.SetMatched(kvp.Key);   // this address element is matched
                }
                else // fixed value, has to be matched by item
                {
                    bool matched = false;
                    if (address.ContainsKey(kvp.Key))
                    {
                        if (address.GetAsString(kvp.Key) == kvp.Value)
                        {
                            matched = true;
                            address.SetMatched(kvp.Key);
                        }
                    }
                    if (!matched)
                    {
                        return(new List <RouteData>());
                    }
                }
            }

            if (!address.FullyMatched) // Fails because one or more address elements could not have come from this route
            {
                return(new List <RouteData>());
            }

            return(rvds
                   .Select(r =>
            {
                var rd = new RouteData();
                r.Do(kvp => rd.Values.Add(kvp.Key, kvp.Value));
                rd.Route = route;
                rd.RouteHandler = route.RouteHandler;
                return rd;
            })
                   .ToList());
        }
 /// <summary>
 /// Initialise the type system, the collator and the repository for a content type
 /// </summary>
 /// <param name="t">content type</param>
 /// <param name="coll">the collator</param>
 /// <param name="repo">the repository</param>
 public static void SetupType(this ITypeSystemRegistrar regr, Type t, ICollator coll, IRepository repo)
 {
     regr.SetupType(t, coll, repo, null);
 }
 /// <summary>
 /// Initialise the type system, the collator, the repository and the editor redirect for a content type
 /// </summary>
 /// <typeparam name="T">content type</typeparam>
 /// <param name="coll">the collator</param>
 /// <param name="repo">the repository</param>
 /// <param name="redir">the editor redirect</param>
 public static void SetupType <T>(this ITypeSystemRegistrar regr, ICollator coll, IRepository repo, Func <IRouter, RouteContext, object, IRouter> redir)
 {
     regr.SetupType(typeof(T), coll, repo, redir);
 }
Example #10
0
 protected void ResetCollator()
 {
     _collator = null;
     IsValid   = false;
 }
Example #11
0
 /// <summary>
 /// Initialise the type system, the collator, the repository and the editor redirect for a content type
 /// </summary>
 /// <typeparam name="T">content type</typeparam>
 /// <param name="coll">the collator</param>
 /// <param name="repo">the repository</param>
 /// <param name="redir">the editor redirect</param>
 public static void SetupType <T>(this ITypeSystemRegistrar regr, ICollator coll, IRepository repo, DiversionStrategy redir)
 {
     regr.SetupType(typeof(T), coll, repo, redir);
 }
        /// <summary>
        /// Searches an index for the specified string.
        /// </summary>
        /// <param name="indexId">The index ID.</param>
        /// <param name="tss">The string.</param>
        /// <returns>The search results.</returns>
        public IEnumerable <T> Search(int indexId, ITsString tss)
        {
            if (tss == null || string.IsNullOrEmpty(tss.Text))
            {
                return(Enumerable.Empty <T>());
            }

            HashSet <T> results = null;

            foreach (Tuple <int, string> wsStr in GetWsStrings(tss))
            {
                SortKeyIndex index    = GetIndex(indexId, wsStr.Item1);
                ICollator    collator = m_wsManager.Get(wsStr.Item1).Collator;
                switch (m_type)
                {
                case SearchType.Exact:
                case SearchType.Prefix:
                {
                    byte[] sortKey = collator.GetSortKey(wsStr.Item2).KeyData;
                    var    lower   = new byte[wsStr.Item2.Length * SortKeyFactor];
                    Icu.GetSortKeyBound(sortKey, Icu.UColBoundMode.UCOL_BOUND_LOWER, ref lower);
                    var upper = new byte[wsStr.Item2.Length * SortKeyFactor];
                    Icu.GetSortKeyBound(sortKey,
                                        m_type == SearchType.Exact
                                                                                                        ? Icu.UColBoundMode.UCOL_BOUND_UPPER
                                                                                                        : Icu.UColBoundMode.UCOL_BOUND_UPPER_LONG, ref upper);
                    IEnumerable <T> items = index.GetItems(lower, upper);
                    if (results == null)
                    {
                        results = new HashSet <T>(items);
                    }
                    else
                    {
                        results.IntersectWith(items);
                    }
                    break;
                }

                case SearchType.FullText:
                    string   locale = m_wsManager.GetStrFromWs(wsStr.Item1);
                    string[] tokens = Icu.Split(Icu.UBreakIteratorType.UBRK_WORD, locale, wsStr.Item2).ToArray();
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        byte[] sortKey = collator.GetSortKey(tokens[i]).KeyData;
                        var    lower   = new byte[tokens[i].Length * SortKeyFactor];
                        Icu.GetSortKeyBound(sortKey, Icu.UColBoundMode.UCOL_BOUND_LOWER, ref lower);
                        var upper = new byte[tokens[i].Length * SortKeyFactor];
                        Icu.GetSortKeyBound(sortKey,
                                            i < tokens.Length - 1
                                                                                                        ? Icu.UColBoundMode.UCOL_BOUND_UPPER
                                                                                                        : Icu.UColBoundMode.UCOL_BOUND_UPPER_LONG, ref upper);
                        IEnumerable <T> items = index.GetItems(lower, upper);
                        if (results == null)
                        {
                            results = new HashSet <T>(items);
                        }
                        else
                        {
                            results.IntersectWith(items);
                        }
                    }
                    break;
                }
            }
            return(results ?? Enumerable.Empty <T>());
        }