示例#1
0
 private SiteIni GetGlobalSiteini(SiteIni siteini)
 {
     try
     {
         return(Siteinis.Where(s => s.name == siteini.name).First());
     }
     catch
     {
         return(null);
     }
 }
示例#2
0
        public void InitSiteinis()
        {
            Log.Info("Searching for siteinis. Disabling missing ones.");
            try
            {
                foreach (var channel in GetChannels(includeOffset: false))
                {
                    // Skip channels that have no siteinis
                    if (!channel.HasSiteinis)
                    {
                        Log.Warning("Channel '" + channel.name + "' has no available siteinis. Channel deactivated!");
                        channel.active = false;
                        continue;
                    }

                    // Iterate over channel siteinis and enable/disable them or add properties
                    foreach (var siteini in channel.siteinis)
                    {
                        // Search for global siteini
                        var globalSiteini = GetGlobalSiteini(siteini);
                        if (globalSiteini != null)
                        {
                            // If global siteini is not enabled, disable all local siteinis
                            if (!globalSiteini.Enabled)
                            {
                                siteini.Enabled = false;
                                Log.Error(String.Format("Siteini {0} disabled in global siteinis configuraiton!", siteini.name));
                            }
                            else
                            {
                                siteini.Enabled = true;
                                // Global siteini is enabled, check whether it has a valid path (.ini file exists)
                                globalSiteini.path = globalSiteini.GetPath(folder);
                                if (!String.IsNullOrEmpty(globalSiteini.path))
                                {
                                    // If path is valid and existing assign it to the local ini path
                                    siteini.path = globalSiteini.path;
                                    // If there is no overwriting global timespan value use the default period days value from master config
                                    siteini.timespan = globalSiteini.timespan ?? period.days;
                                    // If we don't have global siteini offset use config offset
                                    siteini.offset = globalSiteini.offset ?? offset;
                                    // assign the type
                                    siteini.type = globalSiteini.type;
                                }
                                else
                                {
                                    // No .ini file was found so disable the global and local siteini
                                    globalSiteini.Enabled = false;
                                    siteini.Enabled       = globalSiteini.Enabled;
                                }
                            }
                        }
                        else // There is no global siteini for this siteini, so we will add one
                        {
                            // Get local siteini ini path
                            siteini.path = siteini.GetPath(folder);
                            if (!String.IsNullOrEmpty(siteini.path))
                            {
                                // if siteini file exists
                                siteini.Enabled = true;
                                // Since this is a local siteini and there was no overwriting global siteini use default timespan
                                siteini.timespan = period.days;
                                // Since there is no global siteini offset, overwrite with config offset
                                // Later it could be overwritten by channel offset
                                siteini.offset = offset;
                            }
                            else
                            {
                                siteini.Enabled = false;
                                Log.Error(String.Format("Siteini {0} not found in config folder {1} or siteini.user/siteini.pack sub folders (Depth=6). Siteini will be disabled globally!", siteini.GetName(), folder));
                            }
                            // Create a global siteini and add it to the list
                            Siteinis.Add(siteini);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message + ": " + ex.ToString());
            }
        }