public void ShareTicketResolvedFeed(Ticket ticket)
        {
            // record the activity
            ActivityFeedRepository activityFeedRepository = new ActivityFeedRepository();
            ActivityFeed           activityFeed           = new ActivityFeed();

            activityFeed.FeedActionCreatorUserId = UserHelpers.GetUserId(HttpContext.Current.User.Identity.Name);
            activityFeed.FeedActionDescription   = "Resolved & closed ticket #" + ticket.TicketId;

            int stringLenght = ticket.TicketResolutionDetails.Length;

            if (stringLenght > 180)
            {
                activityFeed.FeedActionDetails = ticket.TicketResolutionDetails.Substring(0, 180);
            }
            else
            {
                activityFeed.FeedActionDetails = ticket.TicketResolutionDetails.Substring(0, stringLenght);
            }

            activityFeed.FeedActionTimeStamp = DateTime.UtcNow;
            activityFeed.FeedMoreUrl         = HttpContext.Current.Request.ApplicationPath + "/Tickets/Ticket/Details/" + ticket.TicketId;

            activityFeedRepository.Add(activityFeed);
            activityFeedRepository.Save();
        }
        public string GetActivities(Array emailAddresses, DateTime startTime)
        {
            ActivityFeed af = null;

            try
            {
                af = m_provider.GetActivities((string[])emailAddresses, startTime, true, m_provider.ProviderData.SchemaVersion == ProviderSchemaVersion.v1_1);
            }
            catch (COMException cex)
            {
                if (Helpers.IsOSCException(cex))
                {
                    throw;
                }
                else
                {
                    throw new OSCException(@"GetActivities call failed.", OSCExceptions.OSC_E_INTERNAL_ERROR, cex);
                }
            }
            catch (ApplicationException ex)
            {
                throw new OSCException(@"GetActivities call failed.", OSCExceptions.OSC_E_INTERNAL_ERROR, ex);
            }
            if (af == null || af.Activities == null || af.Activities.Count == 0)
            {
                throw new OSCException(@"No changes", OSCExceptions.OSC_E_NO_CHANGES);
            }
            af.SchemaVersion = m_provider.ProviderData.SchemaVersion;
            return(af.Xml);
        }
        public void Valid_ActivityFeed_Has_Name_And_Type(string feedString)
        {
            var feed = new ActivityFeed(feedString);

            Assert.StartsWith(feed.Group.Name, feedString);
            Assert.EndsWith(feed.Name, feedString);
        }
        public void ShareTicketCommentReplyFeed(int ticketId, int ticketParentId, string commentReplyDetails)
        {
            ActivityFeedRepository activityFeedRepository = new ActivityFeedRepository();
            ActivityFeed           activityFeed           = new ActivityFeed();

            activityFeed.FeedActionCreatorUserId = UserHelpers.GetUserId(HttpContext.Current.User.Identity.Name);
            activityFeed.FeedActionDescription   = "Replied to commented on ticket #" + ticketId;

            int stringLenght = commentReplyDetails.Length;

            if (stringLenght > 180)
            {
                activityFeed.FeedActionDetails = commentReplyDetails.Substring(0, 180);
            }
            else
            {
                activityFeed.FeedActionDetails = commentReplyDetails.Substring(0, stringLenght);
            }

            activityFeed.FeedActionTimeStamp = DateTime.UtcNow;
            activityFeed.FeedMoreUrl         = HttpContext.Current.Request.ApplicationPath + "/Tickets/Ticket/Details/" + ticketId;

            activityFeedRepository.Add(activityFeed);
            activityFeedRepository.Save();
        }
Esempio n. 5
0
        public bool UpdateFeedItem(ActivityFeedCreate model)
        {
            var entity = new ActivityFeed()
            {
                UserID     = _userId,
                BusinessID = model.BusinessID,
                Activity   = $"{model.Activity}",
                ObjectID   = model.ObjectID,
                ObjectType = model.ObjectType,
                Content    = model.Content,
                Created    = DateTimeOffset.Now,
            };

            using (var ctx = new ApplicationDbContext())
            {
                var activity = $"{model.Activity}";
                try
                {
                    var oldActivity = ctx.ActivityFeed.Where(e => e.ObjectID == model.ObjectID && e.Activity == activity && e.UserID == _userId).First();
                    ctx.ActivityFeed.Remove(oldActivity);
                }
                catch { }
                ctx.ActivityFeed.Add(entity);
                ctx.SaveChanges();
                return(true);
            }
        }
