public override ValueTask <CheckResult> CheckAsync(RiasCommandContext context)
        {
            var localization = context.ServiceProvider.GetRequiredService <Localization>();

            var isValid = false;

            if ((_contexts & ContextType.Guild) != 0)
            {
                isValid = context.Channel is CachedGuildChannel;
            }
            if ((_contexts & ContextType.DM) != 0)
            {
                isValid = isValid || context.Channel is CachedDmChannel;
            }

            if (isValid)
            {
                return(CheckResult.Successful);
            }

            var guildId  = context.Guild?.Id;
            var contexts = _contexts.ToString()
                           .Split(",", StringSplitOptions.RemoveEmptyEntries)
                           .Select(x => localization.GetText(guildId, Localization.CommonContextType(x.ToLower())));

            var contextsHumanized = contexts.Humanize(x => $"**{x}**", localization.GetText(guildId, Localization.CommonOr).ToLowerInvariant());

            return(CheckResult.Unsuccessful(localization.GetText(guildId, Localization.AttributeContext, contextsHumanized)));
        }
        /// <summary>
        /// Switcher of used context.
        /// </summary>
        /// <param name="context">New context for using.</param>
        /// <returns>Self reference.</returns>
        public IManager switchOn(ContextType context)
        {
            if (this.Context != context)
            {
                Log.Trace("Config-Manager: switched context '{0}'", context.ToString());
            }
            this.Context = context;

            configure(UserConfig.Data);
            return(this);
        }
Example #3
0
 public Context Create(ContextType type)
 {
     switch (type)
     {
         case ContextType.Empty:
             return EmptyContext();
         case ContextType.Stub:
             return StubContext();
         case ContextType.PublishAndConsume:
             return PublishConsumeContext();
         default:
             throw new NotImplementedException(type.ToString());
     }
 }
Example #4
0
        public string DetailedStatus()
        {
            switch (ContextType)
            {
            case SchedulingContextType.Activation:
                return(Activation.ToDetailedString(true));

            case SchedulingContextType.SystemTarget:
                return(SystemTarget.ToDetailedString());

            case SchedulingContextType.SystemThread:
                return(String.Format("DispatcherTarget{0}", DispatcherTarget));

            default:
                return(ContextType.ToString());
            }
        }
Example #5
0
        public override string ToString()
        {
            switch (ContextType)
            {
            case SchedulingContextType.Activation:
                return(Activation.ToString());

            case SchedulingContextType.SystemTarget:
                return(SystemTarget.ToString());

            case SchedulingContextType.SystemThread:
                return(String.Format("DispatcherTarget{0}", DispatcherTarget));

            default:
                return(ContextType.ToString());
            }
        }
Example #6
0
        ///// <summary>
        ///// Dictionary of Context types vs connection strings
        ///// </summary>
        //private static Dictionary<ContextType, string> contextConnections;


        ///// <summary>
        ///// Initialize the context connection string names
        ///// </summary>
        ///// <param name="connections"></param>
        //public static void InitializeContexts(Dictionary<ContextType, string> connections)
        //{
        //    contextConnections = connections;
        //}


        /// <summary>
        /// Factory method that needs to be called whenever a new context is needed.
        /// If no parameters are specified default context is created as Development.
        /// </summary>
        /// <param name="contextToUse">The type of context to use, each context has its own connection string with a different db specified</param>
        /// <returns>A new InventorContext with the context specified</returns>
        public static InventorContext CreateContext(ContextType contextToUse = ContextType.Default)
        {
            string contextString = contextToUse.ToString();

            return(new InventorContext(contextString));
        }
