protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            var baseDir = Path.Combine (Application.ApplicationInfo.DataDir, "image_cache");
            if (!Directory.Exists (baseDir))
                Directory.CreateDirectory (baseDir);

            var data = new List<IDictionary<string,object>> ();
            var hr = new HttpWebRequest (new Uri ("http://api.twitter.com/1/statuses/public_timeline.json"));
            #if REACTIVE
            var req = Observable.FromAsyncPattern<WebResponse> (hr.BeginGetResponse, hr.EndGetResponse);
            Observable.Defer (req).Subscribe (v => {
            #else
            {
                var v = hr.GetResponse ();
            #endif
                var urls = new Dictionary<Uri,string> ();
                var json = (IEnumerable<JsonValue>)JsonValue.Load (v.GetResponseStream ());
            #if REACTIVE
                json.ToObservable ().Select (j => j.AsDynamic ()).Subscribe (jitem => {
            #else
                var items = from item in json select item.AsDynamic ();
                foreach (dynamic jitem in items) {
            #endif
                    var dic = new Dictionary<string,object> ();
                    dic ["Text"] = (string) jitem.text;
                    dic ["Name"] = (string) jitem.user.name;
                    var uri = new Uri ((string) jitem.user.profile_image_url);
                    var file = Path.Combine (baseDir, (string) jitem.id + new FileInfo (uri.LocalPath).Extension);
                    urls.Add (uri, file);
                    dic ["Icon"] = Path.Combine (baseDir, file);
                    data.Add (dic);
            #if REACTIVE
                });
            #else
                }
            #endif
                urls.ToList ().ForEach (p => new WebClient ().DownloadFileAsync (p.Key, p.Value));

                var from = new string [] {"Text", "Name", "Icon"};
                var to = new int [] { Resource.Id.textMessage, Resource.Id.textName, Resource.Id.iconView};

                this.RunOnUiThread (() => {
                    ListAdapter = new SimpleAdapter (this, data, Resource.Layout.ListItem, from, to);
                });
            #if REACTIVE
            });
            #else
            }
            #endif
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var stringList = new List<string>();
            Random random = new Random();
            for (int i = 0; i < 100000; ++i)
            {
            stringList.Add(random.NextDouble().ToString());
            }

            string[] strvec = stringList.ToArray();

            doDynamic(strvec);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            var baseDir = Path.Combine (Application.ApplicationInfo.DataDir, "image_cache");
            if (!Directory.Exists (baseDir))
                Directory.CreateDirectory (baseDir);

            var from = new string [] {"Text", "Name", "Icon"};
            var to = new int [] { Resource.Id.textMessage, Resource.Id.textName, Resource.Id.iconView};
            var data = new List<IDictionary<string,object>> ();
            data.Add (new JavaDictionary<string,object> () { {"Text", "loading"}, {"Name", ""} });
            var urls = new Dictionary<Uri,List<string>> ();
            var getUrl = new Uri ("https://api.github.com/repos/mono/mono/commits");
            #if REACTIVE
            var hr = new HttpWebRequest (getUrl);
            var req = Observable.FromAsyncPattern<WebResponse> (hr.BeginGetResponse, hr.EndGetResponse);
            Observable.Defer (req).Subscribe (v => {
                var v = hr.GetResponse ();
                var json = (IEnumerable<JsonValue>) JsonValue.Load (v.GetResponseStream ());
            #else
            var wc = new WebClient ();
            wc.Headers ["USER-AGENT"] = "Xamarin Android sample HTTP client";
            wc.DownloadStringCompleted += (sender, e) => {
                data.Clear ();
                var v = e.Result;
                var json = (IEnumerable<JsonValue>) JsonValue.Parse (v);
            #endif
            #if REACTIVE
                json.ToObservable ().Select (j => j.AsDynamic ()).Subscribe (jitem => {
            #else
                foreach (var item in json.Select (j => j.AsDynamic ())) {
            #endif
                    var uri = new Uri ((string) item.author.avatar_url);
                    var file = Path.Combine (baseDir, (string) item.author.id + new FileInfo (uri.LocalPath).Extension);
                    if (!urls.ContainsKey (uri))
                        urls.Add (uri, new List<string> () {file});
                    else
                        urls [uri].Add (file);
                    data.Add (new JavaDictionary<string,object> () { {"Text", item.commit.message}, {"Name", item.author.login}, {"Icon", Path.Combine (baseDir, file) }});
            #if REACTIVE
                });
            #else
                }
            #endif
                urls.ToList ().ForEach (p => {
                        var iwc = new WebClient ();
                        iwc.DownloadDataCompleted += (isender, ie) => p.Value.ForEach (s => {
                            using (var fs = File.Create (s))
                                fs.Write (ie.Result, 0, ie.Result.Length);
                        });
                        iwc.DownloadDataAsync (p.Key);
                    });

                this.RunOnUiThread (() => {
                    ListAdapter = new SimpleAdapter (this, data, Resource.Layout.ListItem, from, to);
                });
            #if REACTIVE
            });
            #else
            };
            wc.DownloadStringAsync (getUrl);
            #endif
            ListAdapter = new SimpleAdapter (this, data, Resource.Layout.ListItem, from, to);
        }
Esempio n. 4
0
 public static int G(int[] values)
 {
     int n = 10;
     List list = new List();
     for (int i = 0; i < n; i++)
         list.InsertToEnd(values[i]);
     return list.Get(3);
 }