Esempio n. 1
0
 static void Main(string[] args)
 {
     string url = "http://date.jsontest.com/";
     OnCompletedDelegate del = new OnCompletedDelegate(OnCompleted);
     GetJson(url, del);
     Console.ReadLine();
 }
Esempio n. 2
0
        private void PostAnnotationsButton_Click(object sender, RoutedEventArgs e)
        {
            XmlElement selectedImage = imagesListBox.Items.CurrentItem as XmlElement;

            if (selectedImage == null)
            {
                MessageBox.Show(this, "Please select an image from the Images tab.", "Select image", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            XmlNode predictionsNode = selectedImage.SelectSingleNode("predictions");

            if (predictionsNode == null)
            {
                MessageBox.Show(this, "Please process the image first.", "Process image", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            OnCompletedDelegate o = delegate(String response)
            {
                update(response);
            };

            XmlNode state = selectedImage.SelectSingleNode("predictions/@state");

            state.Value = "Posted to server";
            Request("post " + "<image>" + selectedImage.InnerXml + "</image>", o);
        }
        public HttpPromise(UnityWebRequest unityWebRequest, OnCompletedDelegate onCompleted)
        {
            if (unityWebRequest == null)
            {
                throw new ArgumentNullException("unityWebRequest");
            }

            this.unityWebRequest = unityWebRequest;
            this.onCompleted     = onCompleted;
            var asyncOperation = unityWebRequest.SendWebRequest();

            asyncOperation.completed += _ =>
            {
                this.ResponseCode = this.unityWebRequest.responseCode;
                this.notCompleted = false;
                try
                {
                    if (this.onCompleted != null)
                    {
                        this.onCompleted(this.unityWebRequest, new HttpPromiseSeter(this));
                    }
                }
                catch (Exception)
                {
                    this.HasError = true;
                    throw;
                }
                finally
                {
                    this.InvokeCompleted();
                }
            };
        }
Esempio n. 4
0
        public static HttpPromise <TResult, TError> JsonPut(Uri uri, object bodyObj, OnCompletedDelegate onCompleted)
        {
            var json    = JsonUtility.ToJson(bodyObj);
            var request = UnityWebRequest.Put(uri, json);

            request.SetRequestHeader("Content-Type", "application/json");
            return(new HttpPromise <TResult, TError>(request, onCompleted));
        }
 public IDisposable Subscribe(IObserver <T> observer)
 {
     lock (syncObject)
     {
         onNext      += observer.OnNext;
         onError     += observer.OnError;
         onCompleted += observer.OnCompleted;
     }
     return(new EventObserverCollectionHandle(this, observer));
 }
 private void Unsubscribe(IObserver <T> observer)
 {
     lock (syncObject)
     {
         // ReSharper disable DelegateSubtraction
         onNext      -= observer.OnNext;
         onError     -= observer.OnError;
         onCompleted -= observer.OnCompleted;
         // ReSharper restore DelegateSubtraction
     }
 }
        public void UnsubscribeAll(bool sendOnCompleted)
        {
            var curCompleted = onCompleted;

            lock (syncObject)
            {
                onNext      = null;
                onError     = null;
                onCompleted = null;
            }

            if (sendOnCompleted)
            {
                curCompleted?.Invoke();
            }
        }
Esempio n. 8
0
        private void Request(String command, OnCompletedDelegate onCompleted)
        {
            try
            {
                command  = command.Replace("\n", "");
                command += "\n";
                State s = new State(serverAdressTextBox.Text);
                s.onCompleted += onCompleted;

                UTF8Encoding asen = new UTF8Encoding();
                byte[]       ba   = asen.GetBytes(command);
                s.netstream.Write(ba, 0, ba.Length);
                s.netstream.Flush();

                s.netstream.BeginRead(s.buffer, 0, s.tcpclnt.ReceiveBufferSize, OnRead, s);
            }
            catch
            {
                update("Cannot complete request.");
            }
        }
Esempio n. 9
0
        private void FaceDetectionButtonButton_Click(object sender, RoutedEventArgs e)
        {
            XmlElement selectedImage = imagesListBox.Items.CurrentItem as XmlElement;

            if (selectedImage == null)
            {
                MessageBox.Show(this, "Please select an image from the Images tab.", "Select image", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            Cursor oldCursor = windowGrid.Cursor;

            windowGrid.Cursor = Cursors.Wait;
            DateTime            start = DateTime.Now;
            OnCompletedDelegate o     = delegate(String response)
            {
                try
                {
                    byte[]      imageBase64Encoding = Convert.FromBase64String(response);
                    BitmapImage bi = new BitmapImage();
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.BeginInit();
                    bi.StreamSource = new MemoryStream(imageBase64Encoding);
                    bi.EndInit();

                    update("Face detection in " + (DateTime.Now - start).TotalSeconds.ToString("0.00") + " seconds.");
                    windowGrid.Cursor = oldCursor;

                    new ImageWindow(bi).ShowDialog();
                }
                catch
                {
                    update(response);
                    windowGrid.Cursor = oldCursor;
                }
            };

            Request("facedetection " + toBase64(selectedImage.SelectSingleNode("path").InnerText), o);
            update("Face detection...");
        }
Esempio n. 10
0
        private void ProcessImageButton_Click(object sender, RoutedEventArgs e)
        {
            XmlElement selectedImage = imagesListBox.Items.CurrentItem as XmlElement;

            if (selectedImage == null)
            {
                MessageBox.Show(this, "Please select an image from the Images tab.", "Select image", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            XmlNode predictionsNode = selectedImage.SelectSingleNode("predictions");

            if (predictionsNode == null)
            {
                Cursor oldCursor = windowGrid.Cursor;
                windowGrid.Cursor = Cursors.Wait;
                try
                {
                    DateTime            start = DateTime.Now;
                    OnCompletedDelegate o     = delegate(String response)
                    {
                        try
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(response);
                            predictionsNode = doc.SelectSingleNode("predictions");
                            XmlNode      predictionsCurrNode = this.imagesXml.Document.CreateNode(XmlNodeType.Element, "predictions", "");
                            XmlAttribute dir     = this.imagesXml.Document.CreateAttribute("conceptsDir", "");
                            XmlNode      concept = predictionsNode.SelectSingleNode("@conceptsDir");
                            dir.Value = concept.Value;

                            XmlAttribute state = this.imagesXml.Document.CreateAttribute("state", "");
                            state.Value = "Processed";

                            predictionsCurrNode.Attributes.Append(dir);
                            predictionsCurrNode.Attributes.Append(state);
                            foreach (XmlNode node in predictionsCurrNode.SelectNodes("probability"))
                            {
                                node.InnerText = Double.Parse(node.InnerText).ToString("0.0000000000");
                            }

                            predictionsCurrNode.InnerXml = predictionsNode.InnerXml;
                            selectedImage.AppendChild(predictionsCurrNode);
                            update("Image processed in " + (DateTime.Now - start).TotalSeconds.ToString("0.00") + " seconds.");

                            windowGrid.Cursor               = oldCursor;
                            this.tabControl.SelectedItem    = this.predictionTabItem;
                            this.imagesListBox.SelectedItem = selectedImage;
                            this.predictionsListBox.ScrollIntoView(this.predictionsListBox.Items[0]);
                        }
                        catch
                        {
                            update(response);
                            windowGrid.Cursor = oldCursor;
                        }
                    };

                    String imagePath = selectedImage.SelectSingleNode("path").InnerText;
                    String tags      = getImageUserTags(imagePath);
                    tags.Replace(" ", "");
                    Request("predict 1 " + tags + " " + toBase64(imagePath), o);
                    update("Processing image...");
                }
                catch
                {
                    MessageBox.Show(this, "Something went wrong while connecting to server.\nPlease be sure the server is online.", "Prediction", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                update("Image already processed.");
                this.tabControl.SelectedItem = this.predictionTabItem;
            }
        }
Esempio n. 11
0
 // Get
 public static HttpPromise <TResult, TError> Get(string url, OnCompletedDelegate onCompleted)
 {
     return(new HttpPromise <TResult, TError>(UnityWebRequest.Get(url), onCompleted));
 }
Esempio n. 12
0
        public static HttpPromise <TResult, TError> JsonPut(Uri uri, string bodyData, OnCompletedDelegate onCompleted)
        {
            var request = UnityWebRequest.Put(uri, bodyData);

            request.SetRequestHeader("Content-Type", "application/json");
            return(new HttpPromise <TResult, TError>(request, onCompleted));
        }
Esempio n. 13
0
 public static HttpPromise <TResult, TError> Put(Uri uri, string bodyData, OnCompletedDelegate onCompleted)
 {
     return(new HttpPromise <TResult, TError>(UnityWebRequest.Put(uri, bodyData), onCompleted));
 }
Esempio n. 14
0
 public static HttpPromise <TResult, TError> Delete(Uri uri, OnCompletedDelegate onCompleted)
 {
     return(new HttpPromise <TResult, TError>(UnityWebRequest.Delete(uri), onCompleted));
 }