Example #1
0
        private void CopyApplication()
        {
            _Copying = true;
            toolStripProgressBar1.Visible = true;
            toolStripProgressBar1.Increment(10);
            toolStripStatusLabel1.Text = "Copying application...";
            Application.DoEvents();
            SreDataSource newApp = new SreDataSource();

            newApp.Name                       = txtApplicationName.Text;
            newApp.Description                = txtApplicationName.Text;
            newApp.IsSystem                   = _FromApplication.IsSystem;
            newApp.DataFeederType             = _FromApplication.DataFeederType;
            newApp.DataFormatType             = _FromApplication.DataFormatType;
            newApp.Delimiter                  = _FromApplication.Delimiter;
            newApp.SystemDataSourceId         = _FromApplication.SystemDataSourceId;
            newApp.DataContainerValidatorType = _FromApplication.DataContainerValidatorType;
            newApp.OutputWriterType           = _FromApplication.OutputWriterType;
            newApp.PlugInsType                = _FromApplication.PlugInsType;
            newApp.ProcessingBy               = _FromApplication.ProcessingBy;
            newApp.PusherType                 = _FromApplication.PusherType;
            List <SreRuleDataSource> ruleSets = new List <SreRuleDataSource>();

            newApp.Id        = _AttributeManager.Save(newApp, ruleSets);
            NewApplicationId = newApp.Id;

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Copying attributes...";
            Application.DoEvents();

            BindingList <Symplus.RuleEngine.Utilities.Data.Attribute> attributes = _UtilDataManager.GetAttributes(_FromApplication.Id);
            List <object> esAttributes = new List <object>();

            foreach (Symplus.RuleEngine.Utilities.Data.Attribute a in attributes)
            {
                a.AttributeExternalSystemId = 0;
                esAttributes.Add(a);
            }
            _UtilDataManager.SaveAssociations(newApp.Id, esAttributes);

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Copying keys...";
            Application.DoEvents();

            List <SreKey> fromAppKeys = _AttributeManager.GetApplicationKeys(_FromApplication.Id, false);

            if (fromAppKeys != null)
            {
                for (int i = 0; i < fromAppKeys.Count; i++)
                {
                    SreKey newKey = new SreKey();

                    newKey.Name      = fromAppKeys[i].Name;
                    newKey.Value     = fromAppKeys[i].Value;
                    newKey.Type      = fromAppKeys[i].Type;
                    newKey.IsDefault = fromAppKeys[i].IsDefault;

                    _AttributeManager.Save(newApp.Id, newKey);
                }
            }

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Copying rules...";
            Application.DoEvents();
            string         newRuleName  = string.Empty;
            int            newRuleId    = 0;
            List <SreRule> fromRuleSets = _AttributeManager.GetRules(_FromApplication.Id);

            foreach (SreRule sr in fromRuleSets)
            {
                newRuleName = (sr.Name).Replace(_FromApplication.Name, "");
                newRuleName = newRuleName + "_" + newApp.Name;
                sr.Id       = 0;
                newRuleId   = 0;
                newRuleId   = _AttributeManager.Save(sr);
                SreRuleDataSource ruleSetApp = new SreRuleDataSource();
                ruleSetApp.DataSourceId = 0;
                ruleSetApp.RuleId       = newRuleId;
                ruleSetApp.DataSourceId = newApp.Id;
                ruleSetApp.IsActive     = true;
                _AttributeManager.Save(null, null, null, ruleSetApp);
            }
            //for (int i = 0; i < fromRuleSets.Count; i++)
            //{


            //    fromRuleSets[i].Id = 0;
            //    if (fromRuleSets[i].Name.IndexOf("precontainer", StringComparison.OrdinalIgnoreCase) >= 0)
            //        fromRuleSets[i].Name = newApp.Name + "PreContainer";
            //    else if (fromRuleSets[i].Name.IndexOf("preparse", StringComparison.OrdinalIgnoreCase) >= 0)
            //        fromRuleSets[i].Name = newApp.Name + "PreParse";
            //    else if (fromRuleSets[i].Name.IndexOf("postparse", StringComparison.OrdinalIgnoreCase) >= 0)
            //        fromRuleSets[i].Name = newApp.Name + "PostParse";
            //    else if (fromRuleSets[i].Name.IndexOf("postcontainer", StringComparison.OrdinalIgnoreCase) >= 0)
            //        fromRuleSets[i].Name = newApp.Name + "PreContainer";
            //    else
            //    {
            //        newRuleName = (fromRuleSets[i].Name).Replace(_FromApplication.Name, "");

            //        fromRuleSets[i].Name = newRuleName.Replace("_","") + "_" + newApp.Name;
            //    }
            //}
            //_AttributeManager.Save(fromRuleSets);

            //ruleSets = _AttributeManager.GetRuleSetApplication(_FromApplication.Id);
            //foreach (SreRuleDataSource ruleSet in ruleSets)
            //{
            //    SreRuleDataSource ruleSetApp = new SreRuleDataSource();
            //    ruleSetApp.DataSourceId = 0;
            //    ruleSetApp.RuleId = 0;
            //    ruleSetApp.DataSourceId = newApp.Id;
            //    //ruleSetApp.RuleName = ruleSet.RulesetName + "_" + newApp.Id;
            //    //ruleSetApp.RulesetType = ruleSet.RulesetType;
            //    _AttributeManager.Save(null, null, null, ruleSetApp);
            //}

            toolStripProgressBar1.Increment(30);
            toolStripStatusLabel1.Text = "Done";
            txtApplicationName.Enabled = false;
            btnOK.Enabled = false;
            _Copying      = false;
            Application.DoEvents();

            toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
            Application.DoEvents();
        }
