// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ISynologyConnection connection,
            ISynologyConnectionSettings synologyConnectionSettings)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            connection.Api().Auth().Login(new LoginParameters
            {
                Username = synologyConnectionSettings.Username,
                Password = synologyConnectionSettings.Password
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemplo n.º 2
0
        public async Task <bool> ConnectUser(string url, string username, string password)
        {
            try
            {
                Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/", RegexOptions.None, TimeSpan.FromMilliseconds(150));
                Match m = r.Match(url);
                if (m.Success)
                {
                    Console.WriteLine(m.Result("${proto}${port}"));
                    int port = 80;
                    if (string.IsNullOrEmpty(m.Groups["port"].Value))
                    {
                        port = (m.Groups["proto"].Value == "https") ? 443 : 80;
                    }
                    else
                    {
                        port = int.Parse(m.Groups["port"].Value.Replace(":", ""));
                    }

                    Uri uri = new Uri(url);

                    settingsSave = _scope.ServiceProvider.GetService <ISynologyConnectionSettings>();

                    settingsSave.BaseHost    = uri.Host;
                    settingsSave.Ssl         = (m.Groups["proto"].Value == "https");
                    settingsSave.Port        = port;
                    settingsSave.SslPort     = port;
                    settingsSave.Username    = username;
                    settingsSave.Password    = password;
                    settingsSave.SessionName = "SynoConnect";

                    ISynologyConnection      syno     = _scope.ServiceProvider.GetService <ISynologyConnection>();
                    ResultData <IAuthResult> resLogin = await syno.Api().Auth().LoginAsync();

                    if (resLogin.Error == null || (resLogin.Error != null && resLogin.Error.Code == 403))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(false);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public static IApi Api(this ISynologyConnection connection) => connection.Api <IApi>();
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public static ISurveillanceStationApi SurveillanceStation(this ISynologyConnection connection) => connection.Api <ISurveillanceStationApi>();
 /// <summary>
 /// Files the station.
 /// </summary>
 /// <returns>The station.</returns>
 /// <param name="connection">Connection.</param>
 public static IFileStationApi FileStation(this ISynologyConnection connection) => connection.Api <IFileStationApi>();
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public static IDownloadStation2Api DownloadStation2(this ISynologyConnection connection) => connection.Api <IDownloadStation2Api>();
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public static IVideoStationApi VideoStation(this ISynologyConnection connection) => connection.Api <IVideoStationApi>();
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public static IAudioStationApi AudioStation(this ISynologyConnection connection) => connection.Api <IAudioStationApi>();