Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            SqlDependency.Start(conn.getDbConnection().ConnectionString);
            services.AddControllersWithViews();

            // services.AddMvc().AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddTransient <IMessageRepository, MessageRepository>();

            services.AddIdentity <User, IdentityRole>(options => {
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequiredLength         = 6;
            })
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();
            services.AddSignalR();
            services.AddControllersWithViews()
            .AddNewtonsoftJson(options =>
                               options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                               );

            services.AddDistributedMemoryCache();

            services.AddSession(options =>
            {
                options.Cookie.Name        = ".AdventureWorks.Session";
                options.IdleTimeout        = TimeSpan.FromSeconds(10);
                options.Cookie.IsEssential = true;
            });
        }
        public List <Message> GetAllNotifications()
        {
            notifications = new List <Message>();
            SingletonDbConnect conn = SingletonDbConnect.getDbInstance();

            using (HomeController.command = new SqlCommand("select Id, Name, ChatId from dbo.Messages where ChatId = 28", conn.getDbConnection()))
            {
                HomeController.command.Notification = null;

                if (HomeController.dependency == null)
                {
                    SqlDependency dependency = new SqlDependency(HomeController.command);

                    dependency.OnChange += new OnChangeEventHandler(GetAllNotificationsDep_OnChange);
                    // HomeController.dependency = new SqlDependency(HomeController.command);
                    //    HomeController.dependency.OnChange += new OnChangeEventHandler(GetAllNotificationsDep_OnChange);
                }
                var reader = HomeController.command.ExecuteReader();


                while (reader.Read())
                {
                    var Message = new Message
                    {
                        Id     = Convert.ToInt32(reader["Id"]),
                        Name   = reader["Name"].ToString(),
                        ChatId = Convert.ToInt32(reader["ChatId"])
                    };

                    notifications.Add(Message);
                }
            }

            return(notifications);
        }