private void SetSourceControlInfo(FileToCreate file)
        {
            if (!UseTfsToCheckoutFiles)
            {
                return;
            }

            var items = TfsWorkspace.VersionControlServer.GetItems(file.Path, new WorkspaceVersionSpec(TfsWorkspace), RecursionType.None).Items;

            if (items.Any())
            {
                file.TfsItem = items[0];
            }
            // else, Most likely the item doesn't exist in TFS and so nothing to add
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="theFile"></param>
        /// <returns></returns>
        private async Task <String> UploadInBlobAsync(FileToCreateDto theFile)
        {
            FileToCreate fToCreate = _mapper.Map <FileToCreate>(theFile);

            fToCreate.FileAsBase64    = _picFormatter.CleanData(theFile.FileAsBase64);
            fToCreate.FileAsByteArray = Convert.FromBase64String(fToCreate.FileAsBase64);

            var   directoryTask = _picFormatter.GetPathAsync(fToCreate);
            await directoryTask;

            if (directoryTask.IsCompletedSuccessfully)
            {
                using var fs = new MemoryStream(fToCreate.FileAsByteArray);
                String rootUrl  = _config.Value?.BlobRootURI;
                String blobPath = rootUrl + directoryTask.Result +
                                  theFile.SubmittedPicture.Id.ToString() +
                                  "." +
                                  "jpeg";
                Uri blobUri = new Uri(blobPath);

                // Create StorageSharedKeyCredentials object by reading
                // the values from the configuration (appsettings.json)
                String credNameValue = _config?.Value?.StorageSharedKeyCredentialName;
                String pwd           = _config?.Value?.Password;
                StorageSharedKeyCredential storageCredentials =
                    new StorageSharedKeyCredential(credNameValue, pwd);

                // Create the blob client.
                BlobClient blobClient = new BlobClient(blobUri, storageCredentials);
                // Upload the file
                var   uploadTask = blobClient.UploadAsync(fs);
                await uploadTask;
                if (uploadTask.IsCompletedSuccessfully)
                {
                    return(blobPath);
                }
                else
                {
                    throw new Exception("blobClient.UploadAsync failed.");
                }
            }
            else
            {
                throw new Exception("_picFormatter.GetPathAsync failed.");
            }
        }
        private void WriteFileIfDifferent(ProjectFile project, FileToCreate file)
        {
            SetSourceControlInfo(file);
            if (!file.HasChanged)
            {
                if (file.IsMainFile)
                {
                    if (UseTfsToCheckoutFiles)
                    {
                        TfsWorkspace.Undo(file.Path);
                    }
                    Console.WriteLine(file.Path + " was unchanged.");
                }
                return;
            }

            EnsureFileIsAccessible(file.Path);
            project.AddFileIfMissing(file.Path);

            Trace.TraceInformation(Path.GetFileName(file.Path) + " created / updated..");
            Log("Writing file: " + file.Path);
            File.WriteAllText(file.Path, file.Contents);
            Log("Completed file: " + file);
        }
        private void WriteFileIfDifferent(ProjectFile project, FileToCreate file)
        {
            SetSourceControlInfo(file);
            if (!file.HasChanged)
            {
                if (file.IsMainFile)
                {
                    if (UseTfsToCheckoutFiles)
                    {
                        TfsWorkspace.Undo(file.Path);
                    }
                    Console.WriteLine(file.Path + " was unchanged.");
                }
                return;
            }

            EnsureFileIsAccessible(file.Path);
            project.AddFileIfMissing(file.Path);

            Trace.TraceInformation(Path.GetFileName(file.Path) + " created / updated..");
            Log("Writing file: " + file.Path);
            File.WriteAllText(file.Path, file.Contents);
            Log("Completed file: " + file);
        }
        private void SetSourceControlInfo (FileToCreate file)
        {
            if (!UseTfsToCheckoutFiles)
            {
                return;
            }

            var items = TfsWorkspace.VersionControlServer.GetItems(file.Path, new WorkspaceVersionSpec(TfsWorkspace), RecursionType.None).Items;
            if (items.Any())
            {
                file.TfsItem = items[0];
            }
            // else, Most likely the item doesn't exist in TFS and so nothing to add
        }
예제 #6
0
        /// <summary>
        ///  vernacularname/Sex/Age
        /// </summary>
        /// <param name="fileToCreate"></param>
        /// <returns></returns>
        public async Task <String> GetPathAsync(FileToCreate fileToCreate)
        {
            if (fileToCreate == null)
            {
                throw new ArgumentNullException();
            }
            StringBuilder sb = new StringBuilder();

            if (fileToCreate.SubmittedPicture == null ||
                String.IsNullOrEmpty(fileToCreate.SubmittedPicture.VernacularName) ||
                String.IsNullOrWhiteSpace(fileToCreate.SubmittedPicture.VernacularName))
            {
                sb.Append(UNKNOWN_VERNACULAR_NAME);
            }
            else
            {
                //1- vernacular Name
                String vernacularName = fileToCreate.SubmittedPicture.VernacularName;
                String age            = String.Empty;
                String gender         = String.Empty;
                sb.Append(vernacularName.Replace(" ", "_"));
                sb.Append("/");
                //2- Sex and age
                var         ageTask    = _repo.GetAgeTypeAsync(fileToCreate.SubmittedPicture.AgeType);
                var         genderTask = _repo.GetGenderTypeAsync(fileToCreate.SubmittedPicture.GenderType);
                List <Task> allTasks   = new List <Task> {
                    ageTask, genderTask
                };
                while (allTasks.Count != 0)
                {
                    //Await any task to finish
                    Task justFinishedTask = await Task.WhenAny(allTasks);

                    if (justFinishedTask == ageTask)
                    {
                        if (justFinishedTask.IsCompletedSuccessfully)
                        {
                            allTasks.Remove(ageTask);
                            age = ageTask.Result.Age.Replace(" ", "_");
                        }
                        else
                        {
                            throw new Exception("_repo.GetAgeTypeAsync fail");
                        }
                    }
                    else if (justFinishedTask == genderTask)
                    {
                        if (justFinishedTask.IsCompletedSuccessfully)
                        {
                            allTasks.Remove(genderTask);
                            gender = genderTask.Result.SubmitGender.Replace(" ", "_");
                        }
                        else
                        {
                            throw new Exception("_repo.GetGenderTypeAsync fail");
                        }
                    }
                    else
                    {
                        //Strange .. must have missed something...
                        allTasks.Remove(justFinishedTask);
                    }
                }
                sb.Append(gender.Trim());
                sb.Append("/");
                sb.Append(age.Trim());
                sb.Append("/");
            }
            //3- return
            return(sb.ToString());
        }