Beispiel #1
0
 static void ShowEntityAssemblyConfig()
 {
     try
     {
         FormEntity <MessageEntityConfigEntryAttribute, IMessageEntityConfig> frm = new FormEntity <MessageEntityConfigEntryAttribute, IMessageEntityConfig>(Log, true);
         if (frm.ShowDialog() == DialogResult.OK)
         {
             EntityAssemblyConfig e = frm.Entity;
             if (e != null)
             {
                 ConfigMgt.Config.EntityAssembly = e;
                 if (ConfigMgt.Save())
                 {
                     Log.Write("Save config file succeeded. " + ConfigMgt.FileName);
                 }
                 else
                 {
                     Log.Write(LogType.Error, "Save config file failed. " + ConfigMgt.FileName);
                     Log.Write(ConfigMgt.LastError);
                 }
             }
         }
     }
     catch (Exception err)
     {
         Log.Write(err);
     }
 }
Beispiel #2
0
        static EntityAssemblyConfig GetEntityAssemblyConfigForEntity(EntityAssemblyConfig cfg)
        {
            EntityAssemblyConfig c = new EntityAssemblyConfig();

            string appPath    = Application.StartupPath;
            string folderName = Path.GetFileName(appPath.TrimEnd('\\'));

            if (Path.IsPathRooted(cfg.AssemblyLocation))
            {
                c.AssemblyLocation = cfg.AssemblyLocation;
            }
            else
            {
                c.AssemblyLocation = "..\\..\\" + cfg.AssemblyLocation;
            }

            if (Path.IsPathRooted(cfg.InitializeArgument.ConfigFilePath))
            {
                c.InitializeArgument.ConfigFilePath = cfg.InitializeArgument.ConfigFilePath;
            }
            else
            {
                c.InitializeArgument.ConfigFilePath = "..\\..\\" + cfg.InitializeArgument.ConfigFilePath;
            }

            c.ClassName              = cfg.ClassName;
            c.EntityInfo.Name        = cfg.EntityInfo.Name;
            c.EntityInfo.EntityID    = cfg.EntityInfo.EntityID;
            c.EntityInfo.Description = cfg.EntityInfo.Description;

            return(c);
        }
Beispiel #3
0
        private void AdapterConfig()
        {
            EntityAssemblyConfig cfg = GetSelectedAdapterConfig();

            if (cfg == null)
            {
                return;
            }

            // FormMain.AdapterEnableUpdate() may save NTServiceConfig.xml file, the EntityAssemblyConfig in this file should be readonly.
            // Therefore we use EntityAssemblyConfig in SolutionDir instead, as the EntityInitializeArgument and other properties in the EntityAssemblyConfig
            // may be modified when it is need to load the IMessageEntityConfig from the assembly.
            // And therefore, there is no need to deep copy EntityAssemblyConfig object.

            EntityContractBase contract = _solutionConfigMgr.Config.FindEntityByID(cfg.EntityInfo.EntityID);

            if (contract == null)
            {
                return;
            }

            EntityAssemblyConfig safeCfg = contract.AssemblyConfig;

            safeCfg.AssemblyLocation = Path.Combine(_solutionDirPath, safeCfg.AssemblyLocation);
            safeCfg.InitializeArgument.ConfigFilePath = Path.Combine(_solutionDirPath, safeCfg.InitializeArgument.ConfigFilePath);
            safeCfg.InitializeArgument.Description    = "HL7 Gateway Configuration GUI";

            FormEntity frm = new FormEntity(safeCfg);

            frm.ShowDialog(this);
        }
