コード例 #1
0
        public EidssEventLog(ConnectionCredentials credentials = null, string clientID = null)
        {
            m_EventDbService = ClassLoader.LoadClass("Event_DB");
            if ((clientID != null))
            {
                PropertyInfo pi = m_EventDbService.GetType()
                                  .GetProperty("ClientID",
                                               BindingFlags.Public | BindingFlags.Instance |
                                               BindingFlags.Static);
                pi.SetValue(m_EventDbService, clientID, null);
            }

            if ((credentials != null))
            {
                MethodInfo mi = GetDbServiceMethod("NewConnection");
                mi.Invoke(m_EventDbService, new object[]
                {
                    credentials.SQLServer,
                    credentials.SQLDatabase,
                    credentials.SQLUser,
                    credentials.SQLPassword,
                    credentials.SQLConnectionString
                });
            }
            //Dim siteID As String = EIDSS.model.Core.EidssSiteContext.Instance.SiteID
        }
コード例 #2
0
 /// <summary>
 /// Validates the status of an <code>HttpURLConnection</code> against an
 /// expected HTTP status code.
 /// </summary>
 /// <remarks>
 /// Validates the status of an <code>HttpURLConnection</code> against an
 /// expected HTTP status code. If the current status code is not the expected
 /// one it throws an exception with a detail message using Server side error
 /// messages if available.
 /// <p/>
 /// <b>NOTE:</b> this method will throw the deserialized exception even if not
 /// declared in the <code>throws</code> of the method signature.
 /// </remarks>
 /// <param name="conn">the <code>HttpURLConnection</code>.</param>
 /// <param name="expectedStatus">the expected HTTP status code.</param>
 /// <exception cref="System.IO.IOException">
 /// thrown if the current status code does not match the
 /// expected one.
 /// </exception>
 public static void ValidateResponse(HttpURLConnection conn, int expectedStatus)
 {
     if (conn.GetResponseCode() != expectedStatus)
     {
         Exception   toThrow;
         InputStream es = null;
         try
         {
             es = conn.GetErrorStream();
             ObjectMapper mapper = new ObjectMapper();
             IDictionary  json   = mapper.ReadValue <IDictionary>(es);
             json = (IDictionary)json[ErrorJson];
             string exClass = (string)json[ErrorClassnameJson];
             string exMsg   = (string)json[ErrorMessageJson];
             if (exClass != null)
             {
                 try
                 {
                     ClassLoader     cl     = typeof(HttpExceptionUtils).GetClassLoader();
                     Type            klass  = cl.LoadClass(exClass);
                     ConstructorInfo constr = klass.GetConstructor(typeof(string));
                     toThrow = (Exception)constr.NewInstance(exMsg);
                 }
                 catch (Exception)
                 {
                     toThrow = new IOException(string.Format("HTTP status [%d], exception [%s], message [%s] "
                                                             , conn.GetResponseCode(), exClass, exMsg));
                 }
             }
             else
             {
                 string msg = (exMsg != null) ? exMsg : conn.GetResponseMessage();
                 toThrow = new IOException(string.Format("HTTP status [%d], message [%s]", conn.GetResponseCode
                                                             (), msg));
             }
         }
         catch (Exception)
         {
             toThrow = new IOException(string.Format("HTTP status [%d], message [%s]", conn.GetResponseCode
                                                         (), conn.GetResponseMessage()));
         }
         finally
         {
             if (es != null)
             {
                 try
                 {
                     es.Close();
                 }
                 catch (IOException)
                 {
                 }
             }
         }
         //ignore
         ThrowEx(toThrow);
     }
 }
コード例 #3
0
        public static void ShowClient(Type typeForm, Control parentControl, IObject bo, Dictionary <string, object> @params = null)
        {
            if (typeForm == null)
            {
                return;
            }
            IApplicationForm appForm = null;

            try
            {
                using (new WaitDialog())
                {
                    var o = ClassLoader.LoadClass(typeForm);
                    appForm = o as IApplicationForm;
                    if (appForm == null)
                    {
                        return;
                    }
                    if (!Register(appForm, bo.Key))
                    {
                        return;
                    }
                    if (bo.Key == null || (bo.Key is long && ((long)bo.Key) <= 0))
                    {
                        object id = null;
                        if (!LoadData(appForm, ref id))
                        {
                            UnRegister(appForm);
                            return;
                        }
                    }

                    var basePanel = appForm as IBasePanel;
                    if (basePanel != null)
                    {
                        basePanel.BusinessObject = bo;
                        if (ReadOnly)
                        {
                            basePanel.ReadOnly = true;
                        }
                    }

                    DisplayClientForm(appForm, parentControl);
                    //if (!CanViewObject(frm))
                    //{
                    //    return;
                    //}
                }
            }
            catch (Exception ex)
            {
                UnRegister(appForm);
                Dbg.Debug("error during form showing", ex.ToString());
                throw;
            }
        }
