Exemple #1
0
        private static void Main(string[] args)
        {
            // ((CDCS.ModelTransformation.CdcsOrganisationsInput)organisation_request).Organisations.FindAll(x=>x.UsedNames_FR.Count>0)
            // TODO encrypt app.config strings

            Console.WriteLine("Import CDCS Xml file into SqlServer database");
            string folderPath          = ConfigurationManager.AppSettings["XmlDirectory"];
            string inputCategories     = ConfigurationManager.AppSettings["InputCategories"];
            string outputCategories    = ConfigurationManager.AppSettings["OutputCategories"];
            string inputOrganisations  = ConfigurationManager.AppSettings["InputOrganisations"];
            string outputOrganisations = ConfigurationManager.AppSettings["OutputOrganisations"];

            // var test_organisations_deserialization = ConfigurationManager.AppSettings["TEST_ORGANISATIONS_DESERIALIZATION"];
            string xslTransformer = ConfigurationManager.AppSettings["XslTransformer"];

            // XmlImport.CleanXml(input_organisations, output_organisations, xsl_transformer, folder_path);
            // XmlImport.CleanXml(input_categories, output_categories, xsl_transformer, folder_path);

            var organisationInput = XmlImport.XmlToObjects(File.ReadAllText($@"{folderPath}{outputOrganisations}.xml"), typeof(CdcsOrganisationsInput));
            var categoryInput     = XmlImport.XmlToObjects(File.ReadAllText($@"{folderPath}{outputCategories}.xml"), typeof(CdcsCategoriesInput));

            var config = new MapperConfiguration(cfg => cfg.AddProfile <CdcsProfile>());

            config.AssertConfigurationIsValid();
            var mapper = config.CreateMapper();

            var categories    = mapper.Map <CdcsCategoriesInput, CategoriesInput>((CdcsCategoriesInput)categoryInput);
            var organisations = mapper.Map <CdcsOrganisationsInput, OrganisationsInput>((CdcsOrganisationsInput)organisationInput);

            Check_ForeignKeys(organisations);

            int nbOfChanges = SaveOrganisationsToDb(organisations, categories);
        }
        public ImportResult ImportContent()
        {
            var result = new ImportResult();

            var request = HttpContext.Current.Request;

            var allowSystemChanges = UserInfo.IsSuperUser;

            var appId  = int.Parse(request["AppId"]);
            var zoneId = int.Parse(request["ZoneId"]);

            if (request.Files.Count > 0)
            {
                var file = request.Files[0];
                if (file.FileName.EndsWith(".zip"))
                {   // ZIP
                    var zipImport = new ZipImport(zoneId, appId, PortalSettings.UserInfo.IsSuperUser);
                    result.Succeeded = zipImport.ImportZip(file.InputStream, HttpContext.Current.Server, PortalSettings, result.Messages);
                }
                else
                {   // XML
                    using (var fileStreamReader = new StreamReader(file.InputStream))
                    {
                        var xmlImport   = new XmlImport(PortalSettings.DefaultLanguage, UserIdentity.CurrentUserIdentityToken, allowSystemChanges);
                        var xmlDocument = XDocument.Parse(fileStreamReader.ReadToEnd());
                        result.Succeeded = xmlImport.ImportXml(zoneId, appId, xmlDocument);
                        result.Messages  = xmlImport.ImportLog;
                    }
                }
            }
            return(result);
        }
Exemple #3
0
        void Test_XmlImport()
        {
            var frame       = new EmberSequence(new BerTag(BerClass.Application, 1));
            var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
            var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);

            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

            Console.WriteLine("\r\n------------------------ XML Import");
            DumpXml(frame);

            var buffer = new StringBuilder();

            using (var writer = XmlWriter.Create(buffer))
                XmlExport.Export(frame, writer);

            using (var stream = new StringReader(buffer.ToString()))
                using (var reader = new XmlTextReader(stream))
                {
                    var root = XmlImport.Import(reader, this);

                    DumpXml(root);
                }
        }
Exemple #4
0
        void Test_XmlImport()
        {
            var frame       = new EmberSequence(new BerTag(BerClass.Application, 1));
            var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
            var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);

            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

            Console.WriteLine("\r\n------------------------ XML Import");
            var xml1 = GetXml(frame);

            using (var stream = new StringReader(xml1))
                using (var reader = new XmlTextReader(stream))
                {
                    var root = XmlImport.Import(reader, this);
                    var xml2 = GetXml(root);

                    Console.WriteLine(xml2);

                    Debug.Assert(xml1 == xml2);
                }
        }
Exemple #5
0
        internal void Version080302()
        {
            logger.LogStep("08.03.02", "Start", false);

            var userName = "******";

            // Add new content types and entities
            var xmlToImport =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.03.02.xml"));
            var xmlImport = new XmlImport("en-US", userName, true);
            var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), true);

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to 08.03.02 failed: " + messages);
            }

            // 2016-03-13 2dm: disabled this rename again, because I tested it without and it seems the manifest works, so this could only lead to trouble one day
            //var desktopModuleNames = new[] { "2sxc", "2sxc-app" };
            //// Update BusinessController class name in desktop module info
            //foreach (var d in desktopModuleNames)
            //{
            //    var dmi = DesktopModuleController.GetDesktopModuleByModuleName(d, -1);
            //    dmi.BusinessControllerClass = "ToSic.SexyContent.Environment.Dnn7.DnnBusinessController";
            //    DesktopModuleController.SaveDesktopModule(dmi, false, true);
            //}
        }
        private void OnTestDataClick(bool detailed)
        {
            if (!fuFileUpload.HasFile)
            {
                lblFileUploadError.Visible = true;
                return;
            }

            FileName = fuFileUpload.FileName;

            var fileContent = fuFileUpload.FileContent;
            var fileImport  = new XmlImport(ZoneId.Value, ApplicationId, ContentTypeIdSelected, fileContent, Languages, LanguageFallback, EntityClearOptionSelected, ResourceReferenceOptionSelected);

            if (fileImport.HasErrors)
            {
                ShowErrorPanel(fileImport);
            }
            else
            {
                var fileInfo = new FileInfo(FilePath);
                fileInfo.WriteStream(fileContent);

                ShowDetailPanel(fileImport, detailed);
            }
        }
Exemple #7
0
 public static void Main()
 {
     JsonImport.ImportAstronomers();
     JsonImport.ImportTelescopes();
     JsonImport.ImportPlanets();
     XmlImport.ImportStars();
     XmlImport.ImportDiscoveries();
 }
Exemple #8
0
        private static void ImportBooks()
        {
            ICollection <BookDTO> books = XmlImport.ImportBooks("../../catalog/books.xml");

            foreach (BookDTO book in books)
            {
                BookDML.AddBook(book);
            }
        }
        static void Main(string[] args)
        {
            // Import files saved in Solution/Import

            JsonImport.ImportAstronomers();
            JsonImport.ImportTelescopes();
            JsonImport.ImportPlanets();

            XmlImport.ImportStars();
            XmlImport.ImportDiscoveries();
        }
Exemple #10
0
        public async Task Save()
        {
            var doc    = XDocument.Load(Path.Combine("TestData", "TestData.xml"));
            var import = new XmlImport(doc, "http://tempuri.org/Database.xsd");
            {
                using (var session = _db.OpenSession())
                    using (var tnx = session.BeginTransaction())
                    {
                        var orderCustomer = new Dictionary <int, int>();
                        import.ParseIntProperty("Order", "Customer",
                                                (orderId, customerId) => { orderCustomer.Add(orderId, customerId); });
                        foreach (var(type, obj) in import.Parse(new[] { typeof(Customer), typeof(Order), typeof(Product) },
                                                                onIgnore: (type, property) =>
                        {
                            Console.WriteLine("Not mapped: " + type.Name + " " + property.Name);
                        }))
                        {
                            switch (obj)
                            {
                            case Customer c:
                                await session.CreateCustomer(c.Id, c.Firstname, c.Lastname, c.Version);

                                break;

                            case Order o:
                                await session.CreateOrder(o.Id, o.OrderDate,
                                                          orderCustomer.TryGetValue(o.Id, out var v)?v : (int?)null,
                                                          o.Version);

                                break;

                            case Product p:
                                await session.CreateProduct(p.Id, p.Name, p.Cost, p.Version);

                                break;

                            default: throw new Exception(obj.GetType().FullName);
                            }
                        }
                        tnx.Commit();
                    }

                using (var session = _db.OpenSession())
                    using (var tnx = session.BeginTransaction())
                    {
                        foreach (var(productId, orderId) in import.ParseConnections("OrderProduct", "Product", "Order"))
                        {
                            await session.AddProductToOrder(productId, orderId);
                        }
                        tnx.Commit();
                    }
            }
        }
        protected void OnImportDataClick(object sender, EventArgs e)
        {
            var fileInfo    = new FileInfo(FilePath);
            var fileContent = fileInfo.ReadStream();

            fileInfo.Delete();

            var fileImport   = new XmlImport(ZoneId.Value, ApplicationId, ContentTypeIdSelected, fileContent, Languages, LanguageFallback, EntityClearOptionSelected, ResourceReferenceOptionSelected);
            var fileImported = fileImport.PersistImportToRepository(UserName);

            ShowDonePanel(!fileImported);
        }
