Example #1
0
		public void Template(object o, System.EventArgs e)
		{
			Cambro.Web.Helpers.WriteAlertHeader();

			Cambro.Web.Helpers.WriteAlert("Selecting xxx...", 1);
			Query q = new Query();
			//q.QueryCondition=???
			CommentSet bs = new CommentSet(q);
			for (int count = 0; count < bs.Count; count++)
			{
				Comment c = bs[count];

				try
				{
					// Do work here!
					c.Update();

					if (count % 10 == 0)
						Cambro.Web.Helpers.WriteAlert("Done " + count + "/" + bs.Count, 2);

				}
				catch(Exception ex)
				{
					Cambro.Web.Helpers.WriteAlert("Exception " + count + "/" + bs.Count + " - " + ex.ToString(), 3);
				}

				bs.Kill(count);

			}
			Cambro.Web.Helpers.WriteAlert("Done!", 3);
			Cambro.Web.Helpers.WriteAlertFooter();
		}
Example #2
0
			public MakerReturn Post()
			{
				MakerReturn r = new MakerReturn();
				#region look for duplicate
				Query qDup = new Query();
				qDup.TopRecords = 1;
				qDup.Columns = new ColumnSet(Bobs.Comment.Columns.K, Bobs.Comment.Columns.ThreadK);
				qDup.QueryCondition = new Q(Bobs.Comment.Columns.DuplicateGuid, (Guid)DuplicateGuid);
				CommentSet csDup = new CommentSet(qDup);
				if (csDup.Count > 0)
				{
					r.Success = false;
					r.MessageHtml = "Duplicate thread detected";
					r.Thread = csDup[0].Thread;
					r.Duplicate = true;
					return r;
				}
				#endregion
				#region ensure two parents are different types...
				if (ParentType.Equals(Model.Entities.ObjectType.Group) && GroupK != ParentK)
				{
					r.Success = false;
					r.MessageHtml = "Posting to group, but GroupK!=ParentK";
					return r;
				}
				#endregion
				#region Make sure Group and ParentType are syncronised
				if (GroupK > 0 && ParentType.Equals(Model.Entities.ObjectType.None))
				{
					ParentType = Model.Entities.ObjectType.Group;
					ParentK = GroupK;
				}
				if (GroupK == 0 && ParentType.Equals(Model.Entities.ObjectType.Group))
				{
					GroupK = ParentK;
				}
				#endregion
				#region if we're posting in a group, make sure we are a member
				if (GroupK > 0)
				{
					GroupUsr gu = ParentGroup.GetGroupUsr(PostingUsr);
					if (!PostingUsr.CanGroupMember(gu))
					{
						r.Success = false;
						r.MessageHtml = "You have tried to post a message in the " + ParentGroup.Link() + " group, but you're not currently a member of this group. Check out the group homepage for more information.";
						return r;
					}
				}
				#endregion
				#region ensure both parents map to real objects
				if (!ParentType.Equals(Model.Entities.ObjectType.None))
				{
					if (ParentBob == null)
					{
						r.Success = false;
						r.MessageHtml = "You've tried to post a message in a non-existant chat. Maybe it's been deleted.";
						return r;
					}
				}
				if (GroupK > 0)
				{
					if (ParentGroup == null)
					{
						r.Success = false;
						r.MessageHtml = "You've tried to post a message in a non-existant group. Maybe it's been deleted.";
						return r;
					}
				}
				#endregion
				#region Private
				bool tPrivate = false;
				bool gPrivate = false;
				if (Private)
				{
					if (GroupK == 0)
						tPrivate = true;
					else
						gPrivate = true;
				}
				#endregion
				#region News
				tNews = false;
				tNewsStatus = NewsStatusEnum.None;
				int tNewsLevel = 0;
				int tNewsUsrK = 0;
				int tNewsModeratorUsrK = 0;
				if (News)
				{
					if (tPrivate)
					{
						r.Success = false;
						r.MessageHtml = "You've tried to post private news! How did this happen?";
						return r;
					}
					else if (GroupK == 0)
					{
						r.Success = false;
						r.MessageHtml = "You've tried to post public non-group news. How did this happen?";
						return r;

						//if (PostingUsr.NewsPermissionLevel >= 10 || PostingUsr.IsSuper)
						//{
						//    tNews = true;
						//    tNewsStatus = NewsStatusEnum.Recommended;
						//    tNewsModeratorUsrK = Usr.GetNewsModeratorUsrK();
						//    tNewsLevel = 10;
						//    tNewsUsrK = PostingUsr.K;
						//}
						//else
						//{
						//    tNews = false;
						//    tNewsStatus = NewsStatusEnum.Recommended;
						//    tNewsModeratorUsrK = Usr.GetNewsModeratorUsrK();
						//    tNewsLevel = 0;
						//    tNewsUsrK = PostingUsr.K;
						//}
					}
					else
					{
						GroupUsr gu = ParentGroup.GetGroupUsr(PostingUsr);

						if (PostingUsr.CanGroupNewsAdmin(gu))
						{
							tNews = true;
							tNewsStatus = NewsStatusEnum.Done;
							tNewsLevel = 10;
							tNewsUsrK = PostingUsr.K;
						}
						else
						{
							tNews = false;
							tNewsStatus = NewsStatusEnum.Recommended;
							tNewsLevel = 10;
							tNewsUsrK = PostingUsr.K;
						}
					}
				}
				#endregion
				#region Sealed
				bool tSealed = false;
				if (Sealed)
				{
					if (tPrivate)
						tSealed = true;
				}
				#endregion
				#region Closed
				bool tClosed = false;
				if (Closed)
				{
					tClosed = true;
				}
				#endregion
				#region Review
				bool tReview = false;
				if (Review)
				{
					if (ParentType.Equals(Model.Entities.ObjectType.Event) && GroupK == 0)
					{
						Query qReviews = new Query();
						qReviews.QueryCondition = new And(
							new Q(Columns.UsrK, PostingUsr.K),
							new Q(Columns.ParentObjectType, Model.Entities.ObjectType.Event),
							new Q(Columns.ParentObjectK, ParentK),
							new Q(Columns.IsReview, true)
							);
						qReviews.TopRecords = 1;
						qReviews.Columns = new ColumnSet(Thread.Columns.K);
						ThreadSet tsReviews = new ThreadSet(qReviews);
						if (tsReviews.Count > 0)
						{
							r.Success = false;
							r.MessageHtml = "You've already posted a review. You can only post one review per event.";
							r.Duplicate = true;
							r.Thread = tsReviews[0];
							return r;
						}
						else
							tReview = true;
					}
					else
					{
						r.Success = false;
						r.MessageHtml = "You must post a review in an event chat board.";
						return r;
					}
				}
				#endregion

				if (GroupK > 0)
					CurrentGroupUsr = ParentGroup.GetGroupUsr(PostingUsr);

				Transaction trans = null;//new Transaction();

				NewThread = new Thread();

				try
				{
					#region Create thread
					NewThread.DateTime = DateTime.Now;
					NewThread.Enabled = true;
					NewThread.UsrK = PostingUsr.K;
					NewThread.LastPostUsrK = PostingUsr.K;
					NewThread.Subject = Helpers.Strip(Subject, true, true, true, true);

					NewThread.ParentObjectType = ParentType;
					NewThread.ParentObjectK = ParentK;
					if (GroupK > 0)
						NewThread.GroupK = ParentGroup.K;
					else
						NewThread.GroupK = 0;

					NewThread.Private = tPrivate;
					NewThread.GroupPrivate = gPrivate;
					if (GroupK > 0)
						NewThread.PrivateGroup = ParentGroup.PrivateChat;
					else
						NewThread.PrivateGroup = false;

					NewThread.IsNews = tNews;
					NewThread.NewsStatus = tNewsStatus;
					NewThread.NewsLevel = tNewsLevel;
					NewThread.NewsModeratorUsrK = tNewsModeratorUsrK;
					NewThread.NewsUsrK = tNewsUsrK;

					NewThread.Sealed = tSealed;
					NewThread.Closed = tClosed;
					NewThread.IsReview = tReview;

					NewThread.UpdateAncestorLinksNoUpdate();
					NewThread.Update(trans);

					#endregion

					#region Add PostingUsr ThreadUsr
					CurrentThreadUsr = new ThreadUsr();
					CurrentThreadUsr.DateTime = DateTime.Now;
					CurrentThreadUsr.InvitingUsrK = PostingUsr.K;
					CurrentThreadUsr.UsrK = PostingUsr.K;
					CurrentThreadUsr.ThreadK = NewThread.K;
					CurrentThreadUsr.ChangeStatus(ThreadUsr.StatusEnum.Archived, NewThread.DateTime);
					CurrentThreadUsr.StatusChangeObjectK = PostingUsr.K;
					CurrentThreadUsr.StatusChangeObjectType = Model.Entities.ObjectType.Usr;
					CurrentThreadUsr.Update(trans);
					#endregion

					#region Make the comment
					Comment.Maker cMaker = new Comment.Maker();
					cMaker.Body = Body;
					cMaker.ParentThread = NewThread;
					cMaker.DuplicateGuid = DuplicateGuid;
					cMaker.PostingUsr = PostingUsr;
					cMaker.InviteKs = InviteKs;
					cMaker.AlertedUsrs = AlertedUsrs;
					cMaker.NewThread = true;
					cMaker.CurrentThreadUsr = CurrentThreadUsr;
					cMaker.CurrentGroupUsr = CurrentGroupUsr;
					cMaker.RunAsync = RunAsync;
					cMaker.DisableLiveChatMessage = DisableLiveChatMessage;
					Comment.MakerReturn cReturn = null;
					try
					{
						cReturn = cMaker.Post(trans);
					}
					catch (Exception ex)
					{
						NewThread.DeleteAll(null);
						throw ex;
					}
					#endregion

					

					//SendThreadAlertsJob sendThreadsAlert = new SendThreadAlertsJob(NewThread.K, AlertedUsrs, PostingUsr.K, Subject, InviteKs);
					//if (this.RunAsync)
					//{
					//    sendThreadsAlert.ExecuteAsynchronously();
					//}
					//else
					//{
					//    sendThreadsAlert.ExecuteSynchronously();
					//}

					r.Success = true;
					r.Thread = NewThread;
					r.Comment = cReturn.Comment;
					return r;
				}
				catch (Exception ex)
				{
					//trans.Rollback();
					NewThread.DeleteAll(null);
					throw ex;
				}
				finally
				{
					//trans.Close();
				}
			}
