Beispiel #1
0
        public void FetchTweetInformations(IManosContext ctx, string id)
        {
            if (string.IsNullOrEmpty (id))
                 ctx.Response.HandleEmptyJson ();

            string json;
            if (store.TryGetCachedTwitterInfos (id, out json)) {
                ctx.Response.HandleJson (json);
                return;
            }

            string avatar, tweet, screenname, name, url, desc;
            store.GetTwitterInfosFromImage (id, out avatar, out tweet, out screenname, out name, out url, out desc);

            JsonStringDictionary dict = new JsonStringDictionary ();
            dict["avatar"] = avatar;
            dict["tweet"] = System.Web.HttpUtility.HtmlEncode (tweet);
            dict["name"] = name;
            dict["screenname"] = screenname;
            dict["url"] = url;
            dict["desc"] = desc;

            json = dict.Json;
            store.SetCachedTwitterInfos (id, json);

            ctx.Response.HandleJson (json);
        }
Beispiel #2
0
        public void FetchInformations(IManosContext ctx, string id)
        {
            if (string.IsNullOrEmpty (id))
                ctx.Response.HandleEmptyJson ();

            string json;

            if (store.GetPicturesInfos (id, out json)) {
                Log.Info ("Fetching infos for {0} and returning: {1}", id.ToString (), json);
                ctx.Response.HandleJson (json);
                return;
            }

            if (!File.Exists (Path.Combine (imgDirectory, id))) {
                ctx.Response.HandleEmptyJson ();
                return;
            }

            Task.Factory.StartNew (() => {
                JsonStringDictionary dict = new JsonStringDictionary ();

                TagLibMetadata metadata = new TagLibMetadata (imgDirectory, id);
                if (!metadata.IsValid) {
                    Log.Info (id + " is invalid file");
                    json = string.Empty;
                } else {
                    metadata.FillUp (dict);
                    json = dict.Json;
                }
                metadata.Close ();

                store.SetPictureInfos (id, json);
                ctx.Response.HandleJson (json);
            });
        }
Beispiel #3
0
        public void FetchLinkInformations(IManosContext ctx, string id)
        {
            if (string.IsNullOrEmpty (id))
                 ctx.Response.HandleEmptyJson ();

            string json;
            if (store.TryGetPictureLinks (id, out json)) {
                ctx.Response.HandleJson (json);
                return;
            }

            JsonStringDictionary dict = new JsonStringDictionary ();

            var shortUrl = baseServerUrl + "/s/" + store.GetShortUrlForImg (id);
            var longUrl = baseServerUrl + "/i/" + id;
            var ogUrl = baseServerUrl + "/og/" + id;

            dict["short"] = shortUrl;
            dict["permanent"] = longUrl;
            dict["facebook"] = ogUrl;

            json = dict.Json;
            store.SetPictureLinks (id, json);

            ctx.Response.HandleJson (json);
        }
Beispiel #4
0
        public void FetchGeoInformations(IManosContext ctx, string id)
        {
            if (string.IsNullOrEmpty (id))
                ctx.Response.HandleEmptyJson ();

            string json;

            if (store.GetPictureGeo (id, out json)) {
                ctx.Response.HandleJson (json);
                return;
            }

            if (!File.Exists (Path.Combine (imgDirectory, id))) {
                ctx.Response.HandleEmptyJson ();
                return;
            }

            Task.Factory.StartNew (() => {
                json = string.Empty;
                JsonStringDictionary dict = new JsonStringDictionary ();
                TagLibMetadata metadata = new TagLibMetadata (imgDirectory, id);

                if (!metadata.IsValid) {
                    Log.Info (id + " is invalid file");
                } else {
                    var coordinates = metadata.GeoCoordinates;
                    if (coordinates != null) {
                        var invCult = System.Globalization.CultureInfo.InvariantCulture;
                        dict["latitude"] = coordinates.Item1.ToString (invCult);
                        dict["longitude"] = coordinates.Item2.ToString (invCult);
                        json = dict.Json;
                    }
                }
                metadata.Close ();

                store.SetPictureGeo (id, json);
                ctx.Response.HandleJson (json);
            });
        }