Exemplo n.º 1
0
 public async Task <bool> AddItemAsync(VisitorEntry data)
 {
     if (!Usable || SiteIdentity == 0)
     {
         return(false);
     }
     data.Referrer = data.Referrer.Truncate(Globals.MaxUrl);
     data.Url      = data.Url.Truncate(Globals.MaxUrl);
     return(await DataProvider.AddAsync(data));
 }
Exemplo n.º 2
0
        protected override void Write(LogEventInfo logEvent)
        {
            object o;

            if (!logEvent.Properties.TryGetValue("record", out o))
            {
                throw new InternalError("When using the YetaWFDB target for NLog, the NLogMessageEvent property (appsettings.json) must be set to true");
            }
            LogRecord data = (LogRecord)o;

            DataProvider.AddAsync(data).Wait(); // sync is OK as we're saving on a separate thread with async NLog
        }
 private async Task AddConfigAsync(LoginConfigData data)
 {
     data.Id = KEY;
     if (!await DataProvider.AddAsync(data))
     {
         throw new InternalError("Unexpected error adding settings");
     }
     await Auditing.AddAuditAsync($"{nameof(LoginConfigDataProvider)}.{nameof(AddConfigAsync)}", "Config", Guid.Empty,
                                  "Add Login Config",
                                  DataBefore : null,
                                  DataAfter : data,
                                  ExpensiveMultiInstance : true
                                  );
 }
        /// <summary>
        /// Save the site definition for the current site
        /// </summary>
        internal async Task SaveSiteDefinitionAsync(SiteDefinition site)
        {
            SiteDefinition origSite = YetaWF.Core.Audit.Auditing.Active ? await LoadSiteDefinitionAsync(site.OriginalSiteDomain) : null;

            using (await lockObject.LockAsync()) { // protect SiteCache locally
                SiteCache.Remove(site.SiteDomain.ToLower());
                if (!string.IsNullOrWhiteSpace(site.StaticDomain))
                {
                    StaticSiteCache.Remove(site.StaticDomain.ToLower());
                }
                if (!string.IsNullOrWhiteSpace(site.SiteTestDomain))
                {
                    TestSiteCache.Remove(site.SiteTestDomain.ToLower());
                }
                SiteCache.Add(site.SiteDomain.ToLower(), site);
                if (!string.IsNullOrWhiteSpace(site.StaticDomain))
                {
                    StaticSiteCache.Add(site.StaticDomain.ToLower(), site);
                }
                if (!string.IsNullOrWhiteSpace(site.SiteTestDomain))
                {
                    TestSiteCache.Add(site.SiteTestDomain.ToLower(), site);
                }

                AddLockedStatus(site);
                CleanData(site);
                await SaveImagesAsync(ModuleDefinition.GetPermanentGuid(typeof(SitePropertiesModule)), site);

                if (site.OriginalSiteDomain != null)
                {
                    UpdateStatusEnum status = await DataProvider.UpdateAsync(site.OriginalSiteDomain, site.SiteDomain, site);

                    if (status != UpdateStatusEnum.OK)
                    {
                        throw new Error(this.__ResStr("updFail", "Can't update site definition - it may have already been removed", site.OriginalSiteDomain));
                    }
                }
                else
                {
                    if (!await DataProvider.AddAsync(site))
                    {
                        throw new Error(this.__ResStr("siteExists", "Can't add new site \"{0}\" - site already exists", site.SiteDomain));
                    }
                    site.OriginalSiteDomain = site.SiteDomain;
                }
                // update appsettings.json
                if (string.Compare(YetaWFManager.DefaultSiteName, site.OriginalSiteDomain, true) == 0 && site.SiteDomain != site.OriginalSiteDomain)
                {
                    WebConfigHelper.SetValue <string>(YetaWF.Core.Controllers.AreaRegistration.CurrentPackage.AreaName, "DEFAULTSITE", site.SiteDomain);
                    await WebConfigHelper.SaveAsync();

                    await Auditing.AddAuditAsync($"{nameof(SiteDefinitionDataProvider)}.{nameof(SaveSiteDefinitionAsync)}", site.OriginalSiteDomain, Guid.Empty,
                                                 $"DEFAULTSITE", RequiresRestart : true
                                                 );
                }
                // Save a json representation of the site (can be used for batch mode initialization to avoid having to need a SiteProperties reference and access to DB)
                await FileSystem.FileSystemProvider.CreateDirectoryAsync(Path.Combine(YetaWFManager.RootFolderWebProject, Globals.DataFolder, "Sites"));

                string file = Path.Combine(YetaWFManager.RootFolderWebProject, Globals.DataFolder, "Sites", site.SiteDomain + ".json".ToLower());
                string json = Utility.JsonSerialize(site, true);
                await FileSystem.FileSystemProvider.WriteAllTextAsync(file, json);
            }
            await Auditing.AddAuditAsync($"{nameof(SiteDefinitionDataProvider)}.{nameof(SaveSiteDefinitionAsync)}", site.OriginalSiteDomain, Guid.Empty,
                                         "Save Site Settings",
                                         DataBefore : origSite,
                                         DataAfter : site,
                                         ExpensiveMultiInstance : true
                                         );
        }