Chr☆s Kwok 的技术笔记

.NET, C#, WPF, WCF, WF, .NetCore & LINQ ... I know how it works because I know why it works ...

博客园 首页 新随笔 订阅 管理

1、定义一个接口(IMedicareControlFee)定义行为;定义一个适配器(IMedicareControlFeeAdapter)可应对多厂商(多态);

using System;
using System.Diagnostics;
using System.IO;
using JetSun.Infrastructure;
using JetSun.Infrastructure.Services;
using Microsoft.Practices.Unity;
using SecuInter;

namespace JetSun.Presentation
{
    public interface IMedicareControlFeeAdapter
    {
        IMedicareControlFee GetMedicareControlFee();
    }
    
    public interface IMedicareControlFee
    {
        bool checkRulePage(object obj, ReqSceneTypeEnum reqScene);
        bool DuringHospitalizationAudit(int encounterId);
        bool Get_CheckRulePageAnticipateOutOnlyKey(int encounterid, ReqSceneTypeEnum reqScene);
        void PreCut(int encounterId);
        string SignleGroupPreview(int encounterId, out double gainLoss, out double groupPayStd);
    }
    
    public static class MedicareControlFeeHelper
    {
        public static bool IsEnabledMedicareControlFee
        {
            get
            {
                return DRJSMedicareParameter.IsUseDRJSMMedicareSystem;
            }
        }

        static IMedicareControlFee _medicareControlFee;
        public static IMedicareControlFee MedicareControlFee
        {
            get
            {
                if (_medicareControlFee == null)
                {
                    _medicareControlFee = Adapter.GetMedicareControlFee();
                }
                return _medicareControlFee;
            }
        }

        private static IMedicareControlFeeAdapter _adapter;
        private static IMedicareControlFeeAdapter Adapter
        {
            get
            {
                if (_adapter == null)
                {
                    var obj = GetDRJSAdapterInstance();
                    _adapter = (IMedicareControlFeeAdapter)Activator.CreateInstance(obj.GetType());
                }
                return _adapter;
            }
        }

        private static object GetDRJSAdapterInstance()
        {
            try
            {
                var assembly = System.Reflection.Assembly.LoadFile(AppDomainDRJS.BaseDirectory + "IHE.DRJS.MedicareControlFee.dll");
                var typeName = "IHE.DRJS.MedicareControlFee.DRJSAdapter";
                Object obj = AppDomainDRJS.CreateInstanceAndUnwrap(assembly.FullName, typeName);
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private static AppDomain _appDomainDRJS = null;
        private static AppDomain AppDomainDRJS
        {
            get
            {
                if (_appDomainDRJS == null)
                {
                    AppDomainSetup ads = new AppDomainSetup();
                    ads.ApplicationName = "Shadow";

                    //应用程序根目录
                    ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;

                    //设置缓存目录
                    ads.CachePath = ads.ApplicationBase;

                    //获取或设置指示影像复制是打开还是关闭
                    ads.ShadowCopyFiles = "true";

                    //获取或设置目录的名称,这些目录包含要影像复制的程序集
                    ads.ShadowCopyDirectories = ads.ApplicationBase;
                    ads.DisallowBindingRedirects = false;
                    ads.DisallowCodeDownload = true;
                    ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

                    //Create evidence for the new application domain from evidence of
                    var adevidence = AppDomain.CurrentDomain.Evidence;

                    _appDomainDRJS = AppDomain.CreateDomain("AD #2", adevidence, ads);
                }
                return _appDomainDRJS;
            }
        }

        private class EmptyMedicareControlFee : IMedicareControlFee
        {
            public bool checkRulePage(object obj, ReqSceneTypeEnum reqScene)
            {
                return false;
            }
            public bool DuringHospitalizationAudit(int encounterId)
            {
                return false;
            }

            public bool Get_CheckRulePageAnticipateOutOnlyKey(int encounterid, ReqSceneTypeEnum reqScene)
            {
                return false;
            }

            public void PreCut(int encounterId)
            {
            }

            public string SignleGroupPreview(int encounterId, out double gainLoss, out double groupPayStd)
            {
                gainLoss = 0;
                groupPayStd = 0;
                return "";
            }
        }
    }
}

2、实现其中一个厂商(程序集IHE.DRJS.MedicareControlFee.dll),定义一个可序列化的类实现上面定义的适配器接口(多态)

using JetSun.Infrastructure;
using System;

namespace IHE.DRJS.MedicareControlFee
{
    [Serializable]
    public class DRJSAdapter : IMedicareControlFeeAdapter
    {
        public IMedicareControlFee GetMedicareControlFee()
        {
            return DRJSMedicareControlFee.Instance;
        }
    }
}

3、调用场景(应用):

double gainLoss;
double groupPayStd;
string code = MedicareControlFeeHelper.MedicareControlFee.SignleGroupPreview(1234, out gainLoss, out groupPayStd);

 

posted on 2024-10-12 16:06  Chr☆s  阅读(8)  评论(0编辑  收藏  举报