コード例 #1
0
        // ReSharper disable once UnusedMember.Global
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            HttpServerService httpServerService,
            LogService logService,
            ILoggerFactory loggerFactory,
            IServiceProvider serviceProvider,
            GlobalVariablesService globalVariablesService,
            PackageManagerService packageManagerService)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (env == null)
            {
                throw new ArgumentNullException(nameof(env));
            }
            if (httpServerService == null)
            {
                throw new ArgumentNullException(nameof(httpServerService));
            }
            if (logService == null)
            {
                throw new ArgumentNullException(nameof(logService));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            loggerFactory.AddProvider(new LogServiceLoggerProvider(logService));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            ConfigureSwagger(app);
            ConfigureWebApps(app, globalVariablesService, packageManagerService);
            ConfigureMvc(app);

            app.Run(httpServerService.HandleRequestAsync);

            StartServices(serviceProvider);
        }
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            await stepContext.Context.SendActivityAsync($"Removing notifications... please wait. It might take some time.", cancellationToken : cancellationToken);

            var variables = await GlobalVariablesService.GetBitBucketConversationVariables(stepContext.Context.Activity.Recipient.Id);

            variables.PushNotifications = "false";
            if (!await GlobalVariablesService.SetBitBucketConversationVariables(stepContext.Context.Activity.Recipient.Id, variables))
            {
                await stepContext.Context.SendActivityAsync($"Unexpected error happened while trying to remove notification.", cancellationToken : cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            await stepContext.Context.SendActivityAsync("Notifications Removed", cancellationToken : cancellationToken);

            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: geffzhang/Wirehome.Core
        // ReSharper disable once UnusedMember.Global
        public void Configure(
            IApplicationBuilder app,
            HttpServerService httpServerService,
            LogService logService,
            ILoggerFactory loggerFactory,
            IServiceProvider serviceProvider,
            GlobalVariablesService globalVariablesService,
            PackageManagerService packageManagerService,
            MqttService mqttService)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (httpServerService == null)
            {
                throw new ArgumentNullException(nameof(httpServerService));
            }
            if (logService == null)
            {
                throw new ArgumentNullException(nameof(logService));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            if (mqttService == null)
            {
                throw new ArgumentNullException(nameof(mqttService));
            }

            loggerFactory.AddProvider(new LogServiceLoggerProvider(logService));

            app.UseResponseCompression();
            app.UseCors(p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

            ConfigureSwagger(app);
            ConfigureWebApps(app, globalVariablesService, packageManagerService, mqttService);
            ConfigureMvc(app);

            app.Run(httpServerService.HandleRequestAsync);

            StartServices(serviceProvider);
        }
コード例 #4
0
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Result == null)
            {
                await stepContext.Context.SendActivityAsync("Wrong configuration file", cancellationToken : cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            BitBucketConversationVariables pullRequestDetails;

            try
            {
                pullRequestDetails = JsonConvert.DeserializeObject <BitBucketConversationVariables>(stepContext.Result.ToString());
            }
            catch (Exception e)
            {
                await stepContext.Context.SendActivityAsync("Wrong configuration file", cancellationToken : cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            if (pullRequestDetails == null)
            {
                await stepContext.Context.SendActivityAsync("Wrong configuration file", cancellationToken : cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            var rez = await GlobalVariablesService.SetBitBucketConversationVariables(stepContext.Context.Activity.Recipient.Id, pullRequestDetails);

            if (!rez)
            {
                await stepContext.Context.SendActivityAsync("Could not update configuration file", cancellationToken : cancellationToken);
            }
            await stepContext.Context.SendActivityAsync("Configuration file is updated", cancellationToken : cancellationToken);

            return(await stepContext.EndDialogAsync(pullRequestDetails, cancellationToken));
        }
コード例 #5
0
        private async Task <DialogTurnResult> AskForConfigurationFile(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            await stepContext.Context.SendActivityAsync("This is current configuration:", cancellationToken : cancellationToken);

            await stepContext.Context.SendActivityAsync(
                JsonConvert.SerializeObject(
                    await GlobalVariablesService.GetBitBucketConversationVariables(
                        stepContext.Context.Activity.Recipient.Id)), cancellationToken : cancellationToken);

            var reply = MessageFactory.Text("Please provide configuration file");

            try
            {
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = reply }, cancellationToken));
            }
            catch
            {
                await stepContext.Context.SendActivityAsync("Warning. Did not receive configuration file. Configuration file remain unchanged", cancellationToken : cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
        }
コード例 #6
0
ファイル: Startup.cs プロジェクト: pcbing/Wirehome.Core
        private static void ConfigureWebApps(IApplicationBuilder app, GlobalVariablesService globalVariablesService, PackageManagerService packageManagerService)
        {
            var storagePaths          = new StoragePaths();
            var customContentRootPath = Path.Combine(storagePaths.DataPath, "CustomContent");

            var packagesRootPath = Path.Combine(storagePaths.DataPath, "Packages");
            var storageService   = new StorageService(new JsonSerializerService(), new LoggerFactory().CreateLogger <StorageService>());

            storageService.Start();
            if (storageService.TryRead(out PackageManagerServiceOptions repositoryServiceOptions, PackageManagerServiceOptions.Filename))
            {
                if (!string.IsNullOrEmpty(repositoryServiceOptions.RootPath))
                {
                    packagesRootPath = repositoryServiceOptions.RootPath;
                }
            }

            app.UseFileServer(new FileServerOptions
            {
                RequestPath  = "/app",
                FileProvider = new PackageFileProvider(GlobalVariableUids.AppPackageUid, globalVariablesService, packageManagerService)
            });

            app.UseFileServer(new FileServerOptions
            {
                RequestPath  = "/configurator",
                FileProvider = new PackageFileProvider(GlobalVariableUids.ConfiguratorPackageUid, globalVariablesService, packageManagerService)
            });

            // Open the configurator by default if no path is specified.
            var option = new RewriteOptions();

            option.AddRedirect("^$", "/configurator");
            app.UseRewriter(option);

            ExposeDirectory(app, "/customContent", customContentRootPath);
            ExposeDirectory(app, "/packages", packagesRootPath);
        }
コード例 #7
0
 public AppController(AppService appService, GlobalVariablesService globalVariablesService)
 {
     _appService             = appService ?? throw new ArgumentNullException(nameof(appService));
     _globalVariablesService = globalVariablesService ?? throw new ArgumentNullException(nameof(globalVariablesService));
 }
コード例 #8
0
 public PackageFileProvider(string packageUidGlobalVariableUid, GlobalVariablesService globalVariablesService, PackageManagerService packageManagerService)
 {
     _packageUidGlobalVariableUid = packageUidGlobalVariableUid ?? throw new ArgumentNullException(nameof(packageUidGlobalVariableUid));
     _globalVariablesService      = globalVariablesService ?? throw new ArgumentNullException(nameof(globalVariablesService));
     _packageManagerService       = packageManagerService ?? throw new ArgumentNullException(nameof(packageManagerService));
 }
コード例 #9
0
 public GlobalVariablesController(GlobalVariablesService globalVariablesService)
 {
     _globalVariablesService = globalVariablesService ?? throw new ArgumentNullException(nameof(globalVariablesService));
 }
コード例 #10
0
 public GlobalVariablesServicePythonProxy(GlobalVariablesService globalVariablesService)
 {
     _globalVariablesService = globalVariablesService ?? throw new ArgumentNullException(nameof(globalVariablesService));
 }
コード例 #11
0
        public ResourceService(StorageService storageService, JsonSerializerService jsonSerializerService, GlobalVariablesService globalVariablesService, ILoggerFactory loggerFactory)
        {
            _storageService         = storageService ?? throw new ArgumentNullException(nameof(storageService));
            _jsonSerializerService  = jsonSerializerService ?? throw new ArgumentNullException(nameof(jsonSerializerService));
            _globalVariablesService = globalVariablesService ?? throw new ArgumentNullException(nameof(globalVariablesService));

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            _logger = loggerFactory.CreateLogger <ResourceService>();
        }
コード例 #12
0
        private async Task <DialogTurnResult> FetchPullRequests(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            BitBucketConversationVariables = await GlobalVariablesService.GetBitBucketConversationVariables(stepContext.Context.Activity.Recipient.Id);

            if (BitBucketConversationVariables?.GlobalVariables == null)
            {
                await stepContext.Context.SendActivityAsync("No configuration found", cancellationToken : cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            await stepContext.Context.SendActivityAsync("Gathering info...", cancellationToken : cancellationToken);

            bool foundAnyPullRequest = false;

            foreach (var globalVariable in BitBucketConversationVariables.GlobalVariables)
            {
                foreach (var project in globalVariable.Projects)
                {
                    foreach (var repositoryName in project.RepositoryNames)
                    {
                        var pullRequestList = new List <PullRequest>();

                        try
                        {
                            pullRequestList.AddRange((await _bitbucketClient.FetchActivePullRequests(
                                                          globalVariable.BaseUrl,
                                                          project.ProjectName,
                                                          repositoryName,
                                                          globalVariable.PersonalAccessToken,
                                                          globalVariable.Password,
                                                          globalVariable.UserName)).FindAll(x => x.Open));

                            if (pullRequestList.Count > 0)
                            {
                                foundAnyPullRequest = true;
                            }
                        }
                        catch (Exception e)
                        {
                            await stepContext.Context.SendActivityAsync(
                                "Error was thrown during fetching data, maybe there in a wrong info provided for fetching information?",
                                cancellationToken : cancellationToken);

                            await stepContext.Context.SendActivityAsync(e.Message, cancellationToken : cancellationToken);
                        }

                        foreach (var pullRequest in pullRequestList)
                        {
                            var pullRequestCard = CreateAdaptiveCardAttachment(pullRequest, globalVariable.BaseUrl, project.ProjectName,
                                                                               repositoryName);
                            var response = MessageFactory.Attachment(pullRequestCard);
                            await stepContext.Context.SendActivityAsync(response, cancellationToken);
                        }
                    }
                }
            }

            if (!foundAnyPullRequest)
            {
                await stepContext.Context.SendActivityAsync("No active pull requests found", cancellationToken : cancellationToken);
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }
コード例 #13
0
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var dataList      = new List <string>();
            var activityValue = "";

            try
            {
                activityValue = stepContext.Options.ToString();
            }
            catch
            {
                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            if (string.IsNullOrEmpty(activityValue))
            {
                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            dataList = activityValue.Split('>', StringSplitOptions.RemoveEmptyEntries).ToList();

            if (dataList.Count == 5 && dataList[0]?.ToLower() == "approvepullrequest")
            {
                await stepContext.Context.SendActivityAsync("CheckingPullRequestStatus...", cancellationToken : cancellationToken);

                bool resultFound = false;

                foreach (
                    var globalVariable
                    in (await GlobalVariablesService.GetBitBucketConversationVariables(stepContext.Context.Activity.Recipient.Id)).GlobalVariables
                    )

                {
                    foreach (var project in globalVariable.Projects)
                    {
                        foreach (var repositoryName in project.RepositoryNames)
                        {
                            if (string.Equals(globalVariable.BaseUrl, dataList[1], StringComparison.CurrentCultureIgnoreCase) &&
                                string.Equals(project.ProjectName, dataList[2], StringComparison.CurrentCultureIgnoreCase) &&
                                string.Equals(repositoryName, dataList[3], StringComparison.CurrentCultureIgnoreCase))
                            {
                                resultFound = true;
                                try
                                {
                                    await _innerBitbucketClient.ApprovePullRequest(globalVariable.BaseUrl,
                                                                                   project.ProjectName,
                                                                                   repositoryName,
                                                                                   globalVariable.PersonalAccessToken,
                                                                                   globalVariable.Password,
                                                                                   globalVariable.UserName, long.Parse(dataList[4]));

                                    await stepContext.Context.SendActivityAsync("Approved successfully", cancellationToken : cancellationToken);
                                }
                                catch (Exception e)
                                {
                                    await stepContext.Context.SendActivityAsync("Oooops. Something went wrong. Could not approve pull request",
                                                                                cancellationToken : cancellationToken);

                                    await stepContext.Context.SendActivityAsync(e.Message,
                                                                                cancellationToken : cancellationToken);
                                }

                                break;
                            }
                        }
                    }
                }

                if (!resultFound)
                {
                    await stepContext.Context.SendActivityAsync("Could not find such repository. Check project and repository names",
                                                                cancellationToken : cancellationToken);
                }
                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }