public GsaType(GwaKeyword keyword, GwaSetCommandType setCommandType, bool selfContained, params GwaKeyword[] referencedKeywords) { this.Keyword = keyword; this.SetCommandType = setCommandType; this.AnalysisLayer = true; this.DesignLayer = true; this.ReferencedKeywords = referencedKeywords == null ? new GwaKeyword[0] : referencedKeywords; this.SelfContained = selfContained; }
public GsaType(GwaKeyword keyword, GwaSetCommandType setCommandType, bool selfContained, bool designLayer, bool analysisLayer, params GwaKeyword[] referencedKeywords) { this.Keyword = keyword; this.SetCommandType = setCommandType; this.AnalysisLayer = analysisLayer; this.DesignLayer = designLayer; this.ReferencedKeywords = referencedKeywords; this.SelfContained = selfContained; }
//Designed to be called after ProcessGwa - and can handle the SET or SET_AT being included protected bool BasicFromGwa(string gwa, out List <string> remainingItems, string keywordOverride = "") { var items = Split(gwa); remainingItems = new List <string>(); if (items.Count() == 0) { return(false); } //Process and remove just the initial SET or SET_AT <index> items if (items[0].StartsWith("set", StringComparison.InvariantCultureIgnoreCase)) { if (items[0].StartsWith("set_at", StringComparison.InvariantCultureIgnoreCase)) { gwaSetCommandType = GwaSetCommandType.SetAt; if (int.TryParse(items[1], out var foundIndex)) { Index = foundIndex; } //For SET_ATs the format is SET_AT <index> <keyword> .., so remove the first two items.Remove(items[1]); items.Remove(items[0]); } else { gwaSetCommandType = GwaSetCommandType.Set; items.Remove(items[0]); } } if (!ParseKeywordVersionSid(items[0], keywordOverride)) { return(false); } //Remove keyword items.Remove(items[0]); if (gwaSetCommandType == GwaSetCommandType.Set) { if (!int.TryParse(items[0], out var index) || index == 0) { return(false); } Index = index; items.Remove(items[0]); } remainingItems = items; return(true); }
public GSACacheRecord(string keyword, int index, string gwa, string streamId = "", string applicationId = "", bool previous = false, bool latest = true, SpeckleObject so = null, GwaSetCommandType gwaSetCommandType = GwaSetCommandType.Set) { Keyword = keyword; Index = index; Gwa = gwa; Latest = latest; Previous = previous; StreamId = streamId; //values cannot have spaces ApplicationId = (applicationId == null) ? "" : applicationId.Replace(" ", ""); SpeckleObj = so; GwaSetCommandType = gwaSetCommandType; }
public void AddDataLine(string keyword, int index, string streamId, string applicationId, string gwaWithoutSet, GwaSetCommandType gwaSetType) { var line = new ProxyGwaLine() { Keyword = keyword, Index = index, StreamId = streamId, ApplicationId = applicationId, GwaWithoutSet = gwaWithoutSet, GwaSetType = gwaSetType }; ExecuteWithLock(() => data.Add(line)); }
//Not every record has stream IDs (like generated nodes) public bool Upsert(string keyword, int index, string gwa, string applicationId = "", SpeckleObject so = null, GwaSetCommandType gwaSetCommandType = GwaSetCommandType.Set, bool? latest = true, string streamId = null) { if (applicationId == null) { applicationId = ""; } try { var matchingRecords = new List<GSACacheRecord>(); ExecuteWithLock(() => { if (!recordsByKeyword.ContainsKey(keyword)) { recordsByKeyword.Add(keyword, new List<GSACacheRecord>()); } matchingRecords = recordsByKeyword[keyword].Where(r => r.Index == index).ToList(); }); if (matchingRecords.Count() > 0) { var gwaFormatted = gwa.GwaForComparison(); var matchingGwaRecords = matchingRecords.Where(r => r.Gwa.GwaForComparison().Equals(gwaFormatted, StringComparison.InvariantCultureIgnoreCase)).ToList(); if (matchingGwaRecords.Count() > 1) { throw new Exception("Unexpected multiple matches found in upsert of cache records"); } else if (matchingGwaRecords.Count() == 1) { //There should just be one matching record //There is no change to the GWA but it clearly means it's part of the latest if (latest.HasValue) { ExecuteWithLock(() => matchingGwaRecords.First().Latest = latest.Value); } return true; } else { //These will be return at the next call to GetToBeDeletedGwa() and removed at the next call to Snapshot() foreach (var r in matchingRecords) { ExecuteWithLock(() => r.Latest = false); } } } ExecuteWithLock(() => { if (!recordsByKeyword.ContainsKey(keyword)) { recordsByKeyword.Add(keyword, new List<GSACacheRecord>()); } recordsByKeyword[keyword].Add(new GSACacheRecord(keyword, index, gwa, streamId: streamId, applicationId: applicationId, latest: true, so: so, gwaSetCommandType: gwaSetCommandType)); UpsertApplicationIdLookup(keyword, index, applicationId); RemoveFromProvisional(keyword, index); }); return true; } catch { return false; } }
public bool Upsert(string keyword, int index, string gwaWithoutSet, string streamId, string applicationId, GwaSetCommandType gwaSetCommandType) { return Upsert(keyword, index, gwaWithoutSet, applicationId, null, gwaSetCommandType, streamId: streamId); }