Пример #1
0
        /// <summary>
        /// Parses the header of the CandidateFile and handles updating status on the View.
        /// </summary>
        private async Task ValidateHeader()
        {
            DebugHelper.Assert(this.kdbxReader != null);
            if (this.kdbxReader == null)
            {
                throw new InvalidOperationException("Cannot validate KDBX header if there is no reader instance");
            }

            try
            {
                if (CandidateFile == null)
                {
                    ParseResult = null;
                }
                else
                {
                    using (IRandomAccessStream fileStream = await CandidateFile.GetRandomReadAccessStreamAsync())
                    {
                        CancellationTokenSource cts = new CancellationTokenSource(5000);
                        ParseResult = await this.kdbxReader.ReadHeaderAsync(fileStream, cts.Token);
                    }
                }
            }
            catch (COMException)
            {
                // In the Windows 8.1 preview, opening a stream to a SkyDrive file can fail with no workaround.
                ParseResult = new ReaderResult(KdbxParserCode.UnableToReadFile);
            }
            finally
            {
                RaiseHeaderValidated();
                UnlockCommand.RaiseCanExecuteChanged();
                UseSavedCredentialsCommand.RaiseCanExecuteChanged();
            }
        }
Пример #2
0
        public ActionResult SaveAFileToDB(HttpPostedFileBase upload)
        {
            if (upload != null && upload.ContentLength > 0)
            {
                try
                {
                    var file = new CandidateFile
                    {
                        FileType    = FileType.Picture,
                        FileName    = upload.FileName,
                        CandidateId = 1,
                        ContentType = ""
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        file.Content = reader.ReadBytes(upload.ContentLength);
                    }

                    _ctx.CandidateFiles.Add(file);
                    _ctx.SaveChanges();
                }
                catch (Exception)
                {
                    //
                }
            }

            return(RedirectToAction("SaveAFileToDB"));
        }
