private bool ProcessDateAndTimeServiceRequest(string application, string service, string version, string method, Foundation.NSObject parameters, NSObject[] attachments, string requestID, out NSError goodError)
        {
            goodError = null;
            bool didSendResponse = false;

            if (String.Equals(version, "1.0.0"))
            {
                String dateString = DateTime.Now.ToString("g");
                didSendResponse = GDService.ReplyTo(application, new NSString(dateString), GDTForegroundOption.EPreferPeerInForeground, null, requestID, out goodError);
            }

            return(didSendResponse);
        }
Exemplo n.º 2
0
        public void SendErrorTo(string application, NSError error)
        {
            NSError goodError            = null;
            bool    didSendErrorResponse = GDService.ReplyTo(application, error, GDTForegroundOption.EPreferPeerInForeground, null, null, out goodError);

            if (!didSendErrorResponse)
            {
                if (goodError != null)
                {
                    UIAlertView alert = new UIAlertView("Error", goodError.LocalizedDescription, null, "OK", null);
                    alert.Show();
                }
            }
        }
        private bool ProcessGreetingsService(string application, string service, string version, string method, Foundation.NSObject parameters, NSObject[] attachments, string requestID, out NSError goodError)
        {
            goodError = null;
            bool requestProcessed = false;

            if (String.Equals(version, "1.0.0"))
            {
                if (String.Equals(method, "greetMe"))
                {
                    requestProcessed = GDService.ReplyTo(application, new NSString("G'day mate!"), GDTForegroundOption.EPreferPeerInForeground, null, requestID, out goodError);
                }
                else if (String.Equals(method, "sendFiles"))
                {
                    StringBuilder fileString = new StringBuilder(20);
                    GDFileStat    fileStat   = new GDFileStat();
                    for (int i = 0; i < attachments.Length; i++)
                    {
                        NSString file  = (NSString)attachments [i];
                        NSError  error = null;
                        bool     ok    = GDFileSystem.GetFileStat(file, ref fileStat, out error);
                        fileString.AppendFormat("{0}: ", file);

                        if (ok && error == null)
                        {
                            goodError = null;
                            fileString.AppendFormat("{0} bytes; ", fileStat.fileLen);
                            NSData fileData = GDFileSystem.ReadFromFile(file, out error);
                            if (fileData != null && error != null)
                            {
                                Console.WriteLine(String.Format("Filepath: {0}", file));
                                string fileDataString = NSString.FromData(fileData, NSStringEncoding.UTF8);
                                Console.WriteLine(String.Format("File Contents: {0}", fileDataString));
                            }
                        }
                        else
                        {
                            goodError = error;
                            fileString.AppendFormat("Error: {0}", error.LocalizedDescription);
                        }
                    }

                    UIAlertView alertView = new UIAlertView("Recieved Files", fileString.ToString(), null, "OK", null);
                    alertView.Show();
                    requestProcessed = true;
                }
            }

            return(requestProcessed);
        }
Exemplo n.º 4
0
        void DoneButton_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_requestId))
            {
                Console.WriteLine("Service has not connected to client");
                return;
            }

            NSError error = null;
            var     paths = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User,
                                                        true);
            var documentPathForFile = new NSString(paths[0]).AppendPathComponent(
                new NSString("RespondDataFile.txt")).ToString();

            GDFileSystem.WriteToFile(NSData.FromString(textView.Text, NSStringEncoding.UTF8), documentPathForFile,
                                     out error);

            if (error == null)
            {
                var urlString = string.Format("{0}.sc2://", _application);
                var testUrl   = new NSUrl(urlString);
                if (!UIApplication.SharedApplication.CanOpenUrl(testUrl))
                {
                    Console.WriteLine("Client is not installed");
                    return;
                }

                bool replyResult = GDService.ReplyTo(_application, null, GDTForegroundOption.EPreferPeerInForeground,
                                                     new[] { new NSString(documentPathForFile) }, _requestId, out error);

                if (!replyResult)
                {
                    Console.WriteLine("Failed to get Reply");
                }

                if (error != null)
                {
                    Console.WriteLine("Failed to Reply: {0} {1:d} {2}", error.Domain, error.Code,
                                      error.LocalizedDescription);
                }
            }
            else
            {
                Console.WriteLine("Failed to write data to secure storage: {0}", error.LocalizedDescription);
            }
        }
Exemplo n.º 5
0
        void ReportError(string application, string requestID, string message, int code)
        {
            var          localizedKey = NSError.LocalizedDescriptionKey;
            NSError      error        = null;
            NSDictionary userInfo     = new NSDictionary();

            userInfo.SetValueForKey(new NSString(message), localizedKey);

            NSError replyParams = new NSError(ICCErrorConstants.GDServicesErrorDomain, code, userInfo);

            bool replyResult = GDService.ReplyTo(application, replyParams, GDTForegroundOption.ENoForegroundPreference,
                                                 null, requestID, out error);

            if (!replyResult)
            {
                Console.WriteLine("ReplyTo returned false");
            }

            if (error != null)
            {
                Console.WriteLine("GDServiceReceiveFrom failed to reply: {0} {1:d} {2}",
                                  error.Domain, error.Code, error.LocalizedDescription);
            }
        }