Esempio n. 1
0
        public FileResult GetFileStat(string filePath)
        {
            GDFileStat fileStat = new GDFileStat();
            NSError    error;

            if (GDFileSystem.GetFileStat(filePath, ref fileStat, out error))
            {
                return(new FileResult()
                {
                    Filename = new NSString(filePath).LastPathComponent,
                    IsFolder = fileStat.isFolder
                });
            }
            else
            {
                if (error != null)
                {
                    Console.WriteLine("GetFileStat error domain={0} code={1:d} userinfo={2}",
                                      error.Domain, (long)error.Code,
                                      error.UserInfo.Description);
                }
            }

            return(null);
        }
        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);
        }