예제 #1
0
        private async Task <FileInfo> QueryAsyncCore(MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <FileInfo>();
            EventHandler <FileInfo> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleQuery += handler;

                if (MessageLoop == null && messageLoop == null)
                {
                    Query();
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var fileInfo = new PPFileInfo();
                        var result   = (PPError)PPBFileRef.Query(this, out fileInfo,
                                                                 new BlockUntilComplete()
                                                                 );
                        tcs.TrySetResult(new FileInfo(result, fileInfo));
                    }
                                                                   );

                    InvokeHelper(action, messageLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(new FileInfo(PPError.Aborted, new PPFileInfo()));
            }
            finally
            {
                HandleQuery -= handler;
            }
        }
예제 #2
0
        /// <summary>
        /// Query() queries info about a file or directory. You must have access to
        /// read this file or directory if it exists in the external filesystem.
        /// </summary>
        /// <returns>Error code</returns>
        public PPError Query()
        {
            var ficb = new CompletionCallbackWithOutput <PPFileInfo>(OnQuery);

            return((PPError)PPBFileRef.Query(this, out ficb.OutputAdapter.output, ficb));
        }