private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if ((e.Button.ToString() == "Right") && ((System.Windows.Forms.TreeView)sender).SelectedNode != null)
            {
                TreeNode         clickedNode = ((System.Windows.Forms.TreeView)sender).SelectedNode;
                ArtefactNodeInfo artInfo     = (ArtefactNodeInfo)clickedNode.Tag;
                if (artInfo != null)
                {
                    if (clickedNode.ForeColor == Color.Black || clickedNode.ForeColor == Color.DarkGreen)
                    {
                        ContextMenu cm = new ContextMenu();
                        if (clickedNode.ForeColor == Color.Black)
                        {
                            MenuItem tmpMen = cm.MenuItems.Add("Import the " + artInfo.artType.ToString() + " into VTL DB", cm_ItemImportClicked);
                            tmpMen.Tag = clickedNode;
                        }

                        MenuItem tmpMen2 = cm.MenuItems.Add("Drill down", cm_DrillDowntClicked);
                        tmpMen2.Tag = clickedNode;

                        clickedNode.ContextMenu = cm;
                        cm.Show(((System.Windows.Forms.TreeView)sender), new Point(e.X, e.Y));
                    }
                }
            }
        }
        //private void LineCountEventManager(object sender, VTLDBManager.LineCountEventArgs e)
        //{
        //    infoLabel.Text = "Script line count: " + e.LineNumber;
        //    infoLabel.Refresh();
        //}

        private void cm_DrillDowntClicked(object sender, System.EventArgs e)
        {
            try
            {
                TreeNode         tmpNode = (TreeNode)((MenuItem)sender).Tag;
                ArtefactNodeInfo artInfo = (ArtefactNodeInfo)tmpNode.Tag;

                CommonItem.WaitOn();

                if (tmpNode.Level == 3 && tmpNode.Parent != null && tmpNode.Nodes.Count == 0)
                {
                    switch (tmpNode.Parent.Text)
                    {
                    case "DataStructure":
                        LoadDataStructuresComponents(artInfo.webServiceID, tmpNode.Text, tmpNode);
                        break;

                    case "DataFlow":
                        LoadDataFlowComponents(artInfo.webServiceID, tmpNode.Text, tmpNode);
                        break;

                    case "Codelist":
                        LoadCodelistCodes(artInfo.webServiceID, tmpNode.Text, tmpNode);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
            }
            finally
            {
                CommonItem.WaitOff();
            }
        }
        private void cm_ItemImportClicked(object sender, System.EventArgs e)
        {
            try
            {
                TreeNode                     tmpNode = (TreeNode)((MenuItem)sender).Tag;
                ArtefactNodeInfo             artInfo = (ArtefactNodeInfo)tmpNode.Tag;
                VTLInt_Service.ServiceClient VTLMan  = VTLInt_ServiceManager.GetClient(CommonItem.CurrentSettings.InteractionWebService);

                MetadataLoader mtl = null;

                //VTLMan.LineCountEvent += LineCountEventManager;


                switch (artInfo.artType)
                {
                case ArtefactNodeInfo.ArtefactType.ValueDomains:
                    string vd_id      = artInfo.artefactInfo.sdmxId;
                    string vd_agency  = artInfo.artefactInfo.sdmxAgency;
                    string vd_version = artInfo.artefactInfo.sdmxVersion;

                    if (MessageBox.Show("Do you want import into the VTL database the codelist: \n " + vd_id + " " + vd_agency + " " + vd_version, "Import codelist", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        CommonItem.WaitOn();

                        mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                        List <BaseArtefactInfo> dsList = mtl.LoadCodelistCodes21(vd_id, vd_agency, vd_version);

                        VTLMan.InsertValueDomain(vd_id, vd_agency, vd_version, artInfo.artefactInfo.name.ToArray(), dsList.ToArray(), true, BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD, ArtefactInfo.VTL.VTL_Model.VTL_DATATYPE.String);

                        CommonItem.WaitOff();

                        MessageBox.Show("Value domain :" + vd_id + " " + vd_agency + " " + vd_version + " successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tmpNode.ForeColor = Color.Gray;
                    }

                    break;

                case ArtefactNodeInfo.ArtefactType.DataStructureComponents:
                    string[] globIdent = CommonConstant.splitGlobalID(((ArtefactInfo.model.DataStructureComponentInfo)(artInfo.artefactComponentInfo)).valuedomain_id);

                    string cmp_id      = globIdent[0];
                    string cmp_agency  = globIdent[1];
                    string cmp_version = globIdent[2];

                    CommonItem.WaitOn();

                    mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                    List <BaseArtefactInfo> cmpList = mtl.LoadCodelistCodes21(cmp_id, cmp_agency, cmp_version);

                    VTLMan.InsertValueDomain(cmp_id, cmp_agency, cmp_version, artInfo.artefactInfo.name.ToArray(), cmpList.ToArray(), true, BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD, ArtefactInfo.VTL.VTL_Model.VTL_DATATYPE.String);

                    CommonItem.WaitOff();

                    MessageBox.Show("Value domain :" + cmp_id + " " + cmp_agency + " " + cmp_version + " successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    tmpNode.ForeColor = Color.Gray;
                    break;

                case ArtefactNodeInfo.ArtefactType.DataStructures:
                    string dsd_id      = artInfo.artefactInfo.sdmxId;
                    string dsd_agency  = artInfo.artefactInfo.sdmxAgency;
                    string dsd_version = artInfo.artefactInfo.sdmxVersion;
                    List <BaseArtefactInfo>  valueDomainValueList;
                    List <BaseComponentInfo> componentsList = new List <BaseComponentInfo>();

                    if (MessageBox.Show("Do you want import into the VTL database the Datastructure: \n " + dsd_id + " " + dsd_agency + " " + dsd_version + "\n and all the referenced artefacts?", "Import datastructure", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        CommonItem.WaitOn();
                        label1.Text = DateTime.Now.ToString();

                        mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                        List <BaseArtefactInfo> componentList = mtl.LoadDataStructuresComponents21(dsd_id, dsd_agency, dsd_version);

                        foreach (BaseComponentInfo comp in componentList[0].DataStructureDetails.Components)
                        {
                            BaseComponentInfo tmpComponentInfo     = new BaseComponentInfo();
                            ValueDomainInfoInDataStructure tmpInfo = new ValueDomainInfoInDataStructure();
                            string[] globalId = null;

                            tmpComponentInfo.vtlId = comp.vtlId;
                            tmpComponentInfo.name  = comp.name;
                            tmpComponentInfo.datastructure_id_ref = comp.datastructure_id_ref;
                            tmpComponentInfo.seq_id = comp.seq_id;

                            switch (((ArtefactInfo.model.DataStructureComponentInfo)(comp)).role)
                            {
                            case "Dimension":
                                tmpComponentInfo.Role = "Identifier";
                                if (!String.IsNullOrEmpty(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id))
                                {
                                    globalId = CommonConstant.splitGlobalID(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id);
                                }
                                break;

                            case "TimeDimension":
                                tmpComponentInfo.Role = "Identifier";
                                globalId = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.TIME_PERIOD_default_valueDomainID);
                                break;

                            case "PrimaryMeasure":
                                tmpComponentInfo.Role = "Measure";
                                globalId = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.OBS_default_valueDomainID);
                                break;
                            }

                            tmpInfo.vd_id      = globalId[0];
                            tmpInfo.vd_agency  = globalId[1];
                            tmpInfo.vd_version = globalId[2];

                            valueDomainValueList = mtl.LoadCodelistCodes21(globalId[0], globalId[1], globalId[2]);

                            if (valueDomainValueList != null)
                            {
                                tmpInfo.values = valueDomainValueList;
                            }

                            if (comp.name != null)
                            {
                                tmpInfo.names = comp.name;
                            }
                            else
                            {
                                tmpInfo.names = new List <LocalizedValue>();
                                tmpInfo.names.Add(new LocalizedValue("EN", comp.vtlId));
                            }

                            tmpComponentInfo.ValueDomainInfo = tmpInfo;

                            componentsList.Add(tmpComponentInfo);
                        }
                        try
                        {
                            VTLMan.InsertDataStructure(dsd_id, dsd_agency, dsd_version, artInfo.artefactInfo.name.ToArray(), componentsList.ToArray(), BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD);
                        }
                        catch (TimeoutException ext)
                        {
                            MessageBox.Show("Time out exception");
                            return;
                        }

                        label2.Text = DateTime.Now.ToString();
                        CommonItem.WaitOff();

                        MessageBox.Show("Data structures :" + dsd_id + " " + dsd_agency + " " + dsd_version + "  and all the linked components successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tmpNode.ForeColor = Color.Gray;
                    }
                    break;

                case ArtefactNodeInfo.ArtefactType.DataFlows:
                    string ref_dsd_id      = ((DataSetInfo)artInfo.artefactInfo).sdmx_DataStructure_id;
                    string ref_dsd_agency  = ((DataSetInfo)artInfo.artefactInfo).sdmx_DataStructure_agency;
                    string ref_dsd_version = ((DataSetInfo)artInfo.artefactInfo).sdmx_DataStructure_version;
                    string df_id           = ((DataSetInfo)artInfo.artefactInfo).sdmxId;
                    string df_agency       = ((DataSetInfo)artInfo.artefactInfo).sdmxAgency;
                    string df_version      = ((DataSetInfo)artInfo.artefactInfo).sdmxVersion;

                    List <BaseArtefactInfo>  ds_valueDomainValueList;
                    List <BaseComponentInfo> ds_componentsList = new List <BaseComponentInfo>();

                    if (MessageBox.Show("Do you want import into the VTL database the DataSet: \n " + df_id + " " + df_agency + " " + df_version + "\n and all the referenced artefacts?", "Import datastructure", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        CommonItem.WaitOn();
                        label1.Text = DateTime.Now.ToString();

                        mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                        List <BaseArtefactInfo> componentList = mtl.LoadDataStructuresComponents21(ref_dsd_id, ref_dsd_agency, ref_dsd_version);

                        BaseComponentInfo tmpInfo;
                        ValueDomainInfoInDataStructure tmpValueDomain;

                        foreach (BaseComponentInfo comp in componentList[0].DataStructureDetails.Components)
                        {
                            tmpInfo       = new BaseComponentInfo();
                            tmpInfo.vtlId = comp.vtlId;
                            tmpInfo.name  = comp.name;
                            string[] globalId = null;


                            switch (((ArtefactInfo.model.DataStructureComponentInfo)(comp)).role)
                            {
                            case "Dimension":
                                tmpInfo.Role = "Identifier";
                                if (!String.IsNullOrEmpty(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id))
                                {
                                    globalId = CommonConstant.splitGlobalID(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id);
                                }
                                break;

                            case "TimeDimension":
                                tmpInfo.Role = "Identifier";
                                globalId     = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.TIME_PERIOD_default_valueDomainID);
                                break;

                            case "PrimaryMeasure":
                                tmpInfo.Role = "Measure";
                                globalId     = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.OBS_default_valueDomainID);
                                break;
                            }
                            tmpValueDomain = new ValueDomainInfoInDataStructure();

                            tmpValueDomain.vd_id      = globalId[0];
                            tmpValueDomain.vd_agency  = globalId[1];
                            tmpValueDomain.vd_version = globalId[2];

                            if (comp.name != null)
                            {
                                tmpValueDomain.names = comp.name;
                            }
                            else
                            {
                                tmpValueDomain.names = new List <LocalizedValue>();
                                tmpValueDomain.names.Add(new LocalizedValue("EN", comp.vtlId));
                            }

                            ds_valueDomainValueList = mtl.LoadCodelistCodes21(globalId[0], globalId[1], globalId[2]);

                            if (ds_valueDomainValueList != null)
                            {
                                tmpValueDomain.values = ds_valueDomainValueList;
                            }

                            tmpInfo.ValueDomainInfo = tmpValueDomain;
                            ds_componentsList.Add(tmpInfo);
                        }
                        try
                        {
                            VTLMan.InsertDataSet(ref_dsd_id, ref_dsd_agency, ref_dsd_version, df_id, df_agency, df_version, artInfo.artefactInfo.name.ToArray(), ds_componentsList.ToArray(), BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD);
                        }
                        catch (TimeoutException ds_ext)
                        {
                            MessageBox.Show("Time out exception");
                            return;
                        }

                        label2.Text = DateTime.Now.ToString();
                        CommonItem.WaitOff();

                        MessageBox.Show("Data set :" + df_id + " " + df_agency + " " + df_version + "  and all the linked components successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tmpNode.ForeColor = Color.Gray;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
            }
            finally
            {
                CommonItem.WaitOff();
            }
        }