Example #3
0
		public void UpdateTotalComments(Transaction transaction)
		{
			#region Update AverageCommentDateTime, TotalComments, HotTopicsOrder
			Query qStat = new Query();
			qStat.QueryCondition = new Q(Comment.Columns.ThreadK, this.K);
			qStat.TableElement = new JoinLeft(
				Comment.Columns.ThreadK,
				Thread.Columns.K);
			qStat.ExtraSelectElements = ThreadStats.ExtraSelectElements;
			qStat.Columns = new ColumnSet();
			ThreadStats tStat = new ThreadStats(qStat);
			this.AverageCommentDateTime = tStat.AverageCommentDateTime;
			this.TotalComments = tStat.CommentCount;
			this.HotTopicsOrder = this.AverageCommentDateTime.AddHours(this.TotalComments * 2);
			#endregion

			#region Update IndexInThread for all the comments (changed 13/03/2006 to order this by K rather than DateTime to sort problem with incorrect datetimes being set by different servers)
			Db.Qu(@"WITH CommentIndex_Tab AS
			(
			  SELECT *,
				ROW_NUMBER() OVER(ORDER BY [Comment].[K]) AS Row_Number
			  FROM [Comment] WHERE [Comment].[ThreadK] = " + this.K.ToString() + @"
			)
			UPDATE [CommentIndex_Tab]
			SET [CommentIndex_Tab].[IndexInThread] = Row_Number - 1
			WHERE [CommentIndex_Tab].[ThreadK] = " + this.K.ToString() + @" 
			AND [CommentIndex_Tab].[IndexInThread] != Row_Number - 1;");
			#endregion

			#region Update LastPost and LastPostUsrK
			Query qLastComment = new Query();
			qLastComment.TopRecords = 1;
			qLastComment.QueryCondition = new Q(Comment.Columns.ThreadK, this.K);
			qLastComment.OrderBy = new OrderBy(Comment.Columns.DateTime, OrderBy.OrderDirection.Descending);
			CommentSet cs = new CommentSet(qLastComment);
			if (cs.Count == 1)
			{
				this.LastPost = cs[0].DateTime;
				this.LastPostUsrK = cs[0].UsrK;
			}
			else
			{
				this.LastPost = this.DateTime;
				this.LastPostUsrK = this.UsrK;
			}
			#endregion

			this.Update(transaction);

			if (this.GroupK > 0 && this.Group != null)
				this.Group.UpdateTotalComments(transaction);

			if (!this.ParentObjectType.Equals(Model.Entities.ObjectType.Group) && this.Parent != null)
				this.Parent.UpdateTotalComments(transaction);

		}
Example #4
0
    /// <summary>
    /// Ignores current nodeData state and jumps directly to the specified node.
    /// </summary>
    /// <returns>
    /// The node.
    /// </returns>
    /// <param name='id'>
    /// The ID of your Node. Get it from the Dialogue Editor.
    /// </param>
    public NodeData SetNode(int id)
    {
        if (!isLoaded)
        {
            Debug.LogError("You must call the 'BeginDialogue()' method before calling the 'Next()' method!");
            return(null);
        }

        //Look for Node with given ID
        bool foundID = false;
        bool isPl    = false;
        bool isAct   = false;

        for (int i = 0; i < playerNodes.Count; i++)
        {
            if (playerNodes[i].ID == id)
            {
                currentPlayerStep = playerNodes[i];
                isPl    = true;
                foundID = true;
            }
        }
        if (!foundID)
        {
            for (int i = 0; i < npcNodes.Count; i++)
            {
                if (npcNodes[i].ID == id)
                {
                    currentNPCStep = npcNodes[i];
                    foundID        = true;
                }
            }
        }
        if (!foundID)
        {
            for (int i = 0; i < actionNodes.Count; i++)
            {
                if (actionNodes[i].ID == id)
                {
                    currentActionNode = actionNodes[i];
                    foundID           = true;
                    isAct             = true;
                }
            }
        }
        if (!foundID)
        {
            Debug.LogError("Could not find a Node with ID " + id.ToString());
            return(null);
        }

        /* Action node */

        if (isAct)
        {
            lastActionNode = currentActionNode;
            nodeData       = new NodeData();
            DoAction();
            return(nodeData);
        }

        /* Action end */

        if (isPl)
        {
            nodeData = new NodeData(true, false, currentPlayerStep.ID, GetOptions(), GetExtraData(), null, null, null, currentPlayerStep.playerTag);
            jumped   = true;
            return(nodeData);
        }
        else
        {
            List <string> ns = new List <string>();

            string[] rawSplit = Regex.Split(currentNPCStep.text, "<br>");
            foreach (string s in rawSplit)
            {
                if (s != "" && s != " ")
                {
                    ns.Add(s.Trim());
                }
            }

            nodeData = new NodeData(isPl, false, id, null, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag, "");
            return(nodeData);
        }
    }
Example #5
0
 void addComment(CommentSet id)
 {
     id.comment.Add(new Comment(id));
 }
Example #6
0
    /// <summary>
    /// Populates nodeData with the data from next Node based on the current nodeData.
    /// </summary>
    /// <returns></returns>
    public NodeData Next()
    {
        int option = nodeData.selectedOption;

        if (!isLoaded)
        {
            Debug.LogError("You must call the 'BeginDialogue()' method before calling the 'Next()' method!");
            return(null);
        }

        if (!jumped)
        {
            if (!nodeData.currentIsPlayer)
            {
                if (currentNPCStep.endConversation && nodeData.npcCommentIndex == nodeData.npcComment.Length - 1)
                {
                    nodeData.isEnd = true;
                    return(nodeData);
                }
            }
        }

        jumped = false;


        bool nextIsPlayer = true;

        if (!nodeData.currentIsPlayer)
        {
            nextIsPlayer = true;
            if (currentNPCStep.outputSet == null)
            {
                nextIsPlayer = false;
            }
        }
        else
        {
            nextIsPlayer = false;
        }

        if (!nodeData.currentIsPlayer)
        {
            if (nodeData.npcCommentIndex != nodeData.npcComment.Length - 1)
            {
                nodeData.npcCommentIndex++;
                return(nodeData);
            }

            if (nextIsPlayer)
            {
                currentPlayerStep = currentNPCStep.outputSet;
                nodeData          = new NodeData(true, false, currentPlayerStep.ID, GetOptions(), null, null, null);
            }
            else
            {
                currentNPCStep = currentNPCStep.outputNPC;
                List <string> ns = new List <string>();

                string[] rawSplit = Regex.Split(currentNPCStep.text, "<br>");
                foreach (string s in rawSplit)
                {
                    if (s != "" && s != " ")
                    {
                        ns.Add(s.Trim());
                    }
                }

                nodeData = new NodeData(false, false, currentNPCStep.ID, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag);
            }

            return(nodeData);
        }
        else
        {
            //Pick option 0 as default as we passed no params
            currentNPCStep = currentPlayerStep.comment[option].outputAnswer;

            List <string> ns = new List <string>();

            string[] rawSplit = Regex.Split(currentNPCStep.text, "<br>");
            foreach (string s in rawSplit)
            {
                if (s != "" && s != " ")
                {
                    ns.Add(s.Trim());
                }
            }

            nodeData = new NodeData(false, false, currentNPCStep.ID, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag);
            return(nodeData);
        }
    }
Example #7
0
		public void DeleteAll(Transaction transaction)
		{
			if (!this.Bob.DbRecordExists)
				return;


			Query qUsrEventGuestlist = new Query();
			qUsrEventGuestlist.QueryCondition = new Q(UsrEventGuestlist.Columns.UsrK, this.K);
			UsrEventGuestlistSet uegs = new UsrEventGuestlistSet(qUsrEventGuestlist);
			foreach (UsrEventGuestlist ueg in uegs)
			{
				ueg.Delete(transaction);
				ueg.Event.UpdateGuestlistCount(transaction);
			}

			//Promoters
			Query PromoterQ = new Query();
			PromoterQ.TableElement = Promoter.UsrJoin;
			PromoterQ.QueryCondition = new Q(Usr.Columns.K, this.K);
			PromoterSet promoters = new PromoterSet(PromoterQ);

			Delete PromoterUsrDelete = new Delete(
				TablesEnum.PromoterUsr,
				new Q(PromoterUsr.Columns.UsrK, this.K)
			);
			PromoterUsrDelete.CommandTimeout = 3600;
			PromoterUsrDelete.Run(transaction);

			foreach (Promoter p in promoters)
			{
				p.AdminUsrs = null;
				if (p.AdminUsrs.Count == 0)
				{
					p.DeleteAll(transaction);
				}
				else if (p.PrimaryUsrK == this.K)
				{
					p.PrimaryUsrK = p.AdminUsrs[0].K;
					p.Update(transaction);
				}
			}

			//UsrPlaceVisit
			Delete UsrPlaceVisitDelete = new Delete(
				TablesEnum.UsrPlaceVisit,
				new Q(UsrPlaceVisit.Columns.UsrK, this.K)
				);
			UsrPlaceVisitDelete.CommandTimeout = 3600;
			UsrPlaceVisitDelete.Run(transaction);

			//UsrEventAttended
			Delete UsrEventAttendedDelete = new Delete(
				TablesEnum.UsrEventAttended,
				new Q(UsrEventAttended.Columns.UsrK, this.K)
				);
			UsrEventAttendedDelete.CommandTimeout = 3600;
			UsrEventAttendedDelete.Run(transaction);

			//UsrPhotoFavourite
			Delete UsrPhotoFavouriteDelete = new Delete(
				TablesEnum.UsrPhotoFavourite,
				new Q(UsrPhotoFavourite.Columns.UsrK, this.K)
				);
			UsrPhotoFavouriteDelete.CommandTimeout = 3600;
			UsrPhotoFavouriteDelete.Run(transaction);

			//UsrPhotoMe
			PhotoSet psMe = this.PhotosMe(new ColumnSet(Photo.Columns.K, Photo.Columns.EventK, Photo.Columns.FirstUsrK, Photo.Columns.UsrCount), 0);
			foreach (Photo p in psMe)
			{
				this.PhotoMe(p, false, transaction);
			}

			//UsrMusicTypeFavourite
			Delete UsrMusicTypeFavouriteDelete = new Delete(
				TablesEnum.UsrMusicTypeFavourite,
				new Q(UsrMusicTypeFavourite.Columns.UsrK, this.K)
				);
			UsrMusicTypeFavouriteDelete.CommandTimeout = 3600;
			UsrMusicTypeFavouriteDelete.Run(transaction);

			//Buddy / Buddy reverse;
			BuddySet bs = new BuddySet(new Query(new Or(new Q(Buddy.Columns.UsrK, this.K), new Q(Buddy.Columns.BuddyUsrK, this.K))));
			foreach (Buddy b in bs)
				b.DeleteAll(transaction);

			//ChatMessageFrom
			//	Delete ChatMessageFromDelete = new Delete(
			//		TablesEnum.ChatMessage,
			//		new Q(ChatMessage.Columns.FromUsrK,this.K)
			//	);
			//	ChatMessageFromDelete.Run(transaction);

			//ChatMessageTo
			//	Delete ChatMessageToDelete = new Delete(
			//		TablesEnum.ChatMessage,
			//		new Q(ChatMessage.Columns.ToUsrK, this.K)
			//	);
			//	ChatMessageToDelete.Run(transaction);

			//UsrDate
			Delete UsrDateDelete = new Delete(
				TablesEnum.UsrDate,
				new Or(new Q(UsrDate.Columns.UsrK, this.K), new Q(UsrDate.Columns.DateUsrK, this.K))
				);
			UsrDateDelete.CommandTimeout = 3600;
			UsrDateDelete.Run(transaction);

			//Owners - Event
			EventSet esOwner = new EventSet(new Query(new Q(Event.Columns.OwnerUsrK, this.K)));
			foreach (Event e in esOwner)
			{
				e.OwnerUsrK = 8;
				e.Update(transaction);
			}

			BrandSet bsOwner = new BrandSet(new Query(new Q(Brand.Columns.OwnerUsrK, this.K)));
			foreach (Brand b in bsOwner)
			{
				b.OwnerUsrK = 8;
				b.Update(transaction);
			}

			//Owners - Venue
			VenueSet vsOwner = new VenueSet(new Query(new Q(Venue.Columns.OwnerUsrK, this.K)));
			foreach (Venue v in vsOwner)
			{
				v.OwnerUsrK = 8;
				v.Update(transaction);
			}

			//Remove EnabledByUsrK in Photos that this usr has enabled
			PhotoSet pEnableds = new PhotoSet(new Query(new Q(Photo.Columns.EnabledByUsrK, this.K)));
			foreach (Photo p in pEnableds)
			{
				p.EnabledByUsrK = 0;
				p.Update(transaction);
			}

			//ThreadUsr
			Delete ThreadUsrDelete = new Delete(
				TablesEnum.ThreadUsr,
				new Or(new Q(ThreadUsr.Columns.UsrK, this.K), new Q(ThreadUsr.Columns.InvitingUsrK, this.K))
				);
			ThreadUsrDelete.CommandTimeout = 3600;
			ThreadUsrDelete.Run(transaction);

			//CommentAlert
			Delete CommentAlertDelete = new Delete(
				TablesEnum.CommentAlert,
				new Q(CommentAlert.Columns.UsrK, this.K)
			);
			CommentAlertDelete.CommandTimeout = 3600;
			CommentAlertDelete.Run(transaction);


			//GroupUsr
			Delete GroupUsrDelete = new Delete(
				TablesEnum.GroupUsr,
				new Q(GroupUsr.Columns.UsrK, this.K)
				);
			GroupUsrDelete.CommandTimeout = 3600;
			GroupUsrDelete.Run(transaction);


			//Threads?
			ThreadSet ts = new ThreadSet(new Query(new Q(Thread.Columns.UsrK, this.K)));
			foreach (Thread t in ts)
				t.DeleteAll(transaction);

			Bobs.Update uLastPostUsrK = new Bobs.Update();
			uLastPostUsrK.Changes.Add(new Assign(Thread.Columns.LastPostUsrK, 0));
			uLastPostUsrK.Table = TablesEnum.Thread;
			uLastPostUsrK.Where = new Q(Thread.Columns.LastPostUsrK, this.K);
			uLastPostUsrK.CommandTimeout = 3600;
			uLastPostUsrK.Run(transaction);

			Bobs.Update uFirstParticipantUsrK = new Bobs.Update();
			uFirstParticipantUsrK.Changes.Add(new Assign(Thread.Columns.FirstParticipantUsrK, 0));
			uFirstParticipantUsrK.Table = TablesEnum.Thread;
			uFirstParticipantUsrK.Where = new Q(Thread.Columns.FirstParticipantUsrK, this.K);
			uFirstParticipantUsrK.CommandTimeout = 3600;
			uFirstParticipantUsrK.Run();

			//Comments?
			CommentSet cs = new CommentSet(new Query(new Q(Comment.Columns.UsrK, this.K)));
			foreach (Comment c in cs)
				c.DeleteAll(transaction);

			//PhotoReview ???
			PhotoReviewSet prs = new PhotoReviewSet(new Query(new Q(PhotoReview.Columns.UsrK, this.K)));
			foreach (PhotoReview pr in prs)
			{
				pr.Delete(transaction);
				pr.Photo.UpdateStats(transaction);
			}

			//Galleries
			GallerySet gs = new GallerySet(new Query(new Q(Gallery.Columns.OwnerUsrK, this.K)));
			foreach (Gallery g in gs)
				g.DeleteAll(transaction);

			//Photos
			PhotoSet ps = new PhotoSet(new Query(new Q(Photo.Columns.UsrK, this.K)));
			foreach (Photo p in ps)
				p.DeleteAll(transaction);

			//Aticles
			ArticleSet ars = new ArticleSet(new Query(new Q(Article.Columns.OwnerUsrK, this.K)));
			foreach (Article a in ars)
				a.DeleteAll(transaction);

			int k = this.K;

			//Usr-AddedByUsrK
			UsrSet usrsAddedByUsr = new UsrSet(new Query(new Q(Usr.Columns.AddedByUsrK, this.K)));
			foreach (Usr u in usrsAddedByUsr)
			{
				u.AddedByUsrK = 0;
				u.Update(transaction);
			}

			Guid oldPic = this.Pic;

			//Usr
			this.Delete(transaction);

			if (oldPic != Guid.Empty)
				Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

		}
Example #8
0
		public static void Template(string[] args)
		{

			Console.WriteLine("============");
			Console.WriteLine("Template");
			Console.WriteLine("============");
			
			if (args.Length == 0)
			{
				Console.WriteLine("Press any key...");
				Console.ReadLine();
			}

			Q loadBalancer = args.Length == 2 ? new StringQueryCondition(" ([Photo].[K] % " + int.Parse(args[1]).ToString() + " = " + ((int)(int.Parse(args[0]) - 1)).ToString() + ") ") : new Q(true);

			Console.WriteLine("Selecting...", 1);
			Query q = new Query();
			q.QueryCondition = new And(
				loadBalancer
			);
			CommentSet bs = new CommentSet(q);
			Console.WriteLine("Found " + bs.Count.ToString("#,##0") + " item(s)...", 1);
			for (int count = 0; count < bs.Count; count++)
			{
				Comment c = bs[count];

				try
				{
					// Do work here!
					c.Update();

					if (count % 10 == 0)
						Console.WriteLine("Done " + count + "/" + bs.Count, 2);

				}
				catch (Exception ex)
				{
					Console.WriteLine("Exception " + count + "/" + bs.Count + " - " + ex.ToString(), 3);
				}

				bs.Kill(count);

			}
			Console.WriteLine("All done!");
			Console.ReadLine();
		}
Example #9
0
 public Comment()
 {
     outputAnswer = null;
     inputSet     = null;
     text         = "Comment...";
 }
Example #10
0
			public MakerReturn Post(Transaction transaction)
			{
				if (HttpContext.Current!=null)
					HttpContext.Current.Items["VisitComments"]=1;

				MakerReturn r = new MakerReturn();

				#region Look for duplicates
				Query qDuplicate = new Query();
				qDuplicate.QueryCondition=new Q(Comment.Columns.DuplicateGuid,(Guid)DuplicateGuid);
				qDuplicate.Columns=new ColumnSet(Comment.Columns.K, Comment.Columns.IndexInThread, Comment.Columns.ThreadK);
				CommentSet csDuplicate = new CommentSet(qDuplicate);
				if (csDuplicate.Count>0)
				{
					r.Success = false;
					r.Duplicate = true;
					r.Comment = csDuplicate[0];
					return r;
				}
				#endregion
				#region Check permission
				if (!NewThread && !ParentThread.CheckPermissionPost(PostingUsr, CurrentThreadUsr, CurrentGroupUsr))
				{
					r.Success=false;
					r.MessageHtml="You can't post in this topic.";
					return r;
				}
				#endregion
				#region Check for closed thread
				if (!NewThread && ParentThread.Closed)
				{
					r.Success=false;
					r.MessageHtml="This topic is closed - posting is disabled.";
					return r;
				}
				#endregion
			
				#region Create comment
				NewComment = new Comment();
				NewComment.DateTime = DateTime.Now;
				if (HttpContext.Current!=null)
					NewComment.Ip = Utilities.TruncateIp(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]);

				if (ChatItemGuid == null)
					NewComment.ChatItemGuid = Guid.NewGuid();
				else
					NewComment.ChatItemGuid = ChatItemGuid;

				NewComment.Enabled = true;
				NewComment.Text = Body;
				NewComment.ThreadK = ParentThread.K;
				NewComment.UsrK = PostingUsr.K;
				if (!ParentThread.Private)
				{
					PostingUsr.CommentCount++;
					PostingUsr.Update(transaction);
				}
				NewComment.DuplicateGuid = (Guid)DuplicateGuid;
				NewComment.IndexInThread = ParentThread.TotalComments;
				NewComment.Update(transaction);
				#endregion

				#region Update thread
				ParentThread.LastPost=NewComment.DateTime;
				ParentThread.LastPostUsrK=NewComment.UsrK;
				ParentThread.Update(transaction);
				ParentThread.UpdateTotalComments(transaction);
				#endregion
				#region Update / create ThreadUsr
				CurrentThreadUsr.ChangeStatus(ThreadUsr.StatusEnum.Archived, NewComment.DateTime);
				CurrentThreadUsr.ViewDateTime = NewComment.DateTime;
				CurrentThreadUsr.ViewDateTimeLatest = NewComment.DateTime;
				CurrentThreadUsr.ViewComments = ParentThread.TotalComments;
				CurrentThreadUsr.ViewCommentsLatest = ParentThread.TotalComments;
				CurrentThreadUsr.Update(transaction);
				#endregion

				string chatMessageBody = "";
				bool alreadySentChatMessage = false;
				bool commentIsPrivate = ParentThread.Private || ParentThread.GroupPrivate || ParentThread.PrivateGroup;
				if (!DisableLiveChatMessage)
				{
					chatMessageBody = Chat.GetMessageFromCommentBody(Body);

					//If the thread is subject to group privacy and we are inviting people, we should wait until after all the invites have been processed before sending the 
					//message, or we might sent the chat message to people who don't have permission to see the thread
					bool commentIsSubjectToGroupPrivacy = ParentThread.GroupPrivate || ParentThread.PrivateGroup;
					bool canPostImmediatly = !commentIsSubjectToGroupPrivacy || InviteKs.Count == 0;
					if (!NewThread && canPostImmediatly)
					{
						//If we're NOT posting a new thread, we should post the chat message immediatly...
						//if we are posting a new thread, we should wait until after all the invites have been done, so we have a better list of participants.
						sendChatMessageToParticipantsNow(InviteKs, NewComment, ParentThread, PostingUsr, chatMessageBody);
						alreadySentChatMessage = true;
					}

					
					if (!commentIsPrivate)
					{
						//Since we don't invite anyone to this room, we can post immediatly to the random chat room.
						//CommentMessageStub ms = getChatMessage(
						//    //new Chat.RoomSpec(RoomType.RandomChat).Guid,
						//    new Chat.RoomSpec(RoomType.PublicStream).Guid,
						//    ParentThread.GetRoomSpec().Guid,
						//    NewComment,
						//    ParentThread,
						//    PostingUsr,
						//    chatMessageBody);
						//Chat.SendJsonChatItem(ms);

						CommentMessageStub ms1 = getChatMessage(
							new Chat.RoomSpec(RoomType.PublicStream).Guid,
							ParentThread.GetRoomSpec().Guid,
							NewComment,
							ParentThread,
							PostingUsr,
							chatMessageBody);
						Chat.SendJsonChatItem(ms1);
					}

				}

				try
				{
					if (NewThread && !commentIsPrivate && PostingUsr.FacebookConnected)
					{
						bool sentToFacebook = false;

						if (NewComment.Thread.IsReview && PostingUsr.FacebookStoryEventReview)
						{
							FacebookPost.CreateEventReview(PostingUsr, NewComment.Thread, NewComment);
							sentToFacebook = true;
						}

						if (!sentToFacebook && NewComment.Thread.IsNews && PostingUsr.FacebookStoryPostNews)
						{
							FacebookPost.CreateEventReview(PostingUsr, NewComment.Thread, NewComment);
							sentToFacebook = true;
						}

						if (!sentToFacebook && PostingUsr.FacebookStoryNewTopic)
						{
							FacebookPost.CreateNewTopic(PostingUsr, NewComment.Thread, NewComment);
						}
					}
				}
				catch { }

				SendCommentAlertsJob job = new SendCommentAlertsJob(
					this.ParentThread, 
					this.PostingUsr, 
					this.NewComment, 
					this.NewThread, 
					this.AlertedUsrs, 
					this.InviteKs,
					DisableLiveChatMessage,
					alreadySentChatMessage,
					chatMessageBody);

				if (Vars.DevEnv)
				{
					job.ExecuteSynchronously();
				}
				else
				{
					if (this.RunAsync)
						job.ExecuteAsynchronously();
					else
						job.ExecuteSynchronously();
				}

				if (Usr.Current != null && PostingUsr.K != Usr.DsiUsrK)
				{
					Usr.IncrementSpamBotDefeaterCounter(Usr.SpamBotDefeaterCounter.Comments, Usr.Current.K);
				}

				r.Success = true;
				r.Comment = NewComment;
				return r;

			}
    //This method will load the dialogue from the DialogueAssign component sent.
    static bool Load(string dName)
    {
        diags[currentDiag] = new Diags(diags[currentDiag].name, diags[currentDiag].loadTag);

        if (Resources.Load("Dialogues/" + dName) == null)
        {
            return(false);
        }

        Dictionary <string, object> dict = SerializeHelper.ReadFromFile(dName) as Dictionary <string, object>;

        int pDiags = (int)((long)dict["playerDiags"]);
        int nDiags = (int)((long)dict["npcDiags"]);
        int aDiags = 0;

        if (dict.ContainsKey("actionNodes"))
        {
            aDiags = (int)((long)dict["actionNodes"]);
        }

        diags[currentDiag].start = (int)((long)dict["startPoint"]);

        if (dict.ContainsKey("loadTag"))
        {
            diags[currentDiag].loadTag = (string)dict["loadTag"];
        }

        Sprite[]      sprites     = Resources.LoadAll <Sprite>("");
        List <string> spriteNames = new List <string>();

        foreach (Sprite t in sprites)
        {
            spriteNames.Add(t.name);
        }

        //Create first...
        for (int i = 0; i < pDiags; i++)
        {
            string tagt = "";

            if (dict.ContainsKey("pd_pTag_" + i.ToString()))
            {
                tagt = (string)dict["pd_pTag_" + i.ToString()];
            }


            addSet(
                (int)((long)dict["pd_comSize_" + i.ToString()]),
                (int)((long)dict["pd_ID_" + i.ToString()]),
                tagt
                );

            CommentSet com = diags[currentDiag].playerNodes[diags[currentDiag].playerNodes.Count - 1];

            if (dict.ContainsKey("pd_sprite_" + i.ToString()))
            {
                string name = Path.GetFileNameWithoutExtension((string)dict["pd_sprite_" + i.ToString()]);
                if (spriteNames.Contains(name))
                {
                    com.sprite = sprites[spriteNames.IndexOf(name)];
                }
                else
                {
                    Debug.LogError("'" + name + "' not found in any Resources folder!");
                }
            }


            if (dict.ContainsKey("pd_vars" + i.ToString()))
            {
                for (int v = 0; v < (int)(long)dict["pd_vars" + i.ToString()]; v++)
                {
                    com.vars.Add((string)dict["pd_var_" + i.ToString() + "_" + v.ToString()]);
                    com.varKeys.Add((string)dict["pd_varKey_" + i.ToString() + "_" + v.ToString()]);
                }
            }
        }

        for (int i = 0; i < nDiags; i++)
        {
            string tagt = "";

            if (dict.ContainsKey("nd_tag_" + i.ToString()))
            {
                tagt = (string)dict["nd_tag_" + i.ToString()];
            }

            addAnswer(
                (string)dict["nd_text_" + i.ToString()],
                (int)((long)dict["nd_ID_" + i.ToString()]),
                (string)dict["nd_extraData_" + i.ToString()],
                tagt
                );

            Answer npc = diags[currentDiag].npcNodes[diags[currentDiag].npcNodes.Count - 1];

            if (dict.ContainsKey("nd_sprite_" + i.ToString()))
            {
                string name = Path.GetFileNameWithoutExtension((string)dict["nd_sprite_" + i.ToString()]);

                if (spriteNames.Contains(name))
                {
                    npc.sprite = sprites[spriteNames.IndexOf(name)];
                }
                else
                {
                    Debug.LogError("'" + name + "' not found in any Resources folder!");
                }
            }


            if (dict.ContainsKey("nd_vars" + i.ToString()))
            {
                for (int v = 0; v < (int)(long)dict["nd_vars" + i.ToString()]; v++)
                {
                    npc.vars.Add((string)dict["nd_var_" + i.ToString() + "_" + v.ToString()]);
                    npc.varKeys.Add((string)dict["nd_varKey_" + i.ToString() + "_" + v.ToString()]);
                }
            }
        }
        for (int i = 0; i < aDiags; i++)
        {
            float pFloat;
            var   pfl = dict["ac_pFloat_" + i.ToString()];
            if (pfl.GetType() == typeof(System.Double))
            {
                pFloat = System.Convert.ToSingle(pfl);
            }
            else
            {
                pFloat = (float)(long)pfl;
            }


            diags[currentDiag].actionNodes.Add(new ActionNode(
                                                   (int)((long)dict["ac_ID_" + i.ToString()]),
                                                   (string)dict["ac_meth_" + i.ToString()],
                                                   (string)dict["ac_goName_" + i.ToString()],
                                                   (bool)dict["ac_pause_" + i.ToString()],
                                                   (bool)dict["ac_pBool_" + i.ToString()],
                                                   (string)dict["ac_pString_" + i.ToString()],
                                                   (int)((long)dict["ac_pInt_" + i.ToString()]),
                                                   pFloat
                                                   ));

            if (dict.ContainsKey("ac_ovrStartNode_" + i.ToString()))
            {
                diags[currentDiag].actionNodes[diags[currentDiag].actionNodes.Count - 1].ovrStartNode = (int)((long)dict["ac_ovrStartNode_" + i.ToString()]);
            }

            if (dict.ContainsKey("ac_renameDialogue_" + i.ToString()))
            {
                diags[currentDiag].actionNodes[diags[currentDiag].actionNodes.Count - 1].renameDialogue = (string)dict["ac_renameDialogue_" + i.ToString()];
            }
        }

        //Connect now...
        for (int i = 0; i < diags[currentDiag].playerNodes.Count; i++)
        {
            for (int ii = 0; ii < diags[currentDiag].playerNodes[i].comment.Count; ii++)
            {
                diags[currentDiag].playerNodes[i].comment[ii].text = (string)dict["pd_" + i.ToString() + "_com_" + ii.ToString() + "text"];

                if (dict.ContainsKey("pd_" + i.ToString() + "_com_" + ii.ToString() + "extraD"))
                {
                    diags[currentDiag].playerNodes[i].comment[ii].extraData = (string)dict["pd_" + i.ToString() + "_com_" + ii.ToString() + "extraD"];
                }

                int index = (int)((long)dict["pd_" + i.ToString() + "_com_" + ii.ToString() + "iSet"]);

                if (index != -1)
                {
                    diags[currentDiag].playerNodes[i].comment[ii].inputSet = diags[currentDiag].playerNodes[index];
                }

                index = (int)((long)dict["pd_" + i.ToString() + "_com_" + ii.ToString() + "oAns"]);

                if (index != -1)
                {
                    diags[currentDiag].playerNodes[i].comment[ii].outputAnswer = diags[currentDiag].npcNodes[index];
                }

                index = -1;
                if (dict.ContainsKey("pd_" + i.ToString() + "_com_" + ii.ToString() + "oAct"))
                {
                    index = (int)((long)dict["pd_" + i.ToString() + "_com_" + ii.ToString() + "oAct"]);
                }

                if (index != -1)
                {
                    diags[currentDiag].playerNodes[i].comment[ii].outAction = diags[currentDiag].actionNodes[index];
                }
            }
        }

        for (int i = 0; i < diags[currentDiag].npcNodes.Count; i++)
        {
            int index = (int)((long)dict["nd_oSet_" + i.ToString()]);
            if (index != -1)
            {
                diags[currentDiag].npcNodes[i].outputSet = diags[currentDiag].playerNodes[index];
            }

            if (dict.ContainsKey("nd_oNPC_" + i.ToString()))
            {
                int index2 = (int)((long)dict["nd_oNPC_" + i.ToString()]);
                if (index2 != -1)
                {
                    diags[currentDiag].npcNodes[i].outputNPC = diags[currentDiag].npcNodes[index2];
                }
            }

            if (dict.ContainsKey("nd_oAct_" + i.ToString()))
            {
                index = -1;
                index = (int)((long)dict["nd_oAct_" + i.ToString()]);
                if (index != -1)
                {
                    diags[currentDiag].npcNodes[i].outAction = diags[currentDiag].actionNodes[index];
                }
            }
        }

        for (int i = 0; i < diags[currentDiag].actionNodes.Count; i++)
        {
            diags[currentDiag].actionNodes[i].paramType = (int)((long)dict["ac_paramT_" + i.ToString()]);

            int index = -1;
            index = (int)((long)dict["ac_oSet_" + i.ToString()]);

            if (index != -1)
            {
                diags[currentDiag].actionNodes[i].outPlayer = diags[currentDiag].playerNodes[index];
            }

            if (dict.ContainsKey("ac_oNPC_" + i.ToString()))
            {
                index = -1;
                index = (int)((long)dict["ac_oNPC_" + i.ToString()]);
                if (index != -1)
                {
                    diags[currentDiag].actionNodes[i].outNPC = diags[currentDiag].npcNodes[index];
                }
            }

            if (dict.ContainsKey("ac_oAct_" + i.ToString()))
            {
                index = -1;
                index = (int)((long)dict["ac_oAct_" + i.ToString()]);
                if (index != -1)
                {
                    diags[currentDiag].actionNodes[i].outAction = diags[currentDiag].actionNodes[index];
                }
            }
        }

        diags[currentDiag].loaded = true;
        return(true);
    }
    /// <summary>
    /// Loads up the dialogue just sent. Populates the nodeData variable with the first Node based on the Start Node. Also returns the current NodeData package.
    /// </summary>
    /// <param name="diagToLoad"></param>
    /// <returns>NodeData</returns>
    public static NodeData BeginDialogue(VIDE_Assign diagToLoad)
    {
        if (diagToLoad.assignedIndex < 0 || diagToLoad.assignedIndex > diagToLoad.diags.Count - 1)
        {
            Debug.LogError("No dialogue assigned to VIDE_Assign!");
            return(null);
        }

        int theIndex = -1;

        for (int i = 0; i < diags.Count; i++)
        {
            if (diagToLoad.assignedDialogue == diags[i].name)
            {
                theIndex = i;
            }
        }

        if (theIndex == -1)
        {
            Debug.LogError("'" + diagToLoad.assignedDialogue + "' dialogue assigned to " + diagToLoad.gameObject.name + " not found! Did you delete the dialogue?");
            return(null);
        }

        currentDiag = theIndex; //assign current dialogue index

        //Check if the dialogue is already loaded
        if (!diags[currentDiag].loaded)
        {
            //Let's load the dialogue
            if (Load(diagToLoad.assignedDialogue))
            {
                isLoaded = true;
            }
            else
            {
                isLoaded    = false;
                currentDiag = -1;
                Debug.LogError("Failed to load '" + diagToLoad.diags[diagToLoad.assignedIndex] + "'");
                return(null);
            }
        }
        else
        {
            isLoaded = true;
        }

        //Make sure that variables were correctly reset after last conversation
        if (nodeData != null)
        {
            Debug.LogError("You forgot to call 'EndDialogue()' on last conversation!");
            return(null);
        }

        assigned   = diagToLoad;
        startPoint = diags[currentDiag].start;

        if (assigned.overrideStartNode != -1)
        {
            startPoint = assigned.overrideStartNode;
        }

        int  startIndex = -1;
        bool isPlayer   = false;
        bool isAct      = false;

        for (int i = 0; i < diags[currentDiag].npcNodes.Count; i++)
        {
            if (startPoint == diags[currentDiag].npcNodes[i].ID)
            {
                startIndex = i; isPlayer = false; break;
            }
        }
        for (int i = 0; i < diags[currentDiag].playerNodes.Count; i++)
        {
            if (startPoint == diags[currentDiag].playerNodes[i].ID)
            {
                startIndex = i; isPlayer = true; break;
            }
        }
        for (int i = 0; i < diags[currentDiag].actionNodes.Count; i++)
        {
            if (startPoint == diags[currentDiag].actionNodes[i].ID)
            {
                startIndex        = i;
                currentActionNode = diags[currentDiag].actionNodes[i]; isPlayer = true; isAct = true; break;
            }
        }

        /* Action node */

        if (isAct)
        {
            lastActionNode = currentActionNode;
            nodeData       = new NodeData();
            DoAction();
            return(nodeData);
        }

        /* Action end */

        if (startIndex == -1)
        {
            Debug.LogError("Start point not found! Check your IDs!");
            return(null);
        }

        if (isPlayer)
        {
            currentPlayerStep = diags[currentDiag].playerNodes[startIndex];

            lastActionNode = null;
            nodeData       = new NodeData(true, false, currentPlayerStep.ID, GetOptions(), GetExtraData(), null, null, null, currentPlayerStep.playerTag, currentPlayerStep.sprite, GetExtraVars(currentPlayerStep.varKeys.ToArray(), currentPlayerStep.vars.ToArray()));
            if (OnNodeChange != null)
            {
                OnNodeChange(nodeData);
            }
            return(nodeData);
        }
        else
        {
            currentNPCStep = diags[currentDiag].npcNodes[startIndex];

            List <string> ns = new List <string>();

            string[] rawSplit = Regex.Split(currentNPCStep.text, "<br>");
            foreach (string s in rawSplit)
            {
                if (s != "" && s != " ")
                {
                    ns.Add(s.Trim());
                }
            }

            lastActionNode = null;
            nodeData       = new NodeData(false, false, currentNPCStep.ID, null, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag, "", currentNPCStep.sprite, GetExtraVars(currentNPCStep.varKeys.ToArray(), currentNPCStep.vars.ToArray()));
            if (OnNodeChange != null)
            {
                OnNodeChange(nodeData);
            }
            return(nodeData);
        }
    }
    /// <summary>
    /// Modify the Extra Variables of a dialogue node.
    /// </summary>
    /// <param name="dialogueName">The dialogue to modify. Use VIDE_Data.assign.assignedDialogue to use currently active dialogue</param>
    /// <param name="nodeID">The node to modify. Make sure it exists.</param>
    /// <param name="newVars">A dictionary with the new content</param>
    public static void UpdateExtraVariables(string dialogueName, int nodeID, Dictionary <string, object> newVars)
    {
        int        diag       = -1;
        CommentSet playerNode = null;
        Answer     NPCNode    = null;

        for (int i = 0; i < diags.Count; i++)
        {
            if (diags[i].name == dialogueName)
            {
                if (diags[i].loaded)
                {
                    diag = i; break;
                }
                else
                {
                    Debug.LogError("'" + dialogueName + "' not loaded! Load it first by calling LoadDialogues()");
                    return;
                }
            }
        }

        if (diag == -1)
        {
            Debug.LogError("'" + dialogueName + "' not found!");
            return;
        }

        for (int i = 0; i < diags[diag].playerNodes.Count; i++)
        {
            if (diags[diag].playerNodes[i].ID == nodeID)
            {
                playerNode = diags[diag].playerNodes[i]; break;
            }
        }

        for (int i = 0; i < diags[diag].npcNodes.Count; i++)
        {
            if (diags[diag].npcNodes[i].ID == nodeID)
            {
                NPCNode = diags[diag].npcNodes[i]; break;
            }
        }

        if (playerNode == null && NPCNode == null)
        {
            Debug.LogError("Node ID " + nodeID.ToString() + " not found within the Player and NPC nodes!");
            return;
        }

        if (playerNode != null)
        {
            List <string> newStrings = new List <string>();
            foreach (KeyValuePair <string, object> entry in newVars)
            {
                newStrings.Add(entry.Value.ToString());
            }
            playerNode.vars = newStrings;
        }
        if (NPCNode != null)
        {
            List <string> newStrings = new List <string>();
            foreach (KeyValuePair <string, object> entry in newVars)
            {
                newStrings.Add(entry.Value.ToString());
            }
            NPCNode.vars = newStrings;
        }

        if (isLoaded && nodeData != null)
        {
            nodeData.dirty = true;
        }
    }
