/// <summary> /// Construct the device by obtainin the device properties and the sub data. /// /// NOTE: /// There is a difference with the device id and the id. /// The id indicates the object id within the windows portable device. /// The device id indicates the object id within the operating system. /// /// The initial id for all windows portable devices is hard coded to "DEVICE" /// </summary> /// <param name="deviceId"></param> public Device(string deviceId, bool withDeviceItems = true) : base("DEVICE") { DeviceId = deviceId; ComDeviceObject = new PortableDeviceClass(); Connect(); IPortableDeviceValues deviceProperties = ExtractDeviceProperties(ComDeviceObject); ContentType = new ContentTypeProperty(deviceProperties); DeviceType = new TypeProperty(deviceProperties); FirmwareVersion = new FirmwareVersionProperty(deviceProperties); FriendlyName = new FriendlyNameProperty(deviceProperties); Manufacturer = new ManufacturerProperty(deviceProperties); Model = new ModelProperty(deviceProperties); Name = new NameProperty(deviceProperties); SerialNumber = new SerialNumberProperty(deviceProperties); if (withDeviceItems == true) { LoadDeviceData(ComDeviceObject); do { System.Threading.Thread.Sleep(100); } while (UtilityHelper.threadList.Count > 0); } Disconnect(); }
private bool IsInFolderList(string objectId, IPortableDeviceContent content) { bool result = false; DeviceContent = content; IPortableDeviceProperties properties; content.Properties(out properties); IPortableDeviceKeyCollection keys; properties.GetSupportedProperties(objectId, out keys); IPortableDeviceValues values; properties.GetValues(objectId, keys, out values); var theContentType = new ContentTypeProperty(values); var theName = new NameProperty(values); if (LoadFolders.Count == 0 || LoadFolders.Contains(theName.Value.ToUpper())) { result = true; } return(result); }
private void GuardAgainstDuplicatePropertyInInheritingContentTypes(ContentTypeProperty property) { if (InheritingContentTypes.Any(t => t.Name.Equals(property.Name))) { throw new ArgumentException(String.Format("The content type {0} has inheriting content types that already contains a property named {1}", Name, property.Name)); } }
private void GuardAgainstDuplicateProperty(ContentTypeProperty property) { if (HasPropertyNamed(property.Name)) { throw new ArgumentException(String.Format("The content type {0} already contains a property named {1}", Name, property.Name)); } }
/// <summary> /// Static constructor. /// </summary> static NListBoxMixedContentExample() { NListBoxMixedContentExampleSchema = NSchema.Create(typeof(NListBoxMixedContentExample), NExampleBase.NExampleBaseSchema); // Properties ContentTypeProperty = NListBoxMixedContentExampleSchema.AddSlot("ContentType", typeof(ENListBoxContentType), defaultContentType); ContentTypeProperty.AddValueChangedCallback(delegate(NNode t, NValueChangeData d) { ((NListBoxMixedContentExample)t).OnContentTypeChanged(d); }); // Designer NListBoxMixedContentExampleSchema.SetMetaUnit(new NDesignerMetaUnit(typeof(NListBoxMixedContentDesigner))); }
public Item(string objectId, IPortableDeviceContent content) : base(objectId) { DeviceContent = content; IPortableDeviceProperties properties; content.Properties(out properties); IPortableDeviceKeyCollection keys; properties.GetSupportedProperties(objectId, out keys); IPortableDeviceValues values; properties.GetValues(objectId, keys, out values); ContentType = new ContentTypeProperty(values); Name = new NameProperty(values); // Only load the sub information if the current object is a folder or functional object. switch (ContentType.Type) { case WindowsPortableDeviceEnumerators.ContentType.FunctionalObject: { //TODO: Replace it back to LoadDeviceItems if not correct LoadDeviceItemsByThread(content); break; } case WindowsPortableDeviceEnumerators.ContentType.Folder: { OriginalFileName = new OriginalFileNameProperty(values); LoadDeviceItems(content); break; } case WindowsPortableDeviceEnumerators.ContentType.Image: case WindowsPortableDeviceEnumerators.ContentType.Video: case WindowsPortableDeviceEnumerators.ContentType.Audio: { OriginalFileName = new OriginalFileNameProperty(values); break; } } }
private ContentTypeProperty AddProperty(ContentTypeProperty property) { GuardAgainstDuplicateProperty(property); GuardAgainstDuplicatePropertyInInheritingContentTypes(property); _properties.Add(property.Name, property); //Tous les type enfants doivent avoir une InheritedContentTypeProperty //Il se peut qu'un type enfant ait déjà une propriété du même nom var inheritingContentTypes = InheritingContentTypes.ToList(); while (inheritingContentTypes.Any()) { inheritingContentTypes.ForEach(c => c.AddInheritedProperty(c.BaseContentType[property.Name])); inheritingContentTypes = inheritingContentTypes.SelectMany(t => t.InheritingContentTypes).ToList(); } return(property); }
/// <summary> /// Construct the device by obtainin the device properties and the sub data. /// /// NOTE: /// There is a difference with the device id and the id. /// The id indicates the object id within the windows portable device. /// The device id indicates the object id within the operating system. /// /// The initial id for all windows portable devices is hard coded to "DEVICE" /// </summary> /// <param name="deviceId"></param> public Device(string deviceId) : base("DEVICE") { DeviceId = deviceId; ComDeviceObject = new PortableDeviceClass(); Connect(); IPortableDeviceValues deviceProperties = ExtractDeviceProperties(ComDeviceObject); ContentType = new ContentTypeProperty(deviceProperties); DeviceType = new TypeProperty(deviceProperties); FirmwareVersion = new FirmwareVersionProperty(deviceProperties); FriendlyName = new FriendlyNameProperty(deviceProperties); Manufacturer = new ManufacturerProperty(deviceProperties); Model = new ModelProperty(deviceProperties); Name = new NameProperty(deviceProperties); SerialNumber = new SerialNumberProperty(deviceProperties); LoadDeviceData(ComDeviceObject); Disconnect(); }
set => SetValue(ContentTypeProperty, value);
private void ProcessProperty(Item item, ContentProperty propertyData, bool packaging) { ItemProvider propertyItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext); if (propertyData.Value != null) { var items = JsonConvert.DeserializeObject <EmbeddedContentItem[]>(propertyData.Value.ToString()); foreach (EmbeddedContentItem embeddedContent in items) { var contentType = ExecutionContext.DatabasePersistence.RetrieveItem <DocumentType>( new ItemIdentifier(embeddedContent.ContentTypeAlias, ItemProviderIds.documentTypeItemProviderGuid) ); if (contentType == null) { continue; } if (packaging) { item.Dependencies.Add(contentType.UniqueId.ToString(), ItemProviderIds.documentTypeItemProviderGuid); } foreach (KeyValuePair <string, object> property in embeddedContent.Properties.ToList()) { ContentTypeProperty propertyType = contentType.Properties.FirstOrDefault(_ => _.Alias == property.Key); if (propertyType == null) { continue; } var dataType = ExecutionContext.DatabasePersistence.RetrieveItem <DataType>( new ItemIdentifier(propertyType.DataTypeDefinitionId.ToString(), ItemProviderIds.dataTypeItemProviderGuid) ); if (dataType == null) { continue; } var fakeItem = new ContentPropertyData { ItemId = item.ItemId, Name = $"{item.Name} [{EditorAlias}: Nested {dataType.PropertyEditorAlias} ({property.Key})]", Data = new List <ContentProperty> { new ContentProperty { Alias = propertyType.Alias, DataType = propertyType.DataTypeDefinitionId, PropertyEditorAlias = dataType.PropertyEditorAlias, Value = property.Value } } }; if (packaging) { ResolutionManager.Instance.PackagingItem(fakeItem, propertyItemProvider); item.Dependencies.AddRange(fakeItem.Dependencies); item.Resources.AddRange(fakeItem.Resources); } else { ResolutionManager.Instance.ExtractingItem(fakeItem, propertyItemProvider); } ContentProperty data = fakeItem.Data?.FirstOrDefault(); if (data != null) { embeddedContent.Properties[property.Key] = data.Value; if (packaging) { item.Dependencies.Add(data.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid); } } } } propertyData.Value = JsonConvert.SerializeObject(items); } }
private void ProcessItemPropertyData(Item item, ContentTypeProperty propertyType, JToken innerContentItem, ItemProvider propertyItemProvider, Action action, Dictionary <string, DataType> resolvedDataTypes) { var value = innerContentItem[propertyType.Alias]; if (value != null) { var dataType = GetDataType(propertyType.DataTypeDefinitionId.ToString(), resolvedDataTypes); // create a 'fake' item for Courier to process var pseudoPropertyDataItem = new ContentPropertyData { ItemId = item.ItemId, Name = string.Format("{0} [{1}: Inner {2} ({3})]", item.Name, this.EditorAlias, dataType.PropertyEditorAlias, propertyType.Alias), Data = new List <ContentProperty> { new ContentProperty { Alias = propertyType.Alias, DataType = dataType.UniqueID, PropertyEditorAlias = dataType.PropertyEditorAlias, Value = value.ToString() } } }; if (action == Action.Packaging) { try { // run the 'fake' item through Courier's data resolvers ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyItemProvider); } catch (Exception ex) { CourierLogHelper.Error <InnerContentPropertyDataResolver>(string.Concat("Error packaging data value: ", pseudoPropertyDataItem.Name), ex); } } else if (action == Action.Extracting) { try { // run the 'fake' item through Courier's data resolvers ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyItemProvider); } catch (Exception ex) { CourierLogHelper.Error <InnerContentPropertyDataResolver>(string.Concat("Error extracting data value: ", pseudoPropertyDataItem.Name), ex); } } // pass up the dependencies and resources item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies); item.Resources.AddRange(pseudoPropertyDataItem.Resources); if (pseudoPropertyDataItem.Data != null && pseudoPropertyDataItem.Data.Any()) { // get the first (and only) property of the pseudo item created above var firstProperty = pseudoPropertyDataItem.Data.FirstOrDefault(); if (firstProperty != null) { // serialize the value of the property var serializedValue = firstProperty.Value as string ?? JsonConvert.SerializeObject(firstProperty.Value); // replace the values on the Inner Content item property with the resolved values innerContentItem[propertyType.Alias] = new JValue(serializedValue); // if packaging - add a dependency for the property's data-type if (action == Action.Packaging) { item.Dependencies.Add(firstProperty.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid); } } } } }