private Dictionary <string, string> GetContentSelectedRelated(ContentSelectedRelatedModel data) { try { if (data.Server != null) { WebClient wc = new WebClient { Encoding = Encoding.UTF8 }; var node = JsonNetWrapper.DeserializeObject <Dictionary <string, string> >(wc.UploadString($"{data.Server}/scs/platform/contenttreeselectedrelated.scsvc", "POST", $@"{{ ""selectedIds"": {JsonNetWrapper.SerializeObject(data.SelectedIds)}, ""server"": null}}")); return(node); } } catch (RuntimeBinderException) { } Dictionary <string, string> ret = new Dictionary <string, string>(); foreach (string selectedId in data.SelectedIds) { BuildRelatedTree(ret, selectedId); } return(ret); }
public ChildrenItemDataModel GetRemoteItemDataWithChildren(Guid id, string server) { string url = $"{server}/scs/cm/cmgetitemyamlwithchildren.scsvc"; string parameters = JsonNetWrapper.SerializeObject(id); string json = MakeRequest(url, parameters); return(JsonNetWrapper.DeserializeObject <ChildrenItemDataModel>(json)); }
public bool SynchronizeLevels(Database db) { HttpClient wc = new HttpClient(); try { string str = wc.GetStringAsync($"{DemandbaseContext.RestApi}?query={DemandbaseContext.DemandbaseIp}&key={DemandbaseContext.Key}") .Result; var data = new HashSet <string>( JsonNetWrapper.DeserializeObject <IDictionary <string, object> >(str) .Where(x => x.Value?.GetType().FullName == "Newtonsoft.Json.Linq.JObject") .Select(x => x.Key)); using (new SecurityDisabler()) { if (data.Contains("domestichq")) { ValidateInstalled(db, DomesticHq, "Domestic HQ", "domestichq"); } else { ValidateRemoved(db, DomesticHq); } if (data.Contains("hq")) { ValidateInstalled(db, Hq, "HQ", "hq"); } else { ValidateRemoved(db, Hq); } if (data.Contains("worldhq")) { ValidateInstalled(db, WorldHq, "World HQ", "worldhq"); } else { ValidateRemoved(db, WorldHq); } } if (data.Count <= 1) { DemandbaseContext._noHq = true; } return(true); } catch (Exception e) { Log.Error("Unable to synchronize levels, this is likely due to the Demandbase service being down. Aborting validation of rules as without proper levels it could have a detrimental effect on existing rules.", e, this); } return(false); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var segments = controllerContext.HttpContext?.Request?.Url?.Segments; if (segments == null || segments.Length < 2 || !segments[1].Equals("scs/", StringComparison.Ordinal) || !(segments.Last().EndsWith(".json") || segments.Last().EndsWith(".scsvc"))) { return(Default.BindModel(controllerContext, bindingContext)); } Stream s = controllerContext.HttpContext.Request.InputStream; s.Seek(0, SeekOrigin.Begin); return(JsonNetWrapper.DeserializeObject(new StreamReader(s).ReadToEnd(), bindingContext.ModelType)); }
/// <summary> /// gets post data from post request /// </summary> /// <param name="context"></param> /// <returns>dynamic object containing post javascript object</returns> public static dynamic GetPostData(HttpContextBase context) { using (StreamReader sr = new StreamReader(context.Request.InputStream)) { dynamic ret = JsonNetWrapper.DeserializeObject <ExpandoObject>(sr.ReadToEnd()); try { HttpContext.Current.Items["datasource"] = ret.sc_itemid; } catch (RuntimeBinderException) { } return(ret); } }
public static bool HasProperty(dynamic obj, string name) { Type objType = obj.GetType(); if (objType == typeof(string)) { ExpandoObject o = JsonNetWrapper.DeserializeObject <ExpandoObject>(obj); return(((IDictionary <string, object>)o).ContainsKey(name)); } if (objType == typeof(ExpandoObject)) { return(((IDictionary <string, object>)obj).ContainsKey(name)); } return(objType.GetProperty(name) != null); }
public CompareContentTreeNode GetContentTreeNode(RemoteContentTreeArgs args) { string url = $"{args.Server}/scs/cm/cmcontenttree.scsvc"; string parameters = $@"{{ ""id"": ""{args.Id}"", ""database"": ""{args.Database}""}}"; string response = MakeRequest(url, parameters); var node = JsonNetWrapper.DeserializeObject <CompareContentTreeNode>(response); if (!string.IsNullOrWhiteSpace(args.Id)) { node.SimpleCompare(args.Database, args.Id); } return(node); }
private ExpandoObject GetCurrentSessionValue(bool abort = false) { var tmp = HttpContext.Current.Session["demandBaseUser"]?.ToString(); dynamic data = HttpContext.Current.Items["demandbaseObject"]; if (data == null && tmp != null) { HttpContext.Current.Items["demandbaseObject"] = JsonNetWrapper.DeserializeObject <ExpandoObject>(tmp); return((ExpandoObject)HttpContext.Current.Items["demandbaseObject"]); } if (!abort && (data == null || ValidateUser.GetIpAddress() != HttpContext.Current.Session["demandBaseUserIp"]?.ToString())) { Log.Debug($"[Demandbase Debug][xdb] Demandbase data not found, going to Demandbase. {DemandbaseContext.CurrentRequestIp}"); ValidateUserData(ValidateUser.GetIpAddress()); return(GetCurrentSessionValue(true)); } return(data); }
private ExpandoObject GetCurrentSessionValue(bool abort = false) { var contact = Tracker.Current?.Contact; var tmp = contact?.GetFacet <IXdbFacetDemandbaseData>("Demandbase Data"); dynamic data = HttpContext.Current.Items["demandbaseObject"]; if (data == null && tmp?.DemandBaseData != null) { data = JsonNetWrapper.DeserializeObject <ExpandoObject>(tmp.DemandBaseData); HttpContext.Current.Items["demandbaseObject"] = data; } var dictionary = data as IDictionary <string, object>; if (!abort && (dictionary == null || tmp?.DemandBaseData == null || dictionary["ip"]?.ToString() != DemandbaseContext.CurrentRequestIp)) { Log.Debug($"[Demandbase Debug][xdb] Demandbase data not found, going to Demandbase. {DemandbaseContext.CurrentRequestIp}"); ValidateUserData(ValidateUser.GetIpAddress()); return(GetCurrentSessionValue(true)); } return(data as ExpandoObject); }
public void Rebuild() { if (Rebuilding) { return; } Rebuilt = 0; Task.Run(() => { Rebuilding = true; lock (_locker) { _dir.ClearLock("rebuilding"); using (var writer = new IndexWriter(_dir, Analyzer, IndexWriter.MaxFieldLength.UNLIMITED)) { writer.DeleteAll(); } } DateTime start = DateTime.Now.Subtract(TimeSpan.FromDays(_recordDays)); while (start < DateTime.Now.AddDays(1)) { string file = _dataDirectory + "/source/" + start.ToString("yyyy-MMM-dd") + "/source.src"; if (File.Exists(file)) { byte[] txt = File.ReadAllBytes(file); foreach (string entry in StringZipper.Unzip(txt).Split(new[] { "<|||>" }, StringSplitOptions.RemoveEmptyEntries)) { AuditSourceRecord record = JsonNetWrapper.DeserializeObject <AuditSourceRecord>(entry); Task.Delay(1000).Wait(); Log(record.Entry, record.Content, false); Rebuilt++; } } start = start.AddDays(1); } Rebuilt = -1; Rebuilding = false; }); }