Example #14
0
		public void Bind()
		{
			RadioMaybe.Checked = false;
			RadioYes.Checked = false;
			RadioNo.Checked = false;
			RadioWrongSex.Checked = false;

			Pic.Src = ThisUsr.PicPath;
			NicknameH1.InnerHtml = ThisUsr.NickNameSafe;
			NicknameLabel.Text = ThisUsr.NickName;
			NicknameLabel1.Text = ThisUsr.NickName;

			Query commentCountQ = new Query();
			commentCountQ.TableElement = Comment.ThreadJoin;
			commentCountQ.QueryCondition = new And(new Q(Comment.Columns.UsrK, UsrK), new Q(Thread.Columns.Private, false));
			commentCountQ.ReturnCountOnly = true;
			CommentSet cs = new CommentSet(commentCountQ);
			UsrCommentsLabel.Text = cs.Count.ToString() + " comment" + (cs.Count == 1 ? "" : "s");

			int photosMeCount = ThisUsr.PhotosMeCount;
			if (photosMeCount == 0)
				UsrSpottedLabel.Text = "I've not been spotted yet";
			else if (photosMeCount == 1)
				UsrSpottedLabel.Text = "I've been spotted once";
			else
				UsrSpottedLabel.Text = "I've been spotted " + photosMeCount + " times";

			UsrMusicTypesLabel.Text = "";
			for (int i = 0; i < ThisUsr.MusicTypesFavourite.Count; i++)
			{
				UsrMusicTypesLabel.Text += (i == 0 ? "" : (i == ThisUsr.MusicTypesFavourite.Count - 1 ? " and " : ", ")) + ThisUsr.MusicTypesFavourite[i].GenericName;
			}

			UsrPlaceVisitLabel.Text = "";
			PlaceSet ps = ThisUsr.PlacesVisit(Place.NameColumns, 0);
			for (int i = 0; i < ps.Count; i++)
			{
				UsrPlaceVisitLabel.Text += (i == 0 ? "" : (i == ps.Count - 1 ? " and " : ", ")) + ps[i].Name;
			}

			if (ThisUsr.PersonalStatement.Length > 0)
			{
				string html = ThisUsr.PersonalStatement;
				if (html.IndexOf("<p>") == -1)
				{
					html = html.Replace("\n", "<br>");
					html = "<p>" + html + "</p>";
				}
				PersonalStatementLabel.Text = html;
			}
			else
			{
				PersonalStatementPanel.Visible = false;
				PersonalStatementLabel.Text = "";
			}

			PhotosIFrame.Attributes["src"] = "/popup/datephotolist/usrk-" + ThisUsr.K.ToString();

			if (Usr.Current.DateSexFemale && Usr.Current.DateSexMale)
				RadioWrongSex.Visible = false;
			else
			{
				RadioWrongSex.Text = RadioWrongSex.Text.Replace("?", Usr.Current.DateSexMale ? "boy" : "girl");
				RadioWrongSex.Attributes["onclick"] = "document.getElementById('WrongSexP').style.display=''";
			}

			try
			{
				UsrDate ud = new UsrDate(Usr.Current.K, ThisUsr.K);
				if (ud.Status.Equals(UsrDate.StatusEnum.Maybe))
					RadioMaybe.Checked = true;
				else if (ud.Status.Equals(UsrDate.StatusEnum.Yes))
					RadioYes.Checked = true;
				else if (ud.Status.Equals(UsrDate.StatusEnum.No))
					RadioNo.Checked = true;
			}
			catch { }

			Query q = new Query();
			q.OrderBy = new OrderBy(new OrderBy(Photo.Columns.WeightedSexyRating, OrderBy.OrderDirection.Descending), new OrderBy(Photo.Columns.WeightedCoolRating, OrderBy.OrderDirection.Descending));
			q.TableElement = Photo.UsrMeJoin;
			q.QueryCondition = new Q(Usr.Columns.K, UsrK);
			q.TopRecords = 1;
			PhotoSet psMe = new PhotoSet(q);
			if (psMe.Count == 1)
			{
				PhotosPanel.Visible = true;
				WebImg.Src = psMe[0].WebPath;
			}
			else
				PhotosPanel.Visible = false;
		}
        // 请求例子  /httpSever/CommentHandler.ashx?json={"jsonEntity":{"GetByPostId":""},"action":"GetByPostId"}
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            // context.Response.Write("Hello World");
            HttpReSultMode resultMode = new HttpReSultMode();

            try
            {
                JObject httpObject = JsonHelper.FromJson(context.Request["json"]);
                int     pageIndex  = 1;
                int     pageSize   = 10000;
                int     res        = 0;
                switch (httpObject["action"].ToString())
                {
                case "add":
                    #region
                    Comment Rmodel = JsonHelper.FromJson <Comment>(httpObject["jsonEntity"].ToString());
                    Rmodel.Id        = Guid.NewGuid();
                    Rmodel.AddTime   = DateTime.Now;
                    Rmodel.States    = 0;
                    Rmodel.isValid   = true;
                    Rmodel.isDeleted = false;
                    OPBiz.Add(Rmodel);
                    resultMode.Code = 11;
                    resultMode.Msg  = "添加成功";
                    resultMode.Data = Rmodel.Id.ToString();

                    #endregion
                    break;

                case "delete":
                    #region
                    string Id = httpObject["jsonEntity"]["Id"].ToString();
                    //var mqlD = CommentSet.Id.Equal(Id);
                    //int f = OPBiz.Remove<CommentSet>(mqlD);
                    int f = OPBiz.DelForSetDelete("Id", Id);
                    if (f > 0)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "删除成功";
                        resultMode.Data = "";
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "删除失败";
                        resultMode.Data = "";
                    }
                    #endregion
                    break;

                case "GetById":
                    #region
                    Id = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString());
                    var     mqlG   = CommentSet.SelectAll().Where(CommentSet.Id.Equal(Id));
                    Comment modelG = OPBiz.GetEntity(mqlG);
                    if (modelG != null)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "获取成功";
                        resultMode.Data = JsonHelper.ToJson(modelG, true);
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "数据不存在";
                        resultMode.Data = "";
                    }
                    #endregion

                    break;

                case "GetByPostId":
                    #region
                    string         IdG     = httpObject["jsonEntity"]["PostId"].ToString();
                    var            mqlG2   = CommentSet.SelectAll().Where(CommentSet.PostId.Equal(IdG).And(CommentSet.isDeleted.Equal(0)).And(CommentSet.isValid.Equal(1)));
                    List <Comment> modelG2 = OPBiz.GetEntities(mqlG2);
                    if (modelG2 != null)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "获取成功";
                        resultMode.Data = JsonHelper.ToJson(modelG2, true);
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "数据不存在";
                        resultMode.Data = "";
                    }
                    #endregion

                    break;

                case "GetByPostIdPage":
                    #region
                    if (httpObject["pageIndex"] != null)
                    {
                        pageIndex = int.Parse(httpObject["pageIndex"].ToString());
                    }

                    if (httpObject["pageSize"] != null)
                    {
                        pageSize = int.Parse(httpObject["pageSize"].ToString());
                    }
                    string  PostId = httpObject["jsonEntity"]["PostId"].ToString();
                    int     sum    = 0;
                    int     page   = 0;
                    var     sqlp   = CommentSet.SelectAll().Where(CommentSet.PostId.Equal(PostId).And(CommentSet.isDeleted.Equal(0)).And(CommentSet.isValid.Equal(1)));
                    DataSet listp  = OPBiz.GetPagingDataSet(sqlp, out page, out sum, pageIndex, pageSize, "AddTime");
                    if (listp != null)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "获取成功";
                        resultMode.Data = JsonHelper.ToJson(listp, true);
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "数据不存在";
                        resultMode.Data = "";
                    }
                    #endregion
                    break;

                case "GetByUserId":
                    #region
                    string         Idu   = httpObject["jsonEntity"]["UserId"].ToString();
                    var            mqlu  = CommentSet.SelectAll().Where(CommentSet.UserId.Equal(Idu).And(CommentSet.isDeleted.Equal(0)).And(CommentSet.isValid.Equal(1)));
                    List <Comment> listu = OPBiz.GetEntities(mqlu);
                    if (mqlu != null)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "获取成功";
                        resultMode.Data = JsonHelper.ToJson(listu, true);
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "数据不存在";
                        resultMode.Data = "";
                    }
                    #endregion

                    break;

                case "GetByUserIdPage":
                    #region
                    if (httpObject["pageIndex"] != null)
                    {
                        pageIndex = int.Parse(httpObject["pageIndex"].ToString());
                    }

                    if (httpObject["pageSize"] != null)
                    {
                        pageSize = int.Parse(httpObject["pageSize"].ToString());
                    }
                    string  UserId = httpObject["jsonEntity"]["UserId"].ToString();
                    int     sum2   = 0;
                    int     page2  = 0;
                    var     sqlp2  = CommentSet.SelectAll().Where(CommentSet.UserId.Equal(UserId).And(CommentSet.isDeleted.Equal(0)).And(CommentSet.isValid.Equal(1)));
                    DataSet listp2 = OPBiz.GetPagingDataSet(sqlp2, out page2, out sum2, pageIndex, pageSize, "AddTime");
                    if (listp2 != null)
                    {
                        resultMode.Code = 11;
                        resultMode.Msg  = "获取成功";
                        resultMode.Data = JsonHelper.ToJson(listp2, true);
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Msg  = "数据不存在";
                        resultMode.Data = "";
                    }
                    #endregion
                    break;

                case "PraiseCount":    //点赞量加1
                    Id  = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString());
                    res = OPBiz.SetCout("Id", Id, "Praises");
                    if (res > 0)
                    {
                        resultMode.Code = 11;
                        resultMode.Data = res.ToString();
                        resultMode.Msg  = "统计成功";
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Data = "0";
                        resultMode.Msg  = "统计失败!";
                    }


                    break;

                case "ReportsCount":    //举报加1
                    Id  = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Id"].ToString());
                    res = OPBiz.SetCout("Id", Id, "Reports");
                    if (res > 0)
                    {
                        resultMode.Code = 11;
                        resultMode.Data = res.ToString();
                        resultMode.Msg  = "统计成功";
                    }
                    else
                    {
                        resultMode.Code = -13;
                        resultMode.Data = "0";
                        resultMode.Msg  = "统计失败!";
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                resultMode.Code = -11;
                resultMode.Data = ex.ToString();
            }
            context.Response.Write(JsonHelper.ToJson(resultMode, true));
            context.Response.End();
        }
