public void Assert_results_are_mapped_into_metrics() { var fakes = new[] { new FakeQueryType { Long = 42, Integer = 27, Short = 12, Byte = 255, Decimal = 407.54m, Comment = "Utterly worthless... except for logging", EventTime = DateTime.Now, } }; var sqlQuery = new SqlQuery(typeof (FakeQueryType), new SqlServerQueryAttribute("foo.sql", "Fake/"), Substitute.For<IDapperWrapper>(), ""); var componentData = new ComponentData(); sqlQuery.AddMetrics(new QueryContext(sqlQuery) {ComponentData = componentData, Results = fakes,}); var expected = new[] {"Fake/Long", "Fake/Integer", "Fake/Short", "Fake/Decimal", "Fake/Byte"}; string[] actual = componentData.Metrics.Keys.ToArray(); Assert.That(actual, Is.EquivalentTo(expected), "Properties discovered and mapped wrong"); }
protected ContentItem(TcmUri itemId, SessionAwareCoreServiceClient client) { ReadOptions = new ReadOptions(); Client = client; Content = (ComponentData) client.Read(itemId, ReadOptions); ContentManager = new ContentManager(Client); }
protected ContentItem(ComponentData content, SessionAwareCoreServiceClient client) { Content = content; Client = client; ReadOptions = new ReadOptions(); ContentManager = new ContentManager(Client); }
/// <summary> /// Initializes a new instance of the <see cref="Component"/> class. /// </summary> /// <param name="client"><see cref="T:TcmCoreService.Client" /></param> /// <param name="componentData"><see cref="T:Tridion.ContentManager.CoreService.Client.ComponentData" /></param> protected Component(Client client, ComponentData componentData) : base(client, componentData) { if (componentData == null) throw new ArgumentNullException("componentData"); mComponentData = componentData; }
public Component DeserializeAndAdd(ComponentData input, GameObject item) { var data = (PlacedItemData) input; var catalogItem = Catalog.GetInstance().GetItemById(data.Id); var component = item.AddComponent<PlacedItem>(); component.CatalogEntry = catalogItem; component.UniqueInSlot = data.Unique; return component; }
public override void LoadData( ComponentData componentData ) { ModelBoneControllerData data = componentData as ModelBoneControllerData; if ( data != null ) { m_boneName = data.BoneName; m_transformType = data.TransformType; m_speed = data.Speed; } }
private static ComponentData GetDelta(ComponentData currentData, ComponentData previousData) { var delta = new ComponentData { Name = currentData.Name, Guid = currentData.Guid, Duration = currentData.Duration }; var commonMetricNames = currentData.Metrics.Select(m => m.Key).Intersect(previousData.Metrics.Select(m => m.Key)); commonMetricNames.ForEach(mn => { var currentVal = currentData.Metrics[mn]; var previousVal = previousData.Metrics[mn]; if (!MetricMapper.IsMetricNumeric(currentVal)) { //Simply add the latest value delta.Metrics.Add(mn, currentVal); } //Add metric as Positive Change, if negative add 0 as value if (currentVal is decimal) { var currentValDecimal = (decimal) currentVal; var previousValDecimal = (decimal) previousVal; var val = 0.0m; if (currentValDecimal >= previousValDecimal) { val = currentValDecimal - previousValDecimal; } _VerboseMetricsLogger.InfoFormat("Generated Delta for Component: {0}; Metric: {1}; Value: {2}", currentData.Name, mn, val); delta.Metrics.Add(mn, val); } else if (currentVal is int) { var currentValInt = (int) currentVal; var previousValInt = (int) previousVal; var val = 0; if (currentValInt >= previousValInt) { val = currentValInt - previousValInt; } _VerboseMetricsLogger.InfoFormat("Generated Delta for Component: {0}; Metric: {1}; Value: {2}", currentData.Name, mn, val); delta.Metrics.Add(mn, val); } }); return delta; }
private MonoBehaviour DeserializeComponent( ComponentData data ) { if( data != null ) { MonoBehaviour component = gameObject.AddComponent( data.type ) as MonoBehaviour; JsonUtility.FromJsonOverwrite( data.data, component ); return component; } return null; }
private ComponentData SerializeComponent( MonoBehaviour component ) { if( component != null ) { ComponentData componentData = new ComponentData( component.GetType(), JsonUtility.ToJson( component ) ); DestroyImmediate( component ); return componentData; } return null; }
public Component DeserializeAndAdd(ComponentData input, GameObject item) { //NOTE: other components should first be added to the gameobject, //Transform is an exception because it is intrinsic to the object //Other implementations should always add the component first: // var component = item.AddComponent<TheComponent>(); // //do stuff with component var data = (TransformData) input; item.transform.position = new Vector3(data.PositionX, data.PositionY, data.PositionZ); item.transform.rotation = Quaternion.Euler(data.RotationX, data.RotationY, data.RotationZ); item.transform.localScale = new Vector3(data.ScaleX, data.ScaleY, data.ScaleZ); return item.transform; }
public static ComponentResult From(ComponentData item, string currentUserId) { var result = new ComponentResult { Schema = LinkEntry.From(item.Schema, Resources.LabelSchema, currentUserId) }; if (item.ComponentType == ComponentType.Multimedia) { if (item.BinaryContent.FileSize != null) { result.FileSize = TextEntry.From(FormatFileSize((long)item.BinaryContent.FileSize), Resources.LabelFileSize); } result.FileName = TextEntry.From(item.BinaryContent.Filename, Resources.LabelFileName); } AddCommonProperties(item, result); AddPropertiesForRepositoryLocalObject(item, result, currentUserId); return result; }
public static CodeGenFile CorrespondingFile(this ComponentData component, CodeGenFile[] codeGenFiles) => codeGenFiles.FirstOrDefault(f => f.fileName.EndsWith($"{component.GetContextNames().First()}{component.ComponentName()}Component.cs"));
public static string[] GetContextNames(this ComponentData data) { return((string[])data[COMPONENT_CONTEXTS]); }
void when_providing() { context["component"] = () => { Type type = null; ComponentData data = null; before = () => { type = typeof(MyNamespaceComponent); data = getData <MyNamespaceComponent>(); }; it["get data"] = () => { data.should_not_be_null(); }; it["gets full type name"] = () => { data.GetFullTypeName().GetType().should_be(typeof(string)); data.GetFullTypeName().should_be(type.ToCompilableString()); }; it["gets contexts"] = () => { var contextNames = data.GetContextNames(); contextNames.GetType().should_be(typeof(string[])); contextNames.Length.should_be(2); contextNames[0].should_be("Test"); contextNames[1].should_be("Test2"); }; it["sets first context as default when component has no context"] = () => { var contextNames = getData <NoContextComponent>().GetContextNames(); contextNames.Length.should_be(1); contextNames[0].should_be("Game"); }; it["gets unique"] = () => { data.IsUnique().GetType().should_be(typeof(bool)); data.IsUnique().should_be_false(); getData <UniqueStandardComponent>().IsUnique().should_be_true(); }; it["gets member data"] = () => { data.GetMemberData().GetType().should_be(typeof(MemberData[])); data.GetMemberData().Length.should_be(1); data.GetMemberData()[0].type.should_be("string"); }; it["gets generate component"] = () => { data.ShouldGenerateComponent().GetType().should_be(typeof(bool)); data.ShouldGenerateComponent().should_be_false(); data.ContainsKey(ShouldGenerateComponentComponentDataExtension.COMPONENT_OBJECT_TYPE).should_be_false(); }; it["gets generate index"] = () => { data.ShouldGenerateIndex().GetType().should_be(typeof(bool)); data.ShouldGenerateIndex().should_be_true(); getData <DontGenerateIndexComponent>().ShouldGenerateIndex().should_be_false(); }; it["gets generate methods"] = () => { data.ShouldGenerateMethods().GetType().should_be(typeof(bool)); data.ShouldGenerateMethods().should_be_true(); getData <DontGenerateMethodsComponent>().ShouldGenerateMethods().should_be_false(); }; it["gets unique prefix"] = () => { data.GetUniquePrefix().GetType().should_be(typeof(string)); data.GetUniquePrefix().should_be("is"); getData <CustomPrefixFlagComponent>().GetUniquePrefix().should_be("My"); }; }; context["non component"] = () => { Type type = null; ComponentData data = null; before = () => { type = typeof(ClassToGenerate); data = getData <ClassToGenerate>(); }; it["get data"] = () => { data.should_not_be_null(); }; it["gets full type name"] = () => { // Not the type, but the component that should be generated // See: no namespace data.GetFullTypeName().should_be("ClassToGenerateComponent"); }; it["gets contexts"] = () => { var contextNames = data.GetContextNames(); contextNames.Length.should_be(2); contextNames[0].should_be("Test"); contextNames[1].should_be("Test2"); }; it["gets unique"] = () => { data.IsUnique().should_be_false(); }; it["gets member data"] = () => { data.GetMemberData().Length.should_be(1); data.GetMemberData()[0].type.should_be(type.ToCompilableString()); }; it["gets generate component"] = () => { data.ShouldGenerateComponent().GetType().should_be(typeof(bool)); data.ShouldGenerateComponent().should_be_true(); data.GetObjectType().should_be(typeof(ClassToGenerate).ToCompilableString()); }; it["gets generate index"] = () => { data.ShouldGenerateIndex().should_be_true(); }; it["gets generate methods"] = () => { data.ShouldGenerateMethods().should_be_true(); }; it["gets unique prefix"] = () => { data.GetUniquePrefix().should_be("is"); }; }; context["multiple types"] = () => { it["creates data for each type"] = () => { var types = new [] { typeof(NameAgeComponent), typeof(Test2ContextComponent) }; var provider = new ComponentDataProvider(types); provider.Configure(new Preferences(new Properties( "Entitas.CodeGeneration.Plugins.Contexts = Game, GameState" ))); var data = provider.GetData(); data.Length.should_be(types.Length); }; }; context["multiple custom component names"] = () => { Type type = null; ComponentData data1 = null; ComponentData data2 = null; before = () => { type = typeof(CustomName); var data = getMultipleData <CustomName>(); data1 = data[0]; data2 = data[1]; }; it["creates data for each custom component name"] = () => { data1.GetObjectType().should_be(type.ToCompilableString()); data2.GetObjectType().should_be(type.ToCompilableString()); data1.GetFullTypeName().should_be("NewCustomNameComponent1Component"); data2.GetFullTypeName().should_be("NewCustomNameComponent2Component"); }; }; context["configure"] = () => { Type type = null; ComponentData data = null; before = () => { var preferences = new Preferences(new Properties( "Entitas.CodeGeneration.Plugins.Contexts = ConfiguredContext" + "\n" )); type = typeof(NoContextComponent); data = getData <NoContextComponent>(preferences); }; it["gets default context"] = () => { var contextNames = data.GetContextNames(); contextNames.Length.should_be(1); contextNames[0].should_be("ConfiguredContext"); }; }; }
private static void AddPropertyCode(MemberData member, CodeGenFile codeGenFile, ComponentData component) { string typeAndName = $" {member.type} {component.ComponentName().UppercaseFirst()}"; string withProperty = $"{ValueAndPropertyStringStart}{typeAndName}{ValueAndPropertyStringEnd}"; ReplaceWithResolvedNames(codeGenFile, component, ValueBaseString, withProperty); }
public Article(ComponentData component, SessionAwareCoreServiceClient client) : base(component, client) { }
public static bool SaveMultimediaComponentFromBinary(MappingInfo mapping, string filePath, string title, string tcmContainer, out string stackTraceMessage) { stackTraceMessage = ""; if (!File.Exists(filePath)) return false; if (!EnsureValidClient(mapping)) return false; if (String.IsNullOrEmpty(title)) title = Path.GetFileName(filePath); if (ExistsItem(mapping, tcmContainer, title) || ExistsItem(mapping, tcmContainer, Path.GetFileNameWithoutExtension(filePath)) || ExistsItem(mapping, tcmContainer, Path.GetFileName(filePath))) { string id = GetItemTcmId(mapping, tcmContainer, title); if (String.IsNullOrEmpty(id)) id = GetItemTcmId(mapping, tcmContainer, Path.GetFileNameWithoutExtension(filePath)); if (String.IsNullOrEmpty(id)) id = GetItemTcmId(mapping, tcmContainer, Path.GetFileName(filePath)); if (String.IsNullOrEmpty(id)) return false; return SaveMultimediaComponentFromBinary(mapping, id, filePath, out stackTraceMessage); } try { BinaryContentData binaryContent = GetBinaryData(mapping, filePath); if (binaryContent == null) return false; string tcmPublication = GetPublicationTcmId(tcmContainer); string schemaId = GetSchemas(mapping, tcmPublication).Single(x => x.Title == "Default Multimedia Schema").TcmId; ComponentData multimediaComponent = new ComponentData { Title = title, LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = tcmContainer } }, Id = "tcm:0-0-0", BinaryContent = binaryContent, ComponentType = ComponentType.Multimedia, Schema = new LinkToSchemaData { IdRef = schemaId }, IsBasedOnMandatorySchema = false, IsBasedOnTridionWebSchema = true, ApprovalStatus = new LinkToApprovalStatusData { IdRef = "tcm:0-0-0" } }; multimediaComponent = Client.Save(multimediaComponent, new ReadOptions()) as ComponentData; if (multimediaComponent == null) return false; Client.CheckIn(multimediaComponent.Id, true, "Saved from TridionVSRazorExtension", new ReadOptions()); return true; } catch (Exception ex) { stackTraceMessage = ex.Message; return false; } }
public LCDDataReader() { brightness = new BrightnessData(); this.currentPowerScheme = PowerSettings.GetActivePowerScheme(); }
public void Provide(Type type, ComponentData data) { data.ShouldGenerateIndex(getGenerateIndex(type)); }
public void ScrollCellToTop(GameObject cell, int animation = 1000) { ScrollCellToTop(ComponentData.Get(cell.transform.parent.gameObject).Id, animation); }
public HardDiskDataReader(string instanceName, string identifier) { this.identifier = identifier; bytesPerSec = new HardDiskIOData(); hdPCounter = new PerformanceCounter("PhysicalDisk", "Disk Bytes/sec", instanceName); }
private string ImportSingleItem(IEclUri eclUri) { string id = "tcm:0-0-0"; IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri); string extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1); MemoryStream ms = null; string tempPath; try { // create some template attributes IList <ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem); // determine if item has content or is available online string publishedPath = eclItem.GetDirectLinkToPublished(attributes); if (string.IsNullOrEmpty(publishedPath)) { // we can directly get the content IContentResult content = eclItem.GetContent(attributes); ms = new MemoryStream(); content.Stream.CopyTo(ms); ms.Position = 0; } else { // read the content from the publish path using (WebClient webClient = new WebClient()) { byte[] thumbnailData = webClient.DownloadData(publishedPath); ms = new MemoryStream(thumbnailData, false); } } // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012")) { tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms); } } finally { if (ms != null) { ms.Dispose(); } } // create tcm item var mmComponent = new ComponentData { Id = id, Title = eclItem.Title, Schema = new LinkToSchemaData { IdRef = _schemaUri }, LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = _folderUri } } }; // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012")) { // impersonate with current user client.Impersonate(_username); // set metadata var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions()); if (schemaFields.MetadataFields.Any()) { var fields = Fields.ForMetadataOf(schemaFields, mmComponent); if (!string.IsNullOrEmpty(eclItem.MetadataXml)) { XNamespace ns = GetNamespace(eclItem.MetadataXml); XDocument metadata = XDocument.Parse(eclItem.MetadataXml); var children = metadata.Element(ns + "Metadata").Descendants(); for (int i = 0; i < children.Count(); i++) { fields.AddFieldElement(new ItemFieldDefinitionData { Name = "data" }); var embeddedFields = fields["data"].GetSubFields(i); embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "key" }); embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "value" }); embeddedFields["key"].Value = children.ElementAt(i).Name.LocalName; embeddedFields["value"].Value = children.ElementAt(i).Value; } } mmComponent.Metadata = fields.ToString(); } // find multimedia type var list = client.GetSystemWideList(new MultimediaTypesFilterData()); var multimediaType = list.OfType <MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension)); // set BinaryContent of a component mmComponent.BinaryContent = new BinaryContentData { UploadFromFile = tempPath, Filename = eclItem.Filename, MultimediaType = new LinkToMultimediaTypeData { IdRef = multimediaType.Id } }; // create (and save) component ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions()); id = data.Id; } //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username); return(id); }
public override void LoadData( ComponentData componentData ) { ModelRenderData data = componentData as ModelRenderData; if ( data != null ) { m_modelName = data.Model; m_localTransform = data.Transform; } }
private string ImportSingleItem(IEclUri eclUri) { string id = "tcm:0-0-0"; IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri); string extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1); MemoryStream ms = null; string tempPath; try { // create some template attributes IList<ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem); // determine if item has content or is available online string publishedPath = eclItem.GetDirectLinkToPublished(attributes); if (string.IsNullOrEmpty(publishedPath)) { // we can directly get the content IContentResult content = eclItem.GetContent(attributes); ms = new MemoryStream(); content.Stream.CopyTo(ms); ms.Position = 0; } else { // read the content from the publish path using (WebClient webClient = new WebClient()) { byte[] thumbnailData = webClient.DownloadData(publishedPath); ms = new MemoryStream(thumbnailData, false); } } // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012")) { tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms); } } finally { if (ms != null) { ms.Dispose(); } } // create tcm item var mmComponent = new ComponentData { Id = id, Title = eclItem.Title, Schema = new LinkToSchemaData { IdRef = _schemaUri }, LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = _folderUri } } }; // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012")) { // impersonate with current user client.Impersonate(_username); // set metadata var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions()); if (schemaFields.MetadataFields.Any()) { var fields = Fields.ForMetadataOf(schemaFields, mmComponent); if (!string.IsNullOrEmpty(eclItem.MetadataXml)) { XNamespace ns = GetNamespace(eclItem.MetadataXml); XDocument metadata = XDocument.Parse(eclItem.MetadataXml); var children = metadata.Element(ns + "Metadata").Descendants(); for (int i = 0; i < children.Count(); i++) { fields.AddFieldElement(new ItemFieldDefinitionData { Name = "data" }); var embeddedFields = fields["data"].GetSubFields(i); embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "key" }); embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "value" }); embeddedFields["key"].Value = children.ElementAt(i).Name.LocalName; embeddedFields["value"].Value = children.ElementAt(i).Value; } } mmComponent.Metadata = fields.ToString(); } // find multimedia type var list = client.GetSystemWideList(new MultimediaTypesFilterData()); var multimediaType = list.OfType<MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension)); // set BinaryContent of a component mmComponent.BinaryContent = new BinaryContentData { UploadFromFile = tempPath, Filename = eclItem.Filename, MultimediaType = new LinkToMultimediaTypeData { IdRef = multimediaType.Id } }; // create (and save) component ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions()); id = data.Id; } //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username); return id; }
public void Provide(Type type, ComponentData data) { data.SetContextNames(GetContextNames(type)); }
private void LoadPersistablesInGameObjectFromComponentData(GameObject gameObject, ComponentData componentData) { foreach (IPersistable persistable in gameObject.GetComponents<IPersistable>()) { SerializableDictionary<string, object> componentConfiguration = componentData.configurations [persistable.GetType ().FullName]; foreach (FieldInfo field in persistable.GetType().GetFields()) { field.SetValue (persistable, componentConfiguration [field.Name]); } } }
public static bool ShouldGenerateIndex(this ComponentData data) { return((bool)data[COMPONENT_GENERATE_INDEX]); }
public void Assert_try_create_mapper_handles_decimal_correctly() { var fake = new FakeQueryType {Decimal = 12.3m}; var componentData = new ComponentData(); var query = new SqlQuery(fake.GetType(), new SqlServerQueryAttribute(null, "Fake"), null, ""); var queryContext = new QueryContext(query) {ComponentData = componentData,}; var mapper = MetricMapper.TryCreate(fake.GetType().GetProperty("Decimal")); Assert.That(mapper, Is.Not.Null, "Mapping Decimal failed"); mapper.AddMetric(queryContext, fake); const string metricKey = "Fake/Decimal"; Assert.That(componentData.Metrics.ContainsKey(metricKey), "Expected metric with correct name to be added"); var condition = componentData.Metrics[metricKey]; Assert.That(condition, Is.EqualTo(fake.Decimal), "Metric not mapped correctly"); }
/// <summary> /// Reload the <see cref="Component" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.ComponentData" /> /// </summary> /// <param name="componentData"><see cref="T:Tridion.ContentManager.CoreService.Client.ComponentData" /></param> protected void Reload(ComponentData componentData) { if (componentData == null) throw new ArgumentNullException("componentData"); mComponentData = componentData; base.Reload(componentData); mApprovalStatus = null; mSchema = null; mBinaryContent = null; mWorkflow = null; }
private static ComponentData CreateComponentDataForFake(object fake, string propertyName) { var componentData = new ComponentData(); var query = new SqlQuery(fake.GetType(), new SqlServerQueryAttribute(null, "Fake"), null, ""); var queryContext = new QueryContext(query) {ComponentData = componentData,}; var metricMapper = new MetricMapper(fake.GetType().GetProperty(propertyName)); metricMapper.AddMetric(queryContext, fake); return componentData; }
protected bool OnConfirmation(ComponentData data) { return true; //return (visualizerService.ShowDialog(data) == true); }
//运行时将控件赋值给lua变量 public static void BindToLua(GameObject obj, LuaTable table) { if (obj == null || table == null) { return; } UIComponentBind bind = obj.GetComponent <UIComponentBind>(); if (bind == null) { return; } bind.CompentsTable = table; table.Set("transform", obj.transform); table.Set("gameObject", obj); for (int i = 0; i < bind.mComponentDataList.Count; i++) { ComponentData data = bind.mComponentDataList[i]; switch (data.type) { case "Button": { table.Set(data.name, data.component as Button); //table[data.name] = data.component as Button; } break; case "Dropdown": { table.Set(data.name, data.component as Dropdown); //table[data.name] = data.component as Dropdown; } break; case "InputField": { table.Set(data.name, data.component as InputField); //table[data.name] = data.component as InputField; } break; case "Slider": { table.Set(data.name, data.component as Slider); //table[data.name] = data.component as Slider; } break; case "Toggle": { table.Set(data.name, data.component as Toggle); //table[data.name] = data.component as Toggle; } break; case "GridLayoutGroup": { table.Set(data.name, data.component as GridLayoutGroup); //table[data.name] = data.component as GridLayoutGroup; } break; case "VerticalLayoutGroup": { table.Set(data.name, data.component as VerticalLayoutGroup); //table[data.name] = data.component as VerticalLayoutGroup; } break; case "HorizontalLayoutGroup": { table.Set(data.name, data.component as HorizontalLayoutGroup); } break; case "LoopVerticalScrollRect": { table.Set(data.name, data.component as LoopVerticalScrollRect); } break; case "LoopHorizontalScrollRect": { table.Set(data.name, data.component as LoopHorizontalScrollRect); } break; case "ScrollRect": { table.Set(data.name, data.component as ScrollRect); //table[data.name] = data.component as ScrollRect; } break; case "Image": { table.Set(data.name, data.component as Image); //table[data.name] = data.component as Image; } break; case "ImageExt": { table.Set(data.name, data.component as ImageExt); //table[data.name] = data.component as ImageExt; } break; case "RawImage": { table.Set(data.name, data.component as RawImage); //table[data.name] = data.component as RawImage; } break; case "RawImageExt": { table.Set(data.name, data.component as RawImageExt); //table[data.name] = data.component as RawImageExt; } break; case "TextMeshProUGUI": { table.Set(data.name, data.component as TextMeshProUGUI); } break; case "Text": { table.Set(data.name, data.component as Text); //table[data.name] = data.component as Text; } break; case "RectTransform": { table.Set(data.name, data.component as RectTransform); //table[data.name] = data.component as RectTransform; } break; case "Transform": { table.Set(data.name, data.component as Transform); //table[data.name] = data.component as Transform; } break; } } }
public virtual void LoadData( ComponentData data ) { }
public static List <PublicMemberInfo> GetMemberInfos(this ComponentData data) { return((List <PublicMemberInfo>)data[COMPONENT_MEMBER_INFOS]); }
/// <summary> /// Apply interpolated values of this Data and the rightData /// to the given target component, using the given interpolation factor. /// </summary> abstract public void ApplyLerp( Component targetComponent, ComponentData rightData, float factor);
public static void SetMemberInfos(this ComponentData data, List <PublicMemberInfo> memberInfos) { data[COMPONENT_MEMBER_INFOS] = memberInfos; }
public static bool IsUniqueAndSingleValueComponent(this ComponentData component, MemberData[] members) => component.IsUnique() && members.Length == 1 && string.Compare(members[0].name, "Value", StringComparison.InvariantCultureIgnoreCase) == 0;
public void Provide(Type type, ComponentData data) { data.SetMemberInfos(type.GetPublicMemberInfos()); }
private void TreeViewItem_Selected(object sender, RoutedEventArgs e) { ItemInfo item = ((TreeViewItem)e.OriginalSource).DataContext as ItemInfo; if (item == null) { return; } //check if item is valid ItemType itemType = MainService.GetItemType(item.TcmId); ItemType templateType = MainService.GetItemType(this.TestTemplateTcmId); if (itemType == ItemType.Component && templateType == ItemType.ComponentTemplate) { ComponentData component = MainService.GetComponent(this.CurrentMapping, item.TcmId); ComponentTemplateData template = MainService.ReadItem(this.CurrentMapping, this.TestTemplateTcmId) as ComponentTemplateData; if (component == null || template == null) { ((TreeViewItem)e.OriginalSource).IsEnabled = false; MessageBox.Show("Selected component is invalid", "Test item", MessageBoxButton.OK, MessageBoxImage.Hand); return; } if (template.RelatedSchemas.All(x => MainService.GetId(x.IdRef) != MainService.GetId(component.Schema.IdRef))) { ((TreeViewItem)e.OriginalSource).IsEnabled = false; MessageBox.Show("Selected component is invalid", "Test item", MessageBoxButton.OK, MessageBoxImage.Hand); return; } } else if (itemType == ItemType.Page && templateType == ItemType.PageTemplate) { PageData page = MainService.ReadItem(this.CurrentMapping, item.TcmId) as PageData; PageTemplateData template = MainService.ReadItem(this.CurrentMapping, this.TestTemplateTcmId) as PageTemplateData; if (page == null || template == null) { ((TreeViewItem)e.OriginalSource).IsEnabled = false; MessageBox.Show("Selected page is invalid", "Test item", MessageBoxButton.OK, MessageBoxImage.Hand); return; } if (MainService.GetId(page.PageTemplate.IdRef) != MainService.GetId(template.Id)) { ((TreeViewItem)e.OriginalSource).IsEnabled = false; MessageBox.Show("Selected page is invalid", "Test item", MessageBoxButton.OK, MessageBoxImage.Hand); return; } } else { return; } this.TestItemTcmId = item.TcmId; List <ItemInfo> list = new List <ItemInfo>(); MainService.AddPathItem(list, item); Common.IsolatedStorage.Service.SaveToIsolatedStorage(Common.IsolatedStorage.Service.GetId("DebugItemPath", this.TbbTcmId, this.TestTemplateTcmId), string.Join("|", list.Select(x => x.TcmId))); this.btnOk.IsEnabled = true; }
public static bool ShouldGenerateMethods(this ComponentData data) { return((bool)data[COMPONENT_GENERATE_METHODS]); }
public static void SetContextNames(this ComponentData data, string[] contextNames) { data[COMPONENT_CONTEXTS] = contextNames; }
public static void ShouldGenerateMethods(this ComponentData data, bool generate) { data[COMPONENT_GENERATE_METHODS] = generate; }
public static (double total, double average) CalculateDifference(ComponentData expected, ComponentData actual) { BigInteger totalDiff = 0; if (actual.WidthInBlocks < expected.WidthInBlocks) { throw new Exception("actual.WidthInBlocks < expected.WidthInBlocks"); } if (actual.HeightInBlocks < expected.HeightInBlocks) { throw new Exception("actual.HeightInBlocks < expected.HeightInBlocks"); } int w = expected.WidthInBlocks; int h = expected.HeightInBlocks; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { Block8x8 aa = expected.SpectralBlocks[x, y]; Block8x8 bb = actual.SpectralBlocks[x, y]; long diff = Block8x8.TotalDifference(ref aa, ref bb); totalDiff += diff; } } int count = w * h; double total = (double)totalDiff; double average = (double)totalDiff / (count * Block8x8.Size); return(total, average); }
void SetAchievementImages(List<ImageFile> imageFileList) { try { AchievementComponents achievementComponent = (AchievementComponents)m_componentManager.GetComponent(new Guid(AchievementGUID)); foreach (ImageFile imageFile in imageFileList) { Achievement achievement = achievementComponent.groupManager.achievementList.Find(x => x.name == imageFile.FileName); if (achievement != null) { string key = imageFile.FileName + "_System.Drawing.Bitmap"; if (!achievementComponent.componentData.ContainsKey(key)) { ComponentData data = new ComponentData(); Bitmap img = (Bitmap)Image.FromFile(imageFile.FullFilePath); MemoryStream ms = new MemoryStream(); img.Save(ms, img.RawFormat); data.dataType = img.GetType(); data.fileName = imageFile.FileName; data.data = ms.ToArray(); achievementComponent.componentData.Add(key, data); achievement.icon = key; } } } achievementComponent.Assemble(); m_componentManager.AddComponents(achievementComponent); } catch(Exception e) { HandleException("SetAchievementImage", e); } }
public static void ShouldGenerateIndex(this ComponentData data, bool generate) { data[COMPONENT_GENERATE_INDEX] = generate; }
private bool ProcessComponent(ComponentData componentData) { XmlDocument componentXml = new XmlDocument(); componentXml.LoadXml(componentData.Metadata); XmlNode rootNode = componentXml.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(componentXml.NameTable); nsmgr.AddNamespace("ns", rootNode.NamespaceURI); XmlNodeList sourceNodes = rootNode.SelectNodes("ns:" + OldField, nsmgr); if (sourceNodes.Count == 0) { return false; } foreach (XmlNode sourceNode in sourceNodes) { RenameNode(sourceNode, rootNode.NamespaceURI, NewField); } Console.WriteLine(Util.PrettyXml(componentXml.OuterXml)); componentData.Metadata = componentXml.OuterXml; return true; }
public void RefreshSlotEmployee(ComponentData componentData) { RemoveAllSlotEmployee(); AddSlotEmployee(componentData); memberPanel.gameObject.SetActive(true); }
public Source(ComponentData content, SessionAwareCoreServiceClient client) : base(content, client) { }
public override void Process(ServiceProcess process, object arguments) { ImageUploadParameters parameters = (ImageUploadParameters)arguments; try { string directory = parameters.Directory; if (!Directory.Exists(directory)) { process.Failed = true; process.Complete(string.Format(CultureInfo.InvariantCulture, "Directory '{0}' does not exist. No images were uploaded!", directory)); return; } string[] files = Directory.GetFiles(directory); int i = 0; _client = PowerTools.Common.CoreService.Client.GetCoreService(); //Get all component titles in the target folder _componentTitles = getAllComponentTitles(parameters.FolderUri); foreach (string file in files) { process.SetStatus("Importing image: " + Path.GetFileName(file)); process.SetCompletePercentage(++i * 100 / files.Length); FileInfo fileInfo = new FileInfo(file); if (fileInfo.Exists) { string mmType = GetMultiMediaType(fileInfo.Extension); if (mmType != null) { BinaryContentData bcd = new BinaryContentData { UploadFromFile = file, MultimediaType = new LinkToMultimediaTypeData { IdRef = mmType }, Filename = file, IsExternal = false }; ComponentData compData = new ComponentData { LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = parameters.FolderUri //Organizational item }, }, ComponentType = ComponentType.Multimedia, Title = MakeValidFileName(fileInfo.Name), Schema = new LinkToSchemaData { IdRef = parameters.SchemaUri //schemaData.IdRef }, IsBasedOnMandatorySchema = false, IsBasedOnTridionWebSchema = true, ApprovalStatus = new LinkToApprovalStatusData { IdRef = "tcm:0-0-0" }, Id = "tcm:0-0-0", BinaryContent = bcd }; ComponentData comp = (ComponentData)_client.Create(compData, new ReadOptions()); } } } process.Complete(); } finally { if (_client != null) { _client.Close(); } } }
public static Fields ForContentOf(SchemaFieldsData _data, ComponentData _component) { return(new Fields(_data, _data.Fields, _component.Content)); }
public bool UploadToTridion(string fileName) { client = PowerTools.Common.CoreService.Client.GetCoreService(); try { string mmType = GetMultiMediaType(Path.GetExtension(fileName)); if (mmType != null) { BinaryContentData bcd = new BinaryContentData { UploadFromFile = fileName, MultimediaType = new LinkToMultimediaTypeData { IdRef = mmType }, Filename = Path.GetFileName(fileName), IsExternal = false }; ComponentData compData = new ComponentData { LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = orgItemUri //Organizational item }, }, ComponentType = ComponentType.Multimedia, Title = MakeValidFileName(Path.GetFileNameWithoutExtension(fileName)), Schema = new LinkToSchemaData { IdRef = schemaUri }, IsBasedOnMandatorySchema = false, IsBasedOnTridionWebSchema = true, ApprovalStatus = new LinkToApprovalStatusData { IdRef = "tcm:0-0-0" }, Id = "tcm:0-0-0", BinaryContent = bcd }; ComponentData comp = (ComponentData)client.Create(compData, new ReadOptions()); return true; } } catch (Exception ex) { string d = ex.Message; } finally { if (client != null) { client.Close(); } } return false; }
public async Task <ChildConfigComponent> InitializeAt(Components.ComponentTree tree, ComponentData data, ProjectSettings settings) { var configPath = new FileInfo(Path.Combine(tree.Path.FullName, $"{data.Name}.childconfig.yml")); if (configPath.Exists) { throw new InvalidOperationException($"You can't add child config {data.Name} at \"{tree.Path.FullName}\". It already exists."); } await Templates.Extract( "childconfig.yml", configPath.FullName, Templates.TemplateType.Infrastructure, ("NAME", TemplateData.SanitizeResourceName(data.Name))); return(await ChildConfigComponent.Init(configPath)); }
public Organization(ComponentData content, SessionAwareCoreServiceClient client) : base(content, client) { }
CodeGenFile[] generateExtensions(ComponentData data) { return(data.GetContextNames() .Select(contextName => generateExtension(contextName, data)) .ToArray()); }
void when_providing() { context["component"] = () => { Type[] types = null; ComponentData[] data = null; ComponentData d = null; before = () => { types = new [] { typeof(MyNamespaceComponent) }; var provider = new ComponentDataProvider(types); data = (ComponentData[])provider.GetData(); d = data[0]; }; it["get data"] = () => { data.Length.should_be(1); }; it["gets component name"] = () => { d.GetComponentName().GetType().should_be(typeof(string)); d.GetComponentName().should_be("MyNamespace"); d.GetFullComponentName().GetType().should_be(typeof(string)); d.GetFullComponentName().should_be("MyNamespaceComponent"); }; it["gets full type name"] = () => { d.GetFullTypeName().GetType().should_be(typeof(string)); d.GetFullTypeName().should_be(types[0].ToCompilableString()); }; it["gets contexts"] = () => { d.GetContextNames().GetType().should_be(typeof(string[])); d.GetContextNames().Length.should_be(2); d.GetContextNames()[0].should_be("Test"); d.GetContextNames()[1].should_be("Test2"); }; it["sets first context as default when component has no context"] = () => { var contextNames = getData <NoContextComponent>().GetContextNames(); contextNames.Length.should_be(1); contextNames[0].should_be("Game"); }; it["gets unique"] = () => { d.IsUnique().GetType().should_be(typeof(bool)); d.IsUnique().should_be_false(); getData <UniqueStandardComponent>().IsUnique().should_be_true(); }; it["gets member data"] = () => { d.GetMemberData().GetType().should_be(typeof(MemberData[])); d.GetMemberData().Length.should_be(1); }; it["gets generate component"] = () => { d.ShouldGenerateComponent().GetType().should_be(typeof(bool)); d.ShouldGenerateComponent().should_be_false(); d.ContainsKey(ShouldGenerateComponentComponentDataExtension.COMPONENT_OBJECT_TYPE).should_be_false(); }; it["gets generate index"] = () => { d.ShouldGenerateIndex().GetType().should_be(typeof(bool)); d.ShouldGenerateIndex().should_be_true(); getData <DontGenerateIndexComponent>().ShouldGenerateIndex().should_be_false(); }; it["gets generate methods"] = () => { d.ShouldGenerateMethods().GetType().should_be(typeof(bool)); d.ShouldGenerateMethods().should_be_true(); getData <DontGenerateMethodsComponent>().ShouldGenerateMethods().should_be_false(); }; it["gets unique prefix"] = () => { d.GetUniqueComponentPrefix().GetType().should_be(typeof(string)); d.GetUniqueComponentPrefix().should_be("is"); getData <CustomPrefixFlagComponent>().GetUniqueComponentPrefix().should_be("My"); }; }; context["non component"] = () => { Type[] types = null; ComponentData[] data = null; ComponentData d = null; before = () => { types = new [] { typeof(ClassToGenerate) }; var provider = new ComponentDataProvider(types); data = (ComponentData[])provider.GetData(); d = data[0]; }; it["get data"] = () => { data.Length.should_be(1); }; it["gets component name"] = () => { d.GetComponentName().GetType().should_be(typeof(string)); // Not the type, but the component that should be generated // See: no namespace d.GetComponentName().should_be("ClassToGenerate"); d.GetFullComponentName().GetType().should_be(typeof(string)); // Not the type, but the component that should be generated // See: no namespace d.GetFullComponentName().should_be("ClassToGenerateComponent"); }; it["gets full type name"] = () => { d.GetFullTypeName().GetType().should_be(typeof(string)); // Not the type, but the component that should be generated // See: no namespace d.GetFullTypeName().should_be("ClassToGenerateComponent"); }; it["gets contexts"] = () => { d.GetContextNames().GetType().should_be(typeof(string[])); d.GetContextNames().Length.should_be(2); d.GetContextNames()[0].should_be("Test"); d.GetContextNames()[1].should_be("Test2"); }; it["gets unique"] = () => { d.IsUnique().GetType().should_be(typeof(bool)); d.IsUnique().should_be_false(); }; it["gets member data"] = () => { d.GetMemberData().Length.should_be(1); d.GetMemberData()[0].type.should_be(typeof(ClassToGenerate).ToCompilableString()); }; it["gets generate component"] = () => { d.ShouldGenerateComponent().GetType().should_be(typeof(bool)); d.ShouldGenerateComponent().should_be_true(); d.GetObjectType().should_be(typeof(ClassToGenerate).ToCompilableString()); }; it["gets generate index"] = () => { d.ShouldGenerateIndex().GetType().should_be(typeof(bool)); d.ShouldGenerateIndex().should_be_true(); }; it["gets generate methods"] = () => { d.ShouldGenerateMethods().GetType().should_be(typeof(bool)); d.ShouldGenerateMethods().should_be_true(); }; it["gets unique prefix"] = () => { d.GetUniqueComponentPrefix().GetType().should_be(typeof(string)); d.GetUniqueComponentPrefix().should_be("is"); }; }; context["multiple types"] = () => { it["creates data for each type"] = () => { var types = new [] { typeof(NameAgeComponent), typeof(Test2ContextComponent) }; var provider = new ComponentDataProvider(types); var data = provider.GetData(); data.Length.should_be(types.Length); }; }; context["multiple custom component names"] = () => { Type[] types = null; ComponentData[] data = null; ComponentData d1 = null; ComponentData d2 = null; before = () => { types = new [] { typeof(CustomName) }; var provider = new ComponentDataProvider(types); data = (ComponentData[])provider.GetData(); d1 = data[0]; d2 = data[1]; }; it["get data"] = () => { data.Length.should_be(2); }; it["creates data for each custom component name"] = () => { d1.GetComponentName().should_be("NewCustomNameComponent1"); d2.GetComponentName().should_be("NewCustomNameComponent2"); d1.GetObjectType().should_be(types[0].ToCompilableString()); d2.GetObjectType().should_be(types[0].ToCompilableString()); d1.GetFullTypeName().should_be("NewCustomNameComponent1Component"); d2.GetFullTypeName().should_be("NewCustomNameComponent2Component"); d1.GetComponentName().should_be("NewCustomNameComponent1"); d2.GetComponentName().should_be("NewCustomNameComponent2"); d1.GetFullComponentName().should_be("NewCustomNameComponent1Component"); d2.GetFullComponentName().should_be("NewCustomNameComponent2Component"); }; }; }
private static ComponentData GetZeroedComponentData(ComponentData componentData) { var zeroedData = new ComponentData { Name = componentData.Name, Guid = componentData.Guid, Duration = componentData.Duration }; componentData.Metrics.ForEach(m => { var val = m.Value; if (MetricMapper.IsMetricNumeric(val)) { val = 0; } _VerboseMetricsLogger.InfoFormat("Zeroing Component: {0}; Metric: {1}; Value: {2}", zeroedData.Name, m.Key, val); zeroedData.Metrics.Add(m.Key, val); }); return zeroedData; }
public void Save(bool checkOutIfNeeded = false) { if (checkOutIfNeeded) { if (!Content.IsEditable.GetValueOrDefault()) { Client.CheckOut(Content.Id, true, null); } } if (string.IsNullOrEmpty(Content.Title)) Content.Title = "No title specified!"; // Item titles cannot contain backslashes :) if (Content.Title.Contains("\\")) Content.Title = Content.Title.Replace("\\", "/"); Content.Content = _fields.ToString(); TcmUri contentId = new TcmUri(Content.Id); if(!contentId.IsVersionless) { contentId = new TcmUri(contentId.ItemId, contentId.ItemType, contentId.PublicationId); Content.Id = contentId.ToString(); } try { Content = (ComponentData)Client.Save(Content, ReadOptions); Client.CheckIn(Content.Id, null); } catch (Exception ex) { Console.WriteLine("Ooops, something went wrong saving component " + Content.Title); Console.WriteLine(ex.Message); } }
public void DisplayOnlyMode(ComponentData componentData) { displayOnlyMode = true; Display(componentData); }
public override void LoadData( ComponentData componentData ) { PrimitiveRenderData data = componentData as PrimitiveRenderData; if ( data != null ) { this.GeometricPrimitiveType = data.PrimitiveType; this.m_color = data.Color; this.Wireframe = data.Wireframe; this.m_size = data.Size; } }
public void ComponentListAddMode(ComponentData componentData, List <ComponentData> componentDatas, Action action) { componentListAddMode = true; Display(componentData); AddComponentMode(componentDatas, action); }