Пример #3
0
        public ActionResult UploadResizeSaveAFileToDB(HttpPostedFileBase upload)
        {
            if (upload != null && upload.ContentLength > 0)
            {
                try
                {
                    var file = new CandidateFile
                    {
                        FileType    = FileType.Picture,
                        FileName    = upload.FileName,
                        CandidateId = 1,
                        ContentType = "image/jpeg"
                    };

                    var bmpImg = BhvImageLib.ResizeByWidth(upload.InputStream, 1024);

                    bmpImg.Save(@"D:\pic1Resized-XYZ.jpg", ImageFormat.Jpeg);

                    file.Content = BhvImageLib.ImageToByte(bmpImg);

                    _ctx.CandidateFiles.Add(file);
                    _ctx.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(RedirectToAction("UploadResizeSaveAFileToDB"));
        }
Пример #4
0
    public void CreationFile(Vector3 position, Quaternion rotation, Transform parent)
    {
        _fileNumber++;
        Shuffle();

        if (_isLegendary == false)
        {
            _candidatePrefab      = Instantiate(_candidateGO, position, rotation, parent);
            _candidatePrefab.name = "Candidate number: " + _fileNumber;
            CandidateFile file = _candidatePrefab.GetComponent <CandidateFile>();
            file.CandidatePrice = _salary;
            file.CandidateGain  = _gain;
            _candidate.Add(_candidatePrefab);
        }

        else
        {
            _legendaryPrefab      = Instantiate(_choosenLegendaryGO, position, rotation, parent);
            _legendaryPrefab.name = "Legendary number: " + _fileNumber;
            CandidateFile file = _legendaryPrefab.GetComponent <CandidateFile>();
            file.CandidatePrice = _salary;
            file.CandidateGain  = _gain;
            _candidate.Add(_legendaryPrefab);
            _isLegendary = false;
        }
    }
    public void OnPickUp()
    {
        CandidateFile file = _objectCache.GetComponent <CandidateFile>();

        if (PlayerManager.Instance.Money > file.CandidatePrice)
        {
            _objectCache.position    = PlayerManager.Instance.Interactions.ChoosenOne.position;
            _objectCache.useGravity  = true;
            _objectCache.isKinematic = false;

            IAction action = _objectCache.GetComponent <IAction>();
            action.Enter();
            InputManager.Instance.Interact -= OnPickUp;
        }
    }
 protected override void Dequeue()
 {
     string filename;
     if (queue.TryDequeue(out filename))
     {
         try
         {
             var candidate = new CandidateFile(basePath, alias, filename);
             if (IndexRepository.ShouldAdd(client.Value, ref candidate))
             {
                 enqueueToPrepare(candidate);
             }
         }
         catch (Exception e)
         {
             logger.Error("Exception checking {0}: {1}", filename, e);
         }
     }
     else
     {
         Thread.Sleep(0);
     }
 }
 public void Enqueue(CandidateFile candidate)
 {
     queue.Enqueue(candidate);
 }
Пример #8
0
        /// <summary>
        /// Attempts to unlock the document file.
        /// </summary>
        /// <param name="storedCredential">The key to use for decryption - if null, the ViewModel's
        /// credentials are used instead.</param>
        private async Task DoUnlockAsync(IBuffer storedCredential)
        {
            DebugHelper.Assert(CanUnlock());
            if (!CanUnlock())
            {
                throw new InvalidOperationException("The ViewModel is not in a state that can unlock the database!");
            }

            CancellationTokenSource cts = new CancellationTokenSource();

            try
            {
                using (IRandomAccessStream stream = await CandidateFile.GetRandomReadAccessStreamAsync())
                {
                    Task <KdbxDecryptionResult> decryptionTask;
                    if (storedCredential != null)
                    {
                        decryptionTask = this.kdbxReader.DecryptFile(stream, storedCredential, cts.Token);
                    }
                    else
                    {
                        decryptionTask = this.kdbxReader.DecryptFileAsync(stream, Password, KeyFile, cts.Token);
                    }

                    if (this.taskNotificationService.CurrentTask == null || this.taskNotificationService.CurrentTask.IsCompleted)
                    {
                        this.taskNotificationService.PushOperation(decryptionTask, cts, AsyncOperationType.DatabaseDecryption);
                    }
                    KdbxDecryptionResult result = await decryptionTask;

                    ParseResult = result.Result;

                    DebugHelper.Trace($"Got ParseResult from database unlock attempt: {ParseResult}");
                    if (!ParseResult.IsError)
                    {
                        // The database candidate to proceed into the next stage with
                        IDatabaseCandidate candidateToUse = CandidateFile;

                        if (CacheDatabase)
                        {
                            // We do not use UseAppControlledDatabaseAsync here because it has extra baggage.
                            // We don't need to refresh the view at this stage, just fire an event using
                            // the cached file.
                            candidateToUse = await GetCachedCandidateAsync();
                        }
                        if (RememberDatabase)
                        {
                            string accessToken = this.futureAccessList.Add(candidateToUse.File, candidateToUse.FileName);
                            DebugHelper.Trace($"Unlock was successful and database was remembered with token: {accessToken}");
                        }
                        else
                        {
                            DebugHelper.Trace("Unlock was successful but user opted not to remember the database.");
                        }

                        if (SaveCredentials)
                        {
                            bool storeCredential = false;

                            // If we were not already using a stored credential, we need user
                            // consent to continue.
                            if (storedCredential == null)
                            {
                                Task <bool> identityTask = this.identityService.VerifyIdentityAsync();
                                if (this.taskNotificationService.CurrentTask == null || this.taskNotificationService.CurrentTask.IsCompleted)
                                {
                                    this.taskNotificationService.PushOperation(identityTask, AsyncOperationType.IdentityVerification);
                                }

                                storeCredential  = await identityTask;
                                storedCredential = result.GetRawKey();
                            }
                            else
                            {
                                // If we have a stored credential, we already got consent.
                                storeCredential = true;
                            }

                            if (storeCredential)
                            {
                                if (!await this.credentialProvider.TryStoreRawKeyAsync(candidateToUse.File, storedCredential))
                                {
                                    EventHandler <CredentialStorageFailureEventArgs> handler = CredentialStorageFailed;
                                    if (handler != null)
                                    {
                                        // If we could not store a credential, give the View a chance to try again.
                                        CredentialStorageFailureEventArgs eventArgs =
                                            new CredentialStorageFailureEventArgs(
                                                this.credentialProvider,
                                                this.credentialViewModelFactory,
                                                candidateToUse,
                                                storedCredential
                                                );

                                        handler(this, eventArgs);
                                        await eventArgs.DeferAsync();
                                    }
                                }
                            }
                        }

                        await RaiseDocumentReady(result.GetDocument(), candidateToUse);
                    }
                }
            }
            catch (COMException)
            {
                // In the Windows 8.1 preview, opening a stream to a SkyDrive file can fail with no workaround.
                ParseResult = new ReaderResult(KdbxParserCode.UnableToReadFile);
            }
        }