Example #16
0
		static void SendAll(int delay, string type)
		{
			Random r = new Random();
			Query q = new Query();
			q.TopRecords = 10;
			if (type == "c")
			{
				q.QueryCondition = new Q(ChatMessage.Columns.K, QueryOperator.GreaterThan, r.Next(15000000) + 5000);
				ChatMessageSet bs = new ChatMessageSet(q);
				if (bs.Count == 0)
				{
					for (int i = 1; i < 100; i++)
					{
						SendNow(new ChatMessage() { 
							DateTime = new DateTime(2008, 12, 1), 
							UsrK = 1,
							K = 2456543,
							Text = "This is a message"}, r);
						System.Threading.Thread.Sleep(r.Next(delay / 10, delay));
					}
				}
				else
				{
					for (int i = 0; i < bs.Count - 1; i++)
					{
						SendNow(bs[i], r);

						System.Threading.Thread.Sleep(r.Next(delay / 10, delay));
						//Console.ReadLine();
					}
				}
			}
			else if (type == "p")
			{
				q.QueryCondition = new Q(Photo.Columns.K, QueryOperator.GreaterThan, r.Next(8000000) + 5000);
				PhotoSet bs = new PhotoSet(q);

				for (int i = 0; i < bs.Count - 1; i++)
				{
					SendNow(bs[i], r);

					System.Threading.Thread.Sleep(r.Next(delay / 10, delay));
					//Console.ReadLine();
				}
			}
			else if (type == "o")
			{
				q.QueryCondition = new Q(Comment.Columns.K, QueryOperator.GreaterThan, r.Next(8000000) + 5000);
				CommentSet bs = new CommentSet(q);

				for (int i = 0; i < bs.Count - 1; i++)
				{
					try
					{
						bs[i].SendLiveChatMessagesForTesting();
					}
					catch (Exception ex)
					{
						Console.WriteLine(ex.ToString());
					}

					System.Threading.Thread.Sleep(r.Next(delay / 10, delay));
					//Console.ReadLine();
				}
			}
			else if (type == "u")
			{
				q.QueryCondition = new And(new Q(Usr.Columns.K, QueryOperator.GreaterThan, r.Next(2000000) + 100), new Q(Usr.Columns.CommentCount, QueryOperator.GreaterThan, 100));
				UsrSet bs = new UsrSet(q);

				for (int i = 0; i < bs.Count - 1; i++)
				{
					try
					{
						Guid g = Guid.Empty;

						ChatLibrary.ChatServerInterface cs1 = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress);
						cs1.JoinRoom(new Chat.RoomSpec(RoomType.Normal).Guid, bs[i].K);

						ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress);
						string chatItems = cs.GetLatest(bs[i].K, 23423, true, Guid.Empty, ref g);
						Console.WriteLine(chatItems);
					}
					catch(Exception ex)
					{
						Console.WriteLine(ex.ToString());
					}

					System.Threading.Thread.Sleep(r.Next(delay / 10, delay));
					//Console.ReadLine();
				}
			}

		}
