コード例 #1
0
        async void Refresh()
        {
            SaveAndCloseCommand.IsEnabled = false;
            CancelCommand.IsEnabled       = false;
            _isWorking = true;
            var cache = new WhitelistCache();
            await cache.RefreshAsync(_package.InstallPath.FullName);

            var dte2     = (EnvDTE80.DTE2)_package.DTE;
            var projects = ((IEnumerable)dte2.ToolWindows.SolutionExplorer.SelectedItems)
                           .OfType <UIHierarchyItem>()
                           .Select(item => item.Object)
                           .OfType <Project>();

            foreach (var project in projects)
            {
                var projectProperties = MDKProjectProperties.Load(project.FullName, project.Name);
                if (projectProperties.IsValid)
                {
                    var targetCacheFile = Path.Combine(Path.GetDirectoryName(projectProperties.FileName) ?? ".", "MDK\\whitelist.cache");
                    var sourceCacheFile = Path.Combine(_package.InstallPath.FullName, "Analyzers\\whitelist.cache");
                    if (File.Exists(sourceCacheFile))
                    {
                        File.Copy(sourceCacheFile, targetCacheFile, true);
                    }
                }
            }

            _isDone = true;
            SaveAndCloseCommand.IsEnabled = true;
            SaveAndClose();
        }
コード例 #2
0
        /// <summary>
        /// Saves any changed options
        /// </summary>
        /// <returns></returns>
        protected override bool OnSave()
        {
            var cache = new WhitelistCache();

            cache.Refresh(_package.InstallPath.FullName);
            return(true);
        }
コード例 #3
0
        public static ulong WhitelistModel(ulong assetId)
        {
            if (!WhitelistCache.ContainsKey(assetId) || DateTime.UtcNow > WhitelistCache[assetId].ExpirationDate)
            {
                // Extract info from the page.
                AssetPageInfo info = GetAssetPage(assetId);

                // Ensure the thing is a model.
                if (info.AssetType != "Model")
                {
                    throw new FormatException("The asset requested is not a Model.");
                }

                // Post the take request.
                if (!info.UserOwnsAsset)
                {
                    if (!info.IsOnSale)
                    {
                        throw new Exception("The asset cannot be obtained!");
                    }

                    string requestString = string.Format(TakeItemUrl, info.ProductId /*, info.SellerId*/);
                    string payload       = string.Format(
                        "{{\"expectedCurrency\":1,\"expectedPrice\":{1},\"expectedSellerId\":{0}}}",
                        info.SellerId, 0);
                    using (WebClient client = NewPseudoHumanClient())
                    {
                        client.Headers["X-CSRF-TOKEN"] = info.XcsrfToken;
                        client.Headers["content-type"] = "application/json; charset=utf-8";

                        client.UploadString(requestString, payload);
                        Debug.WriteLine("Whitelisted " + assetId + ".");
                        WhitelistCache[assetId] = new AssetIdCache(assetId, assetId, DateTime.UtcNow + new TimeSpan(1, 0, 0, 0));
                        return(assetId);
                    }
                }
                else
                {
                    WhitelistCache[assetId] = new AssetIdCache(assetId, assetId, DateTime.UtcNow + new TimeSpan(1, 0, 0, 0));
                    return(assetId);
                }
            }
            else
            {
                Debug.WriteLine("The asset ID " + assetId + " has recently been whitelisted. Using cache.");
                return(WhitelistCache[assetId].UsableAssetId);
            }
        }