Exemple #12
0
        static void Main(string[] args)
        {
            /* NB! Copy EntityFrameworkSQLServer.dll
             * from Data/bin/Debug to Import/bin/Debug
             */

            JsonImport.ImportSolarSystems();
            JsonImport.ImportStars();
            JsonImport.ImportPlanets();
            JsonImport.ImportPersons();
            JsonImport.ImportAnomalies();
            JsonImport.ImportAnomalyVictims();

            XmlImport.ImportAnomalyVictims();
        }
Exemple #13
0
        internal static void ImportXmlSchemaOfVersion(string version, bool leaveOriginalsUntouched)
        {
            var userName    = "******" + version;
            var xmlToImport =
                File.ReadAllText(
                    HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/" + version + ".xml"));
            var xmlImport = new XmlImport("en-US", userName, true);
            var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport),
                                                leaveOriginalsUntouched);

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to " + version + " failed: " + messages);
            }
        }
Exemple #14
0
        internal void Version080303()
        {
            logger.LogStep("08.03.03", "Start", false);

            var userName = "******";

            // Change "Author" to "Owner" (permissions content type)
            var xmlToImport =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.03.03.xml"));
            var xmlImport = new XmlImport("en-US", userName, true);
            var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // Overwrite existing values

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to 08.03.03 failed: " + messages);
            }
        }
Exemple #15
0
        internal void Version070303()
        {
            logger.LogStep("07.03.03", "Start", false);

            var userName = "******";

            // 1. Import new Attributes for @All content type
            var xmlToImport =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.03.03-01.xml"));
            var xmlImport = new XmlImport("en-US", userName, true);
            var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport));

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to 07.03.03-01 failed: " + messages);
            }

            // 2. Import ContentType-InputType and entities for it
            xmlToImport =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.03.03-02.xml"));
            xmlImport = new XmlImport("en-US", userName, true);
            success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport));

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to 07.03.03-02 failed: " + messages);
            }

            // 3. Hide all unneeded fields - all fields for string, number: all but "Number of Decimals", Minimum and Maximum
            xmlToImport =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.03.03-03.xml"));
            xmlImport = new XmlImport("en-US", userName, true);
            success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // special note - change existing values

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to 07.03.03-03 failed: " + messages);
            }

            logger.LogStep("07.03.03", "Done", false);
        }
        private void ShowDetailPanel(XmlImport dataImport, bool showDebugOutput)
        {
            lblDetailInfo.Text         = LocalizeFormatString("lblDetailInfo", FileName);
            lblDetailElementCount.Text = LocalizeFormatString
                                         (
                "lblDetailElementCount", dataImport.DocumentElements.Count()
                                         );
            lblDetailLanguageCount.Text = LocalizeFormatString
                                          (
                "lblDetailLanguageCount", dataImport.LanguagesInDocument.Count()
                                          );
            lblDetailAttributes.Text = LocalizeFormatString
                                       (
                "lblDetailAttributes", dataImport.AttributeNamesInDocument.Count(), string.Join(", ", dataImport.AttributeNamesInDocument)
                                       );
            lblDetailEntitiesCreate.Text = LocalizeFormatString
                                           (
                "lblDetailEntitiesCreate", dataImport.AmountOfEntitiesCreated
                                           );
            lblDetailEntitiesUpdate.Text = LocalizeFormatString
                                           (
                "lblDetailEntitiesUpdate", dataImport.AmountOfEntitiesUpdated
                                           );
            lblDetailDetailsDelete.Text = LocalizeFormatString
                                          (
                "lblDetailDetailsDelete", dataImport.AmountOfEntitiesDeleted
                                          );
            lblDetailAttributeIgnore.Text = LocalizeFormatString
                                            (
                "lblDetailAttributeIgnore", dataImport.AttributeNamesNotImported.Count(), string.Join(", ", dataImport.AttributeNamesNotImported)
                                            );

            if (showDebugOutput)
            {
                lblDetailDebugOutput.Text = dataImport.GetDebugReport();
            }

            pnlSetup.Visible  = false;
            pnlDetail.Visible = true;
            pnlError.Visible  = false;
            pnlDone.Visible   = false;
        }
        public IEnumerable<Command> Get()
        {
            var commands = new List<Command>();
            var import = new XmlImport(XDocument.Load(Path.Combine("TestData", "TestData.xml")), "http://tempuri.org/Database.xsd");
            import.Parse<AddCustomerCommand>("Customer",
                (obj) =>
                {
                    obj.SequenceNumber = ++sequence;
                    commands.Add(obj);
                }, onIgnore: (type, property) =>
                {
                    throw new Exception(string.Format("ignoring property {1} on {0}", type, property.PropertyType.Name));
                });
            import.Parse<AddOrderCommand>("Order",
                (obj) =>
                {
                    obj.SequenceNumber = ++sequence;
                    commands.Add(obj);
                }, onIgnore: (type, property) =>
                {
                    throw new Exception(string.Format("ignoring property {1} on {0}", type, property.PropertyType.Name));
                });

            import.Parse<AddProductCommand>("Product",
                (obj) =>
                {
                    obj.SequenceNumber = ++sequence;
                    commands.Add(obj);
                }, onIgnore: (type, property) =>
                {
                    throw new Exception(string.Format("ignoring property {1} on {0}", type, property.PropertyType.Name));
                });

            import.ParseConnections("OrderProduct", "Product", "Order", (productId, orderId) =>
            {
                var obj = new AddProductToOrder { ProductId = productId, OrderId = orderId };
                obj.SequenceNumber = ++sequence;
                commands.Add(obj);
            });

            return commands;
        }
Exemple #18
0
        internal void Version080004()
        {
            logger.LogStep("08.00.04", "Start", false);

            var userName = "******";

            // Fix AddressMask field in GPS settings content type
            var xmlToImport =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.00.04.xml"));
            var xmlImport = new XmlImport("en-US", userName, true);
            var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // special note - change existing values

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to 08.00.04 failed: " + messages);
            }

            logger.LogStep("08.00.02", "Done", false);
        }
Exemple #19
0
        internal void Version080100()
        {
            logger.LogStep("08.01.00", "Start", false);

            var userName = "******";

            // Add new content types and entities
            var xmlToImport =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.01.00.xml"));
            var xmlImport = new XmlImport("en-US", userName, true);
            var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // special note - change existing values

            if (!success)
            {
                var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                throw new Exception("The 2sxc module upgrade to 08.01.00 failed: " + messages);
            }

            // Remove unneeded control key for template file editing
            RemoveModuleControls(new[] { "edittemplatefile" });
        }