コード例 #4
0
 /// <exception cref="System.TypeLoadException"/>
 protected override Type LoadClass(string name, bool resolve)
 {
     lock (this)
     {
         if (Log.IsDebugEnabled())
         {
             Log.Debug("Loading class: " + name);
         }
         Type c = FindLoadedClass(name);
         TypeLoadException ex = null;
         if (c == null && !IsSystemClass(name, systemClasses))
         {
             // Try to load class from this classloader's URLs. Note that this is like
             // the servlet spec, not the usual Java 2 behaviour where we ask the
             // parent to attempt to load first.
             try
             {
                 c = FindClass(name);
                 if (Log.IsDebugEnabled() && c != null)
                 {
                     Log.Debug("Loaded class: " + name + " ");
                 }
             }
             catch (TypeLoadException e)
             {
                 if (Log.IsDebugEnabled())
                 {
                     Log.Debug(e);
                 }
                 ex = e;
             }
         }
         if (c == null)
         {
             // try parent
             c = parent.LoadClass(name);
             if (Log.IsDebugEnabled() && c != null)
             {
                 Log.Debug("Loaded class from parent: " + name + " ");
             }
         }
         if (c == null)
         {
             throw ex != null ? ex : new TypeLoadException(name);
         }
         if (resolve)
         {
             ResolveClass(c);
         }
         return(c);
     }
 }
コード例 #5
0
 public static Form ShowNormal
     (Type typeForm, IObject bo, Dictionary <string, object> parameters = null, int width = 0, int height = 0)
 {
     if (typeForm == null)
     {
         return(null);
     }
     using (new WaitDialog())
     {
         var o = ClassLoader.LoadClass(typeForm);
         return(ShowNormal(o as IApplicationForm, bo, parameters, width, height));
     }
 }
コード例 #6
0
 private PropertyInfo GetDbServiceProperty(string propertyName)
 {
     if (m_EventDbService == null)
     {
         m_EventDbService = ClassLoader.LoadClass("Event_DB");
     }
     if ((m_EventDbService != null))
     {
         PropertyInfo pi = m_EventDbService.GetType()
                           .GetProperty(propertyName,
                                        BindingFlags.Public | BindingFlags.Instance |
                                        BindingFlags.Static);
         return(pi);
     }
     return(null);
 }
コード例 #7
0
 private MethodInfo GetDbServiceMethod(string methodName)
 {
     if (m_EventDbService == null)
     {
         m_EventDbService = ClassLoader.LoadClass("Event_DB");
     }
     if ((m_EventDbService != null))
     {
         MethodInfo mi = m_EventDbService.GetType()
                         .GetMethod(methodName,
                                    BindingFlags.Public | BindingFlags.Instance |
                                    BindingFlags.Static);
         return(mi);
     }
     return(null);
 }
コード例 #8
0
ファイル: Kit.cs プロジェクト: hazzik/Rhino.Net
		/// <summary>Attempt to load the class of the given name.</summary>
		/// <remarks>
		/// Attempt to load the class of the given name. Note that the type parameter
		/// isn't checked.
		/// </remarks>
		public static Type ClassOrNull(ClassLoader loader, string className)
		{
			try
			{
				return loader.LoadClass(className);
			}
			catch (TypeLoadException)
			{
			}
			catch (SecurityException)
			{
			}
			catch (LinkageError)
			{
			}
			catch (ArgumentException)
			{
			}
			// Can be thrown if name has characters that a class name
			// can not contain
			return null;
		}
