public void Importer_can_send_ImportItem_with_xml_body_in_request_doc() { // Arrange var dekiApiUri = new XUri("http://mock/@api/deki"); var importManifest = new XDoc("manifest"); var item1Uri = dekiApiUri.At("foo", "bar", "abc"); var importResponse = new XDoc("requests"); var mock = MockPlug.Register(dekiApiUri); mock.Expect().Verb("POST").Uri(dekiApiUri.At("site", "import").With("relto", "0")).RequestDocument(importManifest).Response(DreamMessage.Ok(importResponse)); mock.Expect().Verb("POST").Uri(item1Uri).RequestDocument(new XDoc("item1").Elem("foo", "bar")); // Act Importer importer = Importer.CreateAsync(Plug.New(dekiApiUri), importManifest, 0, new Result <Importer>()).Wait(); var item1 = new ImportItem( "abc", new XDoc("request") .Attr("method", "POST") .Attr("dataid", "abc") .Attr("href", item1Uri) .Start("body") .Attr("type", "xml") .Start("item1").Elem("foo", "bar").End() .End(), new XDoc("manifest"), null, 0); importer.WriteDataAsync(item1, new Result()).Wait(); //Assert Assert.IsTrue(mock.WaitAndVerify(TimeSpan.FromSeconds(1))); }
public void StartImportItem(string itemId, int version, string userId) { ImportItem itemEntity = new ImportItem(); itemEntity.Id = itemId; itemEntity.ImportState = ImportorEnumerations.ImportState.Importing; itemEntity.StartDateTime = DateTime.Now; itemEntity.LastUpdateDate = DateTime.Now; itemEntity.LastUpdateUserId = userId; itemEntity.CurrentVersion = version; ImportItemManager manager = new ImportItemManager(); string sqlUpdateItem = manager.GetUpdateSql(itemEntity, "ImportState", "StartDateTime"); #region 执行SQL以修改对象 using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlUpdateItem); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("启动导入宝贝发生异常 - ", ex); } } #endregion }
public List <ImportItem> ParseMediaItem() { var items = new List <ImportItem>(); using (var csv = new CsvReader(new StreamReader(MediaFile.GetMediaStream()), true)) { var fieldCount = csv.FieldCount; var headers = csv.GetFieldHeaders(); while (csv.ReadNextRecord()) { var item = new ImportItem { Title = MediaFile.Name }; for (var i = 0; i < fieldCount; i++) { item.Fields.Add(headers[i], csv[i]); if (headers[i].ToLower() == "title") { item.Title = csv[i]; } } items.Add(item); } } return(items); }
public ImportStatistics(ImportItem item) { this.TotalFileSize = item.Size; this.NumberOfFiles = this.CountFiles(item as ImportFolder); this.NumberOfDirectories = this.CountFolders(item as ImportFolder); this.NumberOfEmptyDirectories = this.CountEmptyDirectories(item as ImportFolder); }
private bool ValidateIfServersExists() { using (logX.loggerX.InfoCall()) { bool allowServerUpdates = false; foreach (UltraListViewItem lvImport in lvImportStatus.Items) { ImportItem importItem = lvImport.Tag as ImportItem; if (importItem == null || lvImport.CheckState != CheckState.Checked) { continue; //skip element } if (!allowServerUpdates) { if (IsServerAlreadyRegistered(importItem.ServerName)) { if ( MsgBox.ShowConfirm(ErrorMsgs.ImportServersCaption, ErrorMsgs.AllowSqlServersUpdate) == DialogResult.No) { return(false); } allowServerUpdates = true; } } ; } return(true); } }
/// <summary> /// Called during an import to obtain the items contained in the data source /// </summary> /// <param name="additionalData">Reserved for passing additional data through. As of December 2016 only the DBid is provided.</param> /// <returns></returns> public ImportItem GetNextItem(Dictionary <AdditionalDataKeys, DescriptiveData> additionalData) { if (m_reader == null) { MessageBox.Show("The reader is null. Something terrible has occurred.", "Formatter Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } List <string> values = new List <string>(); if (m_reader.Peek() > 0) { values = split(m_reader.ReadLine(), '\t'); } m_itemRow++; // Must return null when we're done. A tab delim file is finished when it contains no more values... ImportItem retVal = null; if (values.Count > 0) { retVal = new ImportItem(m_itemRow.ToString(), values); } return(retVal); }
public static void LoadResource(ImportItem importItem) { if (importItem.ContentResourceName != null) { importItem.Content = ResourceUtils.GetResourceAsString(importItem.ContentResourceName); } }
private T GetOrCreateNew <T>(ImportItem importItem) where T : VersionedItemData { var(tcmItemType, fileExtension) = GetItemTypeData(importItem.ItemType); if (importItem.IsDyndleMergedDll) { fileExtension = ".tbbasm"; } string basepath; string organizationalItemURI; if (ItemType.Page.Equals(importItem.ItemType)) { basepath = DyndleStructureGroup.LocationInfo.WebDavUrl; organizationalItemURI = DyndleStructureGroup.Id; } else { basepath = DyndleFolder.LocationInfo.WebDavUrl; organizationalItemURI = DyndleFolder.Id; } string webdavURL = $"{basepath}/{importItem.Name}{fileExtension}"; T itemData = default(T); if (Client.IsExistingObject(webdavURL)) { itemData = Client.CheckOut(webdavURL, true, DefaultReadOptions) as T; } else { itemData = Client.GetDefaultData(tcmItemType, organizationalItemURI, DefaultReadOptions) as T; } return(itemData); }
private string Import(ImportItem importItem) { try { switch (importItem.ItemType) { case ItemType.Schema: return(ImportSchema(importItem)); case ItemType.TemplateBuildingBlock: return(ImportTBB(importItem)); case ItemType.PageTemplate: return(ImportPageTemplate(importItem)); case ItemType.ComponentTemplate: return(ImportComponentTemplate(importItem)); case ItemType.Page: return(ImportPage(importItem)); } } catch (Exception e) { Console.WriteLine(e); } throw new Exception("unhandled item type " + importItem.ItemType); }
private void OnItemDataBinding(object sender, VirtualizingTreeViewItemDataBindingArgs e) { ProjectItem item = e.Item as ProjectItem; if (item != null) { Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = item.Name; ProjectItemView itemView = e.ItemPresenter.GetComponentInChildren <ProjectItemView>(true); itemView.ProjectItem = item; Toggle toogle = e.ItemPresenter.GetComponentInChildren <Toggle>(true); toogle.isOn = m_treeView.IsItemSelected(item); AssetLibraryImportStatus status = e.ItemPresenter.GetComponentInChildren <AssetLibraryImportStatus>(true); if (item is ImportItem) { ImportItem importItem = (ImportItem)item; status.Current = importItem.Status; } else { status.Current = ImportStatus.None; } e.HasChildren = item.Children != null && item.Children.Count > 0; } }
public PmbiDataMap(Database db, string connectionString, Item importItem, ILogger l) : base(db, connectionString, importItem, l) { // Get start path StartPath = ImportItem.GetItemField("Start Path", Logger); // Get template id TemplateId = ImportItem.GetItemField("Template ID", Logger); // Get year Year = ImportItem.GetItemField("Year", Logger); ArticleNumberPrefix = importItem.Fields[ArticleNumberPrefixStr].Value; var val = importItem.Fields[LastArticleNumber].Value; if (string.IsNullOrWhiteSpace(val)) { ArticleNumber = 0; } else { int articleNumber; int.TryParse(importItem.Fields[LastArticleNumber].Value, out articleNumber); ArticleNumber = articleNumber; } }
public CustomItemBase GetImportToTemplate() { CustomItemBase template = null; //check field value string templateID = ImportItem.GetItemField("Import To What Template", Logger); if (string.IsNullOrEmpty(templateID)) { Logger.Log("the 'To What Template' field is not set", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, "Import To What Template"); return(null); } //check template item Item templateItem = ToDB.Items[templateID]; if (templateItem.IsNull()) { Logger.Log("the 'To What Template' item is null", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, "Import To What Template"); return(null); } //determine template item type if ((BranchItem)templateItem != null) { template = (BranchItem)templateItem; } else { template = (TemplateItem)templateItem; } return(template); }
private static ImportItem ParseLine(Int32 line, String data) { ImportItem result = new ImportItem() { Line = line, Data = data }; Int32 offset = ImportParser.IndexOfWhiteSpace(data); if (offset >= 0 && offset < data.Length) { result.Method = data.Substring(0, offset).Trim().Trim('"'); data = data.Substring(offset).TrimStart(); offset = ImportParser.IndexOfWhiteSpace(data); if (offset >= 0 && offset < data.Length) { result.Checksum = data.Substring(0, offset).Trim().Trim('"'); result.FilePath = data.Substring(offset).Trim().Trim('"'); } } return(result); }
public SitecoreDataMap(Database db, string connectionString, Item importItem, ILogger l) : base(db, connectionString, importItem, l) { //get 'from' language ImportFromLanguage = GetImportItemLanguage("Import From Language"); //get recursive setting RecursivelyFetchChildren = ImportItem.GetItemBool("Recursively Fetch Children"); //populate property definitions PropertyDefinitions = GetPropDefinitions(ImportItem); ReferenceFieldDefinitions = GetReferenceFieldDefinitions(importItem); //populate template definitions TemplateMappingDefinitions = GetTemplateDefinitions(ImportItem); ComponentMappingDefinitions = GetComponentDefinitions(ImportItem); ImportRoot = GetImportRootItem(); DeleteOnOverwrite = ImportItem.GetItemBool("Delete On Overwrite"); PreserveChildren = ImportItem.GetItemBool("Preserve Children on Delete"); AllowItemNameMatch = ImportItem.GetItemBool("Allow Item Name Match"); PathRewrites = ImportItem.GetItemField("Path Rewrites", Logger) .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .ToDictionary(s => s.Split(';')[0], s => s.Split(';')[1]); }
public Language GetImportItemLanguage(string fieldName, Database db) { Language l = LanguageManager.DefaultLanguage; //check the field string langID = ImportItem.GetItemField(fieldName, Logger); if (string.IsNullOrEmpty(langID)) { Logger.Log("The 'Import Language' field is not set on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, fieldName); return(l); } //check item Item iLang = db.GetItem(langID); if (iLang.IsNull()) { Logger.Log("The 'Import Language' Item is null on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, fieldName); return(l); } //check language l = LanguageManager.GetLanguage(iLang.Name); if (l == null) { Logger.Log("The 'Import Language' name is not valid on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, fieldName); } return(l); }
public static IEnumerator CoCreatePreviews(ProjectItem[] items, IProject project, IResourcePreviewUtility resourcePreview) { if (resourcePreview == null) { yield break; } for (int i = 0; i < items.Length; ++i) { ImportItem importItem = items[i] as ImportItem; if (importItem != null) { if (importItem.Preview == null && importItem.Object != null) { importItem.Preview = new Preview { ItemID = importItem.ItemID, PreviewData = resourcePreview.CreatePreviewData(importItem.Object) }; } } else { ImportItem assetItem = items[i] as ImportItem; if (assetItem != null) { UnityObject obj; if (project.IsStatic(assetItem)) { if (!project.TryGetFromStaticReferences(assetItem, out obj)) { obj = null; } } else { if (assetItem.Preview == null) { obj = project.FromID <UnityObject>(assetItem.ItemID); } else { obj = null; } } if (obj != null) { assetItem.Preview = new Preview { ItemID = assetItem.ItemID, PreviewData = resourcePreview.CreatePreviewData(obj) }; } } } yield return(new WaitForSeconds(0.01f)); } }
public void Dado_um_item_com_uma_data_de_entrega_vazia_o_mesmo_nao_pode_ser_gerado() { var deliveryDate = new DateTime(0001, 01, 01); var item = new ImportItem(1, "produto 1", deliveryDate, 2, 2000); Assert.AreEqual(item.Invalid, true); }
protected void RaiseItemProcessed(ImportItem item, string location) { if (this.ItemProcessed == null) { return; } this.ItemProcessed((object)this, new ItemProcessedEventArgs(item, location)); }
protected void RaiseItemProcessed(ImportItem item, string location) { if (ItemProcessed != null) { var args = new ItemProcessedEventArgs(item, location); ItemProcessed(this, args); } }
public void Pack_and_unpack_manifest() { // Arrange string directory = Path.Combine(Path.GetTempPath(), StringUtil.CreateAlphaNumericKey(6)); Directory.CreateDirectory(directory); List <XDoc> docs = new List <XDoc>(); docs.Add(new XDoc("doc1").Attr("dataid", "a")); docs.Add(new XDoc("doc2").Attr("dataid", "b")); docs.Add(new XDoc("doc3").Attr("dataid", "c")); List <Tuplet <string, MemoryStream> > data = new List <Tuplet <string, MemoryStream> >(); foreach (XDoc doc in docs) { string id = doc["@dataid"].AsText; data.Add(new Tuplet <string, MemoryStream>(id, new MemoryStream(doc.ToBytes()))); } XDoc manifest = new XDoc("manifest") .Start("page").Attr("dataid", "a").End() .Start("page").Attr("dataid", "b").End() .Start("page").Attr("dataid", "c").End(); // Act using (FilePackageWriter packageWriter = new FilePackageWriter(directory)) { foreach (Tuplet <string, MemoryStream> tuple in data) { var item = new ExportItem(tuple.Item1, tuple.Item2, tuple.Item2.Length, new XDoc("item").Elem("path", "abc")); packageWriter.WriteDataAsync(item, new Result()).Wait(); } packageWriter.WriteManifest(manifest, new Result()).Wait(); } XDoc manifest2; List <XDoc> docs2 = new List <XDoc>(); using (FilePackageReader packageReader = new FilePackageReader(directory)) { manifest2 = packageReader.ReadManifest(new Result <XDoc>()).Wait(); foreach (XDoc id in manifest2["*/@dataid"]) { using (ImportItem item = packageReader.ReadData(new ImportItem(id.AsText, null, null), new Result <ImportItem>()).Wait()) { using (StreamReader reader = new StreamReader(item.Data)) { docs2.Add(XDocFactory.From(reader, MimeType.TEXT_XML)); } } } } // Assert Assert.IsTrue(File.Exists(Path.Combine(directory, "package.xml"))); Assert.AreEqual(ToCanonical(manifest), ToCanonical(manifest2)); Assert.AreEqual(docs.Count, docs2.Count); foreach (var doc in docs) { Assert.IsTrue(docs2.Select(x => x == doc).Any()); } }
protected IEnumerable <Item> GetImportedArticles() { var templateId = ImportItem.GetItemField("Import To What Template", Logger); var articles = ImportToWhere.Axes.GetDescendants() .Where(i => i.TemplateID.ToString() == templateId && i.Fields[CreatedDate].Value.Contains(Year)); return(articles); }
private static void DisplayImportStatistics(ImportItem items) { ImportStatistics importStatistics = new ImportStatistics(items); DocumentImporter.log.Info((object)("Number of files: " + (object)importStatistics.NumberOfFiles)); DocumentImporter.log.Info((object)("Number of folders: " + (object)importStatistics.NumberOfDirectories)); DocumentImporter.log.Info((object)("Number of empty folders: " + (object)importStatistics.NumberOfEmptyDirectories)); DocumentImporter.log.Info((object)("Total file size: " + DocumentImporter.GetSizeString(importStatistics.TotalFileSize))); }
public void GenerateModel() { var metadataSchema = new ImportItem() { Name = "Dyndle Metadata Schema", ItemType = ItemType.Schema, ContentResourceName = "DyndleMetadata.xsd" }; }
private static void DisplayImportStatistics(ImportItem items) { var s = new ImportStatistics(items); log.Info("Number of files: " + s.NumberOfFiles); log.Info("Number of folders: " + s.NumberOfDirectories); log.Info("Number of empty folders: " + s.NumberOfEmptyDirectories); log.Info("Total file size: " + GetSizeString(s.TotalFileSize)); }
private string ImportTBB(ImportItem importItem) { importItem.FixPublicationContext(Configuration.DyndleFolder); var templateBuildingBlockData = GetOrCreateNew <TemplateBuildingBlockData>(importItem); templateBuildingBlockData.Title = importItem.Name; templateBuildingBlockData.TemplateType = importItem.TemplateType; if (importItem.IsDyndleMergedDll) { // read the merged dll embedded resource and store it in the workfolder ResourceUtils.StoreResourceOnDisk(ResourceRootPath + "." + DyndleTemplateResourceName, Configuration.WorkFolder, DyndleTemplateResourceName); // get an access token (which is simply the current user var accessToken = Client.GetCurrentUser(); // first, upload the merged DLL with the upload client string pathOnServer = null; using (var uploadClient = CoreserviceClientFactory.GetUploadClient()) { using (FileStream stream = new FileStream(Path.Combine(Configuration.WorkFolder.FullName, DyndleTemplateResourceName), FileMode.Open)) { pathOnServer = uploadClient.UploadBinaryContent(accessToken, stream); } } // if all went well, we now have the path of the DLL on the server if (pathOnServer == null) { throw new Exception("unable to upload file"); } templateBuildingBlockData.BinaryContent = new BinaryContentData(); templateBuildingBlockData.BinaryContent.Filename = DyndleTemplateResourceName; templateBuildingBlockData.BinaryContent.UploadFromFile = pathOnServer; } else { templateBuildingBlockData.Content = importItem.Content; } if (!string.IsNullOrEmpty(importItem.ParameterSchemaId)) { templateBuildingBlockData.ParameterSchema = new LinkToSchemaData() { IdRef = importItem.ParameterSchemaId }; } templateBuildingBlockData = (TemplateBuildingBlockData)Client.Save(templateBuildingBlockData, new ReadOptions()); templateBuildingBlockData = (TemplateBuildingBlockData)Client.CheckIn(templateBuildingBlockData.Id, true, "Dyndle installer", new ReadOptions()); return(templateBuildingBlockData.Id); }
private static void UpdateCredentials(ImportItem itemToImport, Repository repository, string connectionName) { RegisteredServer.UpdateCredentials(repository.ConnectionString, connectionName, itemToImport.UserName, itemToImport.Password, (itemToImport.AuthType == SqlServerAuthenticationType.WindowsAuthentication || itemToImport.AuthType == SqlServerAuthenticationType.AzureADAuthentication) ? "W" : "S", itemToImport.UseSameCredentials ? itemToImport.UserName : itemToImport.WindowsUserName, itemToImport.UseSameCredentials ? itemToImport.Password : itemToImport.WindowsUserPassword); }
public void Remove(ImportItem item) { MessageBoxResult messageBoxResult = MessageBox.Show("Bạn có muốn xóa phần tử này hay không?", "Cảnh báo", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (messageBoxResult == MessageBoxResult.OK) { ImportList.Remove(item); UpdateValue(); } }
public static IEnumerator CoCreatePreviews(ProjectItem[] items, IProject project, IResourcePreviewUtility resourcePreview, Action done = null) { if (resourcePreview == null) { if (done != null) { done(); } yield break; } for (int i = 0; i < items.Length; ++i) { ImportItem importItem = items[i] as ImportItem; if (importItem != null) { if (importItem.Preview == null && importItem.Object != null) { importItem.Preview = new Preview { ItemID = importItem.ItemID, PreviewData = resourcePreview.CreatePreviewData(importItem.Object) }; } } else { AssetItem assetItem = items[i] as AssetItem; if (assetItem != null) { UnityObject obj = null; if (assetItem.Preview == null) { obj = project.FromID <UnityObject>(assetItem.ItemID); } if (obj != null) { assetItem.Preview = new Preview { ItemID = assetItem.ItemID, PreviewData = resourcePreview.CreatePreviewData(obj) }; } } } yield return(new WaitForSeconds(0.01f)); } if (done != null) { done(); } }
public Item CreateItem(ImportItem importItem) { var parentItem = _itemReader.GetItem(ParentItemId); var template = _itemReader.GetTemplateItem(TemplateId); var newItem = parentItem.Add(importItem.Title.ToSitecoreSafeString(), template); _iFieldUpdater.AddFieldsDictionaryToItem(newItem, importItem.Fields); return(newItem); }
public static ImportItem CreateComponentTemplate(ComponentTemplateData componentTemplateData) { var importItem = new ImportItem() { ItemType = ItemType.ComponentTemplate, Name = componentTemplateData.Title, Content = componentTemplateData.Content, SourceId = componentTemplateData.Id }; return(importItem); }
private static ImportItem[] MapColumns(IEnumerable<MappingItem> mappingItems, Dictionary<string, int> csvNamesAndIndexes, string[] csvValues) { List<ImportItem> csvNamesAndValues = new List<ImportItem>(); if (mappingItems != null) { foreach (var mappingItem in mappingItems) { if (mappingItem.CsvColumnName != null && csvNamesAndIndexes.ContainsKey(mappingItem.CsvColumnName)) { int columnIndex = csvNamesAndIndexes[mappingItem.CsvColumnName]; ImportItem importItem = new ImportItem(); importItem.Name = mappingItem.EntityColumnName; importItem.Value = csvValues[columnIndex]; csvNamesAndValues.Add(importItem); } } } return csvNamesAndValues.ToArray(); }
public ImportKey(ImportItem importItem) : this(importItem.CurrentLastName, importItem.CurrentFirstName) { }