示例#1
0
    public string ModelToViewDescription(RepositoryRef repositoryRef)
    {
        if (repositoryRef == null)
        {
            return(Description);
        }

        string replaceString = "";

        if (!string.IsNullOrEmpty(repositoryRef?.ResourcesContainerCacheRootUrl))
        {
            replaceString = Path.Combine(repositoryRef?.ResourcesContainerCacheRootUrl, repositoryRef?.ResourcesContainer);
            replaceString = replaceString.Replace(@"\", @"/");
        }
        else
        {
            if (repositoryRef.ResourcesContainerCacheRootPath != null && repositoryRef?.ResourcesContainer != null)
            {
                replaceString = Path.Combine(repositoryRef?.ResourcesContainerCacheRootPath, repositoryRef?.ResourcesContainer);
                replaceString = replaceString.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            }
        }

        return(Description?
               .Replace(repositoryRef.ResourcesContainer, replaceString));
    }
示例#2
0
    public string ViewToModelDescription(RepositoryRef repositoryRef, string contentView)
    {
        if (repositoryRef == null || string.IsNullOrEmpty(contentView))
        {
            return(contentView);
        }

        string replaceString;

        if (!string.IsNullOrEmpty(repositoryRef?.ResourcesContainerCacheRootUrl))
        {
            replaceString = Path.Combine(repositoryRef?.ResourcesContainerCacheRootUrl, repositoryRef?.ResourcesContainer);
            replaceString = replaceString.Replace(@"\", @"/");
        }
        else
        {
            replaceString = Path.Combine(repositoryRef?.ResourcesContainerCacheRootPath, repositoryRef?.ResourcesContainer);
            replaceString = replaceString.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
        }

        return(contentView
               .Replace(replaceString,
                        repositoryRef.ResourcesContainer));
    }
示例#3
0
 public KntUserRepository(DbConnection singletonConnection, RepositoryRef repositoryRef)
     : base(singletonConnection, repositoryRef)
 {
 }
示例#4
0
 public ServiceRef(RepositoryRef repositoryRef)
 {
     RepositoryRef = repositoryRef;
 }
示例#5
0
 public KntSystemValuesRepository(RepositoryRef repositoryRef)
     : base(repositoryRef)
 {
 }
示例#6
0
 public KntUserRepository(RepositoryRef repositoryRef)
     : base(repositoryRef)
 {
 }
示例#7
0
 public KntFolderRepository(RepositoryRef repositoryRef)
     : base(repositoryRef)
 {
 }
示例#8
0
 public KntSystemValuesRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }
示例#9
0
 public KntKAttributeRepository(RepositoryRef repositoryRef)
     : base(repositoryRef)
 {
 }
示例#10
0
 public KntNoteTypeRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }
示例#11
0
 public KntSystemValuesRepository(DbConnection singletonConnection, RepositoryRef repositoryRef)
     : base(singletonConnection, repositoryRef)
 {
 }
示例#12
0
 public KntKAttributeRepository(DbConnection singletonConnection, RepositoryRef repositoryRef)
     : base(singletonConnection, repositoryRef)
 {
 }
示例#13
0
 public KntKAttributeRepository(RepositoryRef repositoryRef, bool throwKntException = false)
     : base(repositoryRef)
 {
 }
示例#14
0
 public KntKAttributeRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }
示例#15
0
 public KntRepositoryBase(KntDbContext singletonConnection, RepositoryRef repositoryRef)
 {
     SingletonConnection             = singletonConnection;
     _repositoryRef                  = repositoryRef;
     _repositoryRef.ConnectionString = singletonConnection.Database.GetConnectionString();
 }