Example #17
0
		protected string Number(int DateSpan, int StatType)
		{
			TimeSpan ts = DateTime.Today.Subtract(new DateTime(1970, 1, 1));
			int dayIndexNow = ts.Days;
			//return dayIndexNow.ToString();
			int dayMin = dayIndexNow;
			int dayMax = dayIndexNow;
			DateTime dateMin = DateTime.Today;
			DateTime dateMax = DateTime.Today.AddDays(1);
			bool estimateWholeDay = false;
			if (DateSpan == 10)
				estimateWholeDay = true;
			else if (DateSpan == 1)
			{
				dayMin = dayIndexNow - 1;
				dayMax = dayIndexNow - 1;
				dateMin = DateTime.Today.AddDays(-1);
				dateMax = DateTime.Today;
			}
			else if (DateSpan == 2)
			{
				dayMin = dayIndexNow - 7;
				dayMax = dayIndexNow - 1;
				dateMin = DateTime.Today.AddDays(-7);
				dateMax = DateTime.Today;
			}
			else if (DateSpan == 3)
			{
				dayMin = dayIndexNow - 30;
				dayMax = dayIndexNow - 1;
				dateMin = DateTime.Today.AddMonths(-1);
				dateMax = DateTime.Today;
			}
			else if (DateSpan == 4)
			{
				dayMin = dayIndexNow - 365;
				dayMax = dayIndexNow - 1;
				dateMin = DateTime.Today.AddDays(-365);
				dateMax = DateTime.Today;
			}
			else if (DateSpan == 5)
			{
				dayMin = 0;
				dayMax = dayIndexNow;
				dateMin = new DateTime(2000, 1, 1);
				dateMax = new DateTime(3000, 1, 1);
			}
			else if (DateSpan == 15)
			{
				dayMin = 0;
				dayMax = dayIndexNow;
				dateMin = DateTime.Now.AddMinutes(-5);
				dateMax = DateTime.Now;
			}
			else if (DateSpan == 130)
			{
				dayMin = 0;
				dayMax = dayIndexNow;
				dateMin = DateTime.Now.AddMinutes(-30);
				dateMax = DateTime.Now;
			}

			int number = 0;


			if (StatType == 1) // Uniques
			{
				Query q = new Query();
				q.NoLock = true;
				q.Columns = new ColumnSet();
				q.ExtraSelectElements["count"] = "count(distinct Guid)";
				q.QueryCondition = new And(
					new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Visit.Columns.DateTimeLast, QueryOperator.GreaterThanOrEqualTo, dateMin)),
					new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.LessThan, dateMax), new Q(Visit.Columns.DateTimeLast, QueryOperator.LessThan, dateMax)),
					new Or(new Q(Visit.Columns.Pages, QueryOperator.GreaterThan, 1), new Q(Visit.Columns.IsNewGuid, false))
					);

				VisitSet vs = new VisitSet(q);

				number = (int)vs[0].ExtraSelectElements["count"];
			}
			else if (StatType == 2) //Pages
			{
				Query q = new Query();
				q.NoLock = true;
				q.Columns = new ColumnSet();
				q.ExtraSelectElements["sum"] = "sum(Count)";
				q.QueryCondition = new And(
					new Q(Log.Columns.Date, QueryOperator.GreaterThanOrEqualTo, dateMin),
					new Q(Log.Columns.Date, QueryOperator.LessThan, dateMax),
					new Q(Log.Columns.Item, Log.Items.DsiPages)
					);

				LogSet ls = new LogSet(q);

				number = (int)ls[0].ExtraSelectElements["sum"];
			}
			else if (StatType == 4) //Photos
			{
				if (DateSpan == 5)
				{
					Query q = new Query();
					q.NoLock = true;
					q.OrderBy = new OrderBy(Photo.Columns.K, OrderBy.OrderDirection.Descending);
					q.Columns = new ColumnSet(Photo.Columns.K);
					q.TopRecords = 1;
					PhotoSet ps = new PhotoSet(q);
					number = ps[0].K;
				}
				else
				{
					Query q = new Query();
					q.NoLock = true;
					q.QueryCondition = new And(
						Photo.EnabledQueryCondition,
						new Q(Photo.Columns.EnabledDateTime, QueryOperator.GreaterThanOrEqualTo, dateMin),
						new Q(Photo.Columns.EnabledDateTime, QueryOperator.LessThan, dateMax)
						);
					q.ReturnCountOnly = true;
					PhotoSet ps = new PhotoSet(q);
					number = ps.Count;
				}
			}
			else if (StatType == 5) //Events
			{
				if (DateSpan == 5)
				{
					Query q = new Query();
					q.NoLock = true;
					q.OrderBy = new OrderBy(Event.Columns.K, OrderBy.OrderDirection.Descending);
					q.Columns = new ColumnSet(Event.Columns.K);
					q.TopRecords = 1;
					EventSet es = new EventSet(q);
					number = es[0].K;
				}
				else
				{
					Query q = new Query();
					q.NoLock = true;
					q.QueryCondition = new And(
						new Q(Event.Columns.AddedDateTime, QueryOperator.GreaterThanOrEqualTo, dateMin),
						new Q(Event.Columns.AddedDateTime, QueryOperator.LessThan, dateMax)
						);
					q.ReturnCountOnly = true;
					EventSet es = new EventSet(q);
					number = es.Count;
				}
			}
			else if (StatType == 6) //New users
			{
				if (DateSpan == 5)
				{
					Query q = new Query();
					q.NoLock = true;
					q.OrderBy = new OrderBy(Usr.Columns.K, OrderBy.OrderDirection.Descending);
					q.Columns = new ColumnSet(Usr.Columns.K);
					q.TopRecords = 1;
					UsrSet us = new UsrSet(q);
					number = us[0].K;
				}
				else
				{
					Query q = new Query();
					q.NoLock = true;
					q.QueryCondition = new And(
						new Q(Usr.Columns.DateTimeSignUp, QueryOperator.GreaterThanOrEqualTo, dateMin),
						new Q(Usr.Columns.DateTimeSignUp, QueryOperator.LessThan, dateMax)
						);
					q.ReturnCountOnly = true;
					UsrSet us = new UsrSet(q);
					number = us.Count;
				}
			}
			else if (StatType == 7) //Users logged on
			{
				if (DateSpan == 5)
				{
					Query q = new Query();
					q.NoLock = true;
					q.QueryCondition = Usr.IsNotSkeletonQ;
					q.ReturnCountOnly = true;
					UsrSet us = new UsrSet(q);
					number = us.Count;
				}
				else
				{
					Query q = new Query();
					q.NoLock = true;
					if (DateSpan == 1)
					{
						q.QueryCondition = new Q(Usr.Columns.DateTimeLastPageRequest, QueryOperator.GreaterThanOrEqualTo, DateTime.Now.AddDays(-1));
					}
					else
					{
						q.QueryCondition = new And(
							new Q(Usr.Columns.DateTimeLastPageRequest, QueryOperator.GreaterThanOrEqualTo, dateMin),
							new Q(Usr.Columns.DateTimeLastPageRequest, QueryOperator.LessThan, dateMax)
							);
					}
					q.QueryCondition = new And(Usr.IsNotSkeletonQ, q.QueryCondition);
					q.ReturnCountOnly = true;
					UsrSet us = new UsrSet(q);
					number = us.Count;
				}
			}
			else if (StatType == 8) //Comments
			{
				if (DateSpan == 5)
				{
					Query q = new Query();
					q.NoLock = true;
					q.OrderBy = new OrderBy(Comment.Columns.K, OrderBy.OrderDirection.Descending);
					q.Columns = new ColumnSet(Comment.Columns.K);
					q.TopRecords = 1;
					CommentSet cs = new CommentSet(q);
					number = cs[0].K;
				}
				else
				{
					Query q = new Query();
					q.NoLock = true;
					q.QueryCondition = new And(
						new Q(Comment.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, dateMin),
						new Q(Comment.Columns.DateTime, QueryOperator.LessThan, dateMax)
						);
					q.ReturnCountOnly = true;
					CommentSet cs = new CommentSet(q);
					number = cs.Count;
				}
			}
			else if (StatType == 9) //PMs
			{
				Query q = new Query();
				q.NoLock = true;
				q.QueryCondition = new And(
					new Q(Comment.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, dateMin),
					new Q(Comment.Columns.DateTime, QueryOperator.LessThan, dateMax),
					new Q(Thread.Columns.Private, true),
					new Q(Comment.Columns.UsrK, QueryOperator.NotEqualTo, 7646)
					);
				q.TableElement = Comment.ThreadJoin;
				q.ReturnCountOnly = true;
				CommentSet cs = new CommentSet(q);
				number = cs.Count;
			}
			else if (StatType == 10) //Chat massages
			{
				if (DateSpan == 5)
				{
					Query q = new Query();
					q.NoLock = true;
					q.OrderBy = new OrderBy(ChatMessage.Columns.K, OrderBy.OrderDirection.Descending);
					q.Columns = new ColumnSet(ChatMessage.Columns.K);
					q.TopRecords = 1;
					ChatMessageSet cms = new ChatMessageSet(q);
					number = cms[0].K;
				}
				else
				{
					Query q = new Query();
					q.NoLock = true;
					q.QueryCondition = new And(
						new Q(ChatMessage.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, dateMin),
						new Q(ChatMessage.Columns.DateTime, QueryOperator.LessThan, dateMax)
						);
					q.ReturnCountOnly = true;
					ChatMessageSet cms = new ChatMessageSet(q);
					number = cms.Count;
				}
			}
			else if (StatType == 11) //Photo views
			{
				Query q = new Query();
				q.NoLock = true;
				q.Columns = new ColumnSet();
				q.ExtraSelectElements["sum"] = "sum(Count)";
				q.QueryCondition = new And(
					new Q(Log.Columns.Date, QueryOperator.GreaterThanOrEqualTo, dateMin),
					new Q(Log.Columns.Date, QueryOperator.LessThan, dateMax),
					new Q(Log.Columns.Item, Log.Items.PhotoImpressions)
				);

				LogSet ls = new LogSet(q);

				number = (int)ls[0].ExtraSelectElements["sum"];
			}
			else if (StatType == 12) // Unique members from visit table
			{
				Query q = new Query();
				q.NoLock = true;
				q.Columns = new ColumnSet();
				q.ExtraSelectElements["count"] = "count(distinct UsrK)";
				q.QueryCondition = new And(
					new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Visit.Columns.DateTimeLast, QueryOperator.GreaterThanOrEqualTo, dateMin)),
					new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.LessThan, dateMax), new Q(Visit.Columns.DateTimeLast, QueryOperator.LessThan, dateMax))
					);

				VisitSet vs = new VisitSet(q);

				number = (int)vs[0].ExtraSelectElements["count"];
			}
			else if (StatType == 13) //New users
			{
				Query q = new Query();
				q.NoLock = true;
				q.QueryCondition = new And(
					new Q(Usr.Columns.DateTimeSignUp, QueryOperator.GreaterThanOrEqualTo, dateMin),
					new Q(Usr.Columns.DateTimeSignUp, QueryOperator.LessThan, dateMax),
					new Or(new Q(Usr.Columns.IsSkeleton, false), new Q(Usr.Columns.IsSkeleton, QueryOperator.IsNull, null))
					);
				q.ReturnCountOnly = true;
				UsrSet us = new UsrSet(q);
				number = us.Count;

			}
			else
				number = 0;


			//if (estimateWholeDay)
			//{
			//    number = (int)Banner.EstimateFullDay(DateTime.Now, number);
			//}
			if (number == 0)
				return "<small>n/a</small>";
			else
				return number.ToString("###,##0");

		}
