Esempio n. 1
0
        /// <summary>
        /// Imports this instance.
        /// </summary>
        public async void Import()
        {
            try
            {
                if (this._currentTask != null)
                {
                    await this._currentTask;
                }

                var text = ClipboardHelper.GetClipboardText();
                if (Uri.TryCreate(text, UriKind.Absolute, out Uri url))
                {
                    var rawUri = new Uri($"https://pastebin.com/raw{url.AbsolutePath}");
                    using (var client = new HttpClient())
                    {
                        var request  = new HttpRequestMessage(HttpMethod.Get, rawUri);
                        var response = await client.SendAsync(request);

                        text = await response.Content.ReadAsStringAsync();
                    }
                }

                if (await this.Initialize(text))
                {
                    AssetService.Create(FileName, text);
                }
            }
            catch
            {
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SettingsViewModel" /> class.
        /// </summary>
        /// <param name="windowManager">The window manager.</param>
        /// <param name="keyboardHelper">The keyboard helper.</param>
        /// <param name="settingsService">The settings service.</param>
        /// <param name="hotkeyService">The key code service.</param>
        /// <param name="soundService">The sound service.</param>
        /// <param name="githubService">The github service.</param>
        /// <param name="pushBulletService">The PushBullet service.</param>
        public SettingsViewModel(
            IWindowManager windowManager,
            KeyboardHelper keyboardHelper,
            SettingsService settingsService,
            HotkeyService hotkeyService,
            SoundService soundService,
            GithubService githubService,
            PushBulletService pushBulletService)
            : base(windowManager)
        {
            this._keyboardHelper       = keyboardHelper;
            this._settingService       = settingsService;
            this._hotkeyService        = hotkeyService;
            this._soundService         = soundService;
            this.DisplayName           = "Settings";
            this._excludePropertyNames = this.GetExcludedPropertyNames();
            this.PropertyChanged      += this.SettingsViewModel_PropertyChanged;

            if (!AssetService.Exists(LottieFileName))
            {
                AssetService.Create(LottieFileName, GetResourceContent(LottieFileName));
            }

            this.BuildManager = new BuildManagerViewModel(this.ShowMessage, githubService);
            this.PushBullet   = new PushBulletViewModel(pushBulletService);
            this.SetupHotkeys();
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SplashscreenViewModel" /> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="eventAggregator">The event aggregator.</param>
        public SplashscreenViewModel(SettingsViewModel settings, IEventAggregator eventAggregator)
        {
            this._settings      = settings;
            this._eventAggrator = eventAggregator;
            if (!AssetService.Exists(LottieFileName))
            {
                AssetService.Create(LottieFileName, GetResourceContent(LottieFileName));
            }

            Execute.OnUIThread(async() =>
            {
                using (var service = new PatreonService())
                {
                    var result = await service.IsPledging();
                    if (result)
                    {
                        return;
                    }

                    this.ShowPatreon    = true;
                    this.TrialAvailable = service.TrialAvailable;
                    if (!this.TrialAvailable)
                    {
                        // this.ShowPatreon = true;
                    }
                }
            });
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SplashscreenViewModel"/> class.
 /// </summary>
 public SplashscreenViewModel()
 {
     if (!AssetService.Exists(LottieFileName))
     {
         AssetService.Create(LottieFileName, GetResourceContent(LottieFileName));
     }
 }
Esempio n. 5
0
        public JsonResult Create(IFormCollection collection)
        {
            var entity = new Asset();

            TryUpdateModelAsync(entity);

            var result = _service.Create(entity, AppUser);

            return(Json(result));
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SettingsViewModel" /> class.
        /// </summary>
        /// <param name="windowManager">The window manager.</param>
        /// <param name="keyboardHelper">The keyboard helper.</param>
        /// <param name="settingsService">The settings service.</param>
        /// <param name="soundService">The sound service.</param>
        public SettingsViewModel(IWindowManager windowManager, KeyboardHelper keyboardHelper, SettingsService settingsService, SoundService soundService)
            : base(windowManager)
        {
            this._keyboardHelper = keyboardHelper;
            this._settingService = settingsService;
            this._soundService   = soundService;
            this.DisplayName     = "Settings";

            this.PropertyChanged += this.SettingsViewModel_PropertyChanged;

            if (!AssetService.Exists(LottieFileName))
            {
                AssetService.Create(LottieFileName, GetResourceContent(LottieFileName));
            }
        }
        /// <summary>
        /// Selects the custom sound.
        /// </summary>
        public void SelectCustomSound()
        {
            if (!this.HasCustomTradeSound)
            {
                try
                {
                    if (this._currentTradeAlert != null)
                    {
                        this._currentTradeAlert.Stop();
                        this._currentTradeAlert = null;
                    }

                    AssetService.Delete(SoundService.TradeAlertFileName);
                }
                catch
                {
                    // Sound was playing.
                    this.HasCustomTradeSound = true;
                }

                return;
            }

            var openFileDialog = new OpenFileDialog
            {
                Filter = "MP3 files (*.mp3)|*.mp3",
            };

            if (openFileDialog.ShowDialog() == true)
            {
                var fileName = openFileDialog.FileName;
                if (!File.Exists(fileName))
                {
                    return;
                }

                var content = File.ReadAllBytes(fileName);
                AssetService.Create(SoundService.TradeAlertFileName, content);
            }
            else
            {
                this.HasCustomTradeSound = false;
            }
        }
Esempio n. 8
0
        public void TestGetUnhandledThreats()
        {
            var riskTypeCreated = _companyService.CreateRiskType(new RiskType()
            {
                Name = "TestRiskType"
            });
            var asset  = CreateAsset();
            var threat = CreateThreat();

            threat.Risks.Add(new Risk(5, 5, 5, 5, 5, 5, 5, 25, 125, riskTypeCreated.RiskTypeId, riskTypeCreated.Name, 0));
            asset.Threats.Add(threat);
            var createdAsset = _assetService.Create(asset);
            var problems     = _assetService.GetUnhandledThreats(5, 5, 1);

            Assert.AreEqual(1, problems.Count());
            Assert.AreEqual(createdAsset.AssetId, problems.First().AssetId);
        }
Esempio n. 9
0
        public IHttpActionResult Post([FromBody] Contracts.Asset.CreateAsset create)
        {
            var created = AssetService.Create(create);

            return(Ok(created));
        }