示例#16
0
文件: Program.cs 项目: afumfer/KNote
    static async void LoadAppStore(Store store)
    {
        var pathApp = Application.StartupPath;

        var appFileConfig = Path.Combine(pathApp, "KNoteData.config");

        if (!File.Exists(appFileConfig))
        {
            // Create default repository and add link

            var pathData = Path.Combine(pathApp, "Data");
            if (!Directory.Exists(pathData))
            {
                Directory.CreateDirectory(pathData);
            }
            var dbFile = Path.Combine(pathData, $"knote_{SystemInformation.UserName}.db");

            var pathResourcesCache = Path.Combine(pathApp, "ResourcesCache");
            if (!Directory.Exists(pathResourcesCache))
            {
                Directory.CreateDirectory(pathResourcesCache);
            }

            var r0 = new RepositoryRef
            {
                Alias            = "Personal respository",
                ConnectionString = $"Data Source={dbFile}",
                Provider         = "Microsoft.Data.Sqlite",
                Orm = "EntityFramework",
                ResourcesContainer = "NotesResources",
                ResourcesContainerCacheRootPath = pathResourcesCache,
                ResourcesContainerCacheRootUrl  = @"file:///" + pathResourcesCache.Replace(@"\", @"/")
            };

            var initialServiceRef = new ServiceRef(r0);
            var resCreateDB       = await initialServiceRef.Service.CreateDataBase(SystemInformation.UserName);

            if (resCreateDB)
            {
                store.AddServiceRef(initialServiceRef);
                store.AppConfig.RespositoryRefs.Add(r0);
            }

            // Default values
            store.AppConfig.AutoSaveActivated = true;
            store.AppConfig.AutoSaveSeconds   = 105;
            store.AppConfig.AlarmActivated    = true;
            store.AppConfig.AlarmSeconds      = 30;
            store.AppConfig.LastDateTimeStart = DateTime.Now;
            store.AppConfig.RunCounter        = 1;
            store.AppConfig.LogFile           = pathApp + @"\KNoteWinApp.log";
            store.AppConfig.LogActivated      = false;
        }
        else
        {
            store.LoadConfig(appFileConfig);
            foreach (var r in store.AppConfig.RespositoryRefs)
            {
                store.AddServiceRef(new ServiceRef(r));
            }
        }

        // Set session values
        store.AppUserName  = SystemInformation.UserName;
        store.ComputerName = SystemInformation.ComputerName;
        store.AppConfig.LastDateTimeStart = DateTime.Now;
        store.AppConfig.RunCounter       += 1;

        store.SaveConfig(appFileConfig);

        // default folder
        var firstService = store.GetFirstServiceRef();
        var folder       = (await firstService.Service.Folders.GetHomeAsync()).Entity;

        store.DefaultFolderWithServiceRef = new FolderWithServiceRef {
            ServiceRef = firstService, FolderInfo = folder
        };
    }
示例#17
0
 public KntRepository(RepositoryRef repositoryRef)
 {
     _repositoryRef = repositoryRef;
 }
示例#18
0
文件: Startup.cs 项目: afumfer/KNote
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(o => o.AddPolicy("KntPolicy", buider =>
            {
                buider.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            var appSettingsSection = configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);
            var appSettings = appSettingsSection.Get <AppSettings>();

            var orm  = configuration["ConnectionStrings:DefaultORM"];
            var prov = configuration["ConnectionStrings:DefaultProvider"];
            var conn = configuration["ConnectionStrings:DefaultConnection"];

            var repositoryRef = new RepositoryRef
            {
                Alias            = "KaNote",
                ConnectionString = conn,
                Provider         = prov,
                Orm = orm,
                ResourceContentInDB             = appSettings.ResourcesContentInDB,
                ResourcesContainer              = appSettings.ResourcesContainer,
                ResourcesContainerCacheRootPath = appSettings.ResourcesContainerRootPath,
                ResourcesContainerCacheRootUrl  = appSettings.ResourcesContainerRootUrl
            };

            if (orm == "Dapper")
            {
                services.AddScoped <IKntRepository>(provider => new DP.KntRepository(repositoryRef));
            }
            else if (orm == "EntityFramework")
            {
                services.AddScoped <IKntRepository>(provider => new EF.KntRepository(repositoryRef));
            }

            services.AddScoped <IKntService, KntService>();

            #region Doc, test
            // For test, use DbContext
            //services.AddDbContext<KntDbContext>(options =>
            //    options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
            #endregion

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
                          options.TokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer           = false,
                ValidateAudience         = false,
                ValidateLifetime         = true,
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(
                    // Encoding.UTF8.GetBytes(configuration["jwt:key"])
                    Encoding.ASCII.GetBytes(appSettings.Secret)
                    ),
                ClockSkew = TimeSpan.Zero
            });

            services.AddScoped <IFileStore, LocalFileStore>();
            services.AddHttpContextAccessor();

            services.AddControllersWithViews().AddNewtonsoftJson(options =>
                                                                 options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddRazorPages();

            services.AddResponseCompression(opts =>
            {
                opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "application/octet-stream" });
            });
        }
示例#19
0
 public KntRepositoryBase(DbConnection singletonConnection, RepositoryRef repositoryRef)
 {
     SingletonConnection = singletonConnection;
     _repositoryRef      = repositoryRef;
 }
示例#20
0
 public KntNoteTypeRepository(RepositoryRef repositoryRef)
     : base(repositoryRef)
 {
 }
示例#21
0
 public KntFolderRepository(KntDbContext singletonContext, RepositoryRef repositoryRef)
     : base(singletonContext, repositoryRef)
 {
 }
示例#22
0
 public KntRepository(DbConnection singletonConnection, RepositoryRef repositoryRef)
     : this(repositoryRef)
 {
     _db = singletonConnection;
 }
示例#23
0
 public KntNoteTypeRepository(DbConnection singletonConnection, RepositoryRef repositoryRef)
     : base(singletonConnection, repositoryRef)
 {
 }