Esempio n. 1
0
        public static void Export(int dataSourceId)
        {
            IdpeDataSource dataSource = new Manager().GetDataSourceDetails((int)dataSourceId);

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter   = "IDPE Exported files (*.idpex)|*.idpex|All files (*.*)|*.*";
            saveFileDialog1.FileName = dataSource.Name + ".idpex";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(saveFileDialog1.FileName))
                {
                    if (MessageBox.Show("The file already exists. Do you want to overwrite the file?", "File Already Exists",
                                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        File.Delete(saveFileDialog1.FileName);
                    }
                    else
                    {
                        return;
                    }
                }
                try
                {
                    DataSourceBundle dsb = new DataSourceBundle();
                    dsb.Export(dataSource.Id, saveFileDialog1.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 2
0
        private static void ExportDataSource(IdpeDataSource dataSource, string fileName)
        {
            if (File.Exists(fileName))
            {
                if (MessageBox.Show("The file " + fileName + " already exists. Do you want to overwrite the file?", "File Already Exists",
                                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    File.Delete(fileName);
                }
                else
                {
                    return;
                }
            }

            try
            {
                DataSourceBundle dsb = new DataSourceBundle();
                dsb.Export(dataSource.Id, fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string operation = string.Empty;

            try
            {
                if (_Exporting)
                {
                    operation = " export ";
                    if (File.Exists(txtExportFile.Text))
                    {
                        if (MessageBox.Show("The file already exists. Do you want to overwrite the file?", "File Already Exists",
                                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            File.Delete(txtExportFile.Text);
                        }
                        else
                        {
                            return;
                        }
                    }
                    DataSourceBundle dsb = new DataSourceBundle();
                    dsb.Export(this._DataSource.Id, txtExportFile.Text);
                }
                else
                {
                    operation = " import ";
                    DataSourceBundle dsb     = new DataSourceBundle(txtExportFile.Text);
                    Manager          manager = new Manager();
                    if (manager.ApplicationExists(dsb.DataSource.Name))
                    {
                        if (MessageBox.Show("A data source with name '" + dsb.DataSource.Name + "' already exist! Do you want to overwrite?", "Import Data Source"
                                            , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        {
                            manager.DeleteDataSource(dsb.DataSource.Name);
                            dsb.Import();
                        }
                    }
                    else
                    {
                        dsb.Import();
                    }
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text    = ex.Message;
                toolStripProgressBar1.Value   = toolStripProgressBar1.Maximum;
                toolStripProgressBar1.Visible = false;

                MessageBox.Show("Failed to" + operation + "!" + Environment.NewLine + ex.ToString(), operation + " falied", MessageBoxButtons.OK, MessageBoxIcon.Error);

                _Working          = false;
                this.DialogResult = System.Windows.Forms.DialogResult.Abort;
            }
        }
Esempio n. 4
0
        private void compareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (compareToolStripMenuItem.Text == __Compare)
            {
                if (lvwVersions.SelectedItems.Count == 2)
                {
                    VersionComparer.Compare(VersionObjectType, ObjectName, (IdpeVersion)lvwVersions.SelectedItems[0].Tag, (IdpeVersion)lvwVersions.SelectedItems[1].Tag);
                }
            }
            else if (compareToolStripMenuItem.Text == __SetToTheVersion)
            {
                if (lvwVersions.SelectedItems.Count == 1)
                {
                    IdpeVersion version = lvwVersions.SelectedItems[0].Tag as IdpeVersion;
                    if (MessageBox.Show(string.Format("Are you sure you want to revert '{0}' to Version {1}?", ObjectName, version.Version)
                                        , "Revert Version", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                    {
                        try
                        {
                            this.Cursor = Cursors.WaitCursor;
                            switch (VersionObjectType)
                            {
                            case VersionObjectTypes.Attribute:
                                break;

                            case VersionObjectTypes.DataSource:
                                DataSourceBundle dataSourceBundle = VersionComparer.ConvertToSreVersionObject(VersionObjectTypes.DataSource, version) as DataSourceBundle;
                                dataSourceBundle.Import();
                                Reverted = true;
                                break;

                            case VersionObjectTypes.Rule:
                                DataSourcePatch dataSourcePatch = VersionComparer.ConvertToSreVersionObject(VersionObjectTypes.Rule, version) as DataSourcePatch;
                                dataSourcePatch.Import();
                                Reverted = true;
                                break;
                            }
                            //this.Close();
                        }
                        catch (Exception ex)
                        {
                            //toolStripStatusLabel1.Text = ex.Message;
                        }
                        finally
                        {
                            this.Cursor = Cursors.Default;
                        }
                    }
                }
            }

            if (Reverted)
            {
                this.ParentForm.DialogResult = DialogResult.OK;
                this.ParentForm.Close();
            }
        }
Esempio n. 5
0
        public static bool Import()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "IDPE Exported files (*.idpex)|*.idpex|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DataSourceBundle dsb     = new DataSourceBundle(openFileDialog1.FileName);
                Manager          manager = new Manager();
                if (manager.ApplicationExists(dsb.DataSource.Name))
                {
                    if (MessageBox.Show("A data source with name '" + dsb.DataSource.Name + "' already exist! Do you want to overwrite?", "Import Data Source"
                                        , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        manager.DeleteDataSource(dsb.DataSource.Name);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if ((dsb.DataSource.IsSystem == false) &&
                    (manager.ApplicationExists(dsb.SystemDataSourceName) == false))
                {
                    string msg = string.Format("The system data source '{0}' of this data source does not exist. Please import system data source first and then try to import this one!",
                                               dsb.SystemDataSourceName);
                    MessageBox.Show(msg, "System Data Source Does Not Exist"
                                    , MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return(false);
                }

                try
                {
                    dsb.Import();
                    string msg = openFileDialog1.FileName + " imported successfully!";
                    if (dsb.DataSource.IsSystem == true)
                    {
                        msg += " Validate in Tools-->System Data Sources";
                    }

                    MessageBox.Show(msg,
                                    "Import Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            return(false);
        }
Esempio n. 6
0
        public void Initialize(string folder)
        {
            List <string> idpeps = new List <string>(Directory.GetFiles(folder, "*.idpep"));

            foreach (string idpep in idpeps)
            {
                DataSourcePatch dsp = new DataSourcePatch(idpep);
                dsp.Import();
                Console.WriteLine("{0} imported.", Path.GetFileName(idpep));
            }

            string[] systemDataSources = Directory.GetFiles(folder, "*system*.idpex");

            DataManager.Manager manager = new DataManager.Manager();
            foreach (string systemDataSource in systemDataSources)
            {
                DataSourceBundle dsb = new DataSourceBundle(systemDataSource);
                if (manager.ApplicationExists(dsb.DataSource.Name))
                {
                    Console.WriteLine("{0} already exists, skipped.", Path.GetFileName(systemDataSource));
                    continue;
                }

                dsb.Import();
                Console.WriteLine("{0} imported.", Path.GetFileName(systemDataSource));
            }

            List <string> dataSources = new List <string>(Directory.GetFiles(folder, "*.idpex"));

            dataSources.RemoveAll(f => f.Contains("System"));

            foreach (string dataSource in dataSources)
            {
                DataSourceBundle dsb = new DataSourceBundle(dataSource);
                if (manager.ApplicationExists(dsb.DataSource.Name))
                {
                    Console.WriteLine("{0} already exists, skipped.", Path.GetFileName(dataSource));
                    continue;
                }

                dsb.Import();
                Console.WriteLine("{0} imported.", Path.GetFileName(dataSource));
            }
        }
Esempio n. 7
0
        public static object ConvertToSreVersionObject(VersionObjectTypes versionObjectType, IdpeVersion version)
        {
            object returnObject = null;

            switch (versionObjectType)
            {
            case VersionObjectTypes.Attribute:
                returnObject = new object();
                break;

            case VersionObjectTypes.DataSource:
                returnObject = new DataSourceBundle(null, GZipArchive.Decompress(version.Data.ToArray()).GetString(), version.Version);
                break;

            case VersionObjectTypes.Rule:
                returnObject = new DataSourcePatch(null, GZipArchive.Decompress(version.Data.ToArray()).GetString(), version.Version);
                break;
            }
            return(returnObject);
        }
Esempio n. 8
0
        private void mnItmImportDataSource_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName    = "";
            openFileDialog1.Filter      = "IDPE Files (*.idpex)|*.idpex|All Files (*.*)|*.*";
            openFileDialog1.Multiselect = true;
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    Manager manager = new Manager();
                    foreach (String file in openFileDialog1.FileNames)
                    {
                        DataSourceBundle dsb = new DataSourceBundle(file);
                        if (manager.ApplicationExists(dsb.DataSource.Name))
                        {
                            if (MessageBox.Show("A data source with name '" + dsb.DataSource.Name + "' already exist! Do you want to overwrite?", "Import Data Source"
                                                , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                            {
                                manager.DeleteDataSource(dsb.DataSource.Name);
                            }
                        }
                        else
                        {
                            continue;
                        }

                        dsb.Import();
                    }

                    MessageBox.Show("Import was successful!", "Import Data Sources", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Import was failed!", "Import Data Sources", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 9
0
        public static bool Import()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "IDPE Exported files (*.idpex)|*.idpex|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DataSourceBundle dsb     = new DataSourceBundle(openFileDialog1.FileName);
                Manager          manager = new Manager();
                if (manager.ApplicationExists(dsb.DataSource.Name))
                {
                    if (MessageBox.Show("A data source with name '" + dsb.DataSource.Name + "' already exist! Do you want to overwrite?", "Import Data Source"
                                        , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        manager.DeleteDataSource(dsb.DataSource.Name);
                    }
                    else
                    {
                        return(false);
                    }
                }

                try
                {
                    dsb.Import();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            return(false);
        }
Esempio n. 10
0
        void Init(string[] args)
        {
            if (Information.LoggedInUser != null)
            {
                maintenanceToolStripMenuItem.Visible = Information.LoggedInUser.IsAdmin();
            }
            else
            {
                maintenanceToolStripMenuItem.Visible = true;
            }

            if (EyediaCoreConfigurationSection.CurrentConfig.Debug)
            {
                maintenanceToolStripMenuItem.Visible = true;
            }

            #region When a file double clicked

            if (args.Length > 0)
            {
                //a file has been double clicked
                string fileExtension = Path.GetExtension(args[0]).ToLower();
                try
                {
                    switch (fileExtension)
                    {
                    case ".idpex":
                        if (MessageBox.Show("Do you want to import " + args[0] + " ?", "Import Datasource",
                                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                        {
                            DataSourceBundle dsb = new DataSourceBundle(args[0]);
                            dsb.Import();
                        }
                        break;

                    case ".idpep":
                        if (MessageBox.Show("Do you want to import " + args[0] + " ?", "Patch",
                                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                        {
                            DataSourcePatch dsp = new DataSourcePatch(args[0]);
                            dsp.Import();
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    switch (fileExtension)
                    {
                    case ".idpex":
                        MessageBox.Show("An error occurred while importing data source from " + args[0] + Environment.NewLine + ex.ToString(), "Import Datasource",
                                        MessageBoxButtons.OK, MessageBoxIcon.Question);
                        break;

                    case ".idpep":
                        MessageBox.Show("An error occurred while importing from " + args[0] + Environment.NewLine + ex.ToString(), "Patch",
                                        MessageBoxButtons.OK, MessageBoxIcon.Question);
                        break;
                    }
                }
            }

            #endregion When a file double clicked
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
        private void ExportApplication()
        {
            Manager utilDataManager = new Manager();
            int     applicationId   = _Application.Id;

            _Working      = true;
            btnOK.Enabled = false;
            toolStripProgressBar1.Visible = true;
            toolStripProgressBar1.Increment(10);
            toolStripStatusLabel1.Text = "Exporting data source...";
            Application.DoEvents();
            DataSourceBundle exportApp = new DataSourceBundle();

            exportApp.DataSource    = _Application;
            exportApp.DataSource.Id = 0;

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Exporting attributes...";
            Application.DoEvents();
            exportApp.Attributes = _DataManager.GetAttributes(applicationId);
            foreach (SreAttribute attrib in exportApp.Attributes)
            {
                attrib.AttributeId = 0;
            }
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            DataTable dt = utilDataManager.GetAttributes2(applicationId);

            // dt.Columns["Name"].ColumnName = "AttriButeName";
            dt.WriteXml(sw, XmlWriteMode.WriteSchema);
            sw.Close();
            exportApp.DataSourceAttributes = sb.ToString();

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Exporting rules...";
            Application.DoEvents();
            exportApp.RuleSets = _DataManager.GetApplicationRuleSets(applicationId);
            foreach (SreRule rs in exportApp.RuleSets)
            {
                rs.Id = 0;
            }

            sb = new StringBuilder();
            sw = new StringWriter(sb);

            List <SreRule> sr = utilDataManager.GetRules(applicationId);

            Type elementType = typeof(SreRule);


            DataTable dtrules = new DataTable("DataSourceAttributes");

            //add a column to table for each public property on T
            foreach (var propInfo in elementType.GetProperties())
            {
                if (propInfo.PropertyType.Name == "Nullable`1")
                {
                    dtrules.Columns.Add(propInfo.Name);
                }
                else
                {
                    dtrules.Columns.Add(propInfo.Name, propInfo.PropertyType);
                }
            }


            foreach (SreRule item in sr)
            {
                DataRow row = dtrules.NewRow();
                foreach (var propInfo in elementType.GetProperties())
                {
                    row[propInfo.Name] = propInfo.GetValue(item, null);
                }

                dtrules.Rows.Add(row);
            }

            dtrules.WriteXml(sw, XmlWriteMode.WriteSchema);
            sw.Close();
            exportApp.DataSourceRuleSets = sb.ToString();

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Exporting keys...";
            Application.DoEvents();
            exportApp.Keys = _DataManager.GetApplicationKeys(applicationId, false);
            foreach (SreKey key in exportApp.Keys)
            {
                key.KeyId = 0;
            }

            sb = new StringBuilder();
            sw = new StringWriter(sb);
            dt = utilDataManager.GetKeys2(applicationId);
            dt.WriteXml(sw, XmlWriteMode.WriteSchema);
            sw.Close();
            exportApp.DataSourceKeys = sb.ToString();

            toolStripProgressBar1.Increment(20);
            toolStripStatusLabel1.Text = "Creating file...";
            Application.DoEvents();
            StreamWriter sw1 = new StreamWriter(txtExportFile.Text);

            sw1.Write(exportApp.Serialize <DataSourceBundle>());
            sw1.Close();

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