public static string GetNumeratorAttributeText(INObject obj, string attributeValue, NCounterDescriptionList description) { if (string.IsNullOrEmpty(attributeValue)) { return(null); } bool deferred = false; string format = attributeValue; if (attributeValue.StartsWith(NumeratorDescription.Deferred)) { deferred = true; format = attributeValue.Substring(NumeratorDescription.Deferred.Length); } if (description.DeferredRegistration) { deferred = true; } return(new NumeratorFormatter(new NumeratorKeywordProviderAggregator(new INumeratorKeywordProvider[] { new CurrentDateProvider(deferred), new AttributeKeywordProvider(), new UnknownProvider(description.DraftText) })).Format(obj, format)); }
private static string GetAttributeText(INObject obj, IReadOnlyDictionary <string, DValue> attributes, INAttribute attr) { if (!attributes.TryGetValue(attr.Name, out var value)) { return(string.Empty); } switch (attr.Type) { case MAttrType.Numerator: try { return(GetNumeratorAttributeText(obj, attr, value.Value?.ToString())); } catch (FormatException) { return(string.Empty); } case MAttrType.DateTime: return(GetDateTimeAttributeText(obj, value)); default: return(value.Value?.ToString()); } }
private static string GetObjectTitle(INObject obj, INType type) { if (type.Id == MType.SMART_FOLDER_ID && obj.Attributes.ContainsKey(SystemAttributes.SMART_FOLDER_TITLE)) { return(obj.Attributes[SystemAttributes.SMART_FOLDER_TITLE].ToString()); } if (obj.Id == DObject.RootId) { return(type.Title); } var sb = new StringBuilder(); var attributes = AttributeFormatter.Format(type, obj.Attributes); foreach (var displayableAttr in type.GetDisplayAttributes()) { var attributeText = GetAttributeText(obj, attributes, displayableAttr); if (sb.Length != 0 && !string.IsNullOrEmpty(attributeText)) { sb.Append(Constants.PROJECT_TITLE_ATTRIBUTES_DELIMITER); } sb.Append(attributeText); } return(sb.ToString()); }
public void Add(INObject nObject) { if (nObject != null) { _nObjects.Add(nObject); } }
public void Delete(INObject nObject) { if (nObject != null) { _nObjects.Remove(nObject); } }
public void DonateStartTimeEntry(IThreadSafeTimeEntry timeEntry) { if (!UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { return; } var relevantShortcuts = new List <INRelevantShortcut>(); var startTimerIntent = new StartTimerIntent(); startTimerIntent.Workspace = new INObject(timeEntry.Workspace.Id.ToString(), timeEntry.Workspace.Name); if (!string.IsNullOrEmpty(timeEntry.Description)) { // If any of the tags or the project id were just created and haven't sync we ignore this action until the user repeats it if (timeEntry.ProjectId < 0 || timeEntry.TagIds.Any(tagId => tagId < 0)) { return; } if (timeEntry.ProjectId is long projectId) { var projectINObject = new INObject(timeEntry.ProjectId.ToString(), timeEntry.Project.Name); startTimerIntent.ProjectId = projectINObject; } startTimerIntent.EntryDescription = timeEntry.Description; var tags = timeEntry.TagIds.Select(tag => new INObject(tag.ToString(), tag.ToString())).ToArray(); startTimerIntent.Tags = tags; var billable = new INObject(timeEntry.Billable.ToString(), timeEntry.Billable.ToString()); startTimerIntent.Billable = billable; startTimerIntent.SuggestedInvocationPhrase = string.Format(Resources.SiriTrackEntrySuggestedInvocationPhrase, timeEntry.Description); // Relevant shortcut for the Siri Watch Face relevantShortcuts.Add(createRelevantShortcut(startTimerIntent)); } else { startTimerIntent.SuggestedInvocationPhrase = Resources.StartTimerInvocationPhrase; } var startTimerInteraction = new INInteraction(startTimerIntent, null); startTimerInteraction.DonateInteraction(trackError); // Descriptionless Relevant Shortcut. Always added even if the intent has one var descriptionlessIntent = new StartTimerIntent(); descriptionlessIntent.Workspace = new INObject(timeEntry.Workspace.Id.ToString(), timeEntry.Workspace.Name); var descriptionlessShortcut = createRelevantShortcut(descriptionlessIntent); relevantShortcuts.Add(descriptionlessShortcut); donateRelevantShortcuts(relevantShortcuts.ToArray()); }
public static bool IsEmpty(this INObject obj) { var emptyObject = new DObject { Id = obj.Id }; return(Comparer.AreEqual(emptyObject, obj)); }
public object GetValue(INObject obj, string keyword) { if (keyword != CURRENT_DATE_KEYWORD) { return(null); } return(_deferred ? (object)"***" : DateTime.Now); }
public static string GetDateTimeAttributeText(INObject obj, DValue attributeValue) { //for backward compatibility - old datetime values were stored as strValue if (attributeValue.DateValue.HasValue) { return(attributeValue.DateValue.Value.ToLocalTime().ToString(CultureInfo.CurrentCulture)); } return(attributeValue); }
public SourcePObject(INObject source, INMetadata metadata, IReadOnlyDictionary <int, INPerson> people, IServerApiService serverApi) : base(source, metadata, people) { Title = "Source files"; Children = source.Dto.GetStorageChildren(serverApi).ToList(); SourceId = source.Id; //Id = Guid.Empty; var type = metadata.Types.FirstOrDefault(t => t.Name == SystemTypes.PROJECT_FOLDER); Type = new PType(type); }
public static string GetTitle(this INObject obj, INType type) { if (type.IsProjectFileOrFolder()) { DValue name; if (obj.Attributes.TryGetValue(SystemAttributes.PROJECT_ITEM_NAME, out name)) { return(name); } return("unnamed"); } return(GetObjectTitle(obj, type)); }
private INIntent constructStartTimerIntent(bool fromClipboard) { if (!(ViewModel.Workspace.Value is IThreadSafeWorkspace selectedWorkspace)) { return(null); } var workspace = new INObject(selectedWorkspace.Id.ToString(), selectedWorkspace.Name); INObject project = null; if (ViewModel.Project.Value is IThreadSafeProject selectedProject) { project = new INObject(selectedProject.Id.ToString(), selectedProject.Name); } INObject[] tags = null; if (ViewModel.Tags.Value.Any()) { tags = ViewModel.Tags .Value .Select(tag => new INObject(tag.Id.ToString(), tag.Id.ToString())) .ToArray(); } var billable = new INObject(ViewModel.IsBillable.Value.ToString(), ViewModel.IsBillable.Value.ToString()); if (fromClipboard) { return(new StartTimerFromClipboardIntent { Workspace = workspace, ProjectId = project, Tags = tags, Billable = billable }); } var entryDescription = ViewModel.Description.Value; return(new StartTimerIntent { Workspace = workspace, ProjectId = project, Tags = tags, Billable = billable, EntryDescription = ViewModel.Description.Value, SuggestedInvocationPhrase = string.Format(Resources.SiriTrackEntrySuggestedInvocationPhrase, entryDescription) }); }
/// <summary> /// Initializes a new instance of the <see cref="NItemCollection"/> class. /// </summary> public NItemCollection(INObject owner, IEnumerable <INItem> items = null) { Owner = owner; _propertyNames = new HashSet <string>(); _compoundNames = new HashSet <string>(); switch (items) { case null: _items = new Dictionary <string, INItem>(); return; default: _items = items.ToDictionary(x => x.Name, x => x); break; } }
private static string GetAttributeText(INObject obj, IReadOnlyDictionary <string, DValue> attributes, INAttribute attr) { DValue value; attributes.TryGetValue(attr.Name, out value); var strValue = value?.Value?.ToString(); if (attr.Type == MAttrType.Numerator) { try { return(GetNumeratorAttributeText(obj, strValue, attr.ParsedConfiguration().CounterDescriptions)); } catch (FormatException) { return(string.Empty); } } return(strValue); }
public string Format(INObject obj, string formatString) { var arguments = new List <object>(); var replaces = new Dictionary <string, string>(); var matches = FormatRegex.Matches(formatString); foreach (Match match in matches) { var keyword = match.Value.Trim('{'); var value = _keywordProvider.GetValue(obj, keyword); replaces.Add(match.Value, match.Value.Replace(keyword, arguments.Count.ToString())); arguments.Add(value); } var netFormatString = formatString; foreach (var replace in replaces) { netFormatString = netFormatString.Replace(replace.Key, replace.Value); } return(string.Format(CultureInfo.CurrentUICulture, netFormatString, arguments.ToArray())); }
public static string GetNumeratorAttributeText(INObject obj, INAttribute attr, string attrValue) { if (string.IsNullOrEmpty(attrValue)) { return(null); } var description = attr.ParsedConfiguration().CounterDescriptions; var keywordProvider = new INumeratorKeywordProvider <INObject>[] { GetCurrentDateKeywordProviders(attrValue, description), new UnknownProvider(description.DraftText) }; if (attrValue.StartsWith(NumeratorDescription.Deferred)) { attrValue = attrValue.Substring(NumeratorDescription.Deferred.Length); } return(new NumeratorFormatter <INObject>(new NumeratorKeywordProviderAggregator <INObject>(keywordProvider)).Format(obj, attrValue)); }
public PObject(INObject source, INMetadata metadata, IReadOnlyDictionary <int, INPerson> people) { Id = source.Id; ParentId = source.ParentId; LastChange = source.LastChange; Children = source.Children; Relations = source.Relations; Subscribers = source.Subscribers; Attributes = source.Attributes.ToDictionary(k => k.Key, v => v.Value.Value); ActualFileSnapshot = source.ActualFileSnapshot; PreviousFileSnapshots = source.PreviousFileSnapshots; Created = source.Created; Access = source.Access; StateInfo = source.StateInfo; SecretInfo = source.SecretInfo; Context = source.Context; var type = metadata.Types.FirstOrDefault(t => t.Id == source.TypeId); Type = new PType(type); Title = source.GetTitle(type); people.TryGetValue(source.CreatorId, out var nPerson); Creator = nPerson; }
public string Divide(INObject nObject) { string output = string.Empty; if (nObject.IsNumber()) { int?num = nObject.GetNumericValue(); if (num != null) { output = string.Concat(this.DivideByLowNumber((int)num), this.DivideByHighNumber((int)num)); if (string.Empty == output) { output = string.Concat("Divided ", num, " by ", lowNumber, "\nDivided ", num, " by ", highNumber); } } } else { output = "Invalid Item."; } return(output); }
public object GetValue(INObject obj, string keyword) { return(_providers.Select(x => x.GetValue(obj, keyword)).FirstOrDefault(x => x != null)); }
public object GetValue(INObject obj, string keyword) { return(_placeholder); }
/// <summary> /// Sets the parent of the <see cref="NObject"/>. /// </summary> /// <param name="newParent">The new parent object.</param> public void SetParent(INObject newParent) { Parent = newParent; }
public object GetValue(INObject obj, string keyword) { return(obj.Attributes.TryGetValue(keyword, out DValue value) ? value.Value : null); }