コード例 #1
0
        /// <summary>
        /// Call this as the VERY FIRST THING in FinishedLaunching
        /// </summary>
        public void Track()
        {
            var needsSync = false;

            // load history
#if SILVERLIGHT
            var noValues = (!AppSettings.Contains(xamVersionsKey) || !AppSettings.Contains(xamBuildsKey));
#else
            var noValues = (!AppSettings.Values.ContainsKey(xamVersionsKey) || !AppSettings.Values.ContainsKey(xamBuildsKey));
#endif

            if (noValues)
            {
                isFirstLaunchEver = true;

                versionTrail = new Dictionary <string, List <string> > {
                    { xamVersionsKey, new List <string>() },
                    { xamBuildsKey, new List <string>() }
                };
            }
            else
            {
#if SILVERLIGHT
                var oldVersionList = AppSettings[xamVersionsKey] as List <string>;

                var oldBuildList = AppSettings[xamBuildsKey] as List <string>;
#else
                var oldVersionList = AppSettings.Values[xamVersionsKey] as List <string>;

                var oldBuildList = AppSettings.Values[xamBuildsKey] as List <string>;
#endif

                versionTrail = new Dictionary <string, List <string> > {
                    { xamVersionsKey, oldVersionList },
                    { xamBuildsKey, oldBuildList }
                };

                isFirstLaunchEver = false;

                needsSync = true;
            }


            //check if this version was previously launched
            if (versionTrail[xamVersionsKey].Contains(CurrentVersion))
            {
                isFirstLaunchForVersion = false;
            }
            else
            {
                isFirstLaunchForVersion = true;

                versionTrail[xamVersionsKey].Add(CurrentVersion);

                needsSync = true;
            }

            //check if this build was previously launched
            if (versionTrail[xamBuildsKey].Contains(CurrentBuild))
            {
                isFirstLaunchForBuild = false;
            }
            else
            {
                isFirstLaunchForBuild = true;

                versionTrail[xamBuildsKey].Add(CurrentBuild);

                needsSync = true;
            }

            //store the new version stuff
            if (needsSync)
            {
                lock (locker) {
#if SILVERLIGHT
                    if (!AppSettings.Contains(xamVersionsKey))
                    {
                        AppSettings.Add(xamVersionsKey, versionTrail[xamVersionsKey]);
                    }
                    else
                    {
                        AppSettings[xamVersionsKey] = versionTrail[xamVersionsKey];
                    }

                    if (!AppSettings.Contains(xamBuildsKey))
                    {
                        AppSettings.Add(xamBuildsKey, versionTrail[xamBuildsKey]);
                    }
                    else
                    {
                        AppSettings[xamBuildsKey] = versionTrail[xamBuildsKey];
                    }

                    AppSettings.Save();
#else
                    if (!AppSettings.Values.ContainsKey(xamVersionsKey))
                    {
                        AppSettings.CreateContainer(xamVersionsKey, ApplicationDataCreateDisposition.Always);
                    }
                    if (AppSettings.Values.ContainsKey(xamBuildsKey))
                    {
                        AppSettings.CreateContainer(xamBuildsKey, ApplicationDataCreateDisposition.Always);
                    }

                    AppSettings.Values[xamVersionsKey] = versionTrail[xamVersionsKey];
                    AppSettings.Values[xamBuildsKey]   = versionTrail[xamBuildsKey];
#endif
                }
            }
        }