Пример #1
0
 public Model()
 {
     YetaWFManager.Syncify(async() => {  // this is needed during model validation
         ConfigData = await LoginConfigDataProvider.GetConfigAsync();
     });
     TwoStepAuth = new SerializableList <Role>();
 }
Пример #2
0
            }                                          // File IO

            public LogDataProvider(Dictionary <string, object> options) : base(options)
            {
                LogFile = Path.Combine(BaseFolder, LogfileName);
                YetaWFManager.Syncify(async() =>  // Log is sync by definition
                                      await FileSystem.FileSystemProvider.CreateDirectoryAsync(Path.GetDirectoryName(LogFile))
                                      );
            }
Пример #3
0
        public void Register()
        {
            // Get config file
#if MVC6
            string configFile = Startup.GetEnvironmentFile(Path.Combine(YetaWFManager.RootFolderWebProject, Globals.DataFolder), "NLog", "config", Optional: true);
#else
            string configFile = Path.Combine(YetaWFManager.RootFolder, Globals.DataFolder, NLogSettingsFile);
#endif
            if (configFile == null)
            {
                return;
            }

            bool useNlog = YetaWFManager.Syncify <bool>(async() => { // registration is sync by definition (this runs once during startup only)
                return(await FileSystem.FileSystemProvider.FileExistsAsync(configFile));
            });
            if (!useNlog)
            {
                return;
            }

            // register custom target (write to Sql table)
            Target.Register <YetaWFDBTarget>("YetaWFDB");

            LogManager.Configuration = new XmlLoggingConfiguration(configFile);

            MessageFormat = WebConfigHelper.GetValue <string>("YetaWF_Logging", NLogMessageFormat);
            MessageFormat = MessageFormat?.ToLower();
            MessageEvent  = WebConfigHelper.GetValue <bool>("YetaWF_Logging", NLogMessageEvent);

            // get logger
            Logger = NLog.LogManager.GetLogger("YetaWF");
        }
Пример #4
0
 /// <summary>
 /// Used from site template to add a site admin role
 /// </summary>
 public void AddAdministratorRole()
 {
     YetaWFManager.Syncify(async() => {  // super-rare so sync is OK
         using (RoleDefinitionDataProvider dataProvider = new RoleDefinitionDataProvider()) {
             await dataProvider.AddAdministratorRoleAsync();
         }
     });
 }
 public void WriteToLogFile(string category, Logging.LevelEnum level, int relStack, string text)
 {
     YetaWFManager.Syncify(async() => {  // Logging is sync by definition (this is only used for startup logging)
         using (ILockObject lockObject = await YetaWF.Core.IO.Caching.LockProvider.LockResourceAsync(LogFile)) {
             await FileSystem.FileSystemProvider.AppendAllTextAsync(LogFile, text + "\r\n");
             await lockObject.UnlockAsync();
         }
     });
 }
Пример #6
0
 /// <summary>
 /// Add a user - used from site template to add a site user
 /// </summary>
 public void AddUser(string name, string pswd)
 {
     YetaWFManager.Syncify(async() => {  // super rare, so sync is OK
         using (UserDefinitionDataProvider dataProvider = new UserDefinitionDataProvider()) {
             await dataProvider.AddUserAsync(name);
         }
         await ChangePasswordAsync(name, pswd);
     });
 }
Пример #7
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableTracker.RemoveObject(this);
         YetaWFManager.Syncify(async() =>  // Only used if caller forgets to Unlock
                               await UnlockAsync()
                               );
     }
 }
Пример #8
0
 // Add a user from a site template
 public void AddUser(string userName)
 {
     YetaWFManager.Syncify(async() => {  // rarely used so sync is OK
         using (UserDefinitionDataProvider dataProvider = new UserDefinitionDataProvider()) {
             UserDefinition user = await dataProvider.GetItemAsync(userName);
             if (user != null)
             {
                 Users.Add(new User {
                     UserId = user.UserId
                 });
                 await SaveAsync();
             }
         }
     });
 }
Пример #9
0
        /// <summary>
        /// Retrieve all roles except user and anonymous.
        /// </summary>
        /// <remarks>
        /// This method is cached and deliberately does not use async/await to simplify usage
        /// </remarks>
        public List <RoleDefinition> GetAllUserRoles(bool force = false)
        {
            bool isInstalled = YetaWFManager.Syncify <bool>(() => DataProvider.IsInstalledAsync()); // There's nothing really async about this

            if (!isInstalled)
            {
                return new List <RoleDefinition>()
                       {
                           MakeSuperuserRole()
                       }
            }
            ;

            List <RoleDefinition> roles;

            if (!force)
            {
                if (PermanentManager.TryGetObject <List <RoleDefinition> >(out roles))
                {
                    return(roles);
                }
            }

            lock (_lockObject) { // lock this to build cached roles list
                // See if we already have it as a permanent object
                if (!force)
                {
                    if (PermanentManager.TryGetObject <List <RoleDefinition> >(out roles))
                    {
                        return(roles);
                    }
                }
                // Load the roles
                DataProviderGetRecords <RoleDefinition> list = YetaWFManager.Syncify <DataProviderGetRecords <RoleDefinition> >(() => GetItemsAsync()); // Only done once during startup and never again, all cached

                roles = list.Data;

                PermanentManager.AddObject <List <RoleDefinition> >(roles);
            }
            return(roles);
        }
