internal async Task RemoveSiteDefinitionAsync()
        {
            SiteDefinition site = Manager.CurrentSite;

            if (site.IsDefaultSite)
            {
                throw new Error(this.__ResStr("cantDeleteDefault", "The default site of a YetaWF instance cannot be removed"));
            }

            using (await lockObject.LockAsync()) { // protect SiteCache locally
                // remove all saved data
                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());
                }

                await Package.RemoveSiteDataAsync(Manager.SiteFolder);

                await DataProvider.RemoveAsync(site.SiteDomain);// remove domain
            }
            await Auditing.AddAuditAsync($"{nameof(SiteDefinitionDataProvider)}.{nameof(SaveSiteDefinitionAsync)}", site.SiteDomain, Guid.Empty,
                                         "Remove Site",
                                         DataBefore : site,
                                         DataAfter : null,
                                         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
                                         );
        }