Exemple #20
0
        public static XmlImportResults UploadXml(string filename, Stream xmlStream)
        {
            var result = new XmlImportResults();

            result.Success = false;
            DeletePreviousImports();


            var xmlDocument = new XmlDocument();

            xmlDocument.Load(xmlStream);
            var import = new XmlImport
            {
                ImportDate  = DateTime.Now,
                XmlFileName = filename,
                XmlData     = XmlUtility.ToString(xmlDocument)
            };
            var importid = import.Insert();

            var menuitems = ParseXml(xmlDocument);

            foreach (var xmlMenuItem in menuitems)
            {
                xmlMenuItem.XmlImportId = Convert.ToInt32(importid);
                var menuid = xmlMenuItem.Insert();
                XmlMenuItemXrefRespositorycs.Save(xmlMenuItem);
                result.MenuItemsUploaded++;
                foreach (var ingredient in xmlMenuItem.Ingredients)
                {
                    ingredient.XmlImportMenuItemId = Convert.ToInt32(menuid);
                    ingredient.Save();
                    XmlIngredientsXrefRepository.Save(ingredient, xmlMenuItem.ItemGuid, xmlMenuItem.ItemName);
                    result.IngredientsUploaded++;
                }
            }

            result.Success = true;
            return(result);
        }
Exemple #21
0
        protected void ImportFromStream(Stream importStream, bool isZip)
        {
            var messages = new List <ExportImportMessage>();
            var success  = false;

            if (isZip)
            {
                success = new ZipImport(ZoneId.Value, AppId.Value, UserInfo.IsSuperUser).ImportZip(importStream, Server, PortalSettings, messages, false);
            }
            else
            {
                string Xml    = new StreamReader(importStream).ReadToEnd();
                var    import = new XmlImport();
                success  = import.ImportXml(ZoneId.Value, AppId.Value, Xml);
                messages = import.ImportLog;
            }

            lstvSummary.DataSource = messages;
            lstvSummary.DataBind();
            pnlSummary.Visible = true;
            pnlUpload.Visible  = false;
        }
Exemple #22
0
        internal void Version070200()
        {
            logger.LogStep("07.02.00", "Start", false);

            var userName = "******";

            // Import new ContentType for permissions
            if (DataSource.GetCache(Constants.DefaultZoneId, Constants.MetaDataAppId).GetContentType("|Config ToSic.Eav.DataSources.Paging") == null)
            {
                var xmlToImport =
                    File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.02.00.xml"));
                //var xmlToImport = File.ReadAllText("../../../../Upgrade/07.00.00.xml");
                var xmlImport = new XmlImport("en-US", userName, true);
                var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport));

                if (!success)
                {
                    var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                    throw new Exception("The 2sxc module upgrade to 07.02.00 failed: " + messages);
                }
            }
            logger.LogStep("07.02.00", "Done", false);
        }
        public static XmlImportResults UploadXml(string filename, Stream xmlStream)
        {
            var result = new XmlImportResults();
            result.Success = false;
            DeletePreviousImports();

            var xmlDocument = new XmlDocument();

            xmlDocument.Load(xmlStream);
            var import = new XmlImport
                        {
                            ImportDate = DateTime.Now,
                            XmlFileName = filename,
                            XmlData = XmlUtility.ToString(xmlDocument)
                        };
            var importid =import.Insert();

            var menuitems = ParseXml(xmlDocument);

            foreach (var xmlMenuItem in menuitems)
            {
                xmlMenuItem.XmlImportId = Convert.ToInt32(importid);
                var menuid = xmlMenuItem.Insert();
                XmlMenuItemXrefRespositorycs.Save(xmlMenuItem);
                result.MenuItemsUploaded++;
                foreach (var ingredient in xmlMenuItem.Ingredients)
                {
                    ingredient.XmlImportMenuItemId = Convert.ToInt32(menuid);
                    ingredient.Save();
                    XmlIngredientsXrefRepository.Save(ingredient, xmlMenuItem.ItemGuid,xmlMenuItem.ItemName);
                    result.IngredientsUploaded++;
                }
            }

            result.Success = true;
            return result;
        }
        private void ShowErrorPanel(XmlImport dataImport)
        {
            lblErrorInfo.Text = LocalizeFormatString("lblErrorInfo", FileName);

            var errorProtocolHtml = string.Empty;

            foreach (var error in dataImport.ErrorProtocol.Errors)
            {
                errorProtocolHtml += string.Format
                                     (
                    "<li>{0}{1}{2}{3}</li>",
                    error.ErrorCode.GetDescription(),
                    error.ErrorDetail != null ? LocalizeFormatString("lblErrorProtocolErrorDetail", error.ErrorDetail) : "",
                    error.LineNumber != null ? LocalizeFormatString("lblErrorProtocolLineNo", error.LineNumber) : "",
                    error.LineDetail != null ? LocalizeFormatString("lblErrorProtocolLineDetail", error.LineDetail) : ""
                                     );
            }
            ulErrorProtocol.InnerHtml = errorProtocolHtml;

            pnlSetup.Visible  = false;
            pnlDetail.Visible = false;
            pnlError.Visible  = true;
            pnlDone.Visible   = false;
        }
Exemple #25
0
        protected void btnGetenerate_OnClick(object sender, EventArgs e)
        {
            _sourceXmlList.Clear();
             _outputXmlList.Clear();
            _additionalOutputXmlList.Clear();
            lblMsg.Text = "";
            grid.InnerHtml = "";

            foreach (GridViewRow row in gvXMLSource.Rows)
            {
                var chk = (row.FindControl("chkSelect") as CheckBox);
                if (chk != null && chk.Checked)
                {
                    var srno = Convert.ToInt32(gvXMLSource.DataKeys[row.RowIndex].Values[0]);

                    using (var dataContext =new EPGDataModel())
                    {
                        var source = dataContext.SourceURLs.Find(srno);
                        if (source != null)
                        {
                            var extension = source.Type.ToLower().Equals("zip") ? ".zip" : ".xml";
                            var fileName = DownloadFile(source.Url, extension);
                            //MODIFY HERE
                            if (!string.IsNullOrEmpty(fileName))
                            {
                                if (Path.GetExtension(fileName).Contains(".zip")) //Zip Archive.
                                {
                                    //extract xmls from zip archive.
                                    ExtractFileToDirectory(fileName, Server.MapPath(@"~/SourceXmlFiles/"));
                                }
                                else if (Path.GetExtension(fileName).Contains(".xml")) //Single Xml.
                                {
                                    //ClearDirectory(Server.MapPath(@"~/SourceXmlFiles/"));

                                    if (File.Exists(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName))))
                                        File.Delete(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));

                                    File.Copy(Server.MapPath(fileName),
                                        Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));

                                    _sourceXmlList.Add(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));
                                }

                                 foreach (var xmlFile in _sourceXmlList)
                                 {

                                     var sourceUri = new Uri(source.Url);
                                     var newChannelName = string.Empty;
                                     var newOffset = 0;

                                     try
                                     {
                                         newChannelName = HttpUtility.ParseQueryString(sourceUri.Query).Get("channelname");
                                         int.TryParse(HttpUtility.ParseQueryString(sourceUri.Query).Get("offset"), out newOffset);
                                     }
                                     catch (Exception)
                                     {
                                         // ignored
                                     }

                                  _outputXmlList.AddRange(ParserEngine.GenerateOutputXml(xmlFile,source.Srno,out _startDate,out _stopDate,  newChannelName, newOffset));
                                   //GenerateOutputXml(xmlFile,source.Srno, newChannelName, newOffset);
                                 }
                            }
                        }
                    }
                }

                _sourceXmlList.Clear();
            }

            if (_outputXmlList != null)
            {
                if (_outputXmlList.Count > 0)
                {
                    grid.InnerHtml += "<span style='text-align:center;' class='alert-danger'>Generated Output Xml(s)</span>";
                    grid.InnerHtml += "<table style='width:50%;' class='table table-striped table-bordered table-hover table-condensed table-mptt'><th class='sortable'>Srno</th><th class='sortable'>Output Xml (click to view xml)</th><th class='sortable'>EPG Start Date</th><th class='sortable'>EPG End Date</th><tbody>";

                    var iCount = 1;
                    foreach (var outFile in _outputXmlList)
                    {
                        var fileDetails = outFile.Split(',');
                        grid.InnerHtml += "<tr><td>" + iCount + "</td><td><a href='XmlTransformation.aspx?file=" + fileDetails[0] + "' target='_blank' class='btn-link'> " + Path.GetFileName(fileDetails[0]) + "</a></td>";
                        grid.InnerHtml += "<td>" + fileDetails[1] + "</td><td>" + fileDetails[2] +"</td></tr>";

                        try
                        {
                            using (var dataContext = new EPGDataModel())
                            {
                                var fileName = Path.GetFileName(fileDetails[0]);
                                var dbEntry =
                                    dataContext.XmlImports.Where(
                                        x => x.XmlFileName.Trim().ToLower().Equals(fileName.Trim().ToLower())).ToList();

                                if (dbEntry != null)
                                {
                                    if (dbEntry.Count > 0)
                                    {
                                        dataContext.Database.ExecuteSqlCommand(
                                            "DELETE FROM XmlImport WHERE XmlFileName='" + fileName + "'");
                                    }
                                }

                                var xmlImport = new XmlImport
                                {
                                    Url = "../Output/" + Path.GetFileName(fileDetails[0]),
                                    EpgStartDt = _startDate,
                                    EpgEndDt = _stopDate,
                                    ImportDate = DateTime.Now,
                                    XmlFileName = Path.GetFileName(fileDetails[0]),
                                    Url2 = !string.IsNullOrEmpty(fileDetails[3])?fileDetails[3]:"",
                                    SourceUrl = !string.IsNullOrEmpty(fileDetails[4]) ? fileDetails[4] : "",
                                };

                                dataContext.XmlImports.Add(xmlImport);
                                dataContext.SaveChanges();
                            }
                        }
                        catch (Exception)
                        {

                        }

                        iCount++;
                    }

                    grid.InnerHtml += "</tbody></table>";
                    lblMsg.Text = "Xml(s) generated successfully!";

                }
            }
        }