Example #18
0
 public Comment(CommentSet id)
 {
     outputAnswer = null;
     inputSet     = id;
     text         = "Comment...";
 }
Example #19
0
			public string GetArchiveItems(int numberOfItems)
			{
				//Get from cache...
				string s = (string)Caching.Instances.Main.Get(GetArchiveCacheKey(this.Guid));
				if (s != null && !Vars.DevEnv)
					return s;

				string roomGuidPacked = this.Guid.Pack();
				System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

				List<ItemStub> items = new List<ItemStub>();
				//Generate...
				if (IsThreadRoom || IsHasPrimaryThreadObject)
				{
					if (ThreadK > 0)
					{
						Query q = new Query();
						q.QueryCondition = new Q(Comment.Columns.ThreadK, ThreadK);
						q.OrderBy = new OrderBy(Comment.Columns.K, OrderBy.OrderDirection.Descending);
						q.TopRecords = numberOfItems;

						CommentSet cs = new CommentSet(q);

						for (int i = 0; i < cs.Count; i++)
						{
							Comment c = cs[i];

							if (!c.ChatItemGuid.HasValue)
							{
								c.ChatItemGuid = Guid.NewGuid();
								c.Update();
							}

							CommentMessageStub cms = c.GetCommentMessageStub();
							items.Add(cms);
						}
					}
				}
				else
				{
					//get from ChatMessage

					bool isBuddyIfRoomIsPrivate = IsPrivateChatRoom && ((Usr)ObjectBob).HasFullBuddy(SecondObjectK);

					Query q = new Query();
					q.QueryCondition = new Q(ChatMessage.Columns.RoomGuid, this.Guid);
					q.OrderBy = new OrderBy(ChatMessage.Columns.K, OrderBy.OrderDirection.Descending);
					q.TopRecords = numberOfItems;

					ChatMessageSet cs = new ChatMessageSet(q);

					for (int i = 0; i < cs.Count; i++)
					{
						ChatMessage cm = cs[i];

						if (cm.Deleted.HasValue && cm.Deleted.Value)
							break;

						if (!cm.ChatItemGuid.HasValue)
						{
							cm.ChatItemGuid = Guid.NewGuid();
							cm.Update();
						}

						if (IsPrivateChatRoom)
						{
							PrivateStub p = new PrivateStub(
								cm.ChatItemGuid.Value.Pack(),
								ItemType.PrivateChatMessage,
								cm.DateTime.Ticks.ToString(),
								roomGuidPacked,
								cm.FromUsr.NickName,
								cm.FromUsr.StmuParams,
								cm.FromUsr.K,
								cm.FromUsr.HasPicNotFacebook ? cm.FromUsr.Pic.ToString() : "0",
								cm.FromUsr.HasChatPic ? cm.FromUsr.ChatPic.Value.ToString() : "0",
								cm.Text,
								"",
								isBuddyIfRoomIsPrivate);
							items.Add(p);
						}
						else
						{
							MessageStub m = new MessageStub(
								cm.ChatItemGuid.Value.Pack(),
								ItemType.PrivateChatMessage,
								cm.DateTime.Ticks.ToString(),
								roomGuidPacked,
								cm.FromUsr.NickName,
								cm.FromUsr.StmuParams,
								cm.FromUsr.K,
								cm.FromUsr.HasPicNotFacebook ? cm.FromUsr.Pic.ToString() : "0",
								cm.FromUsr.HasChatPic ? cm.FromUsr.ChatPic.Value.ToString() : "0",
								cm.Text,
								"");
							items.Add(m);
						}
					}
				}

				string itemsString = "";

				if (items.Count > 0)
				{
					StringBuilder sb = new StringBuilder();
					foreach (ItemStub item in items)
					{
						if (sb.Length > 0)
							sb.Append(",");

						sb.Append(serializer.Serialize(item));
					}
					itemsString = sb.ToString();
				}

				Caching.Instances.Main.Set(GetArchiveCacheKey(this.Guid), itemsString);

				return itemsString;

			}
