Beispiel #1
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            Assembly   a             = Assembly.Load("Microsoft.Phone.InteropServices, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e");
            Type       comBridgeType = a.GetType("Microsoft.Phone.InteropServices.ComBridge");
            MethodInfo dynMethod     = comBridgeType.GetMethod("RegisterComDll", BindingFlags.Public | BindingFlags.Static);
            object     retValue      = dynMethod.Invoke(null, new object[] { "liblw.dll", new Guid("E79018CB-46A6-432D-8077-8C0863533001") });
            //uint retval = Microsoft.Phone.InteropServices.ComBridge.RegisterComDll("libwph.dll", new Guid("56624E8C-CF91-41DF-9C31-E25A98FAF464"));
            Imangodll instance = (Imangodll) new Cmangodll();

            //Update messaging tiles
            int unread = 0;

            instance.getUnreadSMSCount(out unread);

            Microsoft.Phone.Shell.StandardTileData data = new Microsoft.Phone.Shell.StandardTileData();
            data.Count = unread;

            foreach (var t in Microsoft.Phone.Shell.ShellTile.ActiveTiles.Where(t => t.NavigationUri.ToString().Contains("5B04B775-356B-4AA0-AAF8-6491FFEA5610")))
            {
                t.Update(data);
            }

            //Update phone tile


            ScheduledActionService.LaunchForTest("ScheduledAgent", TimeSpan.FromMilliseconds(2200));

            NotifyComplete();
        }
        void checkForDataChange()
        {
            try
            {
                bool update = false;

                if (appSettings.useBing)
                {
                    System.Diagnostics.Debug.WriteLine(DateTime.Now.Subtract(lastbing).Hours);

                    if (DateTime.Now.Subtract(lastbing).Hours > 6)
                    {
                        lastbing = DateTime.Now;
                        updateBingWallpaper();
                        bingUpdateStatePending = true;
                    }
                }


                if (bingUpdateStatePending)
                {
                    return;
                }

                if (appSettings.chkSMS)
                {
                    int count = 0;
                    instance.getUnreadSMSCount(out count);

                    if (count != lastSMSCount)
                    {
                        string data = instance.getLatestSMS();
                        lastSMSBody = data.Substring(data.IndexOf(":") + 1);
                        string number = data.Substring(0, data.IndexOf(":"));

                        Microsoft.Phone.UserData.Contacts cc = new Microsoft.Phone.UserData.Contacts();
                        cc.SearchCompleted += new EventHandler <Microsoft.Phone.UserData.ContactsSearchEventArgs>((object o, Microsoft.Phone.UserData.ContactsSearchEventArgs e) =>
                        {
                            if (e.Results.Count() > 0)
                            {
                                lastSMSFrom = e.Results.First().DisplayName;
                            }
                            else
                            {
                                lastSMSFrom = number;
                            }
                            updateWidgets();
                        });
                        cc.SearchAsync(number, Microsoft.Phone.UserData.FilterKind.PhoneNumber, null);

                        lastSMSCount = count;
                    }
                }

                if (appSettings.chkWeather)
                {
                    if (weatherdata == 1)
                    {
                        weatherdata = 0;

                        string query = "http://weather.yahooapis.com/forecastrss?w=" + appSettings.woeid + "&nocache=" + DateTime.Now.Millisecond.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Hour.ToString();

                        System.Diagnostics.Debug.WriteLine(query);

                        WebClient cl = new System.Net.WebClient();
                        cl.DownloadStringAsync(new Uri(query));
                        cl.DownloadStringCompleted += new System.Net.DownloadStringCompletedEventHandler(cl_DownloadStringCompleted);

                        return;
                    }
                }


                if (counter > 400)
                {
                    updateWidgets();
                    counter = 1;
                    if (weatherdata == 0)
                    {
                        weatherdata = 1;
                    }
                }

                if (lastSMSCount == 0 && counter == 0 && appSettings.chkWeather == false) // first time thing
                {
                    updateWidgets();
                }

                counter++;
            }
            catch (Exception ex)
            {
                msgbox("Actual Exception in checkForDataChange(): " + ex.Message);
            }
        }