// // Functions required by the connector // public async Task <Tuple <AdminShell.AdministrationShell, AdminShell.Asset> > GetAasAssetCore(string index) { // access if (!IsValid()) { throw new PackageConnectorException("PackageConnector connection not valid!"); } if (!index.HasContent()) { throw new PackageConnectorException("PackageConnector::GetAasAssetCore() requires to have " + "valid index data!"); } // do the actual query var response = await _client.GetAsync(StartQuery("aas", index, "core")); response.EnsureSuccessStatusCode(); var frame = Newtonsoft.Json.Linq.JObject.Parse(await response.Content.ReadAsStringAsync()); // proudly to the parsing AdminShell.AdministrationShell aas = null; AdminShell.Asset asset = null; if (frame.ContainsKey("AAS")) { aas = AdminShellSerializationHelper.DeserializeFromJSON <AdminShell.AdministrationShell>(frame["AAS"]); } if (frame.ContainsKey("Asset")) { asset = AdminShellSerializationHelper.DeserializeFromJSON <AdminShell.Asset>(frame["Asset"]); } // result return(new Tuple <AdminShell.AdministrationShell, AdminShell.Asset>(aas, asset)); }
public AdminShell.Referable GetDataAsReferable() { // access if (Data == null) return null; // try deserialize return AdminShellSerializationHelper.DeserializeFromJSON<AdminShell.Referable>(Data); }
public static CopyPasteBuffer FromClipboardString(string cps) { // access if (cps == null) { return(null); } cps = cps.Trim(); if (cps.Length < 1) { return(null); } // quite likely to crash try { // be very straight for allowed formats var isSingleObject = cps.StartsWith("{"); var isArrayObject = cps.StartsWith("["); // try simple way if (isSingleObject) { // TODO (MIHO, 2021-06-22): think of converting Referable to IAasElement var obj = AdminShellSerializationHelper.DeserializeFromJSON <AdminShell.Referable>(cps); // try fake a copy paste item (order matters!) var cpi = CopyPasteItemBase.FactoryConvertFrom(obj); if (cpi != null) { return new CopyPasteBuffer() { Valid = true, ExternalSource = true, Duplicate = true, Items = new ListOfCopyPasteItem(cpi) } } ; } else if (isArrayObject) { // make array of object var objarr = AdminShellSerializationHelper .DeserializePureObjectFromJSON <List <AdminShell.Referable> >(cps); if (objarr != null) { // overall structure var cpb = new CopyPasteBuffer() { Valid = true, ExternalSource = true, Duplicate = true, Items = new ListOfCopyPasteItem() }; // single items foreach (var obj in objarr) { var cpi = CopyPasteItemBase.FactoryConvertFrom(obj); if (cpi != null) { cpb.Items.Add(cpi); } } // be picky with validity if (cpb.Items.Count > 0) { return(cpb); } } } } catch (Exception ex) { Log.Singleton.Error(ex, "when trying to decode clipboad text"); } // ups return(null); }