protected Record getObjectRule(string key) { if (string.IsNullOrEmpty(key)) { return(null); } /*System.Net.ServicePointManager.ServerCertificateValidationCallback += * (se, cert, chain, sslerror) => * { * return true; * }; */ StreamApi streamApi = new StreamApi(session.GetApiClient()); StreamOptionsRecord optionsRecord = new StreamOptionsRecord(); optionsRecord.ObjectKey = key; CheckRuleResult result = streamApi.CheckRule(optionsRecord.ToJson(), null, null); if (result.Hdr.Rc == 0) { return(result.Stream); } else { return(null); } }
private void RefreshApiLink() { try { _apiLink = Activator.CreateInstance(Configuration.Instance.Stream.Api, Configuration.Instance.Stream) as StreamApi; } catch (Exception e) { // api not set } }
private void InitializeBracketApiList() { Type[] apis = Assembly.GetExecutingAssembly().GetTypes().Where((t) => t.IsSubclassOf(typeof(StreamApi))).ToArray(); ApiList = new ObservableCollection <string>(); foreach (var type in apis) { StreamSettings s = new StreamSettings(); StreamApi a = Activator.CreateInstance(type, s) as StreamApi; ApiList.Add(a.ApiName); if (type == Configuration.Instance.Stream?.GetType()) { SelectedApi = ApiList.Count - 1; } } }
private void RefreshApiLink() { try { StreamApi apiLink = Activator.CreateInstance(Configuration.Instance.Stream.Api, Configuration.Instance.Stream) as StreamApi; string url = apiLink.GetChatUrl(); if (ChatUrl != url) { ChatUrl = url; } } catch (Exception e) { Log.Error(e); } }
private void InitializeApiLink() { try { _refreshChannelInfo.Stop(); _apiLink = Activator.CreateInstance(Configuration.Instance.Stream.Api, Configuration.Instance.Stream) as StreamApi; ApiInfo = _apiLink.ApiInfo; IsConfigured = _apiLink.IsCorrectlySetup(); IsInitialized = !IsConfigured; _refreshChannelInfo.Start(); Log.Trace("API Link succesfully created"); } catch { IsConfigured = false; IsInitialized = true; Log.Warn("API Link not created. Probably wrong configuration"); } }
private void MessageHandler(object obj) { logger.Info("Received push message"); JavaScriptSerializer serializer = new JavaScriptSerializer(); string jsonStr = obj.ToString(); dynamic jsonDic = serializer.Deserialize <dynamic>(jsonStr); try { if ((jsonDic["namespace"] as string).Equals("user")) { Dictionary <string, object> dataRecord = jsonDic["data"] as Dictionary <string, object>; VmosoTileDisplayRecord record = new VmosoTileDisplayRecord(); record.character = "connect"; record.isLoginNotif = true; record.actor = dataRecord.ContainsKey("displayName") ? dataRecord["displayName"] as string : string.Empty; record.iconSmall = dataRecord.ContainsKey("iconSmall") ? dataRecord["iconSmall"] as string : string.Empty; record.loginStatus = dataRecord.ContainsKey("loginStatus") ? dataRecord["loginStatus"] as string : string.Empty; if (OnReceiveMessage != null) { record.server = pushServer; OnReceiveMessage(this, new NotifierEventArgs(record, session)); } } else if ((jsonDic["namespace"] as string).Equals("sparc")) { string targetRecordType = jsonDic["data"]["target"][0]["recordtype"]; if (!targetRecordType.Equals("TaskRecord") && !targetRecordType.Equals("PostV2Record") && !targetRecordType.Equals("FileRecord") && !targetRecordType.Equals("NoteV2Record") && !targetRecordType.Equals("FolderRecord") && !targetRecordType.Equals("LinkV2Record") && !targetRecordType.Equals("UserObjectRecord")) { return; } Dictionary <string, object> pushData = jsonDic["data"]; //if (targetRecordType.Equals("FileRecord") && pushData.ContainsKey("containers")) // return; //if (targetRecordType.Equals("FolderRecord") && pushData.ContainsKey("containers")) // return; VmosoTileDisplayRecord record = new VmosoTileDisplayRecord(); record.character = "engage"; Dictionary <string, object> targetRec = jsonDic["data"]["target"][0]["record"]; record.type = !string.IsNullOrEmpty(targetRecordType) ? targetRecordType : ""; if (record.type.Equals("TaskRecord")) { record.taskType = targetRec.ContainsKey("taskType") ? targetRec["taskType"] as string : ""; } Dictionary <string, object> lastUpdater = targetRec.ContainsKey("lastUpdater") ? targetRec["lastUpdater"] as Dictionary <string, object> : new Dictionary <string, object>(); object[] actors = pushData["actors"] as object[]; Dictionary <string, object> actorDic = new Dictionary <string, object>(); if (actors.Length > 0) { actorDic = actors[0] as Dictionary <string, object>; } Dictionary <string, object> actor = actorDic.ContainsKey("record") ? actorDic["record"] as Dictionary <string, object> : new Dictionary <string, object>(); string actorKey = actor.ContainsKey("key") ? actor["key"] as string : ""; //if (actorKey.Equals(AuthData.authinfo.cred.who)) //{ // return; //} //if (actorKey.Equals(AuthData.info.cred.who)) //if (actorKey.Equals(session.UserKey) && (!targetRecordType.Equals("FolderRecord") )) //return; record.iconSmall = actor.ContainsKey("iconSmall") ? actor["iconSmall"] as string : ""; record.isRegistered = actor.ContainsKey("isRegistered") ? (bool)actor["isRegistered"] : false; record.actorUserKey = actor.ContainsKey("key") ? actor["key"] as string : ""; if (record.isRegistered) { record.actor = actor.ContainsKey("displayName") ? actor["displayName"] as string : ""; } else { string firstName = actor["firstName"] as string; string lastName = actor["lastName"] as string; if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName)) { if (!string.IsNullOrEmpty(firstName.Trim())) { record.actor += firstName[0]; } if (!string.IsNullOrEmpty(lastName)) { record.actor += string.IsNullOrEmpty(firstName) ? lastName[0] : ' ' + lastName[0]; } } else { record.actor = actor.ContainsKey("displayName") ? actor["displayName"] as string : ""; } } record.actor = actor.ContainsKey("displayName") ? actor["displayName"] as string : ""; int timeupdated = pushData.ContainsKey("timestamp") ? Convert.ToInt32(pushData["timestamp"]) : 0; record.time = VmosoTimeHelper.ConvertTime(timeupdated); record.timestamp = timeupdated; if ((jsonDic["data"]["verb"] as string).Equals("create")) { if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; if ((jsonDic["data"] as Dictionary <string, object>).ContainsKey("containers")) { Dictionary <string, object> containerRec = jsonDic["data"]["containers"][0]["record"]; if (containerRec.ContainsKey("commentPID")) { record.commentID = containerRec["commentPID"] as string; record.contentKey = containerRec.ContainsKey("contentKey") ? containerRec["contentKey"] as string : ""; string text = containerRec.ContainsKey("text") ? containerRec["text"] as string : ""; record.text = StripeHtmlTag(text); record.url = urlBuilder.CommentUrl(targetRecordType, containerRec); } else { string containerRecordType = jsonDic["data"]["containers"][0]["recordtype"] as string; if (containerRecordType.Equals("UserObjectRecord")) { string addUser = containerRec.ContainsKey("displayName") ? containerRec["displayName"] as string : ""; record.text = "Added User " + addUser; } else if (containerRecordType.Equals("FileRecord")) { string addFile = containerRec.ContainsKey("name") ? containerRec["name"] as string : ""; record.text = "Added Attachment " + addFile; } else if (containerRecordType.Equals("NoteV2Record")) { string addFile = containerRec.ContainsKey("title") ? containerRec["title"] as string : ""; record.text = "Added Attachment " + addFile; } record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } } else { record.text = "Create"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } record.space = BuildTaskRecordSpace(record.actor); } else if (targetRecordType.Equals("PostV2Record")) { int elapsedTime = timeupdated - lastTs; lastTs = timeupdated; record.title = targetRec.ContainsKey("title") ? targetRec["title"] as string : ""; record.space = FetchSpaceForRecord(targetRec); if (!(jsonDic["data"] as Dictionary <string, object>).ContainsKey("containers")) { record.text = "Create"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else { Dictionary <string, object> containerRec = jsonDic["data"]["containers"][0]["record"]; string containerRecordType = jsonDic["data"]["containers"][0]["recordtype"] as string; if (containerRecordType.Equals("FileRecord")) { string recordText = " "; if (containerRec.ContainsKey("name")) { recordText += containerRec["name"] as string; } else { recordText = ""; } record.text = "Added Attachment" + recordText; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (containerRecordType.Equals("NoteV2Record")) { string recordText = " "; if (containerRec.ContainsKey("title")) { recordText += containerRec["title"] as string; } else { recordText = ""; } record.text = "Added Attachment" + recordText; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (containerRecordType.Equals("FolderRecord")) { record.text = "Create a Post"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (containerRecordType.Equals("CommentV2Record")) { record.commentID = containerRec.ContainsKey("commentPID") ? containerRec["commentPID"] as string : ""; string postCommentText = containerRec["text"] as string; record.text = StripeHtmlTag(postCommentText); record.url = urlBuilder.CommentUrl(targetRecordType, containerRec); } else { string recordText = " "; if (containerRec.ContainsKey("title")) { recordText += containerRec["title"] as string; } else { recordText = ""; } record.text = "Added Attachment" + recordText; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } } } else if (targetRecordType.Equals("FileRecord")) { record.text = "Upload"; record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (targetRecordType.Equals("NoteV2Record")) { record.text = "Create"; record.title = targetRec.ContainsKey("title") ? targetRec["title"] as string : ""; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (targetRecordType.Equals("FolderRecord")) { Dictionary <string, object> data = jsonDic["data"]; if (data.ContainsKey("sparcsubtype") && (data["sparcsubtype"] as string).Equals("shareto") && data.ContainsKey("containers")) { string containerRecordType = jsonDic["data"]["containers"][0]["recordtype"]; Dictionary <string, object> containerRec = jsonDic["data"]["containers"][0]["record"]; record.text = "Share"; record.space = FetchSpaceForRecord(containerRec); if (containerRec.ContainsKey("editor")) { Dictionary <string, object> editor = containerRec["editor"] as Dictionary <string, object>; record.actor = editor["displayName"] as string; if (containerRec.ContainsKey("title")) { record.title = containerRec["title"] as string; } } else { lastUpdater = containerRec["lastUpdater"] as Dictionary <string, object>; record.actor = lastUpdater["displayName"] as string; record.iconSmall = lastUpdater["iconSmall"] as string; string destDisplayName = containerRec["displayName"] as string; record.title = destDisplayName; record.space = destDisplayName; } if (containerRecordType.Equals("LinkV2Record")) { record.title = containerRec.ContainsKey("title") ? containerRec["title"] as string : ""; } else if (containerRecordType.Equals("NoteV2Record")) { record.title = containerRec.ContainsKey("title") ? containerRec["title"] as string : ""; } else if (containerRecordType.Equals("FileRecord")) { record.title = containerRec.ContainsKey("name") ? containerRec["name"] as string : ""; } record.url = urlBuilder.NonCommentUrl(containerRecordType, containerRec); record.type = jsonDic["data"]["containers"][0]["recordtype"] as string; } else { return; } //else if (data.ContainsKey("sparcsubtype") && (data["sparcsubtype"] as string).Equals("posts")) //{ // record.text = "Create"; // if ((jsonDic["data"] as Dictionary<string, object>).ContainsKey("containers")){ // record.title = jsonDic["data"]["containers"][0]["record"]["title"] ; // record.space = jsonDic["data"]["target"][0]["record"]["name"]; // } //} } } else if ((jsonDic["data"]["verb"] as string).Equals("delete")) { if (targetRecordType.Equals("TaskRecord") || targetRecordType.Equals("PostV2Record") || targetRecordType.Equals("NoteV2Record") || targetRecordType.Equals("LinkV2Record") || targetRecordType.Equals("FolderRecord")) { Dictionary <string, object> dataDictionary = jsonDic["data"]; record.title = (targetRecordType.Equals("TaskRecord") || targetRecordType.Equals("FolderRecord")) ? targetRec["name"] as string : targetRec["title"] as string; if (dataDictionary.ContainsKey("containers")) { Dictionary <string, object> containerRec = jsonDic["data"]["containers"][0]["record"]; string containerRecordType = jsonDic["data"]["containers"][0]["recordtype"] as string; if (containerRecordType.Equals("UserObjectRecord")) { string removeUser = containerRec.ContainsKey("displayName") ? containerRec["displayName"] as string : ""; record.text = "Remove User " + removeUser; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (containerRecordType.Equals("FileRecord")) { string removeFile = containerRec.ContainsKey("name") ? containerRec["name"] as string : ""; record.text = "Remove Attachment " + removeFile; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (containerRecordType.Equals("NoteV2Record")) { string removeFile = containerRec.ContainsKey("title") ? containerRec["title"] as string : ""; record.text = "Remove Attachment " + removeFile; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } else if (containerRecordType.Equals("CommentV2Record")) { string commentID = containerRec.ContainsKey("commentPID") ? containerRec["commentPID"] as string : ""; if (!string.IsNullOrEmpty(commentID)) { record.text = "Delete Comment #" + commentID; } else { record.text = "Delete Comment"; } record.url = urlBuilder.CommentUrl(targetRecordType, containerRec); } else if (containerRecordType.Equals("PostV2Record")) { record.text = "Remove"; } } else { record.text = "Delete"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); if (targetRecordType.Equals("LinkV2Record")) { object[] tarDest = targetRec["destinations"] as object[]; if (tarDest.Count() > 0) { Dictionary <string, object> dest = tarDest[0] as Dictionary <string, object>; record.space = dest["fullPath"] as string + "/" + dest["displayName"] as string; } record.title = targetRec["link"] as string; } else if (targetRecordType.Equals("FolderRecord")) { object[] tarDest = targetRec["destinations"] as object[]; if (tarDest.Count() == 0) { return; } Dictionary <string, object> dest = tarDest[0] as Dictionary <string, object>; record.space = dest["fullPath"] as string + "/" + dest["displayName"] as string; } } if (targetRecordType.Equals("TaskRecord")) { record.space = BuildTaskRecordSpace(record.actor); } else if (targetRecordType.Equals("PostV2Record") || targetRecordType.Equals("NoteV2Record")) { record.space = FetchSpaceForRecord(targetRec); } } } else if ((jsonDic["data"]["verb"] as string).Equals("follow")) { if (targetRecordType.Equals("PostV2Record")) { record.title = targetRec.ContainsKey("title") ? targetRec["title"] as string : ""; record.text = "Follow"; record.space = FetchSpaceForRecord(targetRec); record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } } else if ((jsonDic["data"]["verb"] as string).Equals("unfollow")) { if (targetRecordType.Equals("PostV2Record")) { record.title = targetRec.ContainsKey("title") ? targetRec["title"] as string : ""; record.text = "Unfollow"; record.space = FetchSpaceForRecord(targetRec); record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } } else if ((jsonDic["data"]["verb"] as string).Equals("update")) { Dictionary <string, object> containerRec = null; if ((jsonDic["data"] as Dictionary <string, object>).ContainsKey("containers")) { containerRec = jsonDic["data"]["containers"][0]["record"]; } if (targetRecordType.Equals("PostV2Record")) { record.title = targetRec.ContainsKey("title") ? targetRec["title"] as string : ""; if (pushData.ContainsKey("containers")) { record.commentID = containerRec.ContainsKey("commentPID") ? containerRec["commentPID"] as string : ""; record.text = containerRec.ContainsKey("text") ? StripeHtmlTag(containerRec["text"] as string) : ""; } record.space = FetchSpaceForRecord(targetRec); record.url = urlBuilder.CommentUrl(targetRecordType, containerRec); } else if (targetRecordType.Equals("TaskRecord")) { if (pushData.ContainsKey("containers")) { record.commentID = containerRec.ContainsKey("commentPID") ? containerRec["commentPID"] as string : ""; record.text = containerRec.ContainsKey("text") ? StripeHtmlTag(containerRec["text"] as string) : ""; } record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.url = urlBuilder.CommentUrl(targetRecordType, containerRec); record.space = BuildTaskRecordSpace(record.actor); } else if (targetRecordType.Equals("NoteV2Record") || targetRecordType.Equals("LinkV2Record")) { Dictionary <string, object> editor = jsonDic["data"]["target"][0]["record"]["editor"]; record.actor = editor["displayName"] as string; record.text = "Edit"; record.space = FetchSpaceForRecord(targetRec); if (string.IsNullOrEmpty(record.space)) { record.space = "/Personal/"; } record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.title = targetRec.ContainsKey("title") ? targetRec["title"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; } else if (targetRecordType.Equals("FolderRecord")) { record.title = targetRec["name"] as string; record.text = "Edit"; record.contentKey = targetRec["key"] as string; record.space = targetRec["path"] + "/" + targetRec["displayName"]; } if (containerRec == null) { if (targetRecordType.Equals("TaskRecord")) { string updateRecordType = jsonDic["data"]["target"][0]["record"]["taskType"] as string; if (updateRecordType.Equals("chat")) { record.text = "Edit Chat"; } else { record.text = "Edit Task"; } } else if (targetRecordType.Equals("PostV2Record")) { record.text = "Edit Post"; } record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); } } else if ((jsonDic["data"]["verb"] as string).Equals("close")) { if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.text = "Close"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.space = BuildTaskRecordSpace(record.actor); } } else if ((jsonDic["data"]["verb"] as string).Equals("complete")) { if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.text = "Complete"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.space = BuildTaskRecordSpace(record.actor); } } else if ((jsonDic["data"]["verb"] as string).Equals("undelete")) { Dictionary <string, object> containerRec = jsonDic["data"]["containers"][0]["record"]; if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.space = BuildTaskRecordSpace(record.actor); } else if (targetRecordType.Equals("PostV2Record")) { record.title = targetRec.ContainsKey("title") ? targetRec["title"] as string : ""; } record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; string commentID = containerRec.ContainsKey("commentPID") ? containerRec["commentPID"] as string : ""; record.commentID = containerRec.ContainsKey("commentPID") ? containerRec["commentPID"] as string : ""; string text = containerRec.ContainsKey("text") ? containerRec["text"] as string : ""; record.text = StripeHtmlTag(text); record.url = urlBuilder.CommentUrl(targetRecordType, containerRec); } else if ((jsonDic["data"]["verb"] as string).Equals("open")) { if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.text = "Open"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.space = BuildTaskRecordSpace(record.actor); } } else if ((jsonDic["data"]["verb"] as string).Equals("suspend")) { if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.text = "Suspend"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.space = BuildTaskRecordSpace(record.actor); } } else if ((jsonDic["data"]["verb"] as string).Equals("resume")) { if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.text = "Resume"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.space = BuildTaskRecordSpace(record.actor); } } else if ((jsonDic["data"]["verb"] as string).Equals("archive")) { if (targetRecordType.Equals("TaskRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.text = "Archive"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.space = BuildTaskRecordSpace(record.actor); } } else if ((jsonDic["data"]["verb"] as string).Equals("rename")) { if (targetRecordType.Equals("FileRecord")) { record.title = targetRec.ContainsKey("name") ? targetRec["name"] as string : ""; record.contentKey = targetRec.ContainsKey("key") ? targetRec["key"] as string : ""; record.text = "Edit"; record.url = urlBuilder.NonCommentUrl(targetRecordType, targetRec); record.space = FetchSpaceForRecord(targetRec); } } else if ((jsonDic["data"]["verb"] as string).Equals("inviteconnectedcontact")) { record.text = "Invite as Connected"; record.character = "connect"; record.title = "Invitation"; } else if ((jsonDic["data"]["verb"] as string).Equals("join")) { if (((jsonDic["data"]["sparcsubtype"]) as string).Equals("admin") || (jsonDic["data"]["containers"][0]["recordtype"] as string).Equals("FolderRecord") ) { return; } string displayName = jsonDic["data"]["containers"][0]["record"]["displayName"] as string; record.space = jsonDic["data"]["target"][0]["record"]["displayName"] as string; record.title = jsonDic["data"]["target"][0]["record"]["displayName"] as string; record.text = "Add " + displayName; } else if ((jsonDic["data"]["verb"] as string).Equals("leave")) { string displayName = jsonDic["data"]["containers"][0]["record"]["displayName"] as string; record.space = jsonDic["data"]["target"][0]["record"]["displayName"] as string; record.title = jsonDic["data"]["target"][0]["record"]["displayName"] as string; record.text = "Remove user " + displayName; } else if ((jsonDic["data"]["verb"] as string).Equals("accept")) { record.title = jsonDic["data"]["target"][0]["record"]["name"] as string; record.space = "/Personal/"; record.text = "Accept"; } else if ((jsonDic["data"]["verb"] as string).Equals("decline")) { record.title = jsonDic["data"]["target"][0]["record"]["name"] as string; record.space = "/Personal/"; record.text = "Decline"; } else if ((jsonDic["data"]["verb"] as string).Equals("invitetrustedcontact")) { record.text = "Invite as Trusted"; record.character = "connect"; record.title = "Invitation"; } if (targetRec.ContainsKey("key")) { record.contentKey = targetRec["key"] as string; } if (!string.IsNullOrEmpty(record.contentKey)) { StreamApi streamApi = new StreamApi(session.GetApiClient()); GetTileCountsResult tileCountsResult = streamApi.GetTileCounts(record.contentKey); //string countStr = VmosoHttpRequest.Get("svc/stream/" + record.contentKey + "/badgecounts/get", vmosoUri, string.Empty, VmosoCookies); if (tileCountsResult.Hdr.Rc == 0) { SparcCountRecord sparcCountRecord = tileCountsResult.Counts; record.unreadCount = (int)sparcCountRecord.TotalNewCount; } } if (!string.IsNullOrEmpty(record.contentKey)) { Record rule = getObjectRule(record.contentKey); if (rule != null) { dynamic dynObj = JsonConvert.DeserializeObject(rule.Json); if (dynObj.record.hideFlag.Equals("yes")) { return; } } } if (OnReceiveMessage != null) { record.server = pushServer; OnReceiveMessage(this, new NotifierEventArgs(record, session)); } } else if ((jsonDic["namespace"] as string).Equals("myPage")) { VmosoCountDisplayRecord countDisplayRecord = new VmosoCountDisplayRecord(); int totalCount = 0; Dictionary <string, object> dataRecord = jsonDic["data"] as Dictionary <string, object>; if (dataRecord.ContainsKey("EANUT")) { object vEANut = dataRecord["EANUT"]; if (vEANut is int) { totalCount += (int)vEANut; } } if (dataRecord.ContainsKey("CANUT")) { object vCANut = dataRecord["CANUT"]; if (vCANut is int) { totalCount += (int)vCANut; } } if (dataRecord.ContainsKey("OANUT")) { object vOANut = dataRecord["OANUT"]; if (vOANut is int) { totalCount += (int)vOANut; } } countDisplayRecord.TotalCount = totalCount.ToString(); if (OnReceiveCount != null) { OnReceiveCount(this, new CountEventArgs(countDisplayRecord)); } } } catch (Exception e) { return; } }
public List <StreamItem> InvokeSearch(PaginationRecord pg) { try { StreamApi streamApi = new StreamApi(session.GetApiClient()); FormatRecord formatRecord = new FormatRecord(); formatRecord.ReturnCounts = true; formatRecord.ReturnRatings = true; formatRecord.ReturnSparc = true; formatRecord.ReturnAcl = true; StreamSearchResult result = streamApi.StreamSearch(options.ToJson(), pg.ToJson(), formatRecord.ToJson()); if (result.Hdr.Rc == 0) { pager = result.Pager; List <StreamItem> streamItems = new List <StreamItem>(); List <StreamRecordWrapper> recordWrappers = result.Stream; foreach (StreamRecordWrapper recordWrapper in recordWrappers) { StreamItem streamItem = new StreamItem(); streamItem.UnreadCount = (int)recordWrapper.BadgeCounts.TotalNewCount; streamItem.RecordType = recordWrapper.Recordtype; String recordJson = JsonConvert.SerializeObject(recordWrapper.Record); switch (streamItem.RecordType) { case RECORD_POSTV2: PostV2Record postRecord = JsonConvert.DeserializeObject <PostV2Record>(recordJson); streamItem.Key = postRecord.Key; streamItem.CommentListKey = postRecord.CommentlistKey; streamItem.Type = postRecord.Type; streamItem.SubType = postRecord.Subtype; streamItem.Name = postRecord.Title; streamItem.Record = postRecord; break; case RECORD_LINKV2: LinkV2Record linkRecord = JsonConvert.DeserializeObject <LinkV2Record>(recordJson); streamItem.Key = linkRecord.Key; streamItem.Type = linkRecord.Type; streamItem.SubType = linkRecord.Subtype; streamItem.Name = linkRecord.Title; streamItem.Record = linkRecord; break; case RECORD_TASK: TaskRecord taskRecord = JsonConvert.DeserializeObject <TaskRecord>(recordJson); streamItem.CommentListKey = taskRecord.CommentlistKey; streamItem.Key = taskRecord.Key; streamItem.Type = taskRecord.Type; streamItem.SubType = taskRecord.Subtype; streamItem.Name = taskRecord.Name; streamItem.Record = taskRecord; break; case RECORD_FILE: FileRecord fileRecord = JsonConvert.DeserializeObject <FileRecord>(recordJson); streamItem.Key = fileRecord.Key; streamItem.Type = fileRecord.Type; streamItem.SubType = fileRecord.Subtype; streamItem.Name = fileRecord.Name; streamItem.Record = fileRecord; break; default: Console.WriteLine(recordWrapper.Recordtype); break; } dynamic recordObject = JsonConvert.DeserializeObject(recordJson); dynamic destinations = recordObject.destinations; try { streamItem.SpacePath = destinations[0].fullPath + "/" + destinations[0].displayName; } catch (Exception ex) { } SparcActionRecord lastAction = recordWrapper.LastAction; if (lastAction != null) { Double timeUpdated = Convert.ToDouble(lastAction.Timestamp); DateTime timeStamp = UnixTimeStampToDateTime(timeUpdated); streamItem.TimeUpdated = timeStamp; List <StreamRecordWrapper> actors = lastAction.Actors; if (actors.Count > 0) { String actorRecordType = actors[0].Recordtype; String userRecordJson = JsonConvert.SerializeObject(actors[0].Record); switch (actorRecordType) { case USER_OBJECT_RECORD: UserObjectRecord userRecord = JsonConvert.DeserializeObject <UserObjectRecord>(userRecordJson); streamItem.LastUpdater = userRecord.DisplayName; streamItem.LastUpdaterFirstName = userRecord.FirstName; streamItem.LastUpdaterLastName = userRecord.LastName; streamItem.LastUpdaterIconKey = userRecord.IconSmall; break; } } String verb = ""; switch (lastAction.Verb) { case "create": verb = "Created"; break; case "update": verb = "Updated"; break; case "delete": verb = "Deleted"; break; case "rename": verb = "Renamed"; break; default: break; } switch (lastAction.Sparctype) { case "summary": switch (lastAction.Sparcsubtype) { case "all": streamItem.LastActionContent = verb + " a " + RECORDS[streamItem.RecordType]; break; default: break; } break; case "content": StreamRecordWrapper actionRecordWrapper = lastAction.Containers[0]; String actionRecordJson = JsonConvert.SerializeObject(actionRecordWrapper.Record); switch (lastAction.Sparcsubtype) { case "comment": CommentV2Record commentRecord = JsonConvert.DeserializeObject <CommentV2Record>(actionRecordJson); String textWithoutComments = Regex.Replace(commentRecord.Text, "<!--.*?-->", String.Empty, RegexOptions.Multiline); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(HttpUtility.HtmlDecode(textWithoutComments)); streamItem.LastActionContent = doc.DocumentNode.InnerText; break; default: break; } break; default: break; } String path = ""; if (PATHS.ContainsKey(streamItem.RecordType)) { path = PATHS[streamItem.RecordType]; } else { log.Error("URL for record type " + streamItem.RecordType + " not found"); } streamItem.Link = session.OriginalHost + "/" + path + "/" + streamItem.Key;; streamItems.Add(streamItem); } } return(streamItems); } else { throw new Exception("Error searching stream"); } } catch (Exception ex) { throw new Exception("Error searching stream", ex); } }
/// <summary> /// Edits a players profile /// </summary> /// <permission cref="UserRole.User">Editing a profile requires the <see cref="SRLClient"/> to be authorized /// with the appropriate account (or the racebot account)</permission> /// <param name="playerName">The players name</param> /// <param name="youtube">The new youtube channel</param> /// <param name="twitter">The new twitter name</param> /// <param name="channel">The new streaming channel</param> /// <param name="api">The new Streaming API</param> /// <param name="country">The new Country</param> /// <param name="casename">The new name capitalization</param> /// <returns>Returns true on success</returns> public bool Edit(string playerName, string youtube = null, string twitter = null, string channel = null, StreamApi api = StreamApi.Unknown, string country = null, string casename = null) { Player p = Get(playerName); if (p != null && SrlClient.User.Role >= UserRole.User && (SrlClient.User.Name.Equals(playerName, StringComparison.OrdinalIgnoreCase) || SrlClient.User.Name.Equals("racebot", StringComparison.OrdinalIgnoreCase))) { Dictionary <string, string> dict = new Dictionary <string, string>(); if (youtube != null) { dict.Add("youtube", p.Youtube); } if (twitter != null) { dict.Add("twitter", p.Twitter); } if (channel != null) { dict.Add("channel", p.Channel); } if (api != StreamApi.Unknown) { dict.Add("api", api.ToString().ToLower()); } if (country != null) { dict.Add("country", p.Country); } if (casename?.Equals(playerName, StringComparison.OrdinalIgnoreCase) == true) { dict.Add("casename", casename); } if (dict.Count > 0 && SrlClient.Put(BasePath + "/" + playerName, dict)) { return(SrlClient.User.Verify()); } } return(false); }