Example #2
0
        private void ImportApplication()
        {
            _Working      = true;
            btnOK.Enabled = false;
            toolStripProgressBar1.Visible = true;
            toolStripProgressBar1.Value   = 0;
            toolStripProgressBar1.Increment(10);
            toolStripStatusLabel1.Text = "Reading file...";
            Application.DoEvents();
            StreamReader sr          = new StreamReader(txtExportFile.Text);
            string       fileContent = sr.ReadToEnd();

            sr.Close();
            DataSourceBundle importedApp = fileContent.Deserialize <DataSourceBundle>();

            if (importedApp == null)
            {
                toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
                Application.DoEvents();
                toolStripProgressBar1.Visible = false;
                btnOK.Enabled = true;
                throw new Exception("Could not read data from file. File might be corrupt.");
            }

            Manager utilDataManager = new Manager();

            ApplicationName = importedApp.DataSource.Name;
            if (utilDataManager.ApplicationExists(importedApp.DataSource.Name))
            {
                toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
                Application.DoEvents();
                toolStripProgressBar1.Visible = false;
                btnOK.Enabled = true;
                throw new Exception("Application already exists!");
            }


            toolStripProgressBar1.Increment(10);
            toolStripStatusLabel1.Text = "Importing application...";
            Application.DoEvents();
            List <SreRuleDataSource> appRules = new List <SreRuleDataSource>();

            utilDataManager.Save(importedApp.DataSource, appRules);
            //importedApp.Application.Id = 104;

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Importing attributes...";
            Application.DoEvents();

            DataTable dt = StringToDataTable(importedApp.DataSourceAttributes);

            List <SreAttributeDataSource> appAttribs = new List <SreAttributeDataSource>();
            int count = 1;

            foreach (SreAttribute attrib in importedApp.Attributes)
            {
                int attributeId = utilDataManager.Save(attrib);

                SreAttributeDataSource saa = new SreAttributeDataSource();
                saa.DataSourceId = importedApp.DataSource.Id;
                saa.AttributeId  = attributeId;
                string str = GetApplicationAttribute(dt, attrib.Name);
                saa.Position     = int.Parse(str.Split("|".ToCharArray())[0]);
                saa.IsAcceptable = bool.Parse(str.Split("|".ToCharArray())[1]);
                appAttribs.Add(saa);
                count++;
            }

            utilDataManager.SaveAssociations(importedApp.DataSource.Id, appAttribs);

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Importing rules...";
            Application.DoEvents();

            dt = StringToDataTable(importedApp.DataSourceRuleSets);

            foreach (SreRule ruleSet in importedApp.RuleSets)
            {
                int ruleSetId = utilDataManager.Save(ruleSet);

                SreRuleDataSource sra = new SreRuleDataSource();
                sra.DataSourceId = importedApp.DataSource.Id;
                sra.RuleId       = ruleSetId;
                sra.IsActive     = true;
                utilDataManager.Save(null, null, null, sra);
            }
            utilDataManager.Save(importedApp.DataSource, appRules);

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Importing keys...";
            Application.DoEvents();

            dt = StringToDataTable(importedApp.DataSourceKeys);

            foreach (SreKey key in importedApp.Keys)
            {
                key.IsDefault = IsKeyIsDefault(dt, key.Name);
                utilDataManager.Save(importedApp.DataSource.Id, key);
            }

            toolStripProgressBar1.Increment(10);
            toolStripStatusLabel1.Text = "Done";
            btnOK.Enabled = true;
            _Working      = false;
            toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
            Application.DoEvents();
        }