Пример #10
0
        static void Main(string[] args)
        {
            Console.Title = "Softel vdm, Inc. - StatusCheck";
            Console.WriteLine("Initializing...");

            // StatusCheck console application settings
            string text = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGSFILE));

            Settings = Newtonsoft.Json.JsonConvert.DeserializeObject <Settings>(text);

            // Initialize the YetaWF console application
            Console.WriteLine("Starting YetaWF Support...");
            StartupBatch.Start(AppDomain.CurrentDomain.BaseDirectory, Settings.SiteDomain);

            Console.WriteLine("Processing...");

            YetaWFManager.Syncify(() => {
                Program pgm = new StatusCheck.Program();
                return(pgm.Process());
            });
        }
Пример #11
0
 public void WriteToLogFile(string category, Logging.LevelEnum level, int relStack, string text)
 {
     if (!YetaWFManager.HaveManager)
     {
         return;
     }
     if (YetaWFManager.Manager != LimitToManager)
     {
         return;                         // this log entry is for another thread
     }
     YetaWFManager.Syncify(async() => {  // Logging is sync (because most log providers like NLog use async tasks), not worth the trouble to make this async. Scheduler is separate thread anyway.
         await logDP.AddItemAsync(new DataProvider.LogData {
             TimeStamp    = DateTime.UtcNow,
             RunId        = CurrentId,
             Name         = CurrentName,
             Level        = level,
             SiteIdentity = CurrentSiteId,
             Info         = text,
         });
     });
 }
Пример #12
0
        public override void SaveMessage(LogRecord record)
        {
            string text = string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}({7})-{8}: {9},{10},{11},{12} - {13}:{14}",
                                        DateTime.Now /*Local Time*/, record.Category, record.SessionId, record.SiteIdentity, record.IPAddress, record.RequestedUrl, record.UserName, record.UserId, record.ReferrerUrl,
                                        record.ModuleName,
                                        record.Class,
                                        record.Method,
                                        record.Namespace,
                                        record.Level, record.Info);

            text = text.Replace("\n", "\r\n");

            YetaWFManager.Syncify(async() => {  // logging is sync by default
                using (ILockObject lockObject = await YetaWF.Core.IO.Caching.LockProvider.LockResourceAsync(LogFile)) {
                    LogCache.Add(text);
                    if (LogCache.Count >= MAXRECORDS)
                    {
                        await FlushAsyncNoLock();
                    }
                    await lockObject.UnlockAsync();
                }
            });
        }
Пример #13
0
        private void Execute()
        {
            // get a manager for the scheduler
            YetaWFManager.MakeInitialThreadInstance(null);

            // TODO: Scheduler logging should not start during startup processing. This timer postpones it (but is not a good solution)

            // Because initialization is called during application startup, we'll wait before we
            // check for any scheduler items that may be due (just so app start isn't all too slow).
            try {
                Thread.Sleep(defaultStartupTimeSpan);
            } catch (ThreadInterruptedException) {
                // thread was interrupted because there is work to be done
            }

            SchedulerLog = new SchedulerLogging();
            SchedulerLog.Init();
            SchedulerLog.LimitTo(YetaWFManager.Manager);

            YetaWFManager.Syncify(async() => {  // there is no point in running the scheduler async
                await Logging.RegisterLoggingAsync(SchedulerLog);
            });

            Logging.AddTraceLog("Scheduler task started");

            // mark all scheduled items that are supposed to be run at application startup
            try {
                YetaWFManager.Syncify(async() => {  // there is no point in running the scheduler async
                    await RunStartupItemsAsync();
                });
            } catch (Exception exc) {
                Logging.AddErrorLog("An error occurred running startup items", exc);
            }

            for (;;)
            {
                TimeSpan delayTime = defaultTimeSpanNoTask;
                if (SchedulerSupport.Enabled)
                {
                    try {
                        YetaWFManager.Syncify(async() => {  // there is no point in running the scheduler async
                            delayTime = await RunItemsAsync();
                        });
                    } catch (Exception exc) {
                        delayTime = defaultTimeSpanError;
                        Logging.AddErrorLog("An error occurred in the scheduling loop.", exc);
                    }
                    if (delayTime < new TimeSpan(0, 0, 5))// at a few seconds
                    {
                        delayTime = new TimeSpan(0, 0, 5);
                    }
                    else if (delayTime > new TimeSpan(1, 0, 0, 0)) // max. 1 day
                    {
                        delayTime = new TimeSpan(1, 0, 0, 0);
                    }
                }
                try {
                    schedulingThreadRunning = false;
                    Logging.AddLog($"Waiting {delayTime}");
                    Thread.Sleep(delayTime);
                } catch (ThreadInterruptedException) {
                    // thread was interrupted because there is work to be done
                } catch (ThreadAbortException) { }
                finally {
                    schedulingThreadRunning = true;
                }
            }

            // This never really ends so we don't need to unregister logging
            //log.Shutdown();
            //Logging.UnregisterLogging(log);
        }
Пример #14
0
 public void InitComplete()
 {
     YetaWFManager.Syncify(async() => {  // Runs only during installation
         await Manager.CurrentSite.SaveAsync();
     });
 }
Пример #15
0
        // LOGGING CALLBACKS
        // LOGGING CALLBACKS
        // LOGGING CALLBACKS

        public static void AddVisitEntryError(string error)
        {
            YetaWFManager.Syncify(async() => {
                await AddVisitEntryAsync(null, error);
            });
        }
Пример #16
0
 public override void SaveMessage(LogRecord record)
 {
     YetaWFManager.Syncify(async() => {  // Logging is advertised as Sync - use NLog instead
         await DataProvider.AddAsync(record);
     });
 }