Exemple #26
0
        public static void ProcessXml()
        {
            XmlConfigurator.Configure();

            SourceXmlList.Clear();
            OutputXmlList.Clear();

            using (var dataContext = new EPGDataModel())
            {
                List<SourceURL> listToProcess=new List<SourceURL>();
                try
                {
                    logger.Info("1.> Getting List of Source from Database");
                    listToProcess = dataContext.SourceURLs.Where(s => s.IsActive).ToList();
                    logger.Info("2.> Retrived List of Source from Database. Total Sources - " + listToProcess.Count);
                }
                catch (Exception exDataException)
                {
                    logger.Error("Error occured while retriving List of Source from Database. Error Message - " + exDataException.Message);

                    if(exDataException.InnerException !=null)
                        logger.Error("Inner Exception - " + exDataException.InnerException.Message);
                }

                foreach (var source in listToProcess)
                {
                    try
                    {
                        logger.Info("ravi");
                        logger.Info("// Proccessing Source - " + source.Url);
                        var extension = source.Type.ToLower().Equals("zip") ? ".zip" : ".xml";
                        logger.Info("// File extension is - " + extension);

                        var fileName = DownloadFile(source.Url, extension);
                        logger.Info("// File Name extension is - " + fileName);

                        if (!string.IsNullOrEmpty(fileName))
                        {
                            if (Path.GetExtension(fileName).Contains(".zip")) //Zip Archive.
                            {
                                logger.Info("// Source is a zip archive.");
                                //extract xmls from zip archive.
                                ExtractFileToDirectory(fileName, SourceXmlFolderPath);

                                logger.Info("// Çompleted extraction of zip archive. Total files extracted - "+ SourceXmlList.Count);

                            }
                            else if (Path.GetExtension(fileName).Contains(".xml")) //Single Xml.
                            {
                                logger.Info("// Source is a xml file.");
                                //ClearDirectory(Environment.CurrentDirectory + @"\SourceXmlFiles\");

                                try
                                {
                                    logger.Info("// Checking if file " + Path.GetFileName(fileName) + " alredy exists in Source Xml Folder.");
                                    if (File.Exists(SourceXmlFolderPath + Path.GetFileName(fileName)))
                                        File.Delete(SourceXmlFolderPath + Path.GetFileName(fileName));

                                    logger.Info("// Copying File " + Path.GetFileName(fileName) + " to Source Xml Folder.");
                                    File.Copy(fileName, SourceXmlFolderPath + Path.GetFileName(fileName));
                                    logger.Info("// Completed Copying File " + Path.GetFileName(fileName) + " to Source Xml Folder.");
                                    SourceXmlList.Add(SourceXmlFolderPath + Path.GetFileName(fileName));
                                    logger.Info("// Çompleted Adding file to SourceXmlList - Total Count is - " + SourceXmlList.Count);
                                }
                                catch (Exception singleXmlException)
                                {
                                     logger.Error("Error occured while copying single xml. Error - " + singleXmlException.Message);

                                    if(singleXmlException.InnerException !=null)
                                        logger.Error("Inner Exception Error - " + singleXmlException.InnerException.Message);
                                }

                            }

                            foreach (var xmlFile in SourceXmlList)
                            {

                                var sourceUri = new Uri(source.Url);
                                var newChannelName = string.Empty;
                                var newOffset = 0;

                                try
                                {
                                    newChannelName = HttpUtility.ParseQueryString(sourceUri.Query).Get("channelname");
                                    int.TryParse(HttpUtility.ParseQueryString(sourceUri.Query).Get("offset"), out newOffset);
                                }
                                catch (Exception)
                                {
                                    // ignored
                                }

                                logger.Info("Calling  GenerateOutputXml(" + xmlFile + ", " + newChannelName + ", " + newOffset + ")");

                                OutputXmlList.AddRange(ParserEngine.GenerateOutputXml(xmlFile, source.Srno, out _startDate, out _stopDate, newChannelName, newOffset));
                                //GenerateOutputXml(xmlFile, newChannelName, newOffset);

                                logger.Info("Completed  GenerateOutputXml(" + xmlFile + ", " + newChannelName + ", " + newOffset + ")");
                            }
                        }

                        SourceXmlList.Clear();
                    }
                    catch (Exception)
                    {

                    }
                }

            }

            Console.WriteLine("Xml Generation Completed");

            if (OutputXmlList != null)
            {
                if (OutputXmlList.Count > 0)
                {
                    logger.Info("Updating Database...");
                    Console.WriteLine("Updating Database");

                    foreach (var outFile in OutputXmlList)
                    {
                        var fileDetails = outFile.Split(',');

                        try
                        {
                            using (var dataContext = new EPGDataModel())
                            {
                                var fileName = Path.GetFileName(fileDetails[0]);
                                var dbEntry =
                                    dataContext.XmlImports.Where(
                                        x => x.XmlFileName.Trim().ToLower().Equals(fileName.Trim().ToLower())).ToList();

                                try
                                {
                                    if (dbEntry != null)
                                    {
                                        if (dbEntry.Count > 0)
                                        {
                                            dataContext.XmlImports.RemoveRange(dbEntry);
                                            dataContext.SaveChanges();
                                        }
                                    }
                                }
                                catch (Exception deleteException)
                                {
                                    logger.Error("Error occured while Deleting. Error Message - " +
                                        deleteException.Message);

                                    if (deleteException.InnerException != null)
                                        logger.Error("Error InnerException - " +
                                                 deleteException.InnerException.Message);
                                }

                                try
                                {
                                    var xmlImport = new XmlImport
                                    {
                                        Url = "../Output/" + Path.GetFileName(fileDetails[0]),
                                        EpgStartDt = _startDate,
                                        EpgEndDt = _stopDate,
                                        ImportDate = DateTime.Now,
                                        XmlFileName = Path.GetFileName(fileDetails[0]),
                                        Url2 = !string.IsNullOrEmpty(fileDetails[3]) ? fileDetails[3] : "",
                                        SourceUrl = !string.IsNullOrEmpty(fileDetails[4]) ? fileDetails[4] : ""
                                    };

                                    dataContext.XmlImports.Add(xmlImport);
                                    dataContext.SaveChanges();
                                }
                                catch (Exception xmlDataImportException)
                                {
                                    logger.Error("Error occured while adding new entry to Database. Error Message - " +
                                        xmlDataImportException.Message);

                                    if (xmlDataImportException.InnerException != null)
                                        logger.Error("Error InnerException - " +
                                                 xmlDataImportException.InnerException.Message);

                                }

                            }
                        }
                        catch (Exception updateException)
                        {
                            logger.Error("Error occured while running UpdatE Database function. Error Message - " +
                            updateException.Message);

                            if (updateException.InnerException != null)
                                logger.Error("Error InnerException - " +
                                         updateException.InnerException.Message);
                        }

                    }

                    Console.WriteLine("Done Updating Database");
                    logger.Info("Done Updating Database");
                }
            }
        }