Esempio n. 6
0
        public static void OnUserPresent()
        {
            Debug.WriteLine("OnUserPresent");
            ActivityFeed.Start();

            var lastActivity = ActivityFeed.Activities.Where(a => a.Type == 1).OrderByDescending(o => o.LastModified).FirstOrDefault();

            // Show Toast
            if (lastActivity != null)
            {
                dynamic payload       = JArray.Parse(lastActivity.Payload);
                string  artifactType  = payload.ArtifactTYpe;
                string  sourceAppName = payload.SourceAppName;
                var     activationId  = string.Empty;
                switch (artifactType)
                {
                case "App":
                    activationId = payload.SourceAppId;
                    break;

                case "WebPage":
                    activationId = payload.Uri;
                    break;

                case "AppItem":
                    activationId = payload.Uri;
                    break;
                }

                ShowToast(sourceAppName, activationId);
            }
        }
        public void ShareNewTicketFeed(Ticket ticket)
        {
            ActivityFeedRepository activityFeedRepository = new ActivityFeedRepository();
            ActivityFeed           activityFeed           = new ActivityFeed();

            activityFeed.FeedActionCreatorUserId = UserHelpers.GetUserId(HttpContext.Current.User.Identity.Name);
            activityFeed.FeedActionDescription   = "Created ticket #" + ticket.TicketId;

            int stringLenth = ticket.TicketDescription.Length;

            if (stringLenth > 180)
            {
                activityFeed.FeedActionDetails = ticket.TicketDescription.Substring(0, 179);
            }
            else
            {
                activityFeed.FeedActionDetails = ticket.TicketDescription.Substring(0, stringLenth);
            }

            activityFeed.FeedActionTimeStamp = DateTime.UtcNow;
            activityFeed.FeedMoreUrl         = HttpContext.Current.Request.ApplicationPath + "/Tickets/Ticket/Details/" + ticket.TicketId;

            activityFeedRepository.Add(activityFeed);
            activityFeedRepository.Save();
        }
        public void Cannot_Create_ActivityFeed_With_Invalid_Data(string feedString)
        {
            Action action = () =>
            {
                var feed = new ActivityFeed(feedString);
            };

            action.Should().Throw <InvalidOperationException>();
        }
Esempio n. 9
0
        public static void getActivities()
        {
            InitProvider();
            OAuth2Authenticator <NativeApplicationClient> auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthorization);

            PlusService  service = new PlusService(auth);
            ActivityFeed list    = service.Activities.List(userid, ActivitiesResource.Collection.Public).Fetch();

            Console.Write("2    " + list.Title);
        }
Esempio n. 10
0
 public bool LikedByUser(ActivityFeed activity)
 {
     foreach (var like in activity.Likes)
     {
         if (like.UserID == _userId)
         {
             return(true);
         }
     }
     return(false);
 }
        public static IList<Activity> GetAllActivitiesPaging(PlusService service, string _userId, int NumberOfPages, int ItemsPerPage, string NextPageToken)
        {
            //List next page activities in the specified collection for the current user.  
            // Documentation: https://developers.google.com/+/api/latest/activities/list
            int max = ItemsPerPage;
            int count = 0;
            int iterate = NumberOfPages;
            ActivitiesResource.ListRequest list = service.Activities.List(_userId, ActivitiesResource.ListRequest.CollectionEnum.Public__);

            if (NextPageToken != "" && NextPageToken != null)
                list.PageToken = NextPageToken;

            list.MaxResults = max;

            ActivityFeed activitesFeed = list.Execute();
            IList<Activity> Activites = new List<Activity>();
            count++;


            while (activitesFeed.Items != null || count <= iterate)
            {
                // Prepare the next page of results
                list.PageToken = activitesFeed.NextPageToken;

                // Adding each item  to the list.
                foreach (Activity item in activitesFeed.Items)
                {
                    Activites.Add(item);
                }

                if (activitesFeed.NextPageToken == null || count >= iterate)
                {
                    break;
                }


                // Execute and process the next page request
                activitesFeed = list.Execute();
                count++;
            }
            Activity token = new Activity();
            token.Title = activitesFeed.NextPageToken;
            Activites.Add(token);
            return Activites;
        }
