コード例 #1
0
        public static string GetAndroidSdkPath()
        {
            //TODO: ask IDE? it should know :)
            string repoFolder;
            var    androidSdk = new[] { "ANDROID_HOME", "ANDROID_SDK", "ANDROID_SDK_ROOT" }
            .Select(i => Environment.GetEnvironmentVariable(i))
            .Concat(new[] { Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), @"AppData\Local\Android\sdk") })
            .Where(i => !string.IsNullOrWhiteSpace(i))
            .OrderByDescending(i => Gradle.HasLocalRepositories(i, out repoFolder))
            .FirstOrDefault();

            return(androidSdk);
        }
コード例 #2
0
        public async Task Generate(string sourceProjectName)
        {
            var androidSdk = await ResolveAndroidSdkPathAsync();

            if (string.IsNullOrWhiteSpace(androidSdk))
            {
                return;
            }

            string                      workingDirectory      = null;
            Exception                   exception             = null;
            List <DependencyFile>       resultDependencies    = null;
            DependencyInputDialogResult dependencyInputResult = null;

            var inputSuccess = await _dependencyInputDialog.ShowAsync(repositores : Gradle.DefaultRepositores, taskExecuter : (dependencyInput) => {
                dependencyInputResult = dependencyInput;
                return(Task.Factory.StartNew(() => {
                    try
                    {
                        resultDependencies = Gradle.ExtractDependencies(dependencyInput.DependencyId,
                                                                        androidSdk, out workingDirectory, dependencyInput.DependencyRepository).ToList();
                    }
                    catch (Exception exc)
                    {
                        exception = exc;
                    }
                }));
            });


            if (!inputSuccess)
            {
                return;
            }

            if (exception != null)
            {
                _errorDialog.ShowError(exception.ToString());
                return;
            }

            try
            {
                string readMeContent = string.Format("Binding for:\n{0}\n\nDependencies:\n\n{1}",
                                                     dependencyInputResult.DependencyId,
                                                     string.Join("\n", resultDependencies.Select(d => string.Format("{1}{0},    Path={2}", Path.GetFileName(d.File), d.IsTransitive ? "\t" : "", d.File))));

                var bindingInfoFilePath = Path.Combine(workingDirectory, "GeneratedBindingInfo.txt");
                File.WriteAllText(bindingInfoFilePath, readMeContent);

                //if we have only one binary
                if (resultDependencies.Count == 1 && !resultDependencies[0].IsTransitive)
                {
                    await _bindingProjectGenerator.GenerateAsync(sourceProjectName, dependencyInputResult.AssemblyName, resultDependencies, bindingInfoFilePath);
                }
                else
                {
                    var filteredDependencies = await _dependencyOutputSelectorDialog.FilterDependenciesAsync(resultDependencies);

                    if (filteredDependencies != null && filteredDependencies.Any())
                    {
                        await _bindingProjectGenerator.GenerateAsync(sourceProjectName, dependencyInputResult.AssemblyName, filteredDependencies, bindingInfoFilePath);
                    }
                }
            }
            catch (Exception exc)
            {
                _errorDialog.ShowError(exc.ToString());
            }
        }