Beispiel #4
0
        private void AdapterEnableUpdate()
        {
            foreach (ListViewItem item in this.listViewAdpaters.Items)
            {
                EntityAssemblyConfig entityCfg = item.Tag as EntityAssemblyConfig;
                if (entityCfg != null)
                {
                    entityCfg.Enable = item.Checked;
                }
            }

            this.Cursor = Cursors.WaitCursor;
            bool res = _serviceConfigMgr.Save();

            this.Cursor = Cursors.Default;

            if (res)
            {
                Program.Log.Write(string.Format("Save configuration file of the NT Service Host success. {0}", _serviceConfigMgr.FileName));
                RefreshDiagram();
            }
            else
            {
                Program.Log.Write(_serviceConfigMgr.LastError);
                MessageBox.Show(this, string.Format("Save configuration file of the NT Service Host failed.\r\n{0}",
                                                    _serviceConfigMgr.FileName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #5
0
        public FormViewEntity(EntityAssemblyConfig cfg)
        {
            InitializeComponent();

            _cfg = cfg;
            LoadSetting();
        }
Beispiel #6
0
        public FormEntity(EntityAssemblyConfig entityCfg)
        {
            InitializeComponent();

            _cfgFilePath = ConfigHelper.GetFullPath(entityCfg.InitializeArgument.ConfigFilePath);
            _cfgFilePath = ConfigHelper.DismissDotDotInThePath(_cfgFilePath);

            LoadSetting(entityCfg);
        }
Beispiel #7
0
        private void listViewEntity_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            EntityAssemblyConfig cfg = e.Item.Tag as EntityAssemblyConfig;

            if (cfg != null)
            {
                cfg.Enable = e.Item.Checked;
            }
        }
Beispiel #8
0
        private bool LoadAssembly()
        {
            _entity   = null;
            _assembly = null;

            string asmLocation = this.textBoxAssemblyLocation.Text.Trim();

            asmLocation = ConfigHelper.GetFullPath(asmLocation);
            if (!File.Exists(asmLocation))
            {
                MessageBox.Show(this, "Cannot find file: " + asmLocation,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            string cfgPath = this.textBoxConfigPath.Text.Trim();

            if (cfgPath.Length < 1)
            {
                cfgPath = this.textBoxConfigPath.Text = Path.GetDirectoryName(asmLocation);
            }

            _assembly = EntityLoader.LoadAssembly(asmLocation);
            if (_assembly == null)
            {
                _log.Write(EntityLoader.LastError);
                MessageBox.Show(this, "Cannot load assembly.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            Type[] tlist = EntityLoader.FindEntryType <A>(_assembly);
            if (tlist == null || tlist.Length < 1)
            {
                _log.Write(EntityLoader.LastError);
                MessageBox.Show(this, "Cannot find message entity in the assembly.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            this.comboBoxClassName.Items.Clear();
            foreach (Type t in tlist)
            {
                this.comboBoxClassName.Items.Add(t);
            }

            if (this.comboBoxClassName.Items.Count > 0)
            {
                this.comboBoxClassName.SelectedIndex = 0;
            }

            return(true);
        }
Beispiel #9
0
        private bool LoadEntity()
        {
            _entity = null;

            Type t = this.comboBoxClassName.SelectedItem as Type;

            if (t == null)
            {
                return(false);
            }

            E e = EntityLoader.CreateEntry <E>(t);

            _entry = e;

            if (e == null)
            {
                _log.Write(EntityLoader.LastError);
                MessageBox.Show(this, "Initialize message entity failed.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            _entity                  = new EntityAssemblyConfig();
            _entity.ClassName        = t.ToString();
            _entity.AssemblyLocation = this.textBoxAssemblyLocation.Text.Trim();
            _entity.InitializeArgument.ConfigFilePath = this.textBoxConfigPath.Text.Trim();

            if (!e.Initialize(_entity.InitializeArgument))
            {
                MessageBox.Show(this, "Initialize message entity failed.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            EntityConfigBase cfg = e.GetConfiguration();

            _cfg = cfg;

            if (cfg == null)
            {
                MessageBox.Show(this, "Initialize message entity failed.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            this.textBoxEntityName.Text        = _entity.EntityInfo.Name = cfg.Name;
            this.textBoxEntityID.Text          = (_entity.EntityInfo.EntityID = cfg.EntityID).ToString();
            this.textBoxEntityDescription.Text = _entity.EntityInfo.Description = cfg.Description;

            return(true);
        }
Beispiel #10
0
        static void UnregisterEntityFromSolution()
        {
            try
            {
                EntityAssemblyConfig entity = Program.ConfigMgt.Config.EntityAssembly;

                EntityContractBase contract = null;
                foreach (EntityContractBase e in SolutionMgt.Config.Entities)
                {
                    if (e.EntityID == entity.EntityInfo.EntityID)
                    {
                        contract = e;
                        break;
                    }
                }

                if (contract == null)
                {
                    MessageBox.Show("Following message entity does not exist in the integration solution.\r\n\r\n"
                                    + entity.EntityInfo.Name + " (" + entity.EntityInfo.EntityID + ")",
                                    "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    //SolutionMgt.Config.Entities.Remove(contract);
                    SolutionMgt.Config.UnregisterEnity(contract);

                    if (SolutionMgt.Save())
                    {
                        Log.Write("Save solution dir file succeeded. " + SolutionMgt.FileName);

                        MessageBox.Show("Unregister following message entity from the integration solution succeeded.\r\n\r\n"
                                        + entity.EntityInfo.Name + " (" + entity.EntityInfo.EntityID + ")",
                                        "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        Log.Write(LogType.Error, "Save solution dir file failed.");
                        Log.Write(SolutionMgt.LastError);

                        MessageBox.Show("Unregister following message entity from the integration solution failed.\r\n\r\n"
                                        + entity.EntityInfo.Name + " (" + entity.EntityInfo.EntityID + ")",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception err)
            {
                Log.Write(err);
            }
        }
Beispiel #11
0
        private void ViewEntity()
        {
            if (this.listViewEntity.SelectedItems.Count < 1)
            {
                return;
            }

            EntityAssemblyConfig e = this.listViewEntity.SelectedItems[0].Tag as EntityAssemblyConfig;

            if (e == null)
            {
                return;
            }

            FormViewEntity frm = new FormViewEntity(e);

            frm.ShowDialog(this);
        }
Beispiel #12
0
        private void LoadSetting(EntityAssemblyConfig entityCfg)
        {
            _entityAgent = new EntityConfigAgent(entityCfg, Program.Log);
            if (!_entityAgent.Initialize(entityCfg.InitializeArgument))
            {
                return;
            }

            LoadMainConfigTabPage();
            LoadTransformPage();

            _cfgConfig = Program.ConfigMgr.Config.GetMessageEntityConfigConfig(entityCfg.EntityInfo.Name);
            if (_cfgConfig != null)
            {
                this.Size = _cfgConfig.ConfigWindowSize;
            }
            this.Text = entityCfg.EntityInfo.Name + " Configuration";
        }
Beispiel #13
0
        //static void SetEntityAssemblyConfig(string[] args)
        //{
        //    int count = 8;
        //    if (args.Length < count)
        //    {
        //        Program.Log.Write("Arguement is not enough.");
        //        return;
        //    }

        //    try
        //    {
        //        string entityID = args[1];
        //        string entityName = args[2];
        //        string deviceName = args[3];
        //        string description = args[4];
        //        string className = args[5];
        //        string assemblyLocation = args[6];
        //        string configFilePath = args[7];

        //        Guid eID = new Guid(entityID);
        //        EntityAssemblyConfig entityCfg = new EntityAssemblyConfig();
        //        entityCfg.ClassName = className;
        //        entityCfg.AssemblyLocation = assemblyLocation;
        //        entityCfg.InitializeArgument.ConfigFilePath = configFilePath;
        //        entityCfg.EntityInfo.EntityID = eID;
        //        entityCfg.EntityInfo.Name = entityName;
        //        entityCfg.EntityInfo.DeviceName = deviceName;
        //        entityCfg.EntityInfo.Description = description;

        //        ConfigMgt.Config.EntityAssembly = entityCfg;

        //        if (ConfigMgt.Save())
        //        {
        //            Log.Write("Set entity assembly config success.");
        //        }
        //        else
        //        {
        //            Log.Write(ConfigMgt.LastError);
        //        }
        //    }
        //    catch (Exception err)
        //    {
        //        Log.Write(err);
        //    }
        //}

        static EntityAssemblyConfig GetEntityAssemblyConfigForSolution(EntityAssemblyConfig cfg)
        {
            EntityAssemblyConfig c = new EntityAssemblyConfig();

            //string appPath = Application.StartupPath;
            //string folderName = Path.GetFileName(appPath.TrimEnd('\\'));

            string slnDirFileName = ConfigHelper.DismissDotDotInThePath(ConfigHelper.GetFullPath(SolutionMgt.FileName));
            string slnDirPath     = Path.GetDirectoryName(slnDirFileName);

            if (Path.IsPathRooted(cfg.AssemblyLocation))
            {
                c.AssemblyLocation = cfg.AssemblyLocation;
            }
            else
            {
                //c.AssemblyLocation = folderName + "\\" + cfg.AssemblyLocation;

                string fullPath     = ConfigHelper.DismissDotDotInThePath(ConfigHelper.GetFullPath(cfg.AssemblyLocation));
                string relativePath = ConfigHelper.GetRelativePath(slnDirPath, fullPath);
                c.AssemblyLocation = relativePath;
            }

            if (Path.IsPathRooted(cfg.InitializeArgument.ConfigFilePath))
            {
                c.InitializeArgument.ConfigFilePath = cfg.InitializeArgument.ConfigFilePath;
            }
            else
            {
                //c.InitializeArgument.ConfigFilePath = folderName + "\\" + cfg.InitializeArgument.ConfigFilePath;

                string fullPath     = ConfigHelper.DismissDotDotInThePath(ConfigHelper.GetFullPath(cfg.InitializeArgument.ConfigFilePath));
                string relativePath = ConfigHelper.GetRelativePath(slnDirPath, fullPath);
                c.InitializeArgument.ConfigFilePath = relativePath + "\\";
            }

            c.ClassName              = cfg.ClassName;
            c.EntityInfo.Name        = cfg.EntityInfo.Name;
            c.EntityInfo.EntityID    = cfg.EntityInfo.EntityID;
            c.EntityInfo.Description = cfg.EntityInfo.Description;

            return(c);
        }
Beispiel #14
0
        private void DeleteEntity()
        {
            if (this.listViewEntity.SelectedItems.Count < 1)
            {
                return;
            }

            EntityAssemblyConfig e = this.listViewEntity.SelectedItems[0].Tag as EntityAssemblyConfig;

            if (e == null)
            {
                return;
            }

            Program.ConfigMgt.Config.Entities.Remove(e);

            RefreshEntityList();
            RefreshEntityButton();
        }
Beispiel #15
0
        private void RefreshDiagram()
        {
            string[] entityList1 = Program.ConfigMgr.Config.GetMessageEntityGroup1();
            for (int i = 0; i < entityList1.Length; i++)
            {
                EntityAssemblyConfig entityCfg = _serviceConfigMgr.Config.FindEntityByName(entityList1[i]);
                if (entityCfg == null)
                {
                    continue;
                }
                if (i >= _labelGroup1.Length)
                {
                    break;
                }
                Label lbl = _labelGroup1[i];
                lbl.Text      = entityCfg.EntityInfo.Name;
                lbl.ForeColor = entityCfg.Enable ? Color.Black : Color.Gray;
                lbl.Font      = new Font(lbl.Font, entityCfg.Enable ? FontStyle.Bold : FontStyle.Regular);
                this.toolTipMain.SetToolTip(lbl, string.Format("{0} ({1})", entityCfg.EntityInfo.Description, entityCfg.Enable ? "Enabled" : "Disabled"));
            }

            string[] entityList2 = Program.ConfigMgr.Config.GetMessageEntityGroup2();
            for (int i = 0; i < entityList2.Length; i++)
            {
                EntityAssemblyConfig entityCfg = _serviceConfigMgr.Config.FindEntityByName(entityList2[i]);
                if (entityCfg == null)
                {
                    continue;
                }
                if (i >= _labelGroup2.Length)
                {
                    break;
                }
                Label lbl = _labelGroup2[i];
                lbl.Text      = entityCfg.EntityInfo.Name;
                lbl.ForeColor = entityCfg.Enable ? Color.Black : Color.Gray;
                lbl.Font      = new Font(_labelGroup2[i].Font, entityCfg.Enable ? FontStyle.Bold : FontStyle.Regular);
                this.toolTipMain.SetToolTip(lbl, string.Format("{0} ({1})", entityCfg.EntityInfo.Description, entityCfg.Enable ? "Enabled" : "Disabled"));
            }
        }
Beispiel #16
0
        private void AddEntity()
        {
            FormEntity <MessageEntityEntryAttribute, IMessageEntity> frm = new FormEntity <MessageEntityEntryAttribute, IMessageEntity>(Program.Log);

            if (frm.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            EntityAssemblyConfig e = frm.Entity;

            if (e == null)
            {
                return;
            }

            bool existed = false;

            foreach (EntityAssemblyConfig cfg in Program.ConfigMgt.Config.Entities)
            {
                if (cfg.EntityInfo.EntityID == e.EntityInfo.EntityID)
                {
                    existed = true;
                    break;
                }
            }

            if (existed)
            {
                MessageBox.Show(this, string.Format("The entity ({0}) is already existed in this host.",
                                                    e.EntityInfo.Name), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Program.ConfigMgt.Config.Entities.Add(e);

            RefreshEntityList();
            RefreshEntityButton();
        }
Beispiel #17
0
 private void AdapterBrowseFile()
 {
     try
     {
         EntityAssemblyConfig cfg = GetSelectedAdapterConfig();
         if (cfg == null)
         {
             return;
         }
         string entityPath     = ConfigHelper.DismissDotDotInThePath(Path.Combine(_serviceConfigPath, cfg.InitializeArgument.ConfigFilePath));
         string entityXSLTPath = Path.Combine(entityPath, "FrameworkTemplates");
         if (!Directory.Exists(entityXSLTPath))
         {
             Directory.CreateDirectory(entityXSLTPath);
         }
         Process p = Process.Start(entityXSLTPath);
     }
     catch (Exception err)
     {
         Program.Log.Write(err);
     }
 }
Beispiel #18
0
        static bool UpdateChannelInResponser(PullChannelConfig cfg)
        {
            EntityAssemblyConfig acfg = null;

            foreach (EntityContractBase c in Program.SolutionMgt.Config.Entities)
            {
                if (c.EntityID == cfg.ReceiverEntityID)
                {
                    acfg = c.AssemblyConfig;
                    break;
                }
            }

            if (acfg == null)
            {
                Program.Log.Write(LogType.Error, "Cannot find responser in the integration solution: "
                                  + cfg.ReceiverEntityName + " (" + cfg.ReceiverEntityID + ")");
                return(false);
            }

            bool ret = false;

            acfg = GetEntityAssemblyConfigForEntity(acfg);
            EntityConfigAgent agent = new EntityConfigAgent(acfg, Program.Log);

            if (agent.Initialize(acfg.InitializeArgument))
            {
                EntityConfigBase ecfg = agent.EntityConfig;
                if (ecfg == null)
                {
                    Program.Log.Write(LogType.Error, "Cannot get responser configuration: "
                                      + cfg.ReceiverEntityName + " (" + cfg.ReceiverEntityID + ")");
                }
                else
                {
                    List <PullChannelConfig> deleteList = new List <PullChannelConfig>();
                    foreach (PullChannelConfig chn in ecfg.ResponseConfig.Channels)
                    {
                        if (chn.SenderEntityID == cfg.SenderEntityID)
                        {
                            deleteList.Add(chn);
                            break;
                        }
                    }

                    foreach (PullChannelConfig chn in deleteList)
                    {
                        ecfg.ResponseConfig.Channels.Remove(chn);
                    }

                    ecfg.ResponseConfig.Channels.Add(cfg);

                    if (agent.EntityConfigInstance.SaveConfiguration())
                    {
                        ret = true;
                        Program.Log.Write("Save responser configuration succeeded: "
                                          + cfg.ReceiverEntityName + " (" + cfg.ReceiverEntityID + ")");
                    }
                    else
                    {
                        Program.Log.Write(LogType.Error, "Save responser configuration failed: "
                                          + cfg.ReceiverEntityName + " (" + cfg.ReceiverEntityID + ")");
                    }
                }

                agent.Uninitialize();
            }

            return(ret);
        }
Beispiel #19
0
 public EntityAgent(EntityAssemblyConfig cfg, ILog log)
 {
     _config = cfg;
     _log    = log;
 }
Beispiel #20
0
        static void RegisterEntityIntoSolution()
        {
            try
            {
                EntityAssemblyConfig entity = Program.ConfigMgt.Config.EntityAssembly;
                foreach (EntityContractBase e in SolutionMgt.Config.Entities)
                {
                    if (e.EntityID == entity.EntityInfo.EntityID)
                    {
                        MessageBox.Show("Following message entity has already existed in the integration solution.\r\n\r\n"
                                        + entity.EntityInfo.Name + " (" + entity.EntityInfo.EntityID + ")",
                                        "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                EntityConfigAgent agent = new EntityConfigAgent(Program.ConfigMgt.Config.EntityAssembly, Program.Log);
                if (agent.Initialize(Program.ConfigMgt.Config.EntityAssembly.InitializeArgument))
                {
                    EntityConfigBase   cfg = agent.EntityConfig;
                    EntityContractBase c   = new EntityContractBase();

                    c.Name        = cfg.Name;
                    c.DeviceName  = cfg.DeviceName;
                    c.Direction   = cfg.Direction;
                    c.Interaction = cfg.Interaction;
                    c.Description = cfg.Description;
                    c.EntityID    = cfg.EntityID;
                    if (cfg.PublishConfig != null)
                    {
                        c.Publication = cfg.PublishConfig.Publication;
                    }
                    if (cfg.ResponseConfig != null)
                    {
                        c.ResponseDescription = cfg.ResponseConfig.ResponseContract;
                    }
                    c.AssemblyConfig = GetEntityAssemblyConfigForSolution(entity);

                    //string webConfigFilePath = Path.Combine(Application.StartupPath, EntityWebConfig.EntityWebConfigFileName);
                    //ConfigManager<EntityWebConfig> webmgt = new ConfigManager<EntityWebConfig>(webConfigFilePath);
                    //if (webmgt.Load())
                    //{
                    //    Log.Write("Register entity with default web config at: " + webConfigFilePath);
                    //    SolutionMgt.Config.RegisterEntity(c, webmgt.Config);
                    //}
                    //else
                    //{
                    //    Log.Write("Register entity without default web config.");
                    //    SolutionMgt.Config.RegisterEntity(c);
                    //}

                    Log.Write("Registering entity.");
                    SolutionMgt.Config.RegisterEntity(c);

                    if (SolutionMgt.Save())
                    {
                        Log.Write("Save solution dir file succeeded. " + SolutionMgt.FileName);

                        MessageBox.Show("Register following message entity into the integration solution succeeded.\r\n\r\n"
                                        + entity.EntityInfo.Name + " (" + entity.EntityInfo.EntityID + ")",
                                        "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        Log.Write(LogType.Error, "Save solution dir file failed.");
                        Log.Write(SolutionMgt.LastError);

                        MessageBox.Show("Register following message entity into the integration solution failed.\r\n\r\n"
                                        + entity.EntityInfo.Name + " (" + entity.EntityInfo.EntityID + ")",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    agent.Uninitialize();
                }
            }
            catch (Exception err)
            {
                Log.Write(err);
            }
        }
Beispiel #21
0
        private void RefreshAdapterButtons()
        {
            EntityAssemblyConfig cfg = GetSelectedAdapterConfig();

            this.buttonAdapterConfig.Enabled = cfg != null;
        }