Esempio n. 12
0
        public string GetFeedPostTime(ActivityFeed activity)
        {
            var timePosted = DateTimeOffset.Now - activity.Created;

            if (timePosted.Days > 0)
            {
                return($"{timePosted.Days}d");
            }
            if (timePosted.Hours > 0)
            {
                return($"{timePosted.Hours}h");
            }
            if (timePosted.Minutes > 0)
            {
                return($"{timePosted.Minutes}m");
            }
            return("now");
        }
        public static IList<Activity> SearchActivitiesPaging(PlusService service, string _query, int NumberOfPages, int ItemsPerPage, string NextPageToken)
        {
            //List all of the activities in the specified collection for the current user.  
            // Documentation: https://developers.google.com/+/api/latest/activities/list
            ActivitiesResource.SearchRequest list = service.Activities.Search(_query);
            int max = ItemsPerPage;
            int iterate = NumberOfPages;
            list.PageToken = NextPageToken;
            list.MaxResults = max;
            int count = 0;
            ActivityFeed activitesFeed = list.Execute();
            IList<Activity> Activites = new List<Activity>();
            count++;
            //// Loop through until we arrive at an empty page
            while (activitesFeed.Items != null || count <= iterate)
            {
                // Prepare the next page of results
                list.PageToken = activitesFeed.NextPageToken;

                // Adding each item  to the list.
                foreach (Activity item in activitesFeed.Items)
                {
                    Activites.Add(item);

                }

                // We will know we are on the last page when the next page token is
                // null.
                // If this is the case, break.
                if (activitesFeed.NextPageToken == null || count >= iterate)
                {
                    break;
                }


                // Execute and process the next page request
                activitesFeed = list.Execute();
                count++;
            }
            Activity token = new Activity();
            token.Title = activitesFeed.NextPageToken;
            Activites.Add(token);
            return Activites;
        }
Esempio n. 14
0
        public bool CreateBusinessFeedItem(ActivityFeedCreate model)
        {
            var entity = new ActivityFeed()
            {
                BusinessID = model.BusinessID,
                Activity   = $"{model.Activity}",
                ObjectID   = model.ObjectID,
                ObjectType = model.ObjectType,
                Content    = model.Content,
                Created    = DateTimeOffset.Now,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.ActivityFeed.Add(entity);
                ctx.SaveChanges();
                return(true);
            }
        }
Esempio n. 15
0
        public static void OnUserAway()
        {
            Debug.WriteLine("OnUserAway");

            ActivityFeed.Start();

            var lastActivity = ActivityFeed.Activities.Where(a => a.Type == 4).OrderByDescending(o => o.LastModified).FirstOrDefault();

            //publish last Activity as type 2
            var newActivity = new Activity
            {
                PackageId = Package.Current.Id.FamilyName,
                DeviceId  = "0018BFFECAB43303",
                Type      = 1,
                Priority  = 1,
                Payload   = lastActivity.Payload
            };

            //"0018BFFEC3585513";//"00187FFFBE535D3E";

            ActivityFeed.Add(newActivity);
        }
        /// <summary>
        /// List all of the activities in the specified collection for a particular user.
        /// 
        /// Documentation: https://developers.google.com/+/api/latest/activities/list
        /// </summary>
        /// <param name="service">a Valid authenticated PlusService</param>
        /// <param name="_userId">The ID of the user to get activities for. The special value "me" can be used to indicate the authenticated user.</param>
        /// <returns></returns>
        public static IList<Activity> GetAllActivities(PlusService service, string _userId)
        {
            //List all of the activities in the specified collection for the current user.  
            // Documentation: https://developers.google.com/+/api/latest/activities/list
            ActivitiesResource.ListRequest list = service.Activities.List(_userId, ActivitiesResource.ListRequest.CollectionEnum.Public__);
            list.MaxResults = 100;
            ActivityFeed activitesFeed = list.Execute();
            IList<Activity> Activites = new List<Activity>();



            //// Loop through until we arrive at an empty page
            while (activitesFeed.Items != null)
            {
                // Adding each item  to the list.
                foreach (Activity item in activitesFeed.Items)
                {
                    Activites.Add(item);
                }

                // We will know we are on the last page when the next page token is
                // null.
                // If this is the case, break.
                if (activitesFeed.NextPageToken == null)
                {
                    break;
                }

                // Prepare the next page of results
                list.PageToken = activitesFeed.NextPageToken;

                // Execute and process the next page request
                activitesFeed = list.Execute();

            }

            return Activites;
        }