コード例 #9
0
        public static void ResetLanguage(IApplicationForm panel)
        {
            IObject bo        = null;
            var     frm       = ((Control)panel).FindForm();
            Control parent    = ((Control)panel).Parent;
            var     basePanel = panel as IBasePanel;

            if (basePanel != null)
            {
                bo     = (basePanel).BusinessObject;
                parent = (((Control)(basePanel).GetLayout())).Parent;
            }
            Close(panel);
            if (bo != null)
            {
                if (frm == MainForm)
                {
                    ShowClient(panel.GetType(), parent, bo);
                }
                else
                {
                    ShowNormal(panel.GetType(), bo, null, ((Control)panel).Width, ((Control)panel).Height);
                }
            }
            else
            {
                object key = panel.Key;
                panel = (IApplicationForm)ClassLoader.LoadClass(panel.GetType());
                if (frm == MainForm)
                {
                    ShowClient(panel, parent, ref key);
                }
                else
                {
                    ShowNormal(panel, ref key, null, ((Control)panel).Width, ((Control)panel).Height);
                }
            }
        }
コード例 #10
0
        internal static Type lookup(Storage storage, String name)
        {
            Hashtable resolvedTypes = ((StorageImpl)storage).resolvedTypes;

            lock (resolvedTypes)
            {
                Type cls = (Type)resolvedTypes[name];
                if (cls != null)
                {
                    return(cls);
                }
                ClassLoader loader = storage.Loader;
                if (loader != null)
                {
                    cls = loader.LoadClass(name);
                    if (cls != null)
                    {
                        resolvedTypes[name] = cls;
                        return(cls);
                    }
                }
#if !WINRT_NET_FRAMEWORK
                Module last = lastModule;
                if (last != null)
                {
                    cls = last.GetType(name);
                    if (cls != null)
                    {
                        resolvedTypes[name] = cls;
                        return(cls);
                    }
                }
#endif
#if USE_GENERICS
                int p = name.IndexOf('=');
                if (p >= 0)
                {
                    Type   genericType   = lookup(storage, name.Substring(0, p));
                    Type[] genericParams = new Type[genericType.GetGenericArguments().Length];
                    int    nest          = 0;
                    int    i             = p += 2;
                    int    n             = 0;

                    while (true)
                    {
                        switch (name[i++])
                        {
                        case '[':
                            nest += 1;
                            break;

                        case ']':
                            if (--nest < 0)
                            {
                                genericParams[n++] = lookup(storage, name.Substring(p, i - p - 1));
                                Debug.Assert(n == genericParams.Length);
                                cls = genericType.MakeGenericType(genericParams);
                                if (cls == null)
                                {
                                    throw new StorageError(StorageError.ErrorCode.CLASS_NOT_FOUND, name);
                                }
                                resolvedTypes[name] = cls;
                                return(cls);
                            }
                            break;

                        case ',':
                            if (nest == 0)
                            {
                                genericParams[n++] = lookup(storage, name.Substring(p, i - p - 1));
                                p = i;
                            }
                            break;
                        }
                    }
                }
#endif
#if WINRT_NET_FRAMEWORK
                cls = Type.GetType(name, false);
#else
                cls = Type.GetType(name, false, false);
#endif
                if (cls != null)
                {
                    resolvedTypes[name] = cls;
                    return(cls);
                }
#if (COMPACT_NET_FRAMEWORK || SILVERLIGHT) && !WINRT_NET_FRAMEWORK
                foreach (Assembly ass in StorageImpl.assemblies)
#else
                foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
#endif
                {
#if WINRT_NET_FRAMEWORK
                    {
                        Type t = ass.GetType(name);
#else
                    foreach (Module mod in ass.GetModules())
                    {
                        Type t = mod.GetType(name);
#endif
                        if (t != null && t != cls)
                        {
                            if (cls != null)
                            {
#if __MonoCS__ || (NET_FRAMEWORK_20 && !COMPACT_NET_FRAMEWORK && !SILVERLIGHT)
                                if (Assembly.GetAssembly(cls) != ass)
#endif
                                {
                                    throw new StorageError(StorageError.ErrorCode.AMBIGUITY_CLASS, name);
                                }
                            }
                            else
                            {
#if WINRT_NET_FRAMEWORK
                                lastModule = t.GetTypeInfo().Module;
#else
                                lastModule = mod;
#endif
                                cls = t;
                            }
                        }
                    }
                }
#if !COMPACT_NET_FRAMEWORK && !SILVERLIGHT
                if (cls == null && name.EndsWith("Wrapper"))
                {
                    Type originalType = lookup(storage, name.Substring(0, name.Length - 7));
                    lock (storage)
                    {
                        cls = ((StorageImpl)storage).getWrapper(originalType);
                    }
                }
#endif
                if (cls == null && !((StorageImpl)storage).ignoreMissedClasses)
                {
                    throw new StorageError(StorageError.ErrorCode.CLASS_NOT_FOUND, name);
                }
                resolvedTypes[name] = cls;
                return(cls);
            }
        }
コード例 #11
0
        private View CreateCustomToolbarItem(string name, Context context, IAttributeSet attrs)
        {
            // android.support.v7.widget.Toolbar
            // android.support.v7.view.menu.ActionMenuItemView
            View view = null;

            try
            {
                if (ActionMenuItemViewClass == null)
                {
                    ActionMenuItemViewClass = ClassLoader.LoadClass(name);
                }
            }
            catch (ClassNotFoundException)
            {
                return(null);
            }

            if (ActionMenuItemViewClass == null)
            {
                return(null);
            }

            if (ActionMenuItemViewConstructor == null)
            {
                try
                {
                    ActionMenuItemViewConstructor = ActionMenuItemViewClass.GetConstructor(new Class[] {
                        Class.FromType(typeof(Context)),
                        Class.FromType(typeof(IAttributeSet))
                    });
                }
                catch (SecurityException)
                {
                    return(null);
                }
                catch (NoSuchMethodException)
                {
                    return(null);
                }
            }
            if (ActionMenuItemViewConstructor == null)
            {
                return(null);
            }

            try
            {
                Java.Lang.Object[] args = new Java.Lang.Object[] { context, (Java.Lang.Object)attrs };
                view = (View)(ActionMenuItemViewConstructor.NewInstance(args));
            }
            catch (IllegalArgumentException)
            {
                return(null);
            }
            catch (InstantiationException)
            {
                return(null);
            }
            catch (IllegalAccessException)
            {
                return(null);
            }
            catch (InvocationTargetException)
            {
                return(null);
            }
            if (null == view)
            {
                return(null);
            }

            View v = view;

            new Handler().Post(() =>
            {
                try
                {
                    if (v is LinearLayout)
                    {
                        var ll = (LinearLayout)v;
                        for (int i = 0; i < ll.ChildCount; i++)
                        {
                            var button = ll.GetChildAt(i) as Button;

                            if (button != null)
                            {
                                var title = button.Text;

                                if (!string.IsNullOrEmpty(title) && title.Length == 1)
                                {
                                    button.SetTypeface(Typeface, TypefaceStyle.Normal);
                                }
                            }
                        }
                    }
                    else if (v is TextView)
                    {
                        var tv       = (TextView)v;
                        string title = tv.Text;

                        if (!string.IsNullOrEmpty(title) && title.Length == 1)
                        {
                            tv.SetTypeface(Typeface, TypefaceStyle.Normal);
                        }
                    }
                }
                catch (ClassCastException)
                {
                }
            });

            return(view);
        }
コード例 #12
0
ファイル: TestRig.cs プロジェクト: rharrisxtheta/antlr4cs
        /// <exception cref="System.Exception"/>
        public virtual void Process()
        {
            //		System.out.println("exec "+grammarName+"."+startRuleName);
            string      lexerName  = grammarName + "Lexer";
            ClassLoader cl         = Antlr4.Runtime.Sharpen.Thread.CurrentThread().GetContextClassLoader();
            Type        lexerClass = null;

            try
            {
                lexerClass = cl.LoadClass(lexerName).AsSubclass <Lexer>();
            }
            catch (TypeLoadException)
            {
                // might be pure lexer grammar; no Lexer suffix then
                lexerName = grammarName;
                try
                {
                    lexerClass = cl.LoadClass(lexerName).AsSubclass <Lexer>();
                }
                catch (TypeLoadException)
                {
                    System.Console.Error.WriteLine("Can't load " + lexerName + " as lexer or parser");
                    return;
                }
            }
            Constructor <Lexer> lexerCtor = lexerClass.GetConstructor(typeof(ICharStream));
            Lexer  lexer       = lexerCtor.NewInstance((ICharStream)null);
            Type   parserClass = null;
            Parser parser      = null;

            if (!startRuleName.Equals(LexerStartRuleName))
            {
                string parserName = grammarName + "Parser";
                parserClass = cl.LoadClass(parserName).AsSubclass <Parser>();
                if (parserClass == null)
                {
                    System.Console.Error.WriteLine("Can't load " + parserName);
                    return;
                }
                Constructor <Parser> parserCtor = parserClass.GetConstructor(typeof(ITokenStream));
                parser = parserCtor.NewInstance((ITokenStream)null);
            }
            if (inputFiles.IsEmpty())
            {
                Stream     @is = Sharpen.Runtime.@in;
                TextReader r;
                if (encoding != null)
                {
                    r = new StreamReader(@is, encoding);
                }
                else
                {
                    r = new StreamReader(@is);
                }
                Process(lexer, parserClass, parser, @is, r);
                return;
            }
            foreach (string inputFile in inputFiles)
            {
                Stream @is = Sharpen.Runtime.@in;
                if (inputFile != null)
                {
                    @is = new FileInputStream(inputFile);
                }
                TextReader r;
                if (encoding != null)
                {
                    r = new StreamReader(@is, encoding);
                }
                else
                {
                    r = new StreamReader(@is);
                }
                if (inputFiles.Count > 1)
                {
                    System.Console.Error.WriteLine(inputFile);
                }
                Process(lexer, parserClass, parser, @is, r);
            }
        }
コード例 #13
0
        private View CreateCustomToolbarItem(string name, Java.Lang.Object context, IAttributeSet attrs)
        {
            // android.support.v7.widget.Toolbar
            // android.support.v7.view.menu.ActionMenuItemView
            View view;

            try
            {
                if (_actionMenuItemViewClass == null)
                {
                    _actionMenuItemViewClass = ClassLoader.LoadClass(name);
                }
            }
            catch (ClassNotFoundException ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
                return(null);
            }

            if (_actionMenuItemViewClass == null)
            {
                return(null);
            }

            if (_actionMenuItemViewConstructor == null)
            {
                try
                {
                    _actionMenuItemViewConstructor =
                        _actionMenuItemViewClass.GetConstructor(Class.FromType(typeof(Context)),
                                                                Class.FromType(typeof(IAttributeSet)));
                }
                catch (SecurityException ex)
                {
                    System.Diagnostics.Debug.Write(ex.Message);
                    return(null);
                }
                catch (NoSuchMethodException ex)
                {
                    System.Diagnostics.Debug.Write(ex.Message);
                    return(null);
                }
            }
            if (_actionMenuItemViewConstructor == null)
            {
                return(null);
            }

            try
            {
                Java.Lang.Object[] args = { context, (Java.Lang.Object)attrs };
                view = (View)_actionMenuItemViewConstructor.NewInstance(args);
            }
            catch (IllegalArgumentException ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
                return(null);
            }
            catch (InstantiationException ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
                return(null);
            }
            catch (IllegalAccessException ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
                return(null);
            }
            catch (InvocationTargetException ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
                return(null);
            }
            if (null == view)
            {
                return(null);
            }

            var v       = view;
            var handler = new Handler();

            handler.Post(() =>
            {
                try
                {
                    var layout = v as LinearLayout;
                    if (layout != null)
                    {
                        var ll = layout;
                        for (var i = 0; i < ll.ChildCount; i++)
                        {
                            var button = ll.GetChildAt(i) as Button;

                            var title = button?.Text;

                            if (!string.IsNullOrEmpty(title) && title.Length == 1)
                            {
                                button.SetTypeface(Typeface, TypefaceStyle.Normal);
                                button.SetTextSize(ComplexUnitType.Sp, size: 27);
                            }
                        }
                    }
                    else if (v is TextView)
                    {
                        var tv    = (TextView)v;
                        var title = tv.Text;

                        if (!string.IsNullOrEmpty(title) && title.Length == 1)
                        {
                            tv.SetTypeface(Typeface, TypefaceStyle.Normal);
                            tv.SetTextSize(ComplexUnitType.Sp, size: 27);
                        }
                    }
                }
                catch (ClassCastException ex)
                {
                    System.Diagnostics.Debug.Write(ex.Message);
                }
            });

            return(view);
        }
コード例 #14
0
        internal static Type lookup(Storage storage, String name)
        {
            Type        cls    = null;
            ClassLoader loader = storage.Loader;

            if (loader != null)
            {
                cls = loader.LoadClass(name);
                if (cls != null)
                {
                    return(cls);
                }
            }
            Module last = lastModule;

            if (last != null)
            {
                Type t = last.GetType(name);
                if (t != null)
                {
                    return(t);
                }
            }
#if COMPACT_NET_FRAMEWORK
            foreach (Assembly ass in StorageImpl.assemblies)
            {
                foreach (Module mod in ass.GetModules())
                {
                    Type t = mod.GetType(name);
                    if (t != null)
                    {
                        if (cls != null)
                        {
                            throw new StorageError(StorageError.ErrorCode.AMBIGUITY_CLASS, name);
                        }
                        else
                        {
                            lastModule = mod;
                            cls        = t;
                        }
                    }
                }
            }
#else
            foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Module mod in ass.GetModules())
                {
                    foreach (Type t in mod.FindTypes(new TypeFilter(FindTypeByName), name))
                    {
                        if (cls != null)
                        {
                            throw new StorageError(StorageError.ErrorCode.AMBIGUITY_CLASS, name);
                        }
                        else
                        {
                            lastModule = mod;
                            cls        = t;
                        }
                    }
                }
            }