Exemple #27
0
        protected void btnGetenerate_OnClick(object sender, EventArgs e)
        {
            _sourceXmlList.Clear();
            _outputXmlList.Clear();
            _additionalOutputXmlList.Clear();
            lblMsg.Text    = "";
            grid.InnerHtml = "";

            foreach (GridViewRow row in gvXMLSource.Rows)
            {
                var chk = (row.FindControl("chkSelect") as CheckBox);
                if (chk != null && chk.Checked)
                {
                    var srno = Convert.ToInt32(gvXMLSource.DataKeys[row.RowIndex].Values[0]);

                    using (var dataContext = new EPGDataModel())
                    {
                        var source = dataContext.SourceURLs.Find(srno);
                        if (source != null)
                        {
                            var extension = source.Type.ToLower().Equals("zip") ? ".zip" : ".xml";
                            var fileName  = DownloadFile(source.Url, extension);
                            //MODIFY HERE
                            if (!string.IsNullOrEmpty(fileName))
                            {
                                if (Path.GetExtension(fileName).Contains(".zip")) //Zip Archive.
                                {
                                    //extract xmls from zip archive.
                                    ExtractFileToDirectory(fileName, Server.MapPath(@"~/SourceXmlFiles/"));
                                }
                                else if (Path.GetExtension(fileName).Contains(".xml")) //Single Xml.
                                {
                                    //ClearDirectory(Server.MapPath(@"~/SourceXmlFiles/"));

                                    if (File.Exists(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName))))
                                    {
                                        File.Delete(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));
                                    }


                                    File.Copy(Server.MapPath(fileName),
                                              Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));

                                    _sourceXmlList.Add(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));
                                }

                                foreach (var xmlFile in _sourceXmlList)
                                {
                                    var sourceUri      = new Uri(source.Url);
                                    var newChannelName = string.Empty;
                                    var newOffset      = 0;

                                    try
                                    {
                                        newChannelName = HttpUtility.ParseQueryString(sourceUri.Query).Get("channelname");
                                        int.TryParse(HttpUtility.ParseQueryString(sourceUri.Query).Get("offset"), out newOffset);
                                    }
                                    catch (Exception)
                                    {
                                        // ignored
                                    }

                                    _outputXmlList.AddRange(ParserEngine.GenerateOutputXml(xmlFile, source.Srno, out _startDate, out _stopDate, newChannelName, newOffset));
                                    //GenerateOutputXml(xmlFile,source.Srno, newChannelName, newOffset);
                                }
                            }
                        }
                    }
                }

                _sourceXmlList.Clear();
            }



            if (_outputXmlList != null)
            {
                if (_outputXmlList.Count > 0)
                {
                    grid.InnerHtml += "<span style='text-align:center;' class='alert-danger'>Generated Output Xml(s)</span>";
                    grid.InnerHtml += "<table style='width:50%;' class='table table-striped table-bordered table-hover table-condensed table-mptt'><th class='sortable'>Srno</th><th class='sortable'>Output Xml (click to view xml)</th><th class='sortable'>EPG Start Date</th><th class='sortable'>EPG End Date</th><tbody>";

                    var iCount = 1;
                    foreach (var outFile in _outputXmlList)
                    {
                        var fileDetails = outFile.Split(',');
                        grid.InnerHtml += "<tr><td>" + iCount + "</td><td><a href='XmlTransformation.aspx?file=" + fileDetails[0] + "' target='_blank' class='btn-link'> " + Path.GetFileName(fileDetails[0]) + "</a></td>";
                        grid.InnerHtml += "<td>" + fileDetails[1] + "</td><td>" + fileDetails[2] + "</td></tr>";


                        try
                        {
                            using (var dataContext = new EPGDataModel())
                            {
                                var fileName = Path.GetFileName(fileDetails[0]);
                                var dbEntry  =
                                    dataContext.XmlImports.Where(
                                        x => x.XmlFileName.Trim().ToLower().Equals(fileName.Trim().ToLower())).ToList();

                                if (dbEntry != null)
                                {
                                    if (dbEntry.Count > 0)
                                    {
                                        dataContext.Database.ExecuteSqlCommand(
                                            "DELETE FROM XmlImport WHERE XmlFileName='" + fileName + "'");
                                    }
                                }

                                var xmlImport = new XmlImport
                                {
                                    Url         = "../Output/" + Path.GetFileName(fileDetails[0]),
                                    EpgStartDt  = _startDate,
                                    EpgEndDt    = _stopDate,
                                    ImportDate  = DateTime.Now,
                                    XmlFileName = Path.GetFileName(fileDetails[0]),
                                    Url2        = !string.IsNullOrEmpty(fileDetails[3])?fileDetails[3]:"",
                                    SourceUrl   = !string.IsNullOrEmpty(fileDetails[4]) ? fileDetails[4] : "",
                                };

                                dataContext.XmlImports.Add(xmlImport);
                                dataContext.SaveChanges();
                            }
                        }
                        catch (Exception)
                        {
                        }


                        iCount++;
                    }


                    grid.InnerHtml += "</tbody></table>";
                    lblMsg.Text     = "Xml(s) generated successfully!";
                }
            }
        }
Exemple #28
0
 private void InitializeImports()
 {
     MSBuildToolsImport = FindImport(@"$(MSBuildToolsPath)\Microsoft.CSharp.targets");
 }