Esempio n. 17
0
 public ActivityController()
 {
     _feed = new ActivityFeed(WebApiApplication.ObjectService);
 }
        public void Valid_ActivityFeed_Has_Name(string feedString)
        {
            var feed = new ActivityFeed(feedString);

            Assert.Equal(feedString, feed.Name);
        }
        //OSC Proxy Library method used to return activities.
        //Called by multiple interface methods that return ActivityFeeds:
        //  ISocialSession GetActivities
        //  ISocialSession2 GetActivitiesEx
        //  ISocialPerson GetActivities
        //  ISocialProfile GetActivitiesOfFriendsAndColleagues
        public override ActivityFeed GetActivities(string[] emailAddresses, DateTime startTime, bool dynamic, bool hashed)
        {
            //Verify that email addresses have been passed in.
            if (emailAddresses == null || emailAddresses.Length == 0)
            {
                throw new OSCException(@"No emails", OSCExceptions.OSC_E_INVALIDARG);
            }

            //Initialize the Activity Feed that will be returned.
            ActivityFeed activityFeed = new ActivityFeed();

            activityFeed.NetworkName = NETWORK_NAME;

            //The OfficeTalkAPI is not publicly available; all code communicating
            //    with OfficeTalk is disabled.
            //Please review the code below to get an idea of the types of activities
            //    you will need to perform when developing an OSC provider.

            //////Get a client for interacting with OfficeTalk.
            ////OfficeTalkClient otClient = OfficeTalkHelper.GetOfficeTalkClient();

            //////First create a list of unique OfficeTalk users to get activities
            //////    for from the email addresses.
            ////List<OTUser> uniquePeople = new List<OTUser>();

            //////Foreach email address call the OfficeTalk API to get the user.
            ////foreach (string emailAddress in emailAddresses)
            ////{
            ////    OTUser otUser = null;

            ////    //Check to see if the OSC passed in email addresses already hashed.
            ////    if (!hashed)
            ////    {
            ////        //Hash the Email address to find the user in OfficeTalk.
            ////        string hashedEmailAddress =
            ////            OSCProvider.Helpers.Hash(emailAddress, HashFunction.SHA1);

            ////        otUser = otClient.GetUserFromHash(hashedEmailAddress, Format.JSON);
            ////    }
            ////    else
            ////    {
            ////        //Email is already hashed, just find the user in OfficeTalk.
            ////        otUser = otClient.GetUserFromHash(emailAddress, Format.JSON);
            ////    }

            ////    //If an OfficeTalk user was found and they are not already in the
            ////    //    uniquePeople list add them to the list .
            ////    if (otUser != null)
            ////    {
            ////        if (!uniquePeople.Contains(otUser))
            ////        {
            ////            uniquePeople.Add(otUser);
            ////        }
            ////    }

            ////    //If the dynamic parameter was set all emailAddresses will be for
            ////    //    one person any remaining email addresses can be ignored.
            ////    if (dynamic && uniquePeople.Count > 0)
            ////    {
            ////        break;
            ////    }
            ////}

            //////For each of the OfficeTalk users get the messages from OfficeTalk and
            //////    add them to the activity feed.
            ////foreach (OTUser otUser in uniquePeople)
            ////{
            ////    //Call OfficeTalk to get all messages for the OfficeTalk User.
            ////    //The GetUserMessages method will return all messages created by the
            ////    //    user as well as all messages the user has responded to.
            ////    List<OTMessage> messages =
            ////      otClient.GetUserMessages(otUser.alias, Format.JSON);

            ////    if (messages != null)
            ////    {
            ////        foreach (OTMessage message in messages)
            ////        {
            ////            //Skip any messages with a created date less than the startTime.
            ////            if (message.created_atAsDateTime < startTime)
            ////            {
            ////                continue;
            ////            }

            ////            //Check to see if this message was created by the OfficeTalk
            ////            //    user or is a message the OfficeTalk user replied to.
            ////            if (message.user.id != otUser.id)
            ////            {
            ////                //Add the OfficeTalk reply messages to the activity feed.
            ////                AddReplyMessagesToActivityFeed(activityFeed, otUser, message);
            ////            }
            ////            else
            ////            {
            ////                //Add the OfficeTalk message to the activity feed.
            ////                AddMessageToActivityFeed(activityFeed, otUser, message);
            ////            }
            ////        }
            ////    }
            ////}

            //If there are activities to return return the activity feed.
            //If there are no activities return the OSC_E_NO_CHANGES error expected
            //    by the OSC.
            if (activityFeed.Activities.Count > 0)
            {
                return(activityFeed);
            }
            else
            {
                throw new OSCException(@"No activities", OSCExceptions.OSC_E_NO_CHANGES);
            }
        }
