public AutoStartService(ISharedSettings sharedSettings, ILogger <AutoStartService> logger, ILiveApis liveApis, IRemoteOperations remoteOperations)
 {
     _remoteSettings   = sharedSettings.RemoteSettings;
     _logger           = logger;
     _liveApis         = liveApis;
     _remoteOperations = remoteOperations;
 }
 public HttpService(ISharedSettings sharedSettings, ILogger <HttpService> logger, ILiveApis liveApis, IMemoryCache memoryCache)
 {
     _sharedSettings = sharedSettings;
     _liveApis       = liveApis;
     _remoteSettings = _sharedSettings.RemoteSettings;
     _logger         = logger;
     _memoryCache    = memoryCache;
 }
 public UpgradeService(ISharedSettings sharedSettings, ILogger <UpgradeService> logger, IHostApplicationLifetime applicationLifetime, ProgramExit programExit, IHttpClientFactory clientFactory)
 {
     _remoteSettings      = sharedSettings.RemoteSettings;
     _logger              = logger;
     _applicationLifetime = applicationLifetime;
     _programExit         = programExit;
     _clientFactory       = clientFactory;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ManifestService"/> class.
 /// </summary>
 /// <param name="sharedSettings">Shared settings.</param>
 /// <param name="fileSystem">File system.</param>
 /// <param name="httpClientFactory">HttpClient factory.</param>
 public ManifestService(ISharedSettings sharedSettings, IFileSystem fileSystem, IHttpClientFactory httpClientFactory)
     : this(sharedSettings, fileSystem)
 {
     if (_sharedSettings.DevelopmentMode)
     {
         HttpClient = httpClientFactory.CreateClient();
     }
 }
Exemple #5
0
 public DownloadDataTask(ISharedSettings sharedSettings, long hubKey, DownloadData downloadData, DownloadUrl downloadUrl, string connectionId, string reference)
 {
     _sharedSettings = sharedSettings;
     _hubKey         = hubKey;
     _downloadData   = downloadData;
     _downloadUrl    = downloadUrl;
     _connectionId   = connectionId;
     _reference      = reference;
 }
Exemple #6
0
 public ListenerService(ISharedSettings sharedSettings, ILogger <ListenerService> logger, IMessageQueue messageQueue, IRemoteOperations remoteOperations, IMemoryCache memoryCache, IHostApplicationLifetime applicationLifetime)
 {
     _sharedSettings      = sharedSettings;
     _remoteSettings      = _sharedSettings.RemoteSettings;
     _messageQueue        = messageQueue;
     _remoteOperations    = remoteOperations;
     _logger              = logger;
     _memoryCache         = memoryCache;
     _applicationLifetime = applicationLifetime;
 }
Exemple #7
0
        public LiveApis(ISharedSettings sharedSettings, ILogger <LiveApis> logger, IHttpClientFactory clientFactory)
        {
            _sharedSettings = sharedSettings;
            _logger         = logger;

            _liveApis        = new ConcurrentDictionary <string, ApiData>();
            _hubs            = new ConcurrentDictionary <long, ConcurrentDictionary <long, string> >();
            _apiDataUpdates  = new ConcurrentDictionary <long, ApiData>();
            _apiQueryUpdates = new ConcurrentDictionary <long, ApiQuery>();
            _clientFactory   = clientFactory;
        }
Exemple #8
0
        public MessageService(
            ILogger <MessageService> logger, IMessageQueue messageQueue, ISharedSettings sharedSettings,
            IManagedTasks managedTasks)
        {
            _logger         = logger;
            _messageQueue   = messageQueue;
            _sharedSettings = sharedSettings;
            _managedTasks   = managedTasks;

            managedTasks.OnProgress += TaskProgressChange;
            managedTasks.OnStatus   += TaskStatusChange;
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AssetService"/> class.
        /// </summary>
        /// <param name="sharedSettings">Shared settings.</param>
        /// <param name="manifestService">Asset manifest service.</param>
        /// <param name="tagBuilder">Asset builder service.</param>
        public AssetService(ISharedSettings sharedSettings, IManifestService manifestService, ITagBuilder tagBuilder)
        {
            if (sharedSettings == null)
            {
                throw new ArgumentNullException(nameof(sharedSettings));
            }

            AssetsDirectoryPath = sharedSettings.AssetsDirectoryPath;
            AssetsWebPath       = sharedSettings.AssetsWebPath;

            _manifestService = manifestService;
            _tagBuilder      = tagBuilder;
        }
Exemple #10
0
 public DownloadFilesTask(ISharedSettings sharedSettings, string messageId, long hubKey, ConnectionFlatFile connectionFlatFile,
                          FlatFile flatFile, EFlatFilePath path, string[] files, DownloadUrl downloadUrl, string connectionId, string reference)
 {
     _sharedSettings     = sharedSettings;
     _messageId          = messageId;
     _hubKey             = hubKey;
     _connectionFlatFile = connectionFlatFile;
     _flatFile           = flatFile;
     _path         = path;
     _files        = files;
     _downloadUrl  = downloadUrl;
     _connectionId = connectionId;
     _reference    = reference;
 }
Exemple #11
0
        public AlertService(
            ILogger <AlertService> logger, IAlertQueue alertQueue, ISharedSettings sharedSettings)
        {
            _logger         = logger;
            _alertQueue     = alertQueue;
            _sharedSettings = sharedSettings;
            _adminEmails    = sharedSettings.RemoteSettings.Alerts.AdminEmails;

            if (sharedSettings.RemoteSettings?.Alerts?.SmtpServer != null)
            {
                _smtpClient = new SmtpClient(sharedSettings.RemoteSettings.Alerts.SmtpServer)
                {
                    UseDefaultCredentials = false,
                    Port      = sharedSettings.RemoteSettings.Alerts.SmtpPort,
                    EnableSsl = sharedSettings.RemoteSettings.Alerts.EnableSsl,

                    Credentials = new NetworkCredential(sharedSettings.RemoteSettings.Alerts.SmtpUserName,
                                                        sharedSettings.RemoteSettings.Alerts.SmtpPassword),
                };

                _smtpClient.SendCompleted += (s, e) =>
                {
                    if (e.Cancelled)
                    {
                        _logger.LogError("The email message was cancelled.");
                    }

                    if (e.Error != null)
                    {
                        _logger.LogError(e.Error, $"There was an error sending an alert email.");
                    }
                };

                _footer = $"Remote Agent Name: {_sharedSettings.RemoteSettings.AppSettings.Name}";
            }
        }
Exemple #12
0
 public HomeController(ISharedSettings settings)
 {
     _settings = settings;
 }
Exemple #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILiveApis liveApis, ISharedSettings sharedSettings, ILogger <HttpService> logger)
        {
//            if (env.IsDevelopment())
//            {
//                app.UseDeveloperExceptionPage();
//            }

            // only allow requests from the original web site.
            app.UseCors(builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
                //    .AllowCredentials()
                .WithHeaders()
                .WithMethods();
                //   .WithOrigins(streams.OriginUrl);
                // .WithOrigins();
            });

            // var rand = EncryptString.GenerateRandomKey();

            app.Run(async(context) =>
            {
                try
                {
                    async Task SendFailedResponse(ReturnValue returnValue)
                    {
                        logger.LogError(returnValue.Exception,
                                        $"Path: {context.Request.Path}, Message: {returnValue.Message}");
                        context.Response.StatusCode  = 400;
                        context.Response.ContentType = "application/json";

                        await using (var writer = new StreamWriter(context.Response.Body))
                        {
                            await writer.WriteAsync(returnValue.Serialize());
                            await writer.FlushAsync().ConfigureAwait(false);
                        }
                    }

                    async Task SendInvalidPath()
                    {
                        var returnValue = new ReturnValue(false, $"Invalid url path.  {context.Request.Path}.", null);
                        await SendFailedResponse(returnValue);
                    }

                    context.Features.Get <IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 1_000_000_000;
                    var path     = context.Request.Path;
                    var segments = path.Value.Split('/');

                    if (segments.Length < 1)
                    {
                        await SendInvalidPath();
                        return;
                    }

                    switch (segments[1])
                    {
                    case "ping":
                        context.Response.StatusCode  = 200;
                        context.Response.ContentType = "application/json";
                        await using (var writer = new StreamWriter(context.Response.Body))
                        {
                            await writer.WriteAsync("{ \"status\": \"alive\"}");
                            await writer.FlushAsync().ConfigureAwait(false);
                        }

                        break;

                    case "setRaw":
                        if (segments.Length < 3)
                        {
                            await SendInvalidPath();
                            return;
                        }

                        try
                        {
                            var key   = segments[2];
                            var value = segments[3];
                            sharedSettings.SetCacheItem(key + "-raw", value);
                        }
                        catch (Exception e)
                        {
                            var returnValue = new ReturnValue(false, "Set raw call failed: " + e.Message, e);
                            await SendFailedResponse(returnValue);
                        }

                        break;

                    case "api":
                        if (segments.Length < 2)
                        {
                            await SendInvalidPath();
                            return;
                        }

                        try
                        {
                            var key1 = HttpUtility.UrlDecode(segments[2]);

                            if (segments.Length > 3 && segments[3] == "ping")
                            {
                                var ping = liveApis.Ping(key1);
                                await using (var writer = new StreamWriter(context.Response.Body))
                                {
                                    await writer.WriteAsync(ping.Serialize());
                                    await writer.FlushAsync().ConfigureAwait(false);
                                }

                                return;
                            }

                            var action = "";
                            if (segments.Length > 3)
                            {
                                action = segments[3];
                            }

                            var parameters = context.Request.QueryString.Value;
                            var ipAddress  = context.Request.HttpContext.Connection.RemoteIpAddress;
                            var data       = await liveApis.Query(key1, action, parameters, ipAddress.ToString());

                            context.Response.StatusCode  = 200;
                            context.Response.ContentType = "application/json";
                            await using (var writer = new StreamWriter(context.Response.Body))
                            {
                                await writer.WriteAsync(data);
                                await writer.FlushAsync().ConfigureAwait(false);
                            }
                        }
                        catch (Exception e)
                        {
                            var returnValue = new ReturnValue(false, "API call failed: " + e.Message, e);
                            await SendFailedResponse(returnValue);
                        }

                        break;

                    case "download":
                        if (segments.Length < 2)
                        {
                            await SendInvalidPath();
                            return;
                        }

                        try
                        {
                            var key = segments[2];
                            using (var downloadStream = await sharedSettings.GetCacheItem <DownloadStream>(key))
                            {
                                if (downloadStream == null)
                                {
                                    throw new RemoteException(
                                        "Remote agent call failed, the response key was not found.");
                                }

                                switch (downloadStream.Type)
                                {
                                case "file":
                                    context.Response.ContentType = "application/octet-stream";
                                    break;

                                case "csv":
                                    context.Response.ContentType = "text/csv";
                                    break;

                                case "json":
                                    context.Response.ContentType = "application/json";
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException(
                                        $"The type {downloadStream.Type} was not recognized.");
                                }

                                context.Response.StatusCode = downloadStream.IsError ? 400 : 200;

                                if (!string.IsNullOrEmpty(downloadStream.FileName))
                                {
                                    context.Response.Headers.Add("Content-Disposition",
                                                                 "attachment; filename=\"" + downloadStream.FileName + "\"");
                                }

                                await downloadStream.Stream.CopyToAsync(context.Response.Body,
                                                                        context.RequestAborted);
                            }
                        }
                        catch (OperationCanceledException)
                        {
                        }
                        catch (Exception e)
                        {
                            var returnValue = new ReturnValue(false, "Remote agent error: " + e.Message, e);
                            await SendFailedResponse(returnValue);
                        }

                        break;

                    case "upload":
                        if (segments.Length < 2)
                        {
                            await SendInvalidPath();
                            return;
                        }

                        try
                        {
                            var files = context.Request.Form.Files;
                            if (files.Count >= 1)
                            {
                                var key2         = segments[2];
                                var uploadStream = await sharedSettings.GetCacheItem <Func <Stream, Task> >(key2);
                                await uploadStream.Invoke(files[0].OpenReadStream());
                            }
                            else
                            {
                                throw new Exception("The file upload only supports one file.");
                            }
                        }
                        catch (Exception e)
                        {
                            var returnValue = new ReturnValue(false, "Upload data failed: " + e.Message, e);
                            await SendFailedResponse(returnValue);
                        }

                        break;
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"Path: {context.Request.Path}, Message: {ex.Message}");
                }
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ManifestService"/> class.
 /// </summary>
 /// <param name="sharedSettings">Shared settings.</param>
 /// <param name="fileSystem">File system.</param>
 public ManifestService(ISharedSettings sharedSettings, IFileSystem fileSystem)
 {
     _sharedSettings = sharedSettings;
     _fileSystem     = fileSystem;
 }