Example #20
0
    /// <summary>
    /// Populates nodeData with the data from next Node based on the current nodeData.
    /// </summary>
    /// <returns></returns>
    public NodeData Next()
    {
        if (!isLoaded)
        {
            Debug.LogError("You must call the 'BeginDialogue()' method before calling the 'Next()' method!");
            return(null);
        }

        int  option       = 0;
        bool nextIsPlayer = true;

        if (nodeData != null)
        {
            option = nodeData.selectedOption;
        }

        if (!jumped && nodeData != null) //Here's where we check if we end
        {
            if (!nodeData.currentIsPlayer && currentNPCStep != null)
            {
                if (currentNPCStep.outputNPC == null && currentNPCStep.outputSet == null && currentNPCStep.outAction == null && nodeData.npcCommentIndex == nodeData.npcComment.Length - 1)
                {
                    nodeData.isEnd = true;
                    isLoaded       = false;
                    LocalDataSingleton.instance.talking = false;
                    LocalDataSingleton.instance.MainCanvas.transform.GetChild(1).GetChild(0).gameObject.SetActive(false);
                    LocalDataSingleton.instance.Inventorycanvas.SetActive(false);
                    return(nodeData);
                }
                else if (currentNPCStep.outputNPC == null && currentNPCStep.outputSet == null && currentNPCStep.outAction == null && nodeData.npcComment.Length < 1)
                {
                    nodeData.isEnd = true;
                    isLoaded       = false;
                    LocalDataSingleton.instance.talking = false;
                    LocalDataSingleton.instance.MainCanvas.transform.GetChild(1).GetChild(0).gameObject.SetActive(false);
                    LocalDataSingleton.instance.Inventorycanvas.SetActive(false);
                    return(nodeData);
                }
            }
        }

        if (nodeData != null)
        {
            if (nodeData.currentIsPlayer)
            {
                //Mark end of conversation for player node
                if (currentPlayerStep != null)
                {
                    if (currentPlayerStep.comment[option].outputAnswer == null && currentPlayerStep.comment[option].outAction == null)
                    {
                        nodeData.isEnd = true;
                        isLoaded       = false;
                        LocalDataSingleton.instance.talking = false;
                        LocalDataSingleton.instance.MainCanvas.transform.GetChild(1).GetChild(0).gameObject.SetActive(false);
                        LocalDataSingleton.instance.Inventorycanvas.SetActive(false);
                        return(nodeData);
                    }
                }
            }
        }
        //If action node is connected to nothing, then it's the end
        if (lastActionNode != null)
        {
            if (lastActionNode.outPlayer == null && lastActionNode.outNPC == null && lastActionNode.outAction == null)
            {
                nodeData.isEnd = true;
                isLoaded       = false;
                LocalDataSingleton.instance.talking = false;
                LocalDataSingleton.instance.MainCanvas.transform.GetChild(1).GetChild(0).gameObject.SetActive(false);
                LocalDataSingleton.instance.Inventorycanvas.SetActive(false);
                return(nodeData);
            }
        }

        jumped = false;

        /* Action Node? */

        if (currentActionNode == null)
        {
            if (nodeData.currentIsPlayer)
            {
                currentActionNode = currentPlayerStep.comment[option].outAction;
            }
            else
            {
                currentActionNode = currentNPCStep.outAction;
            }
        }
        else
        {
            currentActionNode = currentActionNode.outAction;
        }

        //If we found actio node, let's go to it.
        if (currentActionNode != null)
        {
            lastActionNode = currentActionNode;
            DoAction();
            return(nodeData);
        }
        else if (lastActionNode != null)
        {
            if (lastActionNode.outNPC != null)
            {
            }
        }

        /* END Action Node */

        if (!nodeData.currentIsPlayer)
        {
            nextIsPlayer = true;
            if (currentNPCStep.outputSet == null)
            {
                nextIsPlayer = false;
            }
        }
        else
        {
            nextIsPlayer = false;
        }

        if (!nodeData.currentIsPlayer) // WE ARE CURRENTLY NPC NODE
        {
            //Let's scroll through split comments first
            if (nodeData.npcComment.Length > 0)
            {
                if (nodeData.npcCommentIndex != nodeData.npcComment.Length - 1)
                {
                    nodeData.npcCommentIndex++;
                    lastActionNode = null;
                    return(nodeData);
                }
            }

            if (lastActionNode != null)
            {
                if (lastActionNode.outNPC != null)
                {
                    currentNPCStep = lastActionNode.outNPC;

                    List <string> ns       = new List <string>();
                    string[]      rawSplit = Regex.Split(currentNPCStep.text, "<br>");
                    foreach (string s in rawSplit)
                    {
                        if (s != "" && s != " ")
                        {
                            ns.Add(s.Trim());
                        }
                    }

                    lastActionNode = null;
                    nodeData       = new NodeData(false, false, currentNPCStep.ID, null, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag, "");
                    return(nodeData);
                }
            }

            if (lastActionNode != null)
            {
                if (lastActionNode.outPlayer != null)
                {
                    currentPlayerStep = lastActionNode.outPlayer;
                    lastActionNode    = null;
                    nodeData          = new NodeData(true, false, currentPlayerStep.ID, GetOptions(), GetExtraData(), null, null, null, currentPlayerStep.playerTag);
                    return(nodeData);
                }
            }


            if (nextIsPlayer) // NEXT IS PLAYER
            {
                lastActionNode    = null;
                currentPlayerStep = currentNPCStep.outputSet;
                nodeData          = new NodeData(true, false, currentPlayerStep.ID, GetOptions(), GetExtraData(), null, null, null, currentPlayerStep.playerTag);
            }
            else // NEXT IS ANOTHER NPC NODE
            {
                currentNPCStep = currentNPCStep.outputNPC;
                List <string> ns = new List <string>();

                string[] rawSplit = Regex.Split(currentNPCStep.text, "<br>");
                foreach (string s in rawSplit)
                {
                    if (s != "" && s != " ")
                    {
                        ns.Add(s.Trim());
                    }
                }

                lastActionNode = null;
                nodeData       = new NodeData(false, false, currentNPCStep.ID, null, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag, "");
            }

            return(nodeData);
        }
        else // WE ARE CURRENTLY PLAYER NODE
        {
            //Pick next NPC node based on player choice OR next Player Node if there was an Action Node beforehand
            if (lastActionNode == null)
            {
                currentNPCStep = currentPlayerStep.comment[option].outputAnswer;
            }
            else
            {
                if (lastActionNode.outNPC != null)
                {
                    currentNPCStep = lastActionNode.outNPC;
                }
                if (lastActionNode.outPlayer != null)
                {
                    currentPlayerStep = lastActionNode.outPlayer;
                    lastActionNode    = null;
                    nodeData          = new NodeData(true, false, currentPlayerStep.ID, GetOptions(), GetExtraData(), null, null, null, currentPlayerStep.playerTag);
                    return(nodeData);
                }
            }

            List <string> ns = new List <string>();

            string[] rawSplit = Regex.Split(currentNPCStep.text, "<br>");
            foreach (string s in rawSplit)
            {
                if (s != "" && s != " ")
                {
                    ns.Add(s.Trim());
                }
            }

            lastActionNode = null;
            nodeData       = new NodeData(false, false, currentNPCStep.ID, null, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag, "");
            return(nodeData);
        }
    }
