Ejemplo n.º 1
0
        public static void Show()
        {
            Student student = new Student()
            {
                Name = "chenia",
            };

            //直接依赖  学生上层使用下层时,必须将下层new出来,上层再调用对应的下层
            //若增加下层,则需要在上层处增加对应的方法
            MI mi = new MI();

            student.PlayMI(mi);

            Honor honor = new Honor();

            student.PlayHonor(honor);


            //使用抽象后,不用修改
            AbstractPhone abstractPhone = new MI();

            student.Play(abstractPhone);


            //ApplyPay只有IPhone中有,此时只能实例化细节
            IPhone iPhone = new IPhone();

            iPhone.ApplyPay();
        }
Ejemplo n.º 2
0
        private void FillMFDictionary()
        {
            /*
             * 1	General
             * 2	Video
             * 3	Audio
             * 4	Image
             * 5	Text
             * 6	Menu
             * 7	Generic
             * 8	Other
             */

            FillMIDictionaryByType(1, "General");

            var strAudioCount = MI.Get(MediaInfoLib.StreamKind.General, 0, "AudioCount");
            int AudioCount    = 0;

            int.TryParse(strAudioCount, out AudioCount);
            var strVideoCount = MI.Get(MediaInfoLib.StreamKind.General, 0, "VideoCount");
            int VideoCount    = 0;

            int.TryParse(strVideoCount, out VideoCount);
            if (AudioCount > 0)
            {
                FillMIDictionaryByType(3, "Audio");
            }

            if (VideoCount > 0)
            {
                FillMIDictionaryByType(2, "Video");
            }
        }
Ejemplo n.º 3
0
        private KeyValuePair <MethodInfo, ParameterInfo[]>[] GetMethods(Type Type)
        {
            List <KeyValuePair <MethodInfo, ParameterInfo[]> > Result = new List <KeyValuePair <MethodInfo, ParameterInfo[]> >();

            ParameterInfo[]          ParameterInfo;
            IEnumerable <MethodInfo> Methods = Type.GetRuntimeMethods();

            foreach (MethodInfo MI in Methods)
            {
                if (MI.Name != this.name)
                {
                    continue;
                }

                ParameterInfo = MI.GetParameters();
                if (ParameterInfo.Length != this.nrParameters)
                {
                    continue;
                }

                Result.Add(new KeyValuePair <MethodInfo, ParameterInfo[]>(MI, ParameterInfo));
            }

            return(Result.ToArray());
        }
Ejemplo n.º 4
0
        public ObservableList <StandAloneAction> GetStandAloneActions()
        {
            ObservableList <StandAloneAction> list = new ObservableList <StandAloneAction>();

            foreach (PluginService pluginService in GetPluginServices())
            {
                foreach (MethodInfo MI in pluginService.mStandAloneMethods)
                {
                    GingerActionAttribute token = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);
                    StandAloneAction      DA    = new StandAloneAction();
                    DA.ID = token.Id;
                    // AssemblyName AN = MI.DeclaringType.Assembly.GetName();
                    DA.PluginID    = PluginID; //AN.Name;
                    DA.ServiceID   = pluginService.ServiceId;
                    DA.Description = token.Description;
                    foreach (ParameterInfo PI in MI.GetParameters())
                    {
                        if (PI.ParameterType.Name != nameof(GingerAction))
                        {
                            DA.InputValues.Add(new ActionInputValueInfo()
                            {
                                Param = PI.Name, ParamType = PI.ParameterType
                            });
                        }
                    }
                    list.Add(DA);
                }
            }
            return(list);
        }
