コード例 #1
0
        string ExtractReceivedDataFromAttachments(NSObject[] attachments)
        {
            var localFilePath = new NSString(attachments [0].ToString());

            Console.WriteLine("Local File Path: {0}", localFilePath);

            if (!GDFileSystem.FileExistsAtPath(localFilePath, false))
            {
                ReportError(_application, _requestId, "Attachment was not found",
                            (int)GDServicesError.GDServicesErrorInvalidParams);

                return(string.Empty);
            }

            NSError error          = null;
            NSData  attachmentData = GDFileSystem.ReadFromFile(localFilePath, out error);

            if (error != null)
            {
                var description = string.Format("Error Reading attachement: {0} {1}",
                                                localFilePath, error.LocalizedDescription);

                ReportError(_application, _requestId, description, (int)GDServicesError.GDServicesErrorInvalidParams);
                return(string.Empty);
            }

            return(new NSString(attachmentData.ToString(), NSStringEncoding.UTF8).ToString());
        }
        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);
        }
コード例 #3
0
 public NSData ReadFile(string fileName, NSError error)
 {
     return(GDFileSystem.ReadFromFile(fileName, out error));
 }