public static string LinkFieldOptions(this Item item, ID fieldId, LinkFieldOption option) { XmlField field = item.Fields[fieldId]; switch (option) { case LinkFieldOption.Text: return(field?.GetAttribute("text")); case LinkFieldOption.LinkType: return(field?.GetAttribute("linktype")); case LinkFieldOption.Class: return(field?.GetAttribute("class")); case LinkFieldOption.Alt: return(field?.GetAttribute("title")); case LinkFieldOption.Target: return(field?.GetAttribute("target")); case LinkFieldOption.QueryString: return(field?.GetAttribute("querystring")); default: throw new ArgumentOutOfRangeException(nameof(option), option, null); } }
public string GetUrl(XmlField field, Database database) { Assert.ArgumentNotNull((object)field, nameof(field)); Assert.ArgumentNotNull((object)database, nameof(database)); //string attribute1 = field.GetAttribute("linktype"); //string attribute2 = field.GetAttribute("url"); //string attribute3 = field.GetAttribute("id"); //string anchor = field.GetAttribute("anchor"); //string attribute4 = field.GetAttribute("querystring"); //if (!string.IsNullOrEmpty(anchor)) // anchor = "#" + anchor; //if (attribute1 == "anchor") // return anchor; //if (attribute1 == "external") // return this.GetExternalUrl(attribute2); //if (attribute1 == "internal") // return this.GetInternalUrl(database, attribute2, attribute3, anchor, attribute4); //if (attribute1 == "javascript") // return this.GetJavaScriptUrl(attribute2); //if (attribute1 == "mailto") // return this.GetMailToLink(attribute2); //if (attribute1 == "media") // return this.GetMediaUrl(database, attribute3); return(string.Empty); }
private Task ScheduleSteamUpdates(List <Service> services) { var user = TCAdmin.SDK.Session.GetCurrentUser(); var rTask = new RecurringTask { UserId = user.UserId, Name = "Batch Steam Update", Enabled = true, Source = this.GetType().Name, SourceId = "-1", Notes = "Created by Steam Batch Update", }; var trigger = new Trigger { TriggerType = TriggerType.OneTime, OneTime = new TriggerOneTime { StartTimeUtc = DateTime.UtcNow } }; rTask.Triggers = new[] { trigger }; foreach (var service in services) { var arguments = new XmlField { ["ScheduledScript.ServiceId"] = service.ServiceId, ["ScheduledScript.ScriptId"] = "steam", ["ScheduledScript.ForceExecution"] = true, ["ScheduledScript.WaitEmpty"] = false, ["ScheduledScript.SkipExecution"] = false, ["ScheduledScript.CheckSteamApiUpdate"] = false }; var step = new RecurringStep { ModuleId = "d3b2aa93-7e2b-4e0d-8080-67d14b2fa8a9", ProcessId = 18, ServerId = service.ServerId, Arguments = arguments.ToString(), }; var steps = rTask.Steps.ToList(); steps.Add(step); rTask.Steps = steps.ToArray(); } rTask.GenerateKey(); rTask.Save(); rTask.ScheduleNextTask(); return(new Task(rTask.TaskId)); }
private void ParseXmlConfiguration(XmlField fallbackField, Dictionary <ID, Setting> settings) { // complex structure... // TODO: Create a nice Sitecore field editing interface for this /// <fallback> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// ... /// </fallback> foreach (XmlNode child in fallbackField.Xml.FirstChild.ChildNodes) { XmlAttribute target = child.Attributes["target"]; XmlAttribute source = child.Attributes["source"]; XmlAttribute enableEllipsis = child.Attributes["enableEllipsis"]; XmlAttribute clipAt = child.Attributes["clipAt"]; /// TODO: Guard against improper input.. move to factory Setting setting = new Setting(); if (enableEllipsis != null) { setting.UseEllipsis = bool.Parse(enableEllipsis.Value); } if (clipAt != null) { int i; if (int.TryParse(clipAt.Value, out i) && i > 0) { setting.ClipAt = i; } } List <Field> fallbackFields = new List <Field>(); List <string> fallbackFieldNames = source.Value.Split(new char[] { '|', ',', ';' }, System.StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (string fallbackFieldName in fallbackFieldNames) { Field f = InnerItem.Fields[fallbackFieldName]; if (f != null) { fallbackFields.Add(f); } } setting.SourceFields = fallbackFields; ID targetID = new Sitecore.Data.ID(target.Value); settings.Add(targetID, setting); } }
/// <summary> /// 表示名、型を指定して、 /// フィールドを追加します。 /// </summary> /// <param name="this">フィールドコレクション</param> /// <param name="displayName">表示名</param> /// <param name="type">型</param> /// <returns>フィールドを返します。</returns> public static Field AddField(this FieldCollection @this, string displayName, FieldType type) { var xml = new XmlField() { DisplayName = displayName, Type = type.ToString(), }; return(@this.AddField(new XmlField() { DisplayName = displayName, Type = type.ToString(), })); }
public void Field() { var element = package.Element("class"); var @class = new XmlClassGen(package, element); var field = new XmlField(element.Element("field")); Assert.IsTrue(field.Validate(options, new GenericParameterDefinitionList()), "field.Validate failed!"); Assert.AreEqual("Value", field.Name); Assert.AreEqual("value", field.JavaName); Assert.AreEqual("1234", field.Value); Assert.AreEqual("int", field.TypeName); Assert.IsTrue(field.IsStatic); Assert.IsTrue(field.IsConst); }
/// <summary> /// Builds the images HTML. /// </summary> /// <param name="itm">The source itm.</param> /// <returns>The images HTML.</returns> private string BuildImagesHtml(Item itm) { StringBuilder htmlList = new StringBuilder(); htmlList.Append("<div class=\"title\">"); htmlList.Append(itm.Fields["Title"].Value); htmlList.Append("</div>"); XmlField xmlField = itm.Fields["image"]; if (xmlField != null) { var strUrl = string.Concat("/~/", xmlField.GetAttribute("src"), "?w=1024&h=768&as=1&force=1"); this.downLoadAsWallpaper.Attributes.Add("href", strUrl); } return(htmlList.ToString()); }
private void Initialize() { var _fallbackDefinition = new Dictionary <ID, Setting>(); // don't use fallback on this configuration field using (new FallbackDisabler()) { // try to get this fields as an XML field // Original version of this field was key/value pair // It was converted to XML to support advanced options XmlField test = InnerItem.Fields[FallbackFields]; if (test.Xml == null) { ParseNameValueConfiguration(InnerItem[FallbackFields], _fallbackDefinition); } else { ParseXmlConfiguration(test, _fallbackDefinition); } } FallbackDefinition = _fallbackDefinition; }
/// <summary> /// フィールドを追加します。 /// </summary> /// <typeparam name="TField">フィールドの型</typeparam> /// <param name="setField">フィールド情報設定メソッド</param> /// <param name="action">設定用のメソッド</param> /// <returns>ListManager</returns> protected ListManager AddField <TField>(Action <XmlField> setField, Action <TField> action = null) where TField : Field { if (setField == null) { return(this); } var title = this.ListName; var fieldInfo = new XmlField(); setField(fieldInfo); this.Execute(cn => { var l = cn.Web.Lists.GetByTitle(title); var field = l.Fields.AddField(fieldInfo); var fld = cn.CastTo <TField>(field); action?.Invoke(fld); fld.Update(); }); return(this); }
public static K2Field CreateK2Field(XmlField xmlField) { return(new K2Field(new XmlFieldPart(xmlField))); }
public static bool HasValueAndSet(this XmlField xmlField, string key) { return(xmlField.HasValue(key) && !string.IsNullOrEmpty(xmlField[key].ToString())); }
/// <summary> /// Constructor. /// </summary> internal XmlFieldHelper(XmlField fieldEntity) { _field = fieldEntity; }
private void ParseXmlConfiguration(XmlField fallbackField, Dictionary<ID, Setting> settings) { // complex structure... // TODO: Create a nice Sitecore field editing interface for this /// <fallback> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// <setting target="{id}" source="{id}|{id}|{id}..." enableEllipsis="true|false" clipAt="{number chars}" /> /// ... /// </fallback> foreach (XmlNode child in fallbackField.Xml.FirstChild.ChildNodes) { XmlAttribute target = child.Attributes["target"]; XmlAttribute source = child.Attributes["source"]; XmlAttribute enableEllipsis = child.Attributes["enableEllipsis"]; XmlAttribute clipAt = child.Attributes["clipAt"]; /// TODO: Guard against improper input.. move to factory Setting setting = new Setting(); if (enableEllipsis != null) { setting.UseEllipsis = bool.Parse(enableEllipsis.Value); } if (clipAt != null) { int i; if (int.TryParse(clipAt.Value, out i) && i > 0) { setting.ClipAt = i; } } List<Field> fallbackFields = new List<Field>(); List<string> fallbackFieldNames = source.Value.Split(new char[] { '|', ',', ';' }, System.StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (string fallbackFieldName in fallbackFieldNames) { Field f = InnerItem.Fields[fallbackFieldName]; if (f != null) { fallbackFields.Add(f); } } setting.SourceFields = fallbackFields; ID targetID = new Sitecore.Data.ID(target.Value); settings.Add(targetID, setting); } }
public static IFieldHelper ConvertToFieldHelper(IEntity fieldEntity) { if (fieldEntity == null) { throw new ArgumentNullException("fieldEntity"); } // Ensure we have the specific type of field in question. IEntity field = Entity.AsNative(fieldEntity); if (field == null) { throw new Exception("Assert false"); } StringField stringField = field as StringField; if (stringField != null) { return(new StringFieldHelper(stringField)); } AliasField aliasField = field as AliasField; if (aliasField != null) { return(new AliasFieldHelper(aliasField)); } AutoNumberField autoNumberField = field as AutoNumberField; if (autoNumberField != null) { return(new AutoNumberFieldHelper(autoNumberField)); } BoolField boolField = field as BoolField; if (boolField != null) { return(new BoolFieldHelper(boolField)); } CurrencyField currencyField = field as CurrencyField; if (currencyField != null) { return(new CurrencyFieldHelper(currencyField)); } DateField dateField = field as DateField; if (dateField != null) { return(new DateFieldHelper(dateField)); } DateTimeField dateTimeField = field as DateTimeField; if (dateTimeField != null) { return(new DateTimeFieldHelper(dateTimeField)); } DecimalField decimalField = field as DecimalField; if (decimalField != null) { return(new DecimalFieldHelper(decimalField)); } IntField intField = field as IntField; if (intField != null) { return(new IntFieldHelper(intField)); } TimeField timeField = field as TimeField; if (timeField != null) { return(new TimeFieldHelper(timeField)); } GuidField guidField = field as GuidField; if (guidField != null) { return(new GuidFieldHelper(guidField)); } XmlField xmlField = field as XmlField; if (xmlField != null) { return(new XmlFieldHelper(xmlField)); } throw new Exception("Entity is not a valid field type: " + field.GetType().ToString()); }
protected virtual string GetUrl(XmlField field) { return(field != null ? new UltraLinkUrl().GetUrl(field, this.Item.Database) : LinkManager.GetItemUrl(this.Item, UrlOptions.DefaultOptions)); }
/// <summary> /// Initializes a new instance of the <see cref="XmlProperty"/> class. /// </summary> /// <param name="field">The field to wrap.</param> public XmlProperty(Field field) : base(field) { this.xmlField = field; }
/// <summary> /// フィールド情報を指定して、 /// フィールドを追加します。 /// </summary> /// <param name="this">フィールドコレクション</param> /// <param name="fieldInfo">フィールド情報</param> /// <returns>フィールドを返します。</returns> public static Field AddField(this FieldCollection @this, XmlField fieldInfo) { var field = @this.AddFieldAsXml(fieldInfo.ToString(), false, AddFieldOptions.AddFieldCheckDisplayName); return(field); }
public static string LinkFieldTarget(this Item item, ID fieldID) { XmlField field = item.Fields[fieldID]; return(field?.GetAttribute("target")); }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="XmlProperty"/> class. /// </summary> /// <param name="field">The field to wrap.</param> public XmlProperty(Field field) : base(field) { xmlField = field; }
public static string LinkFieldDescription(this Item item, string fieldName) { XmlField field = item?.Fields?[fieldName]; return(field?.GetAttribute("description")); }
public static string LinkFieldClass(this Item item, string fieldName) { XmlField field = item?.Fields?[fieldName]; return(field?.GetAttribute("class")); }
public static string LinkFieldTarget(this Item item, string fieldId) { XmlField field = item?.Fields?[fieldId]; return(field?.GetAttribute("target")); }
internal static BaseField CreateField(FieldType type) { BaseField field = null; switch (type) { case FieldType.ObjectKey: field = new ObjectKeyField(); break; case FieldType.BigInt: field = new BigIntField(); break; case FieldType.Bool: field = new BoolField(); break; case FieldType.Date: field = new DateField(); break; case FieldType.DateTime: field = new DateTimeField(); break; case FieldType.Decimal: field = new DecimalField(); break; case FieldType.Image: field = new ImageField(); break; case FieldType.Integer: field = new IntegerField(); break; case FieldType.LongText: field = new LongTextField(); break; case FieldType.Password: field = new PasswordField(); break; case FieldType.MonataryAmount: field = new DecimalField(); break; case FieldType.Html: field = new HtmlField(); break; case FieldType.Xml: field = new XmlField(); break; case FieldType.Json: field = new JsonField(); break; case FieldType.Email: field = new EmailField(); break; case FieldType.Phone: field = new PhoneField(); break; case FieldType.ObjectLink: field = new ObjectLinkField(); break; case FieldType.MultiObjectLink: field = new MultiObjectLinkField(); break; case FieldType.Select: field = new SelectField(); break; case FieldType.MultiSelect: field = new MultiSelectField(); break; case FieldType.FilterField: field = new FilterField(); break; case FieldType.OneToMany: field = new OneToManyField(); break; default: field = new StringField(); break; } return(field); }
/// <summary> /// Sets values of this class with values from given XML file. /// </summary> /// <param name="ConfigurationXmlPath">The path to the file with values.</param> private static void LoadDataFromFile(string ConfigurationXmlPath) { XmlDocument ConfigDocument = new XmlDocument(); XmlNamespaceManager NS = new XmlNamespaceManager(ConfigDocument.NameTable); NS.AddNamespace("ns", "https://www.unrealengine.com/BuildConfiguration"); XmlReaderSettings ReaderSettings = new XmlReaderSettings(); ReaderSettings.ValidationEventHandler += (object Sender, System.Xml.Schema.ValidationEventArgs EventArgs) => { throw new BuildException("XmlConfigLoader: Reading config XML failed:\n{0}({1}): {2}", ConfigurationXmlPath, EventArgs.Exception.LineNumber, EventArgs.Message); }; ReaderSettings.ValidationType = ValidationType.Schema; ReaderSettings.Schemas.Add(GetConfigSchema()); using (StringReader SR = new StringReader(File.ReadAllText(ConfigurationXmlPath, Encoding.UTF8))) { XmlReader Reader = XmlReader.Create(SR, ReaderSettings); ConfigDocument.Load(Reader); } XmlNodeList XmlClasses = ConfigDocument.DocumentElement.SelectNodes("/ns:Configuration/*", NS); if (XmlClasses.Count == 0) { if (ConfigDocument.DocumentElement.Name == "Configuration") { ConfigDocument.DocumentElement.SetAttribute("xmlns", "https://www.unrealengine.com/BuildConfiguration"); XmlDocument NSDoc = new XmlDocument(); NSDoc.LoadXml(ConfigDocument.OuterXml); try { File.WriteAllText(ConfigurationXmlPath, WriteToBuffer(NSDoc)); } catch (Exception) { // Ignore gently. } XmlClasses = NSDoc.DocumentElement.SelectNodes("/ns:Configuration/*", NS); } } foreach (XmlNode XmlClass in XmlClasses) { Type ClassType = Type.GetType("UnrealBuildTool." + XmlClass.Name); if (ClassType == null) { Log.TraceVerbose("XmlConfig Loading: class '{0}' doesn't exist.", XmlClass.Name); continue; } if (!IsConfigurableClass(ClassType)) { Log.TraceVerbose("XmlConfig Loading: class '{0}' is not allowed to be configured using XML system.", XmlClass.Name); continue; } XmlConfigLoaderClassData ClassData; if (!Data.TryGetValue(ClassType, out ClassData)) { ClassData = new XmlConfigLoaderClassData(); Data.Add(ClassType, ClassData); } XmlNodeList XmlFields = XmlClass.SelectNodes("*"); foreach (XmlNode XmlField in XmlFields) { FieldInfo Field = ClassType.GetField(XmlField.Name); // allow settings in the .xml that don't exist, as another branch may have it, and can share this file from Documents if (Field == null) { PropertyInfo Property = ClassType.GetProperty(XmlField.Name); if (Property != null) { if (!IsConfigurable(Property)) { throw new BuildException("BuildConfiguration Loading: property '{0}' is either non-public, non-static or not-xml-configurable.", XmlField.Name); } ClassData.SetValue(Property, ParseFieldData(Property.PropertyType, XmlField.InnerText)); } continue; } if (!IsConfigurableField(Field)) { throw new BuildException("BuildConfiguration Loading: field '{0}' is either non-public, non-static or not-xml-configurable.", XmlField.Name); } if (Field.FieldType.IsArray) { // If the type is an array type get items for it. XmlNodeList XmlItems = XmlField.SelectNodes("ns:Item", NS); // Get the C# type of the array. Type ItemType = Field.FieldType.GetElementType(); // Create the array according to the ItemType. Array OutputArray = Array.CreateInstance(ItemType, XmlItems.Count); int Id = 0; foreach (XmlNode XmlItem in XmlItems) { // Append values to the OutputArray. OutputArray.SetValue(ParseFieldData(ItemType, XmlItem.InnerText), Id++); } ClassData.SetValue(Field, OutputArray); } else { ClassData.SetValue(Field, ParseFieldData(Field.FieldType, XmlField.InnerText)); } } } }
/// <summary> /// Sets values of this class with values from given XML file. /// </summary> /// <param name="ConfigurationXmlPath">The path to the file with values.</param> private static void Load(string ConfigurationXmlPath) { var ConfigDocument = new XmlDocument(); var NS = new XmlNamespaceManager(ConfigDocument.NameTable); NS.AddNamespace("ns", "https://www.unrealengine.com/BuildConfiguration"); ConfigDocument.Load(ConfigurationXmlPath); var XmlClasses = ConfigDocument.DocumentElement.SelectNodes("/ns:Configuration/*", NS); if (XmlClasses.Count == 0) { if (ConfigDocument.DocumentElement.Name == "Configuration") { ConfigDocument.DocumentElement.SetAttribute("xmlns", "https://www.unrealengine.com/BuildConfiguration"); var NSDoc = new XmlDocument(); NSDoc.LoadXml(ConfigDocument.OuterXml); try { File.WriteAllText(ConfigurationXmlPath, WriteToBuffer(NSDoc)); } catch (Exception) { // Ignore gently. } XmlClasses = NSDoc.DocumentElement.SelectNodes("/ns:Configuration/*", NS); } } foreach (XmlNode XmlClass in XmlClasses) { var ClassType = Type.GetType("UnrealBuildTool." + XmlClass.Name); if (ClassType == null) { Log.TraceVerbose("XmlConfig Loading: class '{0}' doesn't exist.", XmlClass.Name); continue; } if (!IsConfigurableClass(ClassType)) { Log.TraceVerbose("XmlConfig Loading: class '{0}' is not allowed to be configured using XML system.", XmlClass.Name); continue; } XmlConfigLoaderClassData ClassData; if (!Data.TryGetValue(ClassType, out ClassData)) { ClassData = new XmlConfigLoaderClassData(ClassType); Data.Add(ClassType, ClassData); } var XmlFields = XmlClass.SelectNodes("*"); foreach (XmlNode XmlField in XmlFields) { FieldInfo Field = ClassType.GetField(XmlField.Name); // allow settings in the .xml that don't exist, as another branch may have it, and can share this file from Documents if (Field == null) { continue; } if (!IsConfigurableField(Field)) { throw new BuildException("BuildConfiguration Loading: field '{0}' is either non-public, non-static or not-xml-configurable.", XmlField.Name); } if (Field.FieldType.IsArray) { // If the type is an array type get items for it. var XmlItems = XmlField.SelectNodes("ns:Item", NS); // Get the C# type of the array. var ItemType = Field.FieldType.GetElementType(); // Create the array according to the ItemType. var OutputArray = Array.CreateInstance(ItemType, XmlItems.Count); int Id = 0; foreach (XmlNode XmlItem in XmlItems) { // Append values to the OutputArray. OutputArray.SetValue(ParseFieldData(ItemType, XmlItem.InnerText), Id++); } ClassData.SetValue(Field, OutputArray); } else { ClassData.SetValue(Field, ParseFieldData(Field.FieldType, XmlField.InnerText)); } } } }