Exemple #29
0
        public static void ProcessXml()
        {
            XmlConfigurator.Configure();

            SourceXmlList.Clear();
            OutputXmlList.Clear();


            using (var dataContext = new EPGDataModel())
            {
                List <SourceURL> listToProcess = new List <SourceURL>();
                try
                {
                    logger.Info("1.> Getting List of Source from Database");
                    listToProcess = dataContext.SourceURLs.Where(s => s.IsActive).ToList();
                    logger.Info("2.> Retrived List of Source from Database. Total Sources - " + listToProcess.Count);
                }
                catch (Exception exDataException)
                {
                    logger.Error("Error occured while retriving List of Source from Database. Error Message - " + exDataException.Message);

                    if (exDataException.InnerException != null)
                    {
                        logger.Error("Inner Exception - " + exDataException.InnerException.Message);
                    }
                }

                foreach (var source in listToProcess)
                {
                    try
                    {
                        logger.Info("ravi");
                        logger.Info("// Proccessing Source - " + source.Url);
                        var extension = source.Type.ToLower().Equals("zip") ? ".zip" : ".xml";
                        logger.Info("// File extension is - " + extension);

                        var fileName = DownloadFile(source.Url, extension);
                        logger.Info("// File Name extension is - " + fileName);

                        if (!string.IsNullOrEmpty(fileName))
                        {
                            if (Path.GetExtension(fileName).Contains(".zip")) //Zip Archive.
                            {
                                logger.Info("// Source is a zip archive.");
                                //extract xmls from zip archive.
                                ExtractFileToDirectory(fileName, SourceXmlFolderPath);

                                logger.Info("// Çompleted extraction of zip archive. Total files extracted - " + SourceXmlList.Count);
                            }
                            else if (Path.GetExtension(fileName).Contains(".xml")) //Single Xml.
                            {
                                logger.Info("// Source is a xml file.");
                                //ClearDirectory(Environment.CurrentDirectory + @"\SourceXmlFiles\");

                                try
                                {
                                    logger.Info("// Checking if file " + Path.GetFileName(fileName) + " alredy exists in Source Xml Folder.");
                                    if (File.Exists(SourceXmlFolderPath + Path.GetFileName(fileName)))
                                    {
                                        File.Delete(SourceXmlFolderPath + Path.GetFileName(fileName));
                                    }

                                    logger.Info("// Copying File " + Path.GetFileName(fileName) + " to Source Xml Folder.");
                                    File.Copy(fileName, SourceXmlFolderPath + Path.GetFileName(fileName));
                                    logger.Info("// Completed Copying File " + Path.GetFileName(fileName) + " to Source Xml Folder.");
                                    SourceXmlList.Add(SourceXmlFolderPath + Path.GetFileName(fileName));
                                    logger.Info("// Çompleted Adding file to SourceXmlList - Total Count is - " + SourceXmlList.Count);
                                }
                                catch (Exception singleXmlException)
                                {
                                    logger.Error("Error occured while copying single xml. Error - " + singleXmlException.Message);

                                    if (singleXmlException.InnerException != null)
                                    {
                                        logger.Error("Inner Exception Error - " + singleXmlException.InnerException.Message);
                                    }
                                }
                            }


                            foreach (var xmlFile in SourceXmlList)
                            {
                                var sourceUri      = new Uri(source.Url);
                                var newChannelName = string.Empty;
                                var newOffset      = 0;

                                try
                                {
                                    newChannelName = HttpUtility.ParseQueryString(sourceUri.Query).Get("channelname");
                                    int.TryParse(HttpUtility.ParseQueryString(sourceUri.Query).Get("offset"), out newOffset);
                                }
                                catch (Exception)
                                {
                                    // ignored
                                }

                                logger.Info("Calling  GenerateOutputXml(" + xmlFile + ", " + newChannelName + ", " + newOffset + ")");

                                OutputXmlList.AddRange(ParserEngine.GenerateOutputXml(xmlFile, source.Srno, out _startDate, out _stopDate, newChannelName, newOffset));
                                //GenerateOutputXml(xmlFile, newChannelName, newOffset);

                                logger.Info("Completed  GenerateOutputXml(" + xmlFile + ", " + newChannelName + ", " + newOffset + ")");
                            }
                        }

                        SourceXmlList.Clear();
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            Console.WriteLine("Xml Generation Completed");

            if (OutputXmlList != null)
            {
                if (OutputXmlList.Count > 0)
                {
                    logger.Info("Updating Database...");
                    Console.WriteLine("Updating Database");

                    foreach (var outFile in OutputXmlList)
                    {
                        var fileDetails = outFile.Split(',');

                        try
                        {
                            using (var dataContext = new EPGDataModel())
                            {
                                var fileName = Path.GetFileName(fileDetails[0]);
                                var dbEntry  =
                                    dataContext.XmlImports.Where(
                                        x => x.XmlFileName.Trim().ToLower().Equals(fileName.Trim().ToLower())).ToList();

                                try
                                {
                                    if (dbEntry != null)
                                    {
                                        if (dbEntry.Count > 0)
                                        {
                                            dataContext.XmlImports.RemoveRange(dbEntry);
                                            dataContext.SaveChanges();
                                        }
                                    }
                                }
                                catch (Exception deleteException)
                                {
                                    logger.Error("Error occured while Deleting. Error Message - " +
                                                 deleteException.Message);

                                    if (deleteException.InnerException != null)
                                    {
                                        logger.Error("Error InnerException - " +
                                                     deleteException.InnerException.Message);
                                    }
                                }


                                try
                                {
                                    var xmlImport = new XmlImport
                                    {
                                        Url         = "../Output/" + Path.GetFileName(fileDetails[0]),
                                        EpgStartDt  = _startDate,
                                        EpgEndDt    = _stopDate,
                                        ImportDate  = DateTime.Now,
                                        XmlFileName = Path.GetFileName(fileDetails[0]),
                                        Url2        = !string.IsNullOrEmpty(fileDetails[3]) ? fileDetails[3] : "",
                                        SourceUrl   = !string.IsNullOrEmpty(fileDetails[4]) ? fileDetails[4] : ""
                                    };

                                    dataContext.XmlImports.Add(xmlImport);
                                    dataContext.SaveChanges();
                                }
                                catch (Exception xmlDataImportException)
                                {
                                    logger.Error("Error occured while adding new entry to Database. Error Message - " +
                                                 xmlDataImportException.Message);

                                    if (xmlDataImportException.InnerException != null)
                                    {
                                        logger.Error("Error InnerException - " +
                                                     xmlDataImportException.InnerException.Message);
                                    }
                                }
                            }
                        }
                        catch (Exception updateException)
                        {
                            logger.Error("Error occured while running UpdatE Database function. Error Message - " +
                                         updateException.Message);

                            if (updateException.InnerException != null)
                            {
                                logger.Error("Error InnerException - " +
                                             updateException.InnerException.Message);
                            }
                        }
                    }

                    Console.WriteLine("Done Updating Database");
                    logger.Info("Done Updating Database");
                }
            }
        }
        public void ImportFileTest()
        {
            bool value = false;

            try
            {
                //string expectedFullName = "Glock G17 Imported unit test";
                string expectedFullName = "Glock G17 Open Class";
                if (MyCollection.Exists(_databasePath, expectedFullName, out _errOut))
                {
                    long gId = MyCollection.GetId(_databasePath, expectedFullName, out _errOut);
                    if (_errOut.Length > 0)
                    {
                        throw new Exception(_errOut);
                    }
                    if (!MyCollection.Delete(_databasePath, gId, out _errOut))
                    {
                        throw new Exception(_errOut);
                    }
                }

                if (!XmlImport.Details(_databasePath, _xmlImportFile, _ownerId, false, out _errOut))
                {
                    throw new Exception(_errOut);
                }
                long gunId = MyCollection.GetLastId(_databasePath, out _errOut);
                if (_errOut.Length > 0)
                {
                    throw new Exception(_errOut);
                }
                if (!XmlImport.Accessories(_databasePath, _xmlImportFile, gunId, out _errOut))
                {
                    throw new Exception(_errOut);
                }
                if (!XmlImport.BarrelConverstionKitDetails(_databasePath, _xmlImportFile, gunId, out _errOut))
                {
                    throw new Exception(_errOut);
                }
                if (!XmlImport.GunSmithDetails(_databasePath, _xmlImportFile, gunId, out _errOut))
                {
                    throw new Exception(_errOut);
                }
                if (!XmlImport.MaintanceDetails(_databasePath, _xmlImportFile, gunId, out _errOut))
                {
                    throw new Exception(_errOut);
                }

                List <GunCollectionList> lst = MyCollection.GetList(_databasePath, gunId, out _errOut);
                if (_errOut.Length > 0)
                {
                    throw new Exception(_errOut);
                }
                MyGunCollectionTest obj = new MyGunCollectionTest();
                obj.PrintList(lst);
                value = true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR: {e.Message}");
            }
            General.HasTrueValue(value, _errOut);
        }
Exemple #31
0
        /// <summary>
        /// Add ContentTypes for ContentGroup and move all 2sxc data to EAV
        /// </summary>
        internal void Version070000()
        {
            logger.LogStep("07.00.00", "Start", false);

            var userName = "******";

            #region 1. Import new ContentTypes for ContentGroups and Templates

            logger.LogStep("07.00.00", "1. Import new ContentTypes for ContentGroups and Templates", false);
            if (DataSource.GetCache(Constants.DefaultZoneId, Constants.MetaDataAppId).GetContentType("2SexyContent-Template") == null)
            {
                var xmlToImport =
                    File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.00.00.xml"));
                //var xmlToImport = File.ReadAllText("../../../../Upgrade/07.00.00.xml");
                var xmlImport = new XmlImport("en-US", userName, true);
                var success   = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport));

                if (!success)
                {
                    var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray());
                    throw new Exception("The 2sxc module upgrade to 07.00.00 failed: " + messages);
                }
            }

            #endregion



            // 2. Move all existing data to the new ContentTypes - Append new IDs to old data (ensures that we can fix things that went wrong after upgrading the module)

            #region Prepare Templates
            logger.LogStep("07.00.00", "2. Move all existing data to the new ContentTypes - Append new IDs to old data (ensures that we can fix things that went wrong after upgrading the module)", false);

            var          sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString);
            var          templates     = new DataTable();
            const string sqlCommand    = @"SELECT        ToSIC_SexyContent_Templates.TemplateID, ToSIC_SexyContent_Templates.PortalID, ToSIC_SexyContent_Templates.Name, ToSIC_SexyContent_Templates.Path, 
                         ToSIC_SexyContent_Templates.AttributeSetID, ToSIC_SexyContent_Templates.DemoEntityID, ToSIC_SexyContent_Templates.Script, 
                         ToSIC_SexyContent_Templates.IsFile, ToSIC_SexyContent_Templates.Type, ToSIC_SexyContent_Templates.IsHidden, ToSIC_SexyContent_Templates.Location, 
                         ToSIC_SexyContent_Templates.UseForList, ToSIC_SexyContent_Templates.UseForItem, ToSIC_SexyContent_Templates.SysCreated, 
                         ToSIC_SexyContent_Templates.SysCreatedBy, ToSIC_SexyContent_Templates.SysModified, ToSIC_SexyContent_Templates.SysModifiedBy, 
                         ToSIC_SexyContent_Templates.SysDeleted, ToSIC_SexyContent_Templates.SysDeletedBy, ToSIC_SexyContent_Templates.AppID, 
                         ToSIC_SexyContent_Templates.PublishData, ToSIC_SexyContent_Templates.StreamsToPublish, ToSIC_SexyContent_Templates.PipelineEntityID, 
                         ToSIC_SexyContent_Templates.ViewNameInUrl, ToSIC_SexyContent_Templates.Temp_PresentationTypeID, 
                         ToSIC_SexyContent_Templates.Temp_PresentationDemoEntityID, ToSIC_SexyContent_Templates.Temp_ListContentTypeID, 
                         ToSIC_SexyContent_Templates.Temp_ListContentDemoEntityID, ToSIC_SexyContent_Templates.Temp_ListPresentationTypeID, 
                         ToSIC_SexyContent_Templates.Temp_ListPresentationDemoEntityID, ToSIC_SexyContent_Templates.Temp_NewTemplateGuid, ToSIC_EAV_Apps.ZoneID, 
                         ToSIC_EAV_Entities_1.EntityGUID AS ContentDemoEntityGuid, ToSIC_EAV_Entities_2.EntityGUID AS PresentationDemoEntityGuid, 
                         ToSIC_EAV_Entities_3.EntityGUID AS ListContentDemoEntityGuid, ToSIC_EAV_Entities_4.EntityGUID AS ListPresentationDemoEntityGuid, 
                         ToSIC_EAV_Entities.EntityGUID AS PipelineEntityGuid