Example #7
0
        public bool Save(string DestinationThemeDir, bool OverwriteFile, bool CreateSymlinks)
        {
            char   Sep         = Path.DirectorySeparatorChar;
            string newpath     = DestinationThemeDir + Sep + GetSizeDir() + Sep + contextToStr(Context) + Sep;
            string newfilename = newpath + FdoName + Path.GetExtension(Filename);

            try{
                if (Context == ContextType.cNone)
                {
                    Context = guessContextFromStr(Path.GetFullPath(Filename));
                    Console.WriteLine("Guessing the icon " + Filename + ", belongs probably to " + Context.ToString());
                }
                if (!Directory.Exists(newpath))
                {
                    Directory.CreateDirectory(Path.GetFullPath(newpath));
                }
                //Console.WriteLine("Old: "+Filename+",New: "+ newfilename);
                if (Filename == "")
                {
                    Pixbuf.Save(newfilename, CUtility.ImageTypeToStr(Type));
                }
                else
                {
                    File.Copy(Filename, newfilename, OverwriteFile);                     //File.Move
                }
                //Has to be included in the icon-class if this unit will be the base of a icon-generator-app
                //For now, it's ok to copy it while saving
                string IconFile = Path.ChangeExtension(Filename, "icon");
                if (File.Exists(IconFile))
                {
                    File.Copy(IconFile, Path.ChangeExtension(newfilename, "icon"), OverwriteFile);                //File.Move
                }
                //for max compatibility
                if (CreateSymlinks)
                {
                    foreach (string link in LinkedNames)
                    {
                        CUtility.Execute("ln", "-s " + newfilename + " " + newpath + link + Path.GetExtension(Filename));
                    }
                }
            } catch (Exception e) {
                Console.WriteLine("Warning: " + e.Message);
            }
            return(true);
        }
        public bool Save(string DestinationThemeDir,bool OverwriteFile, bool CreateSymlinks)
        {
            char Sep = Path.DirectorySeparatorChar;
            string newpath = DestinationThemeDir + Sep + GetSizeDir() + Sep + contextToStr(Context) + Sep ;
            string newfilename = newpath + FdoName + Path.GetExtension(Filename);
            try{
                if (Context == ContextType.cNone){
                    Context = guessContextFromStr(Path.GetFullPath(Filename));
                    Console.WriteLine("Guessing the icon "+Filename+", belongs probably to "+ Context.ToString());
                }
                if (!Directory.Exists(newpath))
                    Directory.CreateDirectory(Path.GetFullPath(newpath));
                //Console.WriteLine("Old: "+Filename+",New: "+ newfilename);
                if (Filename == "")
                    Pixbuf.Save(newfilename,CUtility.ImageTypeToStr(Type));
                else
                    File.Copy(Filename, newfilename,OverwriteFile);  //File.Move

                //Has to be included in the icon-class if this unit will be the base of a icon-generator-app
                //For now, it's ok to copy it while saving
                string IconFile = Path.ChangeExtension(Filename,"icon");
                if (File.Exists(IconFile))
                    File.Copy(IconFile, Path.ChangeExtension(newfilename,"icon"),OverwriteFile);  //File.Move

                //for max compatibility
                if (CreateSymlinks){
                    foreach (string link in LinkedNames)
                        CUtility.Execute("ln","-s "+newfilename+" "+newpath + link + Path.GetExtension(Filename));
                }
            } catch (Exception e) {
                Console.WriteLine("Warning: "+e.Message);
            }
            return true;
        }
Example #9
0
        //
        // Private methods for initialization
        //
        private void Initialize()
        {
            if (!_initialized)
            {
                lock (_initializationLock)
                {
                    if (_initialized)
                        return;

                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalContext", "Initializing Context");

                    switch (_contextType)
                    {
                        case ContextType.Domain:
                            DoDomainInit();
                            break;

                        case ContextType.Machine:
                            DoMachineInit();
                            break;

                        case ContextType.ApplicationDirectory:
                            DoApplicationDirectoryInit();
                            break;
            #if TESTHOOK
                        case ContextType.Test:
                            // do nothing
                            break;
            #endif
                        default:
                            // Internal error
                            Debug.Fail("PrincipalContext.Initialize: fell off end looking for " + _contextType.ToString());
                            break;
                    }

                    _initialized = true;
                }
            }
        }
Example #10
0
        /// <summary>
        /// Switcher of used context.
        /// </summary>
        /// <param name="context">New context for using.</param>
        /// <returns>Self reference.</returns>
        public IManager switchOn(ContextType context)
        {
            if(this.Context != context) {
                Log.Trace("Config-Manager: switched context '{0}'", context.ToString());
            }
            this.Context = context;

            configure(UserConfig.Data);
            return this;
        }