/// <summary> /// Handles the LoadComplete event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void Page_LoadComplete(object sender, EventArgs e) { if (String.Compare(Request.Form["__EVENTTARGET"], CommandManager.GetCurrent(this.Page).ID, false) == 0) { object objArgs = Request.Form["__EVENTARGUMENT"]; if (objArgs != null) { Dictionary <string, object> cmd = new System.Web.Script.Serialization.JavaScriptSerializer().DeserializeObject(objArgs.ToString()) as Dictionary <string, object>; if (cmd != null && cmd.Count > 1) { object cmdName = cmd[_CommandName]; if (String.Compare((string)cmdName, _DoImportCommand, true) == 0) { // process move command Dictionary <string, object> args = cmd[_CommandArguments] as Dictionary <string, object>; if (args != null) { // start import in a new thread string siteId = (string)args["SiteId"]; Guid appId = GetCurrentApplicationId(); ProgressControl1.StartOperation(new System.Threading.ThreadStart(delegate { DoImport(new Guid(siteId), appId); })); } } } } } }
/// <summary> /// Handles the Click event of the btnImport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnImport_Click(object sender, EventArgs e) { Guid appId = AppContext.Current.ApplicationId; // start import in a new thread ProgressControl1.StartOperation(new System.Threading.ThreadStart(delegate { DoImport(appId); })); }
/// <summary> /// Handles the Click event of the btnImport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnImport_Click(object sender, EventArgs e) { string filePath = FilesControl.GetSelectedFilePath(); string mappingFilePath = MappingFilesControl.GetSelectedFilePath(); if (String.IsNullOrEmpty(filePath)) { DisplayErrorMessage("No data file selected."); return; } else { SelectedFilePath = filePath; } if (String.IsNullOrEmpty(mappingFilePath)) { DisplayErrorMessage("No mapping file selected."); return; } else { SelectedMappingFilePath = mappingFilePath; } if (!String.IsNullOrEmpty(ListCatalogs.SelectedValue)) { Guid appId = GetCurrentApplicationId(); // start import in a new thread ProgressControl1.StartOperation(new System.Threading.ThreadStart(delegate { DoImport(appId); })); } }
/// <summary> /// Does the export. /// </summary> private void DoExport(Guid appId) { AppContext.Current.ApplicationId = appId; try { string result = String.Empty; if (SiteId != Guid.Empty) { // export site StringBuilder filePath = new StringBuilder(Server.MapPath(ManagementHelper.GetImportExportFolderPath("site"))); filePath.AppendFormat("\\SiteExport_{0}_{1}_{2}.xml", SiteName.Replace(' ', '-'), DateTime.Now.ToString("yyyyMMdd_HHmmss"), System.Environment.MachineName); FileStream fs = new FileStream(filePath.ToString(), FileMode.Create, FileAccess.ReadWrite); try { PageDocument.Init(new SqlPageDocumentStorageProvider(), new SqlTemporaryStorageProvider()); _ImportExport = new Mediachase.Cms.ImportExport.ImportExportHelper(); _ImportExport.ImportExportProgressMessage += new SiteImportExportProgressMessageHandler(ImportExport_ImportExportProgressMessage); _ImportExport.ExportSite(SiteId, fs); } catch (SiteImportExportException ex) { throw ex; } finally { if (fs != null) { fs.Close(); } // refresh files grid //FilesControl.DataBind(); //FilesPanel.Update(); } } else { throw new Exception("SiteId is empty!"); } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, -1); } finally { } }
protected void Page_Load(object sender, EventArgs e) { //ddlObjectName.Items.Insert(0, new ListItem("Please Select...", "-1")); Task.Factory.StartNew(() => { for (int i = 0; i <= 10; i++) { ProgressControl1.AddEvent(10, i); Thread.Sleep(1000); } }); }
/// <summary> /// Processes the rebuild button event. /// </summary> protected void ProcessRebuildButtonEvent(bool rebuild) { _SearchManager = new Mediachase.Search.SearchManager(AppContext.Current.ApplicationName); // start export in a new thread if (rebuild) { ProgressControl1.StartOperation(new System.Threading.ThreadStart(StartIndexing)); } else { ProgressControl1.StartOperation(new System.Threading.ThreadStart(StartIndexing2)); } }
/// <summary> /// Processes the import button event. /// </summary> protected void DoImport() { // save current MetaDataContext MetaDataContext currentContext = OrderContext.MetaDataContext; try { string filePath = SelectedFilePath; if (String.IsNullOrEmpty(filePath)) { throw new Exception("No selected file."); } // import taxes try { _ImportExport.ImportExportProgressMessage += new Mediachase.Commerce.Orders.ImportExport.TaxImportExportProgressMessageHandler(ImportExport_ImportExportProgressMessage); // perform import operation _ImportExport.Import(SelectedFilePath, GetCurrentApplicationId(), null, ','); SelectedFilePath = null; } catch (Mediachase.Commerce.Orders.ImportExport.OrdersImportExportException ex) { throw ex; } catch (Exception ex1) { throw ex1; } finally { } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, -1); } finally { } }
private void DoImport(Guid siteId, Guid appId) { try { AppContext.Current.ApplicationId = appId; _ImportExport = new Mediachase.Cms.ImportExport.ImportExportHelper(); //ImportExportHelper.Current; string filePath = SelectedFilePath; if (String.IsNullOrEmpty(filePath)) { throw new Exception("No selected file."); } // import site FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); try { _ImportExport.ImportExportProgressMessage += new SiteImportExportProgressMessageHandler(ImportExport_ImportExportProgressMessage); _ImportExport.ImportSite(fs, appId, siteId, false); SelectedFilePath = null; } catch (SiteImportExportException ex) { throw ex; } finally { if (fs != null) { fs.Close(); } } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, -1); } finally { } }
private void StartIndexing2() { try { string result = String.Empty; _SearchManager.SearchIndexMessage += new Mediachase.Search.SearchIndexHandler(_SearchManager_SearchIndexMessage); _SearchManager.BuildIndex(false); // set status to 100, meaning that operation completed //Session[_ProgressStatus] = 100; } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, -1); } finally { } }
/// <summary> /// Handles the Click event of the btnImport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnImport_Click(object sender, EventArgs e) { _ImportExport = new Mediachase.Cms.ImportExport.ImportExportHelper(); //ImportExportHelper.Current; Guid appId = GetCurrentApplicationId(); string filePath = SelectedFilePath; if (String.IsNullOrEmpty(filePath)) { throw new Exception("No selected file."); } // import site FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); Guid siteId = _ImportExport.GetSiteID(fs, appId); SiteDto sites = CMSContext.Current.GetSitesDto(appId); if (sites.Site.Count > 0) { CommandParameters cp = new CommandParameters("cmdShowDialogSiteImportConfirm"); Dictionary <string, string> dic = new Dictionary <string, string>(); if (!siteId.Equals(Guid.Empty)) { dic["SiteId"] = siteId.ToString(); } cp.CommandArguments = dic; string cmd = CommandManager.GetCommandString("cmdShowDialogSiteImportConfirm", dic); cmd = cmd.Replace("\"", """); Mediachase.Ibn.Web.UI.WebControls.ClientScript.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString("N"), cmd, true); return; } // start import in a new thread ProgressControl1.StartOperation(new System.Threading.ThreadStart(delegate { DoImport(new Guid(), appId); })); }
/// <summary> /// Handles the Click event of the btnImport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnImport_Click(object sender, EventArgs e) { // start import in a new thread ProgressControl1.StartOperation(new System.Threading.ThreadStart(DoImport)); }
/// <summary> /// Imports the export_ import export progress message. /// </summary> /// <param name="sender"></param> /// <param name="args">The <see cref="Mediachase.Commerce.Orders.ImportExport.TaxImportExportEventArgs"/> instance containing the event data.</param> void ImportExport_ImportExportProgressMessage(object sender, TaxImportExportEventArgs args) { ProgressControl1.AddProgressMessageText(args.Message, false, Convert.ToInt32(args.CompletedPercentage)); }
/// <summary> /// Handles the SearchIndexMessage event of the _SearchManager control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="args">The <see cref="Mediachase.Search.SearchIndexEventArgs"/> instance containing the event data.</param> void _SearchManager_SearchIndexMessage(object source, Mediachase.Search.SearchIndexEventArgs args) { ProgressControl1.AddProgressMessageText(args.Message, false, Convert.ToInt32(args.CompletedPercentage)); }
/// <summary> /// Processes the import button event. /// </summary> protected void DoImport(Guid appId) { AppContext.Current.ApplicationId = appId; try { string filePath = SelectedFilePath; string mappingFilePath = SelectedMappingFilePath; if (String.IsNullOrEmpty(filePath)) { throw new Exception("No selected file."); } if (!String.IsNullOrEmpty(mappingFilePath)) { MetaDataPlus.Import.Rule mapping = MetaDataPlus.Import.Rule.XmlDeserialize(CatalogContext.MetaDataContext, mappingFilePath); char chTextQualifier = '\0'; if (mapping.Attribute["TextQualifier"].ToString() != "") { chTextQualifier = char.Parse(mapping.Attribute["TextQualifier"]); } string sEncoding = "Default"; try { sEncoding = mapping.Attribute["Encoding"]; } catch { } IIncomingDataParser parser = null; DataSet rawData = null; try { parser = new CsvIncomingDataParser(SourcePath, true, char.Parse(mapping.Attribute["Delimiter"].ToString()), chTextQualifier, true, GetEncoding(sEncoding)); rawData = parser.Parse(Path.GetFileName(filePath), null); } catch (Exception ex) { throw ex; } DataTable dtSource = rawData.Tables[0]; MappingMetaClass mc = null; try { int CatalogId = 0; FillResult fr = null; switch (mapping.Attribute["TypeName"]) { case "Category": if (!String.IsNullOrEmpty(ListCatalogs.SelectedValue)) { CatalogId = Int32.Parse(ListCatalogs.SelectedValue); } CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = mapping.Attribute["Language"]; mc = new CategoryMappingMetaClass(CatalogContext.MetaDataContext, mapping.ClassName, CatalogId); fr = ((CategoryMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); CatalogContext.MetaDataContext.UseCurrentUICulture = true; break; case "Entry": if (!String.IsNullOrEmpty(ListCatalogs.SelectedValue)) { CatalogId = Int32.Parse(ListCatalogs.SelectedValue); } CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = mapping.Attribute["Language"]; mc = new EntryMappingMetaClass(CatalogContext.MetaDataContext, mapping.ClassName, CatalogId); fr = ((EntryMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); CatalogContext.MetaDataContext.UseCurrentUICulture = true; break; case "EntryRelation": mc = new EntryRelationMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((EntryRelationMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; case "EntryAssociation": mc = new EntryAssociationMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((EntryAssociationMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; case "Variation": mc = new VariationMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((VariationMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; case "SalePrice": mc = new PricingMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((PricingMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; } if (fr != null) { if (fr.ErrorRows > 0) { foreach (Exception expt in fr.Exceptions) { string exMessage = expt.Message; if (expt is MDPImportException) { MDPImportException mdpEx = (MDPImportException)expt; if (mdpEx.RowIndex > -1) { exMessage = String.Format("Import error. Line {0}: {1}", mdpEx.RowIndex + 1, exMessage); } } ProgressControl1.AddProgressMessageText(exMessage, true, 0); } } if (fr.Warnings.Length > 0) { foreach (MDPImportWarning MDPWarn in fr.Warnings) { ProgressControl1.AddProgressMessageText(String.Format("Line {0}: {1}", MDPWarn.RowIndex + 1, MDPWarn.Message), false, 0); } } string msgSuccessful = RM.GetString("IMPORT_MSG_SUCCESSFUL") + ". " + string.Format(RM.GetString("IMPORT_MSG_RESULT"), fr.SuccessfulRows.ToString(), fr.TotalRows.ToString()); ProgressControl1.AddProgressMessageText(msgSuccessful, false, 100); } } catch (Exception ex) { throw ex; } } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, 100); } finally { } }
/// <summary> /// Processes the export button event. /// </summary> protected void DoExport(Guid appId) { AppContext.Current.ApplicationId = appId; try { if (!String.IsNullOrEmpty(CatalogName)) { // export site StringBuilder sbDirName = new StringBuilder(Path.GetTempPath()); sbDirName.AppendFormat("CatalogExport_{0}_{1}_{2}", AppId, CatalogName, DateTime.Now.ToString("yyyyMMdd-HHmmss")); string dirName = sbDirName.ToString(); if (Directory.Exists(dirName)) { Directory.Delete(dirName, true); } DirectoryInfo dir = Directory.CreateDirectory(dirName); string zipPath = Path.Combine(_CurrentHttpContext.Server.MapPath(ManagementHelper.GetImportExportFolderPath("catalog")), dir.Name); StringBuilder filePath = new StringBuilder(dir.FullName); filePath.AppendFormat("\\Catalog.xml"); FileStream fs = new FileStream(filePath.ToString(), FileMode.Create, FileAccess.ReadWrite); try { _ImportExport.ImportExportProgressMessage += new Mediachase.Commerce.Catalog.ImportExport.ImportExportProgressMessageHandler(ImportExport_ImportExportProgressMessage); int startTime = Environment.TickCount; _ImportExport.Export(CatalogName, fs, Path.Combine(_CurrentHttpContext.Server.MapPath(ManagementHelper.GetImportExportFolderPath("catalog")), dirName));//dir.FullName); if (fs != null) { fs.Close(); fs = null; } ProgressControl1.AddProgressMessageText("Creating zip file.", 99); ZipHelper.CreateZip(dir.FullName, String.Concat(zipPath, ".zip")); ProgressControl1.AddProgressMessageText("Finished.", 100); } catch (Mediachase.Commerce.Catalog.ImportExport.ImportExportException ex) { throw ex; } catch (Exception ex1) { throw ex1; } finally { if (fs != null) { fs.Close(); } // delete temporary folder if (Directory.Exists(dir.FullName)) { Directory.Delete(dir.FullName, true); } } } // if (!String.IsNullOrEmpty(CatalogName)) else { throw new Exception("CatalogName is empty!"); } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, -1); } finally { } }
/// <summary> /// Processes the import button event. /// </summary> protected void DoImport(Guid appId) { AppContext.Current.ApplicationId = appId; // save current MetaDataContext MetaDataContext currentContext = null; try { // set md context if (String.Compare(AppId, "Catalog", true) == 0) { currentContext = Mediachase.Commerce.Catalog.CatalogContext.MetaDataContext; } else if (String.Compare(AppId, "Order", true) == 0) { currentContext = Orders.OrderContext.MetaDataContext; } else if (String.Compare(AppId, "Profile", true) == 0) { currentContext = Mediachase.Commerce.Profile.ProfileContext.MetaDataContext; } if (currentContext == null) { throw new ArgumentNullException("currentContext"); } string filePath = SelectedFilePath; if (String.IsNullOrEmpty(filePath)) { throw new Exception("No selected file."); } // import try { // perform import operation ProgressControl1.AddProgressMessageText("Starting import.", 0); MetaInstaller.RestoreFromFile(currentContext, SelectedFilePath); SelectedFilePath = null; ProgressControl1.AddProgressMessageText("Import completed successfully.", 100); } catch (Exception ex) { throw ex; } finally { } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, -1); } finally { } }
/// <summary> /// Processes the import button event. /// </summary> protected void DoImport(Guid appId) { AppContext.Current.ApplicationId = appId; // save current MetaDataContext MetaDataContext currentContext = CatalogContext.MetaDataContext; try { string filePath = SelectedFilePath; if (String.IsNullOrEmpty(filePath)) { throw new Exception("No selected file."); } // import site ProgressControl1.AddProgressMessageText("Preparing to unpack zip file.", false, 0); // get folder name where to extract files from uploaded zip archive StringBuilder sbDirName = new StringBuilder(Path.GetTempPath()); sbDirName.Append(Path.GetFileNameWithoutExtension(filePath)); string destDir = sbDirName.ToString(); // delete folder if it already exists if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } DirectoryInfo dir = Directory.CreateDirectory(destDir); // unpack archive ZipHelper.ExtractZip(filePath, dir.FullName); ProgressControl1.AddProgressMessageText("Unpacked zip file.", false, 0); FileStream fs = new FileStream(Path.Combine(dir.FullName, "Catalog.xml"), FileMode.Open, FileAccess.Read); try { _ImportExport.ImportExportProgressMessage += new Mediachase.Commerce.Catalog.ImportExport.ImportExportProgressMessageHandler(ImportExport_ImportExportProgressMessage); // perform import operation _ImportExport.Import(fs, appId, dir.FullName); if (fs != null) { fs.Close(); fs = null; } SelectedFilePath = null; } catch (Mediachase.Commerce.Catalog.ImportExport.ImportExportException ex) { throw ex; } catch (Exception ex1) { throw ex1; } finally { if (fs != null) { fs.Close(); } // delete temporary folder if (Directory.Exists(dir.FullName)) { Directory.Delete(dir.FullName, true); } } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, -1); } finally { } }