Ejemplo n.º 5
0
        private void ScanService()
        {
            // Scan once and cache
            if (mServiceActions != null)
            {
                return;
            }
            Console.WriteLine("Scanning Service: " + mService.GetType().FullName);
            mServiceActions = new List <ActionHandler>();

            // Register all actions which have 'GingerAction' attribute
            Type t = mService.GetType();
            var  v = t.GetMethods(); //BindingFlags.Public  BindingFlags.DeclaredOnly);

            foreach (MethodInfo MI in v)
            {
                GingerActionAttribute GAA = (GingerActionAttribute)MI.GetCustomAttribute(typeof(GingerActionAttribute));
                if (GAA != null)
                {
                    ActionHandler AH = new ActionHandler();
                    AH.ServiceActionId = GAA.Id;
                    AH.MethodInfo      = MI;
                    AH.Instance        = mService;
                    mServiceActions.Add(AH);

                    Console.WriteLine("Found Action: " + AH.ServiceActionId);
                }
            }
        }
 protected override EmployeeInfo Parse()
 {
     return(new EmployeeInfo
     {
         ID = ToInt(ID),
         EmployeeNumber = EmployeeNumber.ToString(),
         FirstName = FirstName.ToString(),
         LastName = LastName.ToString(),
         MI = MI.ToString(),
         Email = Email.ToString(),
         Password = Password.ToString(),
         Contact = Contact.ToString(),
         Address = Address.ToString(),
         Birthday = Birthday.ToString(),
         Gender = Gender.ToString(),
         Religion = Religion.ToString(),
         Nationality = Nationality.ToString(),
         Birthplace = Birthplace.ToString(),
         CivilStatus = CivilStatus.ToString(),
         EmployeeStatusID = ToInt(EmployeeStatusID),
         DateHired = DateHired.ToString(),
         DateCreated = DateCreated.ToString(),
         DatedUpdated = DatedUpdated.ToString(),
         DatedDeleted = DatedDeleted.ToString(),
         RoleID = ToInt(RoleID),
         EmployeeStatus = EmployeeStatus.ToString(),
         RoleStatus = RoleStatus.ToString()
     });
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 是否开启了全面屏手势
 /// </summary>
 /// <returns></returns>
 public static bool?IsFullScreenGesture(Context context)
 {
     if (AndroidROM.Current.IsMIUI)
     {
         return(MI.IsFullScreenGesture(context));
     }
     return(null);
 }
Ejemplo n.º 8
0
        public void LocateHooks()
        {
            _discovered = new List <APIPath>(); // Always reset this list at the start of this method!
            try
            {
                int i = 0;
                for (i = 0; i < AppDomain.CurrentDomain.GetAssemblies().Length; i++)
                {
                    Assembly asm = null;

                    try
                    {
                        asm = AppDomain.CurrentDomain.GetAssemblies()[i];
                    } catch (Exception e)
                    {
                        // nothing needs be done here
                    }

                    if (asm != null)
                    {
                        int ii = 0;
                        for (ii = 0; ii < asm.GetTypes().Length; ii++)
                        {
                            Type _type = null;
                            try
                            {
                                _type = asm.GetTypes()[ii];
                            }catch (Exception E) { }
                            if (_type != null)
                            {
                                if (_type.IsClass)
                                {
                                    foreach (MethodInfo MI in _type.GetMethods())
                                    {
                                        APIPath[] paths = (APIPath[])MI.GetCustomAttributes(typeof(APIPath), true);

                                        int ix = 0;
                                        for (ix = 0; ix < paths.Length; ix++)
                                        {
                                            APIPath _path = paths[ix];
                                            _path.AssignedMethod = MI;
                                            _discovered.Add(_path);

                                            Console.WriteLine("Discovered: " + _path.PathLike + "; " + MI.Name);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }catch (Exception e)
            {
            }
        }
Ejemplo n.º 9
0
 private void FillMIDictionaryByType(int idParamsType, string paramTypeTitle)
 {
     foreach (var item in GetMIParameters(idParamsType))
     {
         var tmp = MI.Get(MediaInfoLib.StreamKind.General, 0, item);
         if (!string.IsNullOrWhiteSpace(tmp))
         {
             MFIDictionary.Add(string.Format("{0}.{1}", paramTypeTitle, item), tmp);
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 是否隐藏屏幕刘海
 /// </summary>
 /// <returns></returns>
 public static bool?IsHideNotch(Context context)
 {
     if (AndroidROM.Current.IsMIUI) // https://dev.mi.com/console/doc/detail?pId=1293#_4
     {
         return(MI.IsHideNotch(context));
     }
     else if (AndroidROM.Current.IsEMUI)
     {
         return(HUAWEI.IsHideNotch(context));
     }
     return(null);
 }
Ejemplo n.º 11
0
 private void Handler()
 {
     if ($System.Users.Login($Tag_InputUsername, $Tag_InputPassword))  
     {
         $Pages.MainPage.PasswordBox.Password = ""; //Resets the passwordbox password at login
         $HMI.ShowPage("LidSettings"); //Opens the Lidsettings page
         $Pages.LidSettings.Slider2.Value = 0; //Disables the advanced settings option
         
         _counter++; // increment the counter field
     }
     else
     {  
         $Pages.MainPage.PasswordBox.Password = ""; //resets password
     }
 }
Ejemplo n.º 12
0
        private void ConfiguraSaida_Load(object sender, EventArgs e)
        {
            txtNomeSaida.Text = Nome;

            cboTipo.DisplayMember = "Nome";
            cboTipo.ValueMember   = "Tipo";

            cboTipo.Items.Add(new TipoItem {
                Nome = "Manual", Tipo = "M"
            });
            cboTipo.Items.Add(new TipoItem {
                Nome = "Agendado", Tipo = "A"
            });
            cboTipo.Items.Add(new TipoItem {
                Nome = "Pulso", Tipo = "P"
            });

            if (TS == String.Empty)
            {
                TS = "M";
            }

            if (TS == "M")
            {
                cboTipo.SelectedIndex = 0;
            }
            else if (TS == "A")
            {
                cboTipo.SelectedIndex = 1;
            }
            else if (TS == "P")
            {
                cboTipo.SelectedIndex = 2;
            }



            gbAgendamento.Enabled = (TS == "A");
            gbPulso.Enabled       = (TS == "P");

            txtHI.Text = HI.ToString();
            txtMI.Text = MI.ToString();
            txtHF.Text = HF.ToString();
            txtMF.Text = MF.ToString();

            txtPulso.Text = SP.ToString();
        }
Ejemplo n.º 13
0
        // TODO: get items - to compare menu as joined string

        public void Click(string header)
        {
            foreach (MenuItem MI in mContextMenu.Items)
            {
                if (MI.Header.ToString() == header)
                {
                    //MenuItem MI = (MenuItem)contextMenu.Items[0];
                    MI.RaiseEvent(new MouseEventArgs(Mouse.PrimaryDevice, 0)
                    {
                        RoutedEvent = Mouse.MouseEnterEvent
                    });
                    SleepWithDoEvents(100);
                    // TODO: run on thread as modal dialog might pop up
                    Task.Factory.StartNew(() => {
                        MI.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                        SleepWithDoEvents(100);
                    });
                }
            }
        }
Ejemplo n.º 14
0
        private static MethodInfo GetFindMethod()
        {
            Type T = typeof(Database);

            foreach (MethodInfo MI in T.GetTypeInfo().GetDeclaredMethods("Find"))
            {
                ParameterInfo[] P = MI.GetParameters();
                if (P.Length != 4 ||
                    P[0].ParameterType != typeof(int) ||
                    P[1].ParameterType != typeof(int) ||
                    P[2].ParameterType != typeof(Filter) ||
                    P[3].ParameterType != typeof(string[]))
                {
                    continue;
                }

                return(MI);
            }

            return(null);
        }
Ejemplo n.º 15
0
        public static void DebugPrint(object obj)
        {
            Type t = obj.GetType();
            // private&public
            BindingFlags flags = BindingFlags.Public
                                 | BindingFlags.Instance
                                 | BindingFlags.NonPublic;
            // fields&properties
            List <MemberInfo> members = new List <MemberInfo>();

            members.AddRange(t.GetFields(flags));
            members.AddRange(t.GetProperties(flags));
            foreach (MemberInfo MI in members)
            {
                DebugPrintAttribute DPA =
                    (DebugPrintAttribute)MI.GetCustomAttribute(typeof(DebugPrintAttribute));
                if (DPA != null)
                {
                    Console.WriteLine(DPA.format, MI.GetValue(obj), MI.Name, MI.ReflectedType);
                }
            }
        }
Ejemplo n.º 16
0
 public void Redraw()
 {
     ignore_changes = true;
     if (m_motor != null)
     {
         MA.Set(m_motor.Axis);
         PM.Set(m_motor.PowerManagement);
         PO.Set(m_motor.Polarity);
         MI.Set(m_motor.Microstep);
         TR.Set(m_motor.TravelPerRevolution);
         SA.Text        = m_motor.StepAngle.ToString(CultureInfo.InvariantCulture.NumberFormat);
         ignore_changes = false;
     }
     else
     {
         MA.Items.Clear();
         PM.Items.Clear();
         PO.Items.Clear();
         MI.Items.Clear();
         TR.Clear();
         SA.Text = "";
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 是否为刘海屏设备
 /// </summary>
 /// <param name="activity"></param>
 /// <returns></returns>
 public static bool?IsNotch(Activity activity)
 {
     if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
     {
         return(activity?.Window?.DecorView.RootWindowInsets?.DisplayCutout != null);
     }
     else if (AndroidROM.Current.IsMIUI)
     {
         return(MI.IsNotch());
     }
     else if (AndroidROM.Current.IsEMUI)
     {
         return(HUAWEI.HasNotchInScreen(activity));
     }
     else if (AndroidROM.Current.IsColorOS)
     {
         return(OPPO.IsNotch(activity));
     }
     else if (AndroidROM.Current.IsFuntouchOS)
     {
         return(Vivo.IsNotch(activity));
     }
     return(null);
 }
Ejemplo n.º 18
0
 public override string ToString()
 {
     return(Frame.Index + ": I->(" + NI.ToString("0.0") + ", " + VI.ToString("0.0") + ", " + MI.ToString("0.0") + "), J->(" +
            NJ.ToString("0.0") + ", " + VJ.ToString("0.0") + ", " + MJ.ToString("0.0") + ")");
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Executes a node.
        /// </summary>
        /// <param name="Variables">Set of variables for the activity.</param>
        /// <returns>Next node of execution, if different from the default, otherwise null (for default).</returns>
        public override async Task <LinkedListNode <IActivityNode> > Execute(Variables Variables)
        {
            string     ActionValue = this.action.GetValue(Variables);
            object     Actor       = this.GetActorObject(this.actor, Variables);
            Type       T           = Actor.GetType();
            MethodInfo Method;

            int[] Positions;
            int   i, j, c;

            lock (this.synchObj)
            {
                if (T == this.lastType)
                {
                    Method    = this.lastMethod;
                    Positions = this.argumentPositions;
                }
                else
                {
                    c         = this.argumentNames.Length;
                    Positions = new int[c];
                    Method    = null;

                    IEnumerable <MethodInfo> Methods = T.GetRuntimeMethods();

                    foreach (MethodInfo MI in Methods)
                    {
                        if (MI.IsAbstract || !MI.IsPublic)
                        {
                            continue;
                        }

                        if (MI.Name != ActionValue)
                        {
                            continue;
                        }

                        ParameterInfo[] Parameters = MI.GetParameters();
                        if (Parameters.Length != c)
                        {
                            continue;
                        }

                        for (i = 0; i < c; i++)
                        {
                            ParameterInfo Parameter = Parameters[i];
                            j = Array.IndexOf <string>(this.argumentNames, Parameter.Name);
                            if (j < 0)
                            {
                                Parameters = null;
                                break;
                            }

                            Positions[i] = j;
                        }

                        if (Parameters is null)
                        {
                            continue;
                        }

                        Method = MI;
                        break;
                    }

                    if (Method is null)
                    {
                        throw new Exception("No method named " + this.action + " found on actor " + this.actor + " (of type " + T.FullName + "), with the givet set of arguments.");
                    }

                    this.lastMethod        = Method;
                    this.argumentPositions = Positions;
                    this.lastType          = T;
                }
            }

            c = Positions.Length;

            object[] Arguments = new object[c];

            for (i = 0; i < c; i++)
            {
                Arguments[i] = this.arguments[Positions[i]].Value.Evaluate(Variables);
            }

            object Result = Method.Invoke(Actor, Arguments);

            if (Result is Task Task)
            {
                await Task;
            }

            return(null);
        }
Ejemplo n.º 20
0
 //依赖细节(手机)
 public void PlayMI(MI mi)
 {
     Console.WriteLine($"{Name} is playing {mi.Brand}");
 }
Ejemplo n.º 21
0
        void LoadPluginServicesFromDll()
        {
            if (mServices == null)
            {
                mServices = new ObservableList <PluginServiceInfo>();
                foreach (PluginAssemblyInfo asssembly in mAssembliesInfo)
                {
                    IEnumerable <Type> types = from x in asssembly.Assembly.GetTypes() where x.GetCustomAttribute(typeof(GingerServiceAttribute)) != null select x;
                    foreach (Type type in types)
                    {
                        GingerServiceAttribute gingerServiceAttribute = (GingerServiceAttribute)Attribute.GetCustomAttribute(type, typeof(GingerServiceAttribute), false);
                        bool IsServiceSession = typeof(IServiceSession).IsAssignableFrom(type);
                        // if service impl IServiceSession then mark it so we know we need and agent Start/Stop
                        // if it is not session , then all actions are stand alone

                        PluginServiceInfo pluginServiceInfo = new PluginServiceInfo()
                        {
                            ServiceId = gingerServiceAttribute.Id, IsSession = IsServiceSession
                        };
                        // expecting to get ExcelAction, FileAction, DatabaseAction...
                        MethodInfo[] methods    = type.GetMethods();
                        Type[]       interfaces = type.GetInterfaces();
                        foreach (MethodInfo MI in methods)
                        {
                            //Check if method have token [GingerAction] or is is of interface else we ignore
                            GingerActionAttribute gingerActionAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);

                            if (gingerActionAttr == null && !MI.IsVirtual)   // Virtual if it is interface
                            {
                                continue;
                            }

                            PluginServiceActionInfo action = new PluginServiceActionInfo();

                            if (gingerActionAttr != null)
                            {
                                action.ActionId    = gingerActionAttr.Id;
                                action.Description = gingerActionAttr.Description;
                            }
                            else
                            {
                                // Check if the method is from interface
                                if (MI.IsVirtual)
                                {
                                    foreach (Type serviceInterface in interfaces)
                                    {
                                        //check if marked with [GingerInterface]
                                        GingerInterfaceAttribute gingerInterfaceAttr = (GingerInterfaceAttribute)Attribute.GetCustomAttribute(serviceInterface, typeof(GingerInterfaceAttribute), false);

                                        if (gingerInterfaceAttr != null)
                                        {
                                            var mm = serviceInterface.GetMethod(MI.Name);
                                            if (mm != null)
                                            {
                                                // Get the action id and desc from the interface
                                                action.Interface = serviceInterface.FullName;

                                                GingerActionAttribute interfaceGAAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(mm, typeof(GingerActionAttribute), false);
                                                if (interfaceGAAttr == null)
                                                {
                                                    // no GA attr then ignore
                                                    continue;
                                                }
                                                else
                                                {
                                                    action.ActionId    = interfaceGAAttr.Id;
                                                    action.Description = interfaceGAAttr.Description;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (string.IsNullOrEmpty(action.ActionId))
                            {
                                continue;
                            }

                            foreach (ParameterInfo PI in MI.GetParameters())
                            {
                                if (PI.ParameterType.Name != nameof(IGingerAction))
                                {
                                    action.InputValues.Add(new ActionInputValueInfo()
                                    {
                                        Param = PI.Name, ParamType = PI.ParameterType
                                    });
                                }
                            }
                            pluginServiceInfo.Actions.Add(action);
                        }
                        mServices.Add(pluginServiceInfo);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public WebhookRegistry.HTTPResponseData showHelp(List <string> arguments, string body, string method, NameValueCollection headers)
        {
            WebhookRegistry.HTTPResponseData httpReply = new WebhookRegistry.HTTPResponseData();
            CommandRegistry reg = CommandRegistry.Instance;

            string Final = "<body bgcolor='black'><style type='text/css'>table.HelpTable {  border: 5px solid #1C6EA4;" +
                           "  background - color: #000000; " +
                           "  width: 100 %;            text - align: left;            border - collapse: collapse;" +
                           "        }        table.HelpTable td, table.HelpTable th        {            border: 3px solid #AAAAAA;" +
                           "  padding: 3px 2px;        }        table.HelpTable tbody td {  font-size: 19px;  color: #69FAF7;" +
                           "}    table.HelpTable tr:nth-child(even)    {    background: #000000;}    table.HelpTable thead" +
                           "    {        background: #26A486;  background: -moz-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
                           "  background: -webkit-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
                           "  background: linear-gradient(to bottom, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
                           "  border-bottom: 2px solid #444444;}    table.HelpTable thead th {  font-size: 25px;" +
                           "  font-weight: bold;  color: #FFFFFF;  text-align: center;  border-left: 2px solid #D0E4F5;" +
                           "}table.HelpTable thead th:first-child {  border-left: none;}table.HelpTable tfoot td {  font-size: 14px;" +
                           "}table.HelpTable tfoot.links{    text-align: right;}table.HelpTable tfoot.links a{display: inline - block;" +
                           "background: #1C6EA4;  color: #FFFFFF;  padding: 2px 8px;    border - radius: 5px;}</style>";

            Final += "<table class='HelpTable'><thead><tr><th>Bot Version</th><th>" + ASMInfo.BotVer + "</th></tr></table><br/>";

            Final += "<table class='HelpTable'><thead><tr><th>Command</th><th>Minimum Level Required</th><th>Usage</th><th>Allowed Sources</th></thead><tbody>";
            foreach (KeyValuePair <string, CommandGroup> cmd in reg.Cmds)
            {
                // Command
                Final += "<tr><td>" + cmd.Value.Command + "</td>";
                // Level
                Final += "<td>" + cmd.Value.minLevel.ToString() + "</td>";
                // Usage
                Final += "<td>" + cmd.Value.cmdUsage.RawUsage() + "</td>";
                // Allowed Sources
                Final += "<td>" + cmd.Value.CommandSource + "</td>";
            }
            Final += "</tbody></table>";

            Final += "<table class='HelpTable'><thead><tr><th>Hook Path</th><tr></thead><tbody>";
            WebhookRegistry regx = WebhookRegistry.Instance;

            foreach (KeyValuePair <string, WebhookAttribs> hooks in regx.hooks)
            {
                Final += "<tr><td>" + hooks.Value.Path + "</td></tr>";
            }
            Final += "</tbody></table>";

            Final += "<br/><table class='HelpTable'><thead><tr><th>Assembly</th><th>Version</th><th># Of Commands</th><th>Total Classes</th></tr></thead><tbody>";

            foreach (Assembly A in AppDomain.CurrentDomain.GetAssemblies())
            {
                Final += "<tr><td>" + A.GetName().Name + "</td><td>" + A.GetName().Version + "</td>";
                int TotalCommandsContained = 0;
                int TotalClasses           = 0;
                foreach (Type T in A.GetTypes())
                {
                    if (T.IsClass)
                    {
                        TotalClasses++;
                        foreach (MethodInfo MI in T.GetMethods())
                        {
                            CommandGroup[] CG = (CommandGroup[])MI.GetCustomAttributes(typeof(CommandGroup), false);
                            TotalCommandsContained += CG.Length;
                        }
                    }
                }

                Final += "<td>" + TotalCommandsContained.ToString() + "</td><td>" + TotalClasses.ToString() + "</td></tr>";
            }
            Final += "</tbody></table>";


            httpReply.ReplyString       = Final;
            httpReply.Status            = 200;
            httpReply.ReturnContentType = "text/html";

            return(httpReply);
        }
Ejemplo n.º 23
0
        void LoadPluginServicesFromDll()
        {
            if (mServices == null)                                    // Done only once
            {
                mServices = new ObservableList <PluginServiceInfo>(); // Move down !!!!!!!!!!!!!!!
                foreach (PluginAssemblyInfo pluginAssemblyInfo in mAssembliesInfo)
                {
                    var types2 = pluginAssemblyInfo.Assembly.GetExportedTypes();
                    IEnumerable <Type> types = from x in pluginAssemblyInfo.Assembly.GetTypes() where x.GetCustomAttribute(typeof(GingerServiceAttribute)) != null select x;
                    foreach (Type type in types)
                    {
                        GingerServiceAttribute gingerServiceAttribute = (GingerServiceAttribute)Attribute.GetCustomAttribute(type, typeof(GingerServiceAttribute), false);
                        bool IsServiceSession = typeof(IServiceSession).IsAssignableFrom(type);
                        // if service impl IServiceSession then mark it so we know we need and agent Start/Stop
                        // if it is not session , then all actions are stand alone

                        PluginServiceInfo pluginServiceInfo = new PluginServiceInfo()
                        {
                            ServiceId = gingerServiceAttribute.Id, IsSession = IsServiceSession
                        };
                        // expecting to get ExcelAction, FileAction, DatabaseAction...
                        MethodInfo[] methods    = type.GetMethods();
                        Type[]       interfaces = type.GetInterfaces();
                        foreach (MethodInfo MI in methods)
                        {
                            //Check if method have token [GingerAction] or is is of interface else we ignore
                            GingerActionAttribute gingerActionAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(MI, typeof(GingerActionAttribute), false);

                            if (gingerActionAttr == null && !MI.IsVirtual)   // Virtual if it is interface
                            {
                                continue;
                            }


                            PluginServiceActionInfo action = new PluginServiceActionInfo();

                            if (gingerActionAttr != null)
                            {
                                action.ActionId    = gingerActionAttr.Id;
                                action.Description = gingerActionAttr.Description;
                            }
                            else
                            {
                                // Check if the method is from interface
                                if (MI.IsVirtual)
                                {
                                    foreach (Type serviceInterface in interfaces)
                                    {
                                        /// !!!!!!!!!!!!! see new style and remove !!!!!!!!!!!!!!!!
                                        // Not sure if we need to list all method if they come from interface !!!!!!!!!!!!!! need to list only the interface

                                        //check if marked with [GingerInterface]
                                        GingerInterfaceAttribute gingerInterfaceAttr = (GingerInterfaceAttribute)Attribute.GetCustomAttribute(serviceInterface, typeof(GingerInterfaceAttribute), false);

                                        if (gingerInterfaceAttr != null)
                                        {
                                            var mm = serviceInterface.GetMethod(MI.Name);
                                            if (mm != null)
                                            {
                                                // Get the action id and desc from the interface
                                                action.Interface = serviceInterface.FullName;

                                                GingerActionAttribute interfaceGAAttr = (GingerActionAttribute)Attribute.GetCustomAttribute(mm, typeof(GingerActionAttribute), false);
                                                if (interfaceGAAttr == null)
                                                {
                                                    // no GA attr then ignore
                                                    continue;
                                                }
                                                else
                                                {
                                                    action.ActionId    = interfaceGAAttr.Id;
                                                    action.Description = interfaceGAAttr.Description;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (string.IsNullOrEmpty(action.ActionId))
                            {
                                continue;
                            }

                            foreach (ParameterInfo PI in MI.GetParameters())
                            {
                                if (PI.ParameterType.Name == nameof(IGingerAction))
                                {
                                    continue;
                                }

                                ActionInputValueInfo actionInputValueInfo = new ActionInputValueInfo()
                                {
                                    Param = PI.Name, ParamType = PI.ParameterType
                                };
                                actionInputValueInfo.ParamAttrs = new List <Attribute>();
                                action.InputValues.Add(actionInputValueInfo);

                                // Add Ginger param properties

                                Attribute[] attrs = Attribute.GetCustomAttributes(PI, typeof(Attribute), false);


                                // var v = PI.CustomAttributes; - not good
                                foreach (Attribute attribute in attrs)
                                {
                                    actionInputValueInfo.ParamAttrs.Add(attribute);
                                }
                            }


                            pluginServiceInfo.Actions.Add(action);
                        }

                        // Get all interfaces which are marked with attr 'GingerInterface'
                        foreach (Type PluginInterface in interfaces)
                        {
                            // decide if we need Feature for service and/or Interfaces seperate
                            // ServiceFeatureAttribute gingerInterfaceAttr = (ServiceFeatureAttribute)Attribute.GetCustomAttribute(PluginInterface, typeof(ServiceFeatureAttribute), true);
                            GingerInterfaceAttribute gingerInterfaceAttr = (GingerInterfaceAttribute)Attribute.GetCustomAttribute(PluginInterface, typeof(GingerInterfaceAttribute), true);

                            if (gingerInterfaceAttr != null)
                            {
                                pluginServiceInfo.Interfaces.Add(gingerInterfaceAttr.Id);
                            }
                        }

                        MemberInfo[] members = type.GetMembers();

                        foreach (MemberInfo mi in members)
                        {
                            if (Attribute.GetCustomAttribute(mi, typeof(ServiceConfigurationAttribute), false) is ServiceConfigurationAttribute mconfig)
                            {
                                PluginServiceConfigInfo Config = new  PluginServiceConfigInfo();
                                Config.Name        = mconfig.Name;
                                Config.Description = mconfig.Description;
                                Config.Type        = mconfig.GetType().Name;
                                // Config.DefaultValue = mconfig.DefaultValue?.ToString();

                                if (Attribute.GetCustomAttribute(mi, typeof(ValidValueAttribute), false) is ValidValueAttribute validValues)
                                {
                                    foreach (var val in validValues.ValidValue)
                                    {
                                        Config.OptionalValues.Add(val.ToString());
                                    }
                                }
                                if (Attribute.GetCustomAttribute(mi, typeof(DefaultAttribute), false) is DefaultAttribute DefaultValue)
                                {
                                    Config.DefaultValue = DefaultValue == null ? string.Empty : DefaultValue.ToString();
                                }

                                pluginServiceInfo.Configs.Add(Config);
                            }
                        }
                        mServices.Add(pluginServiceInfo);
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public static Dictionary <string, List <RoleAttribute> > GetAllAction()
        {
            //action 列表
            Dictionary <string, List <RoleAttribute> > ActionList = new Dictionary <string, List <RoleAttribute> >();

            SiteInfo m_SiteInfo = DealMvc.WebCacheHelper.GetSiteInfo();

            if (!m_SiteInfo.WebCompetence)
            {
                return(ActionList);
            }

            try
            {
                //要进行反射的DLL
                string[] S_Ref_Dll = DealMvc.Common.Config.ConfigInfo <DealMvc.Common.Config.RoleDLLInfo> .Instance().path.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); //new string[] { "~/bin/DealMvc.dll" };

                //遍历DLL文件
                foreach (string S_Dll in S_Ref_Dll)
                {
                    //获得DLL里的类型
                    Type[] ActionType = Assembly.LoadFile(System.Web.HttpContext.Current.Server.MapPath(S_Dll)).GetTypes();

                    //遍历DLL里的类型
                    foreach (Type Action_Ref in ActionType)
                    {
                        //获取类上的描述信息
                        object[] ClassObj = Action_Ref.GetCustomAttributes(typeof(ControlInfoAttribute), false);

                        if (ClassObj.Length < 1)
                        {
                            continue;
                        }

                        ControlInfoAttribute ClassObjAttr = ClassObj[0] as ControlInfoAttribute;


                        //获得类Action的Name属性
                        List <RoleAttribute> Type_Action_Lit = new List <RoleAttribute>();

                        //遍历Action
                        foreach (MethodInfo MI in Action_Ref.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                        {
                            object[] ActionObj = MI.GetCustomAttributes(typeof(RoleAttribute), false);

                            if (ActionObj.Length < 1)
                            {
                                continue;
                            }

                            RoleAttribute ActionRoleAttr = ActionObj[0] as RoleAttribute;

                            if (ActionRoleAttr.IsAuthorize)
                            {
                                //给Action Url赋值
                                ActionRoleAttr.ActionUrl = string.Format("{0}/{1}", Action_Ref.Name.Replace("Controller", ""), MI.Name);

                                Type_Action_Lit.Add(ActionRoleAttr);
                            }
                        }

                        //将类信息加到返回集里
                        ActionList.Add(ClassObjAttr.Name, Type_Action_Lit);
                    }
                }
            }
            catch
            {
                ExceptionEx.MyExceptionLog.AddLogError("反射权限dll出错");
            }

            return(ActionList);
        }
Ejemplo n.º 25
0
 public Texi(int off, MI mi, STim st)
     : base(off, mi)
 {
     this.st = st;
 }
Ejemplo n.º 26
0
 public string Create()
 {
     return($"INSERT INTO Marines (FirstName, LastName, MI, Rank, EDIPI, PRUC) Values ('{FirstName.ToUpper()}', '{LastName.ToUpper()}', '{MI.ToUpper()}', '{Rank.ToUpper()}', '{EDIPI}', '{PRUC}');");
 }
Ejemplo n.º 27
0
 public Vifi(int off, MI mi, byte[] vifpkt)
     : base(off, mi)
 {
     this.vifpkt = vifpkt;
 }
Ejemplo n.º 28
0
        public void LocateCommands()
        {
            try
            {
                int i = 0;
                // Locate all commands--
                for (i = 0; i < AppDomain.CurrentDomain.GetAssemblies().Length; i++)
                {
                    Assembly A = null;
                    try
                    {
                        A = AppDomain.CurrentDomain.GetAssemblies()[i];
                    }
                    catch (Exception e)
                    {
                        //                    MHEx(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "")
                    }
                    if (A != null)
                    {
                        int ii = 0;
                        for (ii = 0; ii < A.GetTypes().Length; ii++)
                        {
                            Type T = null;
                            try
                            {
                                T = A.GetTypes()[ii];
                            }
                            catch (Exception e)
                            {
                            }
                            if (T != null)
                            {
                                if (T.IsClass)
                                {
                                    foreach (MethodInfo MI in T.GetMethods())
                                    {
                                        CommandGroup[] Command = (CommandGroup[])MI.GetCustomAttributes(typeof(CommandGroup), false);
                                        //var CommandO = MI.GetCustomAttributes(typeof(CommandGroup), false);
                                        if (Command.Length > 0)
                                        {
                                            for (int ix = 0; ix < Command.Length; ix++)
                                            {
                                                CommandGroup CG = Command[ix];
                                                CG.AssignedMethod = MI;

                                                if (Cmds.ContainsKey(CG.Command.ToLower()) == false)
                                                {
                                                    Log.info(true, "DISCOVER: " + CG.Command);
                                                    Cmds.Add(CG.Command.ToLower(), CG);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                Log.info(log: "Discovered " + Cmds.Count.ToString() + " total commands");
            }
            catch (ReflectionTypeLoadException e)
            {
                MessageFactory.Post(Destinations.DEST_LOCAL, "FAILURE!!!\n\n[Assembly load failure]", UUID.Zero);
                foreach (Exception X in e.LoaderExceptions)
                {
                    MessageFactory.Post(Destinations.DEST_LOCAL, X.Message + "\n \nSTACK: " + X.StackTrace, UUID.Zero);
                }
            }
        }
Ejemplo n.º 29
0
 public Hexi(int off, MI mi)
 {
     this.off = off;
     this.mi  = mi;
 }