Esempio n. 20
0
        public void ProcessRequest(HttpContext context)
        {
            var tenant   = context.Session["TenantID"];
            int tenantId = tenant as int? ?? -1;

            if (tenantId == -1)
            {
                tenantId = Core.Utilities.Tenant.GetMasterID();
            }

            string cacheKey = string.Format("{0}.{1}", CacheKey.Feed, tenantId);

            try {
                if (context.Cache[cacheKey] != null)
                {
                    var cachedJsonResponse = context.Cache[cacheKey] as JsonFeed;
                    if (cachedJsonResponse != null)
                    {
                        context.Response.ContentType = "application/json";
                        context.Response.Write(JsonConvert.SerializeObject(cachedJsonResponse));
                        return;
                    }
                }
            } catch (Exception ex) {
                this.Log().Error("Error looking up feed data in cache: {0}", ex.Message);
            }

            var jsonResponse = new JsonFeed();
            var entries      = new List <JsonFeedEntry>();

            int after = 0;

            int.TryParse(context.Request.QueryString["after"], out after);

            //p.[AvatarID], p.[Username], bl.ListName, b.[UserName] as BadgeName, pp.[PPID], pp.[AwardDate], pp.[AwardReasonCd], pp.[BadgeId]
            try {
                var feed = new ActivityFeed().Latest(after, tenantId);
                foreach (DataRow dataRow in feed.Rows)
                {
                    var entry = new JsonFeedEntry {
                        ID            = (int)dataRow["PPID"],
                        AvatarId      = (int)dataRow["AvatarID"],
                        Username      = (string)dataRow["Username"],
                        AwardedAt     = ((DateTime)dataRow["AwardDate"]).ToString(),
                        AwardReasonId = (int)dataRow["AwardReasonCd"],
                        BadgeId       = (int)dataRow["BadgeId"],
                        ChallengeId   = dataRow["BLID"] == DBNull.Value ? 0 : (int)dataRow["BLID"]
                    };

                    if (entry.ID > jsonResponse.Latest)
                    {
                        jsonResponse.Latest = entry.ID;
                    }

                    switch (entry.AwardReasonId)
                    {
                    case 1:
                        // got badge
                        entry.AchievementName = (string)dataRow["BadgeName"];
                        break;

                    case 2:
                        // completed challenge
                        entry.AchievementName = (string)dataRow["ListName"];
                        break;

                    case 4:
                        entry.AchievementName = (string)dataRow["GameName"];
                        break;
                    }
                    entries.Add(entry);
                }

                jsonResponse.Entries = entries.ToArray();
                jsonResponse.Success = true;
            } catch (Exception ex) {
                this.Log().Error("Error loading feed: {0}", ex.Message);
                jsonResponse.Success = false;
            }

            if (jsonResponse.Success)
            {
                try {
                    DateTime cacheUntil = DateTime.UtcNow.AddSeconds(30);
                    if (context.Cache[cacheKey] == null)
                    {
                        //this.Log().Debug("Caching feed data until {0}",
                        //                 cacheUntil.ToLocalTime().ToLongTimeString());
                        context.Cache.Insert(cacheKey,
                                             jsonResponse,
                                             null,
                                             cacheUntil,
                                             System.Web.Caching.Cache.NoSlidingExpiration,
                                             System.Web.Caching.CacheItemPriority.Default,
                                             null);
                    }
                } catch (Exception ex) {
                    this.Log().Error("Error caching feed response: {0}", ex.Message);
                }
            }

            context.Response.ContentType = "application/json";
            context.Response.Write(JsonConvert.SerializeObject(jsonResponse));
        }