FROM            ToSIC_SexyContent_Templates INNER JOIN
                         ToSIC_EAV_Apps ON ToSIC_SexyContent_Templates.AppID = ToSIC_EAV_Apps.AppID LEFT OUTER JOIN
                         ToSIC_EAV_Entities ON ToSIC_SexyContent_Templates.PipelineEntityID = ToSIC_EAV_Entities.EntityID LEFT OUTER JOIN
                         ToSIC_EAV_Entities AS ToSIC_EAV_Entities_3 ON ToSIC_SexyContent_Templates.Temp_ListContentDemoEntityID = ToSIC_EAV_Entities_3.EntityID LEFT OUTER JOIN
                         ToSIC_EAV_Entities AS ToSIC_EAV_Entities_1 ON ToSIC_SexyContent_Templates.DemoEntityID = ToSIC_EAV_Entities_1.EntityID LEFT OUTER JOIN
                         ToSIC_EAV_Entities AS ToSIC_EAV_Entities_2 ON 
                         ToSIC_SexyContent_Templates.Temp_PresentationDemoEntityID = ToSIC_EAV_Entities_2.EntityID LEFT OUTER JOIN
                         ToSIC_EAV_Entities AS ToSIC_EAV_Entities_4 ON ToSIC_SexyContent_Templates.Temp_ListPresentationDemoEntityID = ToSIC_EAV_Entities_4.EntityID
WHERE        (ToSIC_SexyContent_Templates.SysDeleted IS NULL) AND ((SELECT COUNT(*) FROM ToSIC_EAV_Entities WHERE EntityGUID = ToSIC_SexyContent_Templates.Temp_NewTemplateGuid) = 0)";

            var adapter = new SqlDataAdapter(sqlCommand, sqlConnection);
            adapter.SelectCommand.CommandTimeout = 3600;
            adapter.Fill(templates);

            var existingTemplates = templates.AsEnumerable().Select(t =>
            {
                var templateId = (int)t["TemplateID"];
                var zoneId     = (int)t["ZoneID"];
                var appId      = (int)t["AppID"];
                var cache      = ((BaseCache)DataSource.GetCache(zoneId, appId)).GetContentTypes();

                #region Helper Functions
                Func <int?, string> getContentTypeStaticName = contentTypeId =>
                {
                    if (!contentTypeId.HasValue || contentTypeId == 0)
                    {
                        return("");
                    }
                    if (cache.Any(c => c.Value.AttributeSetId == contentTypeId))
                    {
                        return(cache[contentTypeId.Value].StaticName);
                    }
                    return("");
                };

                #endregion

                // Create anonymous object to validate the types
                var tempTemplate = new
                {
                    TemplateID    = templateId,
                    Name          = (string)t["Name"],
                    Path          = (string)t["Path"],
                    NewEntityGuid = Guid.Parse((string)t["Temp_NewTemplateGuid"]),
                    //AlreadyImported = t["Temp_NewTemplateGuid"] != DBNull.Value,

                    ContentTypeId          = getContentTypeStaticName(t["AttributeSetID"] == DBNull.Value ? new int?() : (int)t["AttributeSetID"]),
                    ContentDemoEntityGuids = t["ContentDemoEntityGuid"] == DBNull.Value ? new List <Guid>() : new List <Guid> {
                        (Guid)t["ContentDemoEntityGuid"]
                    },
                    PresentationTypeId          = getContentTypeStaticName((int)t["Temp_PresentationTypeID"]),
                    PresentationDemoEntityGuids = t["PresentationDemoEntityGuid"] == DBNull.Value ? new List <Guid>() : new List <Guid> {
                        (Guid)t["PresentationDemoEntityGuid"]
                    },
                    ListContentTypeId          = getContentTypeStaticName((int)t["Temp_ListContentTypeID"]),
                    ListContentDemoEntityGuids = t["ListContentDemoEntityGuid"] == DBNull.Value ? new List <Guid>() : new List <Guid> {
                        (Guid)t["ListContentDemoEntityGuid"]
                    },
                    ListPresentationTypeId          = getContentTypeStaticName((int)t["Temp_ListPresentationTypeID"]),
                    ListPresentationDemoEntityGuids = t["ListPresentationDemoEntityGuid"] == DBNull.Value ? new List <Guid>() : new List <Guid> {
                        (Guid)t["ListPresentationDemoEntityGuid"]
                    },

                    Type                = (string)t["Type"],
                    IsHidden            = (bool)t["IsHidden"],
                    Location            = (string)t["Location"],
                    UseForList          = (bool)t["UseForList"],
                    AppId               = appId,
                    PublishData         = (bool)t["PublishData"],
                    StreamsToPublish    = (string)t["StreamsToPublish"],
                    PipelineEntityGuids = t["PipelineEntityGuid"] == DBNull.Value ? new List <Guid>() : new List <Guid> {
                        (Guid)t["PipelineEntityGuid"]
                    },
                    ViewNameInUrl = t["ViewNameInUrl"].ToString(),
                    ZoneId        = zoneId
                };

                return(tempTemplate);
            }).ToList();

            #endregion


            #region Prepare ContentGroups
            logger.LogStep("07.00.00", "2. Prepare Content Groups", false);

            var          contentGroupItemsTable  = new DataTable();
            const string sqlCommandContentGroups = @"SELECT DISTINCT        ToSIC_SexyContent_ContentGroupItems.ContentGroupItemID, ToSIC_SexyContent_ContentGroupItems.ContentGroupID, 
                         ToSIC_SexyContent_ContentGroupItems.TemplateID, ToSIC_SexyContent_ContentGroupItems.SortOrder, ToSIC_SexyContent_ContentGroupItems.Type, 
                         ToSIC_SexyContent_ContentGroupItems.SysCreated, ToSIC_SexyContent_ContentGroupItems.SysCreatedBy, ToSIC_SexyContent_ContentGroupItems.SysModified, 
                         ToSIC_SexyContent_ContentGroupItems.SysModifiedBy, ToSIC_SexyContent_ContentGroupItems.SysDeleted, 
                         ToSIC_SexyContent_ContentGroupItems.SysDeletedBy, ToSIC_SexyContent_Templates.AppID, ToSIC_EAV_Apps.ZoneID, 
                         ToSIC_EAV_Entities.EntityGUID, ToSIC_SexyContent_ContentGroupItems.EntityID, ToSIC_SexyContent_ContentGroupItems.Temp_NewContentGroupGuid, ToSIC_SexyContent_Templates.Temp_NewTemplateGuid