#endif
            if (cls == null)
            {
                throw new StorageError(StorageError.ErrorCode.CLASS_NOT_FOUND, name);
            }
            return(cls);
        }
コード例 #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="parameters">
        /// The predefined order of parameters:
        /// 0 - key of onject to edit
        /// 1- instance of IObject to edit
        /// 2 - instance of IBaseListPanel
        /// 3 - startup parameters
        /// </param>
        /// <param name="actionType"></param>
        /// <param name="readOnly"></param>
        public override IApplicationForm Edit(object key, List <object> parameters, ActionTypes actionType, bool readOnly)
        {
            IObject bo = null;

            if ((parameters != null) && (parameters.Count > 1) && (parameters[1] is IObject))
            {
                bo = (IObject)parameters[1];
            }
            Dictionary <string, object> startupParams = null;

            if ((parameters != null) && (parameters.Count > 3) && (parameters[3] is Dictionary <string, object>))
            {
                startupParams = parameters[3] as Dictionary <string, object>;
            }
            var detailPanelName = GetDetailFormName(bo);

            if (Utils.IsEmpty(detailPanelName))
            {
                ErrorForm.ShowMessage("msgNoDetails", "msgNoDetails");
                return(null);
            }
            object detailPanel;

            using (new WaitDialog())
            {
                detailPanel = ClassLoader.LoadClass(detailPanelName);
                Dbg.Assert(detailPanel != null, "class {0} can't be loaded", detailPanelName);
                Dbg.Assert(detailPanel is IApplicationForm,
                           "detail form  {0} doesn't implement IApplicationFrom interface",
                           detailPanelName);
                InitDetailForm(detailPanel);
                if (detailPanel is IBasePanel)
                {
                    //((IBasePanel)detailPanel).ReadOnly = readOnly;

                    var meta        = ObjectAccessor.MetaInterface(BusinessObject.GetType());
                    var foundAction =
                        meta.Actions.Find(
                            item =>
                            ((item.ActionType == ActionTypes.View) || (item.ActionType == ActionTypes.Edit)) &&
                            (item.PanelType == ActionsPanelType.Top));
                    if (foundAction != null)
                    {
                        using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                        {
                            var childObject = foundAction.RunAction(manager, null as IObject, new List <object> {
                                key
                            });
                            if (childObject.result)
                            {
                                if (readOnly)
                                {
                                    BaseFormManager.ShowNormal_ReadOnly(detailPanel as IApplicationForm, childObject.obj, startupParams);
                                }
                                else
                                {
                                    BaseFormManager.ShowNormal(detailPanel as IApplicationForm, childObject.obj, startupParams);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (Utils.IsEmpty(key))
                    {
                        key = null;
                    }
                    if (readOnly)
                    {
                        BaseFormManager.ShowNormal_ReadOnly(detailPanel as IApplicationForm, ref key, startupParams);
                    }
                    else
                    {
                        BaseFormManager.ShowNormal(detailPanel as IApplicationForm, ref key, startupParams);
                    }
                }
            }
            return(detailPanel as IApplicationForm);
        }
コード例 #16
0
        /// <summary>
        /// </summary>
        /// <param name="key"></param>
        /// <param name="parameters"></param>
        /// <param name="actionType"></param>
        /// <param name="readOnly"></param>
        public override IApplicationForm Edit(object key, List <object> parameters, ActionTypes actionType, bool readOnly)
        {
            //TODO переписать метод более понятным
            IObject processedBusinessObject = null;
            var     meta = ObjectAccessor.MetaInterface(BusinessObject.GetType());

            if (key == null)
            {
                ActionMetaItem createAction = meta.Actions.Find(item => item.ActionType == ActionTypes.Create && item.PanelType == ActionsPanelType.Group);
                if (createAction == null)
                {
                    return(this);
                }

                using (var manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                {
                    var ret = createAction.RunAction(manager, m_DataSourceParent, parameters);
                    if (ret.result)
                    {
                        processedBusinessObject = ret.obj;
                    }
                }
                if (processedBusinessObject != null)
                {
                    SetEnvironment(processedBusinessObject);
                    if (InlineMode == InlineMode.UseCreateButton)
                    {
                        DataSource.Add(processedBusinessObject);
                        for (var i = Grid.GridView.RowCount - 1; i >= 0; i--)
                        {
                            var row = Grid.GridView.GetRow(i);
                            if (row.Equals(processedBusinessObject))
                            {
                                Grid.GridView.FocusedRowHandle = i;
                            }
                        }
                    }
                }
            }
            else
            {
                if (InlineMode == InlineMode.None)
                {
                    ActionMetaItem editAction = meta.Actions.Find(
                        item => item.ActionType == actionType && item.PanelType == ActionsPanelType.Group);
                    if (editAction == null)
                    {
                        return(this);
                    }

                    using (var manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                    {
                        processedBusinessObject = editAction.IsCreate
                            ? editAction.RunAction(manager, null as IObject, new List <object> {
                            key
                        }).obj
                                : FocusedItem;
                    }
                }
            }

            if ((InlineMode == InlineMode.None) && (processedBusinessObject != null))
            {
                using (var manager = CreateDbManagerProxy())
                {
                    var clone = processedBusinessObject.CloneWithSetup(manager);

                    #region В отдельном окне

                    //для нового элемента FocusedItem == null
                    var detailPanelName = GetDetailFormName(FocusedItem ?? BusinessObject);
                    if (Utils.IsEmpty(detailPanelName))
                    {
                        ErrorForm.ShowMessage("msgNoDetails", "msgNoDetails");
                        return(this);
                    }
                    var detailPanel = ClassLoader.LoadClass(detailPanelName);
                    Dbg.Assert(detailPanel != null, "class {0} can't be loaded", detailPanelName);
                    Dbg.Assert(detailPanel is IApplicationForm,
                               "detail form  {0} doesn't implement IApplicationFrom interface",
                               detailPanelName);
                    if (detailPanel is IBasePanel)
                    {
                        var appForm = detailPanel as IApplicationForm;
                        if (readOnly)
                        {
                            clone.ReadOnly = true;
                            (detailPanel as IBasePanel).ReadOnly = true;
                        }

                        /*
                         * var layout = GetLayout() as LayoutEmpty;
                         * if (layout != null)
                         * {
                         *  var cancel = false;
                         *  layout.OnBeforeActionExecutingRaised(this, createAction ?? editAction, clone, ref cancel);
                         *  if (cancel) return this;
                         * }
                         */
                        BaseFormManager.ShowModal(appForm, clone);
                        SetEnvironment(clone);
                        //определяем действие, по которому закрылась форма
                        if (appForm != null)
                        {
                            //если Ok, то заменяем клоном исходный объект
                            LastExecutedActionInternal = appForm.GetLastExecutedAction();
                            if (LastExecutedActionInternal != null)
                            {
                                if (LastExecutedActionInternal.ActionType.Equals(ActionTypes.Ok) ||
                                    LastExecutedActionInternal.ActionType.Equals(ActionTypes.Close) ||
                                    (LastExecutedActionInternal.ActionType.Equals(ActionTypes.Action) && LastExecutedActionInternal.IsNeedClose)
                                    )
                                {
                                    var index = DataSource.IndexOf(processedBusinessObject);
                                    if (index < 0)
                                    {
                                        clone.DeepSetChange();
                                        DataSource.Add(clone);
                                    }
                                    else
                                    {
                                        DataSource.ReplaceAndSetChange(processedBusinessObject as T, clone as T);
                                    }
                                    SetObjects(clone);

                                    Refresh();
                                }
                                else
                                {
                                    //видимо, происходит отмена. Надо дать возможность удалить временные объекты.
                                    DeleteTempObjects(processedBusinessObject);
                                }
                            }
                            else
                            {
                                //видимо, происходит отмена. Надо дать возможность удалить временные объекты.
                                DeleteTempObjects(processedBusinessObject);
                            }
                        }
                    }

                    #endregion
                }
            }
            return(this);
        }