private static void InvokeCallback(AsyncCallback callback, IAsyncResult result)
 {
     if (callback != null)
     {
         callback.Invoke(result);
     }
 }
        public override IAsyncResult BeginDownloadXml(Uri feeduri, AsyncCallback callback)
        {
#if !WINDOWS_PHONE
            if (!IsolatedStorageFile.IsEnabled) throw new MissingFeedException("IsolatedStorage is not enabled! Cannot access files from IsolatedStorage!");
#endif


            try
            {
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if(!PingFeed(feeduri, store)) throw new MissingFeedException(string.Format("Could not find feed at location {0}", feeduri));

                    using (var stream = new IsolatedStorageFileStream(feeduri.OriginalString, FileMode.Open,
                                                                   FileAccess.Read, store))
                    {
                        using(var reader = new StreamReader(stream))
                        {
                            var strOutput = reader.ReadToEnd();
                            //Fake the async result
                            var result = new AsyncResult<FeedTuple>(callback, new FeedTuple { FeedContent = strOutput, FeedUri = feeduri }, true);
                            if (callback != null) callback.Invoke(result);
                            return result;
                        }
                    }
                }
            }
            catch (IsolatedStorageException ex)
            {
                throw new MissingFeedException(string.Format("Unable to open feed at {0}", feeduri), ex);
            }
        }
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     var task = ReadAsync(buffer, offset, count, CancellationToken.None, state);
     if (callback != null)
     {
         task.ContinueWith(t => callback.Invoke(t));
     }
     return task;
 }
        public override ICancellableAsyncResult BeginCommit(AsyncCallback callback, object state)
        {
            Commit();

            ICancellableAsyncResult result = new CompletedCancellableAsyncResult(state);

            if (callback != null)
            {
                callback.Invoke(result);
            }

            return result;
        }
 public void ReadContextBegin(Stream oStream, AsyncCallback fCallback, object oParam)
 {
     try
     {
         m_oStream = oStream;
         m_oParam = oParam;
         int nInputLength = (int)m_oStream.Length;
         m_aBuffer = new byte[nInputLength];
         m_oStream.BeginRead(m_aBuffer, 0, nInputLength, fCallback, oParam);
     }
     catch
     {
         m_eError = ErrorTypes.ReadRequestStream;
     }
     if (ErrorTypes.NoError != m_eError)
         fCallback.Invoke(new AsyncOperationData(oParam));
 }
 public async void updateRequierdData(int days, AsyncCallback callback, AsyncCallback failCallback)
 {
     
     DateTime today=  DateTime.Now;
     LocalWeatherInput weatherInput = new LocalWeatherInput();
     weatherInput.num_of_days = days.ToString();
     callback.Invoke(new Task((object obj) => { },
                 string.Format(" {0} place will be updated!", places.Count)));
     try
     {
         
         foreach (string langName in VoiceCommandInfo.AvailableLanguages)
         {
             if (VoiceCommandService.InstalledCommandSets.ContainsKey(langName))
             {
                 VoiceCommandSet widgetVcs = VoiceCommandService.InstalledCommandSets[langName];
                 widgetVcs.UpdatePhraseListAsync("place", places.Keys);
             }
         }
     }
     catch (Exception e)
     {
         BugReporter.GetInstance().report(e);
     }
     foreach (KeyValuePair<string, Place> dictionaryEntry in places)
     {
         Place place =  dictionaryEntry.Value;
         if (place.LastUpdateTime > DateTime.Now.AddHours(-2) && !Settings.GetInstance().APIKey.Any())
         {
             callback.Invoke(new Task((object obj) => { },
                 "current weather data for " + place.Name + " is not outdated yet!"));
             continue;
         }
         if (place._useName)
             weatherInput.query = place.Name;
         else
             weatherInput.query = place.Latitude + "," + place.Longitude;
         SaveWeatherDataClass saver = new SaveWeatherDataClass(place.Name,callback);
         new FreeAPI().GetLocalWeather(weatherInput,saver.SaveWeatherData, failCallback);
         Thread.Sleep(1000);
     }
     
 }
 public void ReadContextBegin(Stream oStream, AsyncCallback fCallback, object oParam)
 {
     ErrorTypes eError = ErrorTypes.NoError;
     try
     {
         m_oStream = oStream;
         m_fAsyncCallback = fCallback;
         m_oParam = oParam;
         m_oStream.BeginRead(m_aBuffer, 0, m_aBuffer.Length, ClearCacheTaskResultCallback, null);
     }
     catch
     {
         eError = ErrorTypes.ReadRequestStream;
     }
     if (ErrorTypes.NoError != eError)
     {
         m_eError = eError;
         fCallback.Invoke(new AsyncOperationData(oParam));
     }
 }
        public IAsyncResult BeginReceiveFrom(byte[] buffer, ref EndPoint remoteEndPoint, AsyncCallback asynCallback, object state)
        {
            var ar = new MockedAsyncResult(state);
            Encoding.ASCII.GetBytes(MessageString).CopyTo(buffer, 0);

            asynCallback.Invoke(ar);

            return ar;
        }
        protected override IAsyncResult BeginInvokeCore(InvokeArgs invokeArgs, AsyncCallback callback, object userState)
        {
            MockAsyncResult ar = new MockAsyncResult(null, userState, new object[] { invokeArgs.OperationName, invokeArgs.ReturnType, invokeArgs.Parameters, userState });

            // do the invoke and get the return value
            if (invokeArgs.OperationName == "Echo")
            {
                ar.ReturnValue = "Echo: " + (string)invokeArgs.Parameters.Values.First();
            }

            callback.Invoke(ar);

            return ar;
        }
        protected override IAsyncResult BeginSubmitCore(EntityChangeSet changeSet, AsyncCallback callback, object userState)
        {
            IEnumerable<ChangeSetEntry> submitOperations = changeSet.GetChangeSetEntries();
            MockAsyncResult ar = new MockAsyncResult(null, userState, new object[] { changeSet, submitOperations, userState });

            // perform mock submit operations

            callback.Invoke(ar);

            return ar;
        }
        protected override IAsyncResult BeginQueryCore(EntityQuery query, AsyncCallback callback, object userState)
        {
            // load test data and get query result
            IEnumerable<Entity> entities = GetQueryResult(query.QueryName, query.Parameters);
            if (query.Query != null)
            {
                entities = RebaseQuery(entities.AsQueryable(), query.Query).Cast<Entity>();
            }

            MockAsyncResult ar = new MockAsyncResult(entities, userState, null);
            callback.Invoke(ar);

            return ar;
        }
        public void GetBookmarks(Folder folder, AsyncCallback callback)
        {
            String url = "https://www.instapaper.com/api/1/bookmarks/list";
            String[] scriptParams = { url, "folder_id", folder.Id };
            callApi(url, scriptParams, new AsyncCallback(delegate(IAsyncResult res)
            {
                String respResult = readResult();
                List<Bookmark> bookmarks = new List<Bookmark>();

                JsonParser parser = new JsonParser(respResult);
                var parsedBookmarksResult = parser.Decode();

                ArrayList bookmarkArray = parsedBookmarksResult as ArrayList;

                foreach (Dictionary<String, Object> bookmark in bookmarkArray)
                {
                    if ((bookmark["type"] as String).Equals("bookmark"))
                    {
                        Bookmark current = new Bookmark(this);
                        current.Id = (String)bookmark["bookmark_id"];
                        current.Title = (String)bookmark["title"];
                        current.Url = (String)bookmark["url"];
                        current.Starred = ((String)bookmark["starred"]).Equals("1");
                        bookmarks.Add(current);
                    }

                }

                folder.Bookmarks = bookmarks;
                callback.Invoke(res);
            }));
        }
 public void UnStarBookmark(Bookmark bookmark, AsyncCallback callback)
 {
     String url = "https://www.instapaper.com/api/1/bookmarks/unstar";
     String[] scriptParams = { url, "bookmark_id", bookmark.Id };
     callApi(url, scriptParams, new AsyncCallback(delegate(IAsyncResult res)
     {
         bookmark.Starred = false;
         callback.Invoke(res);
     }));
 }
        public void GetFolderList(User user, AsyncCallback callback)
        {
            String url = "https://www.instapaper.com/api/1/folders/list";
            String[] scriptParams = { url };
            callApi(url, scriptParams, delegate(IAsyncResult result){
                String respResult = readResult();
                List<Folder> folders = new List<Folder>();

                // manually add the predefined folders
                Folder unread = new Folder(this);
                unread.Id = Folder.UNREAD;
                unread.Title = "Unread";
                Folder starred = new Folder(this);
                starred.Id = Folder.STARRED;
                starred.Title = "Starred";
                Folder archive = new Folder(this);
                archive.Id = Folder.ARCHIVE;
                archive.Title = "Archive";
                folders.Add(unread);
                folders.Add(starred);
                folders.Add(archive);

                JsonParser parser = new JsonParser(respResult);
                var parsedFolderResult = parser.Decode();

                ArrayList folderArray = parsedFolderResult as ArrayList;

                foreach (Dictionary<String, Object> folder in folderArray)
                {
                    Folder current = new Folder(this);
                    current.Id = folder["folder_id"] as String;
                    current.Title = folder["title"] as String;
                    folders.Add(current);
                }

                user.Folders = folders;
                callback.Invoke(result);
            });
        }
 public void GetBookmarkText(Bookmark bookmark, AsyncCallback callback)
 {
     String url = "https://www.instapaper.com/api/1/bookmarks/get_text";
     String[] scriptParams = { url, "bookmark_id", bookmark.Id };
     callApi(url, scriptParams, new AsyncCallback(delegate(IAsyncResult res) {
         bookmark.HtmlText = readResult();
         callback.Invoke(res);
     }));
 }