FROM            ToSIC_SexyContent_Templates INNER JOIN
                         ModuleSettings INNER JOIN
                         ToSIC_SexyContent_ContentGroupItems ON ModuleSettings.SettingValue = ToSIC_SexyContent_ContentGroupItems.ContentGroupID ON 
                         ToSIC_SexyContent_Templates.TemplateID = ToSIC_SexyContent_ContentGroupItems.TemplateID INNER JOIN
                         ToSIC_EAV_Apps ON ToSIC_SexyContent_Templates.AppID = ToSIC_EAV_Apps.AppID LEFT OUTER JOIN
                         ToSIC_EAV_Entities ON ToSIC_SexyContent_ContentGroupItems.EntityID = ToSIC_EAV_Entities.EntityID
WHERE        (ToSIC_SexyContent_ContentGroupItems.SysDeleted IS NULL) AND (ModuleSettings.SettingName = N'ContentGroupID') AND 
                         ((SELECT COUNT(*) FROM ToSIC_EAV_Entities WHERE EntityGUID = ToSIC_SexyContent_ContentGroupItems.Temp_NewContentGroupGuid) = 0) ORDER BY SortOrder";

            var adapterContentGroups = new SqlDataAdapter(sqlCommandContentGroups, sqlConnection);
            adapterContentGroups.SelectCommand.CommandTimeout = 3600;
            adapterContentGroups.Fill(contentGroupItemsTable);

            var contentGroupItems = contentGroupItemsTable.AsEnumerable().Select(c => new
            {
                ContentGroupId      = (int)c["ContentGroupID"],
                NewContentGroupGuid = Guid.Parse((string)c["Temp_NewContentGroupGuid"]),
                EntityId            = c["EntityID"] == DBNull.Value ? new int?() : (int)c["EntityID"],
                EntityGuid          = c["EntityGUID"] == DBNull.Value ? (Guid?)null : ((Guid)c["EntityGUID"]),
                TemplateId          = c["TemplateID"] == DBNull.Value ? new int?() : (int)c["TemplateID"],
                SortOrder           = (int)c["SortOrder"],
                Type   = (string)c["Type"],
                AppId  = (int)c["AppID"],
                ZoneId = (int)c["ZoneID"],
                TemplateEntityGuids = new List <Guid>()
                {
                    Guid.Parse((string)c["Temp_NewTemplateGuid"])
                }
            });

            var existingContentGroups = contentGroupItems.GroupBy(c => c.ContentGroupId, c => c, (id, items) =>
            {
                var itemsList    = items.ToList();
                var contentGroup = new
                {
                    NewEntityGuid = itemsList.First().NewContentGroupGuid,
                    itemsList.First().AppId,
                    itemsList.First().ZoneId,
                    ContentGroupId        = id,
                    TemplateGuids         = itemsList.First().TemplateEntityGuids,
                    ContentGuids          = itemsList.Where(p => p.Type == "Content").Select(p => p.EntityGuid).ToList(),
                    PresentationGuids     = itemsList.Where(p => p.Type == "Presentation").Select(p => p.EntityGuid).ToList(),
                    ListContentGuids      = itemsList.Where(p => p.Type == "ListContent").Select(p => p.EntityGuid).ToList(),
                    ListPresentationGuids = itemsList.Where(p => p.Type == "ListPresentation").Select(p => p.EntityGuid).ToList()
                };
                return(contentGroup);
            }).ToList();

            #endregion


            // Import all entities
            logger.LogStep("07.00.00", "2. Import all entities", false);
            var apps = existingTemplates.Select(p => p.AppId).ToList();
            apps.AddRange(existingContentGroups.Select(p => p.AppId));
            apps = apps.Distinct().ToList();

            foreach (var app in apps)
            {
                logger.LogStep("07.00.00", "Starting to migrate data for app " + app + "...");

                var currentApp       = app;
                var entitiesToImport = new List <ImportEntity>();

                foreach (var t in existingTemplates.Where(t => t.AppId == currentApp))
                {
                    var entity = new ImportEntity
                    {
                        AttributeSetStaticName = "2SexyContent-Template",
                        EntityGuid             = t.NewEntityGuid,
                        IsPublished            = true,
                        AssignmentObjectTypeId = ContentTypeHelpers.AssignmentObjectTypeIDDefault
                    };
                    entity.Values = new Dictionary <string, List <IValueImportModel> >
                    {
                        { "Name", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.Name
                              }
                          } },
                        { "Path", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.Path
                              }
                          } },
                        { "ContentTypeStaticName", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.ContentTypeId
                              }
                          } },
                        { "ContentDemoEntity", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid> >(entity)
                              {
                                  Value = t.ContentDemoEntityGuids
                              }
                          } },
                        { "PresentationTypeStaticName", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.PresentationTypeId
                              }
                          } },
                        { "PresentationDemoEntity", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid> >(entity)
                              {
                                  Value = t.PresentationDemoEntityGuids
                              }
                          } },
                        { "ListContentTypeStaticName", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.ListContentTypeId
                              }
                          } },
                        { "ListContentDemoEntity", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid> >(entity)
                              {
                                  Value = t.ListContentDemoEntityGuids
                              }
                          } },
                        { "ListPresentationTypeStaticName", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.ListPresentationTypeId
                              }
                          } },
                        { "ListPresentationDemoEntity", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid> >(entity)
                              {
                                  Value = t.ListPresentationDemoEntityGuids
                              }
                          } },
                        { "Type", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.Type
                              }
                          } },
                        { "IsHidden", new List <IValueImportModel> {
                              new ValueImportModel <bool?>(entity)
                              {
                                  Value = t.IsHidden
                              }
                          } },
                        { "Location", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.Location
                              }
                          } },
                        { "UseForList", new List <IValueImportModel> {
                              new ValueImportModel <bool?>(entity)
                              {
                                  Value = t.UseForList
                              }
                          } },
                        { "PublishData", new List <IValueImportModel> {
                              new ValueImportModel <bool?>(entity)
                              {
                                  Value = t.PublishData
                              }
                          } },
                        { "StreamsToPublish", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.StreamsToPublish
                              }
                          } },
                        { "Pipeline", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid> >(entity)
                              {
                                  Value = t.PipelineEntityGuids
                              }
                          } },
                        { "ViewNameInUrl", new List <IValueImportModel> {
                              new ValueImportModel <string>(entity)
                              {
                                  Value = t.ViewNameInUrl
                              }
                          } }
                    };
                    entitiesToImport.Add(entity);
                }

                foreach (var t in existingContentGroups.Where(t => t.AppId == app))
                {
                    var entity = new ImportEntity
                    {
                        AttributeSetStaticName = "2SexyContent-ContentGroup",
                        EntityGuid             = t.NewEntityGuid,
                        IsPublished            = true,
                        AssignmentObjectTypeId = ContentTypeHelpers.AssignmentObjectTypeIDDefault
                    };
                    entity.Values = new Dictionary <string, List <IValueImportModel> >
                    {
                        { "Template", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid> >(entity)
                              {
                                  Value = t.TemplateGuids
                              }
                          } },
                        { "Content", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid?> >(entity)
                              {
                                  Value = t.ContentGuids
                              }
                          } },
                        { "Presentation", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid?> >(entity)
                              {
                                  Value = t.PresentationGuids
                              }
                          } },
                        { "ListContent", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid?> >(entity)
                              {
                                  Value = t.ListContentGuids
                              }
                          } },
                        { "ListPresentation", new List <IValueImportModel> {
                              new ValueImportModel <List <Guid?> >(entity)
                              {
                                  Value = t.ListPresentationGuids
                              }
                          } }
                    };
                    entitiesToImport.Add(entity);
                }

                var import = new Eav.Import.Import(null, app, userName);
                import.RunImport(null, entitiesToImport);

                logger.LogStep("07.00.00", "Migrated data for app " + app);
            }
            logger.LogStep("07.00.00", "Done", false);
        }