Example #1
0
        /// <summary>
        /// Create a single Response from an Assembly containing many Responses.
        /// </summary>
        /// <param name="a">the assembly object</param>
        /// <param name="boxname">The fully-qualified Response Name (as in Response.FullName).</param>
        /// <returns></returns>
        public static Response FromAssembly(System.Reflection.Assembly a, string fullname)
        {
            Type type;

            object[] args;
            Response b = null;

            try
            {
                type = a.GetType(fullname, true, true);
            }
            catch (Exception ex) { b = new InvalidResponse(); b.Name = ex.Message; return(b); }
            args = new object[] { };
            try
            {
                b = (Response)Activator.CreateInstance(type, args);
            }
            catch (Exception ex)
            {
                b = new InvalidResponse(); b.Name = ex.InnerException.Message; return(b);
            }
            b.FullName = fullname;
            try
            {
                int partial = fullname.IndexOf('.');
                b.Name = fullname.Substring(partial + 1, fullname.Length - partial);
            } catch (Exception ex) {}
            return(b);
        }
Example #2
0
 /// <summary>
 /// Create a single Response from a DLL containing many Responses.
 /// </summary>
 /// <param name="fullname">The fully-qualified Response Name (as in 'BoxExamples.Name').  </param>
 /// <param name="dllname">The path and filename of DLL.</param>
 /// <returns></returns>
 public static Response FromDLL(string fullname, string dllname)
 {
     System.Reflection.Assembly a;
     try
     {
         a = System.Reflection.Assembly.LoadFrom(dllname);
     }
     catch (Exception ex) { Response b = new InvalidResponse(); b.Name = ex.Message; return(b); }
     return(FromAssembly(a, fullname));
 }
Example #3
0
        /// <summary>
        /// Create a single Response from an Assembly containing many Responses.
        /// </summary>
        /// <param name="a">the assembly object</param>
        /// <param name="boxname">The fully-qualified Response Name (as in Response.FullName).</param>
        /// <returns></returns>
        public static Response FromAssembly(System.Reflection.Assembly a, string fullname, DebugDelegate deb)
        {
            Response b = null;

            try
            {
                Type     type;
                object[] args;

                // get class from assembly
                type = a.GetType(fullname, true, true);
                args = new object[] { };
                // create an instance of type and cast to response
                b = (Response)Activator.CreateInstance(type, args);
                // if it doesn't have a name, add one
                if (b.Name == string.Empty)
                {
                    b.Name = type.Name;
                }
                if (b.FullName == string.Empty)
                {
                    b.FullName = type.FullName;
                }
                return(b);
            }
            catch (Exception ex)
            {
                if (deb != null)
                {
                    deb(ex.Message + ex.StackTrace);
                }
                b      = new InvalidResponse();
                b.Name = ex.Message + ex.StackTrace;
                return(b);
            }
        }
Example #4
0
        void remresp(object sender, EventArgs e)
        {
            // mark UI entry for removal
            List<int> remdidx = new List<int>();
            // process each selected response
            foreach (int dispidx in _resnames.SelectedIndices)
            {
                // make sure we're still trading it
                if ((dispidx<0) || (dispidx>_disp2real.Count))
                    continue;
                // get actual index
                int selbox = getrindx(dispidx);
                // get name
                string name = _reslist[selbox].FullName;
                // remove id to local association
                int responseID = _reslist[selbox].ID;
                _rid2local.Remove(responseID);
                // remove the response
                _reslist[selbox] = new InvalidResponse();
                // clear it's symbols
                _rsym[selbox] = string.Empty;
                // close it's indicators
                if (_indlog[selbox] != null)
                    _indlog[selbox].Stop();
                // mark it's UI element for removal
                remdidx.Add(dispidx);
                // notify user
                debug("removed #"+dispidx+": "+name+" id:"+responseID);
            }
            // remove response from screen
            for (int i = remdidx.Count -1; i>=0; i--)
            {
                // remove it
                _resnames.Items.RemoveAt(remdidx[i]);
                // remove name map
                _disp2real.RemoveAt(remdidx[i]);
            }

            // update everything
            IndexBaskets();
        }
Example #5
0
 private void Boxes_SelectedIndexChanged(object sender, EventArgs e)
 {
     // make sure something is selected
     if (_availresponses.SelectedIndex == -1) return;
     // make sure we haven't maxed our responses
     if (_NEXTRESPONSEID - _INITIALRESPONSEID >= MAXRESPONSEPERASP)
     {
         status("Exceeded maximum responses: " + MAXRESPONSEPERASP);
         debug("Exceeded maximum responses: " + MAXRESPONSEPERASP);
         return;
     }
     // get selected response
     string resname = (string)_availresponses.SelectedItem;
     // load it into working response
     Response tmp = new InvalidResponse();
     try
     {
         tmp = ResponseLoader.FromDLL(resname, Properties.Settings.Default.boxdll);
     }
     catch (Exception ex)
     {
         // log it
         bigexceptiondump(ex);
         // unselect response
         _availresponses.SelectedIndex = -1;
         return;
     }
     // add it
     int idx = addresponse(tmp);
     // make sure it worked
     if (idx==-1)
     {
         return;
     }
     // save the dll that contains the class for use with skins
     string dll = string.Empty;
     // if we don't have this class, add it
     if (!_class2dll.TryGetValue(resname, out dll))
         _class2dll.Add(resname, Properties.Settings.Default.boxdll);
     else // otherwise replace current dll as providing this class
         _class2dll[resname] = Properties.Settings.Default.boxdll;
     // unselect response
     _availresponses.SelectedIndex = -1;
 }
Example #6
0
        /// <summary>
        /// Create a single Response from an Assembly containing many Responses. 
        /// </summary>
        /// <param name="a">the assembly object</param>
        /// <param name="boxname">The fully-qualified Response Name (as in Response.FullName).</param>
        /// <returns></returns>
        public static Response FromAssembly(System.Reflection.Assembly a, string fullname, DebugDelegate deb)
        {
            Response b = null;
            try
            {

                Type type;
                object[] args;
                
                // get class from assembly
                type = a.GetType(fullname, true, true);
                args = new object[] { };
                // create an instance of type and cast to response
                b = (Response)Activator.CreateInstance(type, args);
                // if it doesn't have a name, add one
                if (b.Name == string.Empty)
                {
                    b.Name = type.Name;
                }
                if (b.FullName == string.Empty)
                {
                    b.FullName = type.FullName;
                }
                return b;
            }
            catch (Exception ex)
            {
                if (deb != null)
                {
                    deb(ex.Message + ex.StackTrace);
                }
                b = new InvalidResponse();
                b.Name = ex.Message + ex.StackTrace;
                return b;
            }
        }