Example #21
0
    /// <summary>
    /// Loads up the dialogue just sent. Populates the nodeData variable with the first Node based on the Start Node. Also returns the current NodeData package.
    /// </summary>
    /// <param name="diagToLoad"></param>
    /// <returns>NodeData</returns>
    public NodeData BeginDialogue(VIDE_Assign diagToLoad)
    {
        if (diagToLoad.assignedIndex < 0 || diagToLoad.assignedIndex > diagToLoad.diags.Count - 1)
        {
            Debug.LogError("No dialogue assigned to VIDE_Assign!");
            return(null);
        }

        //First we load the dialogue we requested
        if (Load(diagToLoad.diags[diagToLoad.assignedIndex]))
        {
            isLoaded = true;
        }
        else
        {
            isLoaded = false;
            Debug.LogError("Failed to load '" + diagToLoad.diags[diagToLoad.assignedIndex] + "'");
            return(null);
        }

        //Make sure that variables were correctly reset after last conversation
        if (nodeData != null)
        {
            Debug.LogError("You forgot to call 'EndDialogue()' on last conversation!");
            return(null);
        }

        assigned = diagToLoad;

        if (assigned.overrideStartNode != -1)
        {
            startPoint = assigned.overrideStartNode;
        }

        int  startIndex = -1;
        bool isPlayer   = false;
        bool isAct      = false;

        for (int i = 0; i < npcNodes.Count; i++)
        {
            if (startPoint == npcNodes[i].ID)
            {
                startIndex = i; isPlayer = false; break;
            }
        }
        for (int i = 0; i < playerNodes.Count; i++)
        {
            if (startPoint == playerNodes[i].ID)
            {
                startIndex = i; isPlayer = true; break;
            }
        }
        for (int i = 0; i < actionNodes.Count; i++)
        {
            if (startPoint == actionNodes[i].ID)
            {
                startIndex        = i;
                currentActionNode = actionNodes[i]; isPlayer = true; isAct = true; break;
            }
        }

        /* Action node */

        if (isAct)
        {
            lastActionNode = currentActionNode;
            nodeData       = new NodeData();
            DoAction();
            return(nodeData);
        }

        /* Action end */

        if (startIndex == -1)
        {
            Debug.LogError("Start point not found! Check your IDs!");
            return(null);
        }

        if (isPlayer)
        {
            currentPlayerStep = playerNodes[startIndex];

            lastActionNode = null;
            nodeData       = new NodeData(true, false, currentPlayerStep.ID, GetOptions(), GetExtraData(), null, null, null, currentPlayerStep.playerTag);
            return(nodeData);
        }
        else
        {
            currentNPCStep = npcNodes[startIndex];

            List <string> ns = new List <string>();

            string[] rawSplit = Regex.Split(currentNPCStep.text, "<br>");
            foreach (string s in rawSplit)
            {
                if (s != "" && s != " ")
                {
                    ns.Add(s.Trim());
                }
            }

            lastActionNode = null;
            nodeData       = new NodeData(false, false, currentNPCStep.ID, null, null, ns.ToArray(), currentNPCStep.extraData, currentNPCStep.tag, "");
            return(nodeData);
        }
    }
Example #22
0
		public void Calendar_Load(object o, System.EventArgs e)
		{
			CalendarPanel.Visible = ContainerPage.Url.HasDayFilter || ContainerPage.Url.HasMonthFilter;

			#region Set up calendar control
			if (ContainerPage.Url.HasDayFilter)
			{
				DateCal.SelectedDate = ContainerPage.Url.DateFilter;
				DateCal.VisibleDate = ContainerPage.Url.DateFilter;
				//CalendarTitleCell.Attributes["onmouseover"] = "this.style.backgroundColor='#FED551';";
				CalendarTitleCell.Style["cursor"] = "pointer";
				//CalendarTitleCell.Attributes["onmouseout"] = "this.style.backgroundColor='#FECA26';";
				CalendarTitleCell.Attributes["onclick"] = "document.location='" + MonthUrlGetter(ContainerPage.Url.DateFilter) + "';";
			}
			else if (ContainerPage.Url.HasMonthFilter)
			{
				DateCal.VisibleDate = ContainerPage.Url.DateFilter;

				CalendarTitleCell.Attributes["class"] = "BorderBlack All";
				CalendarTitleCell.Style["border-width"] = "2px";
			}
			#endregion
			if (ContainerPage.Url.HasDayFilter || ContainerPage.Url.HasMonthFilter)
			{
				#region Find number of comments on each day
				Query q = new Query();

				q.Columns = new ColumnSet();
				q.ExtraSelectElements.Add("count", "COUNT(*)");
				q.ExtraSelectElements.Add("day", "DAY(" + DateTimeColumn.InternalSqlName + ")");
				q.ExtraSelectElements.Add("month", "MONTH(" + DateTimeColumn.InternalSqlName + ")");
				q.ExtraSelectElements.Add("year", "YEAR(" + DateTimeColumn.InternalSqlName + ")");

				q.TableElement = this.TableElement;

				q.GroupBy = new GroupBy("DAY(" + DateTimeColumn.InternalSqlName + "), MONTH(" + DateTimeColumn.InternalSqlName + "), YEAR(" + DateTimeColumn.InternalSqlName + ")");

				q.QueryCondition = new And(
					new Q(DateTimeColumn, QueryOperator.GreaterThanOrEqualTo, new DateTime(ContainerPage.Url.DateFilter.Year, ContainerPage.Url.DateFilter.Month, 1).AddDays(-8)),
					new Q(DateTimeColumn, QueryOperator.LessThan, new DateTime(ContainerPage.Url.DateFilter.Year, ContainerPage.Url.DateFilter.Month, 1).AddMonths(1).AddDays(8)),
					this.QueryCondition);
				CommentSet days = new CommentSet(q);
				Traffic = new Hashtable();
				int TotalCount = 0;
				foreach (Comment c in days)
				{
					string date = c.ExtraSelectElements["year"] + "-" + c.ExtraSelectElements["month"] + "-" + c.ExtraSelectElements["day"];
					int val = (int)c.ExtraSelectElements["count"];
					Traffic[date] = val;
					TotalCount += val;
				}
				#endregion

				bool ShowPrevMonth = true;
				bool ShowNextMonth = true;
				DateTime NextMonth = ContainerPage.Url.DateFilter.AddMonths(1);
				DateTime PrevMonth = ContainerPage.Url.DateFilter.AddMonths(-1);

				if (TotalCount == 0)
				{
					Query PrevQ = new Query();
					PrevQ.TopRecords = 1;
					PrevQ.OrderBy = new OrderBy(DateTimeColumn.ColumnEnum, OrderBy.OrderDirection.Descending);
					PrevQ.TableElement = this.TableElement;
					PrevQ.Columns = new ColumnSet();
					PrevQ.ExtraSelectElements.Add("datetime", DateTimeColumn.InternalSqlName);
					PrevQ.QueryCondition = new And(this.QueryCondition,
						new Q(this.DateTimeColumn, QueryOperator.LessThan, ContainerPage.Url.DateFilter));
					CommentSet PrevBobSet = new CommentSet(PrevQ);
					if (PrevBobSet.Count == 0)
						ShowPrevMonth = false;
					else
						PrevMonth = (DateTime)PrevBobSet[0].ExtraSelectElements["datetime"];

					Query NextQ = new Query();
					NextQ.TopRecords = 1;
					NextQ.OrderBy = new OrderBy(DateTimeColumn.ColumnEnum, OrderBy.OrderDirection.Ascending);
					NextQ.TableElement = this.TableElement;
					NextQ.Columns = new ColumnSet();
					NextQ.ExtraSelectElements.Add("datetime", DateTimeColumn.InternalSqlName);
					NextQ.QueryCondition = new And(this.QueryCondition,
						new Q(this.DateTimeColumn, QueryOperator.GreaterThan, ContainerPage.Url.DateFilter));
					CommentSet NextBobSet = new CommentSet(NextQ);
					if (NextBobSet.Count == 0)
						ShowNextMonth = false;
					else
						NextMonth = (DateTime)NextBobSet[0].ExtraSelectElements["datetime"];

				}


				#region Back, month and forward links
				if (ShowPrevMonth)
				{
					if (PrevMonth.Year == DateTime.Today.Year)
						CalendarBackLabel.Text = PrevMonth.ToString("MMMM");
					else
						CalendarBackLabel.Text = PrevMonth.ToString("MMMM yy");

					CalendarBackLink.HRef = MonthUrlGetter(PrevMonth);
				}
				else
					CalendarBackLink.Visible = false;

				if (ContainerPage.Url.DateFilter.Year == DateTime.Today.Year)
					CalendarMiddleLink.InnerText = ContainerPage.Url.DateFilter.ToString("MMMM");
				else
					CalendarMiddleLink.InnerText = ContainerPage.Url.DateFilter.ToString("MMMM yy");

				if (ContainerPage.Url.HasDayFilter)
					CalendarMiddleLink.HRef = MonthUrlGetter(ContainerPage.Url.DateFilter);


				if (ShowNextMonth)
				{
					if (NextMonth.Year == DateTime.Today.Year)
						CalendarForwardLabel.Text = NextMonth.ToString("MMMM");
					else
						CalendarForwardLabel.Text = NextMonth.ToString("MMMM yy");

					CalendarForwardLink.HRef = MonthUrlGetter(NextMonth);
				}
				else
					CalendarForwardLink.Visible = false;
				#endregion

			}
		}