コード例 #1
0
        private void ReceiveImage(ImageResource resource)
        {
            Resource = resource;
#if ANDROID
            UpdateImgView();
#endif

            if (ReceivedImage != null)
            {
                ReceivedImage(this);
            }

            Element el = this.Parent;
            while (el != null)
            {
                if (el is NPage)
                {
                    NPage page = (NPage)el;
                    page.PositionElements();
                }
                el = el.Parent;
            }
        }
コード例 #2
0
        private void update()
        {
            lock (locker)
            {
                try
                {
                    startQueued();

                    for (int i = 0; i < downloading.Count; i++)
                    {
                        var down = downloading[i];
                        switch (down.dtype)
                        {
                        case LoadType.File:
                        {
                            Task            task = down.Task;
                            IResourceObject res  = null;

                            if (task.Status == TaskStatus.RanToCompletion)
                            {
                                switch (down.type)
                                {
                                case ResourceType.Image:
#if ANDROID
                                    Task <Bitmap> t = (Task <Bitmap>)task;
                                    res = new ImageResource(t.Result);
#elif IOS
                                    Task <UIImage> t = (Task <UIImage>)task;
                                    res = new ImageResource(t.Result);
#else
                                    throw new NotImplementedException();
#endif
                                    if (down.store)
                                    {
                                        resources.Add(down.path.OriginalString, res);
                                    }

                                    downloading.RemoveAt(i);
                                    i--;
                                    for (int j = 0; j < down.Callbacks.Count; j++)
                                    {
                                        Delegate del = (Delegate)down.Callbacks[j];
                                        del.DynamicInvoke(res);
                                        //down.Callbacks[j](res);
                                    }
                                    break;
                                }
                            }
                        }
                        break;

                        case LoadType.Download:
                        {
                            down.client.Dispose();
                            var task = (Task <byte[]>)down.Task;
                            if (task.Status == TaskStatus.RanToCompletion)
                            {
                                // success
                                IResourceObject res = null;
                                switch (down.type)
                                {
                                case ResourceType.Image:
                                    res = new ImageResource(task.Result);
                                    if (task.Result.Length < 10)
                                    {
                                        // decode error
                                        string error = WebUtil.GetASCIIString(task.Result);
                                        continue;
                                    }

                                    break;

                                case ResourceType.String:
                                    res = new StringResource(task.Result);
                                    break;
                                }

                                if (down.store)
                                {
                                    resources.Add(down.path.OriginalString, res);
                                }

                                downloading.RemoveAt(i);
                                i--;

                                for (int j = 0; j < down.Callbacks.Count; j++)
                                {
                                    Delegate del = (Delegate)down.Callbacks[j];
                                    del.DynamicInvoke(res);
                                    //down.Callbacks[j](res);
                                }
                            }
                            else if (task.Status == TaskStatus.Canceled ||
                                     task.Status == TaskStatus.Faulted)
                            {
                                // failure
                                downloading.RemoveAt(i);
                                i--;

                                for (int j = 0; j < down.failureCallbacks.Count; j++)
                                {
                                    down.failureCallbacks[j]();
                                }
                            }
                        }
                        break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    if (ex is WebException)
                    {
                        WebException web = (WebException)ex;
                        using (Stream stream = web.Response.GetResponseStream())
                        {
                            StreamReader reader = new StreamReader(stream);
                            string       data   = reader.ReadToEnd();
                        }
                    }
                }
            }
        }