예제 #1
0
        /// <summary>
        /// CommentLoader收到新留言處理函式
        /// </summary>
        /// <param name="sender">CommentLoader</param>
        /// <param name="lsComments">新留言</param>
        private void On_CommentLoader_CommentsReceive(CommentLoader sender, List <CommentData> lsComments)
        {
            if (lsComments != null)
            {
                foreach (CommentData cmt in lsComments)
                {
                    //將留言加入留言集合中
                    CommentVM vm = new CommentVM(cmt);
                    _commentColle.Add(vm);
                    this.TotalCommentCount = _commentColle.Count;

                    //紀錄留言者ID供人數統計
                    if (!_authorTable.ContainsKey(vm.AuthorID))
                    {
                        _authorTable.Add(vm.AuthorID, vm.AuthorName);
                        this.TotalAuthorCount = _authorTable.Keys.Count;
                    }

                    //將留言送至投票中心
                    if (_votingCenterVM != null)
                    {
                        _votingCenterVM.Vote(vm);
                    }

                    //將留言送至猜謎中心
                    if (_puzzleCenterVM != null)
                    {
                        _puzzleCenterVM.Guessing(vm);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// CommentLoader讀取留言發生錯誤處理函式
        /// </summary>
        /// <param name="sender">CommentLoader</param>
        /// <param name="errCode">錯誤碼</param>
        /// <param name="obj">附加錯誤資訊</param>
        private void On_CommentLoader_Error(CommentLoader sender, CommentLoaderErrorCode errCode, object obj)
        {
            String errStr = "";

            switch (errCode)
            {
            case CommentLoaderErrorCode.CanNotGetLiveChatUrl:
                errStr = String.Format("無法取得聊天室位址。請檢查輸入的網址:{0}", Convert.ToString(obj));
                break;

            case CommentLoaderErrorCode.CanNotGetLiveChatHtml:
                errStr = String.Format("無法取得聊天室內容。 {0}", Convert.ToString(obj));
                break;

            case CommentLoaderErrorCode.CanNotParseLiveChatHtml:
                errStr = String.Format("無法解析聊天室HTML。 {0}", Convert.ToString(obj));
                break;

            case CommentLoaderErrorCode.GetCommentsError:
                errStr = String.Format("取得留言時發生錯誤。 {0}", Convert.ToString(obj));
                break;

            default:
                break;
            }

            this.ErrorText = errStr;
        }
예제 #3
0
            private static CommentLoader GetLoader(Comment dt, string key)
            {
                CommentLoader loader = new CommentLoader
                {
                    Body                   = dt.Body,
                    Date                   = Shared.TimeAgo.Ago(dt.Date),// $"{CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedDayName(dt.Date.DayOfWeek)}, {CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(dt.Date.Month)} {dt.Date.Day}, {dt.Date.Year} {dt.Date.ToShortTimeString()}",
                    DisLikes               = DislikeClass.GetCount(dt.Guid, true),
                    DateReal               = dt.Date,
                    Likes                  = LikeClass.GetCount(dt.Guid, true),
                    Guid                   = dt.Guid,
                    Owner_Guid             = dt.Owner_Guid,
                    Quote                  = dt.Quote,
                    QuotedCommentAvailable = dt.QuotedCommentAvailable,
                    Confess_Guid           = dt.Confess_Guid
                };

                //load colors
                if (LikeClass.CheckExistence(dt.Guid, true, key))
                {
                    loader.LikeColorString = "#1976D2";
                }

                if (DislikeClass.CheckExistence(dt.Guid, true, key))
                {
                    loader.DislikeColorString = "#1976D2";
                }
                if (dt.Owner_Guid == key)
                {
                    loader.DeleteVisibility = true;
                }

                return(loader);
            }
예제 #4
0
        public bool LoadFromFile(string taskDataFile)
        {
            if (!LoadXmlFile(taskDataFile))
            {
                return(false);
            }

            if (!VerifyIsoVersion())
            {
                return(false);
            }

            LinkedIds    = LinkListLoader.Load(this);
            Units        = UnitLoader.Load(this);
            Customers    = CustomerLoader.Load(this);
            Farms        = FarmLoader.Load(this);
            Crops        = CropLoader.Load(this);
            Fields       = FieldLoader.Load(this);
            Products     = ProductLoader.Load(this);
            ProductMixes = ProductMixLoader.Load(this);
            Workers      = WorkerLoader.Load(this);
            Comments     = CommentLoader.Load(this);
            Tasks        = TaskLoader.Load(this);

            RasterPrescriptions = PrescriptionLoader.Load(this);
            Machines            = DeviceLoader.Load(this);

            return(true);
        }
예제 #5
0
 internal static void SaveLoader(CommentLoader load)
 {
     if (!Local.CommentLoader.Exists(d => d.Id == load.Id))
     {
         Local.CommentLoader.Insert(load);
     }
 }
예제 #6
0
        /// <summary>
        /// CommentLoader處理狀態改變
        /// </summary>
        /// <param name="sender">CommentLoader</param>
        /// <param name="status">改變後的狀態</param>
        private void On_CommetLoader_StatusChanged(CommentLoader sender, CommentLoaderStatus status)
        {
            switch (status)
            {
            case CommentLoaderStatus.Null:
                this.StatusText = "已停止";
                break;

            case CommentLoaderStatus.Started:
                this.StatusText   = "開始";
                this.IsStopped    = false;
                this.IsEnableStop = false;
                break;

            case CommentLoaderStatus.GetLiveChatHtml:
                this.StatusText = "讀取聊天室";
                break;

            case CommentLoaderStatus.ParseLiveChatHtml:
                this.StatusText = "解析聊天室內容";
                break;

            case CommentLoaderStatus.GetComments:
                this.StatusText   = "取得留言";
                this.IsEnableStop = true;
                break;

            case CommentLoaderStatus.StopRequested:
                this.StatusText = "停止中";
                break;

            case CommentLoaderStatus.Completed:
                this.StatusText   = "已停止";
                this.IsStopped    = true;
                this.IsEnableStop = false;
                if (App.AppStartupParameter.IsParsed &&
                    App.AppStartupParameter.OutputFilePath != "" &&
                    App.AppStartupParameter.OutputFilePath != null)
                {
                    ExportComment(App.AppStartupParameter.OutputFilePath);
                    if (this.CloseWindow != null &&
                        (App.AppStartupParameter.IsHide || App.AppStartupParameter.IsClose))
                    {
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            CloseWindow();
                        });
                    }
                }
                break;

            default:
                break;
            }
        }
예제 #7
0
        public static CommentLoader ProcessCommentLoader(CommentLoader loader)
        {
            if (!string.IsNullOrEmpty(loader.LikeColorString))
            {
                loader.LikeColor = Color.FromHex(loader.LikeColorString);
            }

            if (!string.IsNullOrEmpty(loader.DislikeColorString))
            {
                loader.DislikeColor = Color.FromHex(loader.DislikeColorString);
            }
            return(loader);
        }
예제 #8
0
        public async Task OpenReview( Review R )
        {
            CommentLoader CL = new CommentLoader(
                R.Id
                , X.Call<XKey[]>( XProto.WRequest, "GetReplies", R.Id )
                , new CommentLoader.CommentXMLParser( GetReplies )
            );

            IList<Comment> FirstLoad = await CL.NextPage();

            Replies.ConnectLoader( CL );
            Replies.UpdateSource( FirstLoad );
        }
예제 #9
0
        public async Task OpenReview(Review R)
        {
            CommentLoader CL = new CommentLoader(
                R.Id
                , X.Call <XKey[]>(XProto.WRequest, "GetReplies", R.Id)
                , new CommentLoader.CommentXMLParser(GetReplies)
                );

            IList <Comment> FirstLoad = await CL.NextPage();

            Replies.ConnectLoader(CL);
            Replies.UpdateSource(FirstLoad);
        }
예제 #10
0
        /// <summary>
        /// CommentLoader處理狀態改變
        /// </summary>
        /// <param name="sender">CommentLoader</param>
        /// <param name="status">改變後的狀態</param>
        private void On_CommetLoader_StatusChanged(CommentLoader sender, CommentLoaderStatus status)
        {
            switch (status)
            {
            case CommentLoaderStatus.Null:
                this.StatusText = "已停止";
                break;

            case CommentLoaderStatus.Started:
                this.StatusText   = "開始";
                this.IsStopped    = false;
                this.IsEnableStop = false;
                break;

            case CommentLoaderStatus.GetLiveChatHtml:
                this.StatusText = "讀取聊天室";
                break;

            case CommentLoaderStatus.ParseYtCfgData:
                this.StatusText = "解析連線設定";
                break;

            case CommentLoaderStatus.ParseLiveChatHtml:
                this.StatusText = "解析聊天室內容";
                break;

            case CommentLoaderStatus.GetComments:
                this.StatusText   = "取得留言";
                this.IsEnableStop = true;
                break;

            case CommentLoaderStatus.StopRequested:
                this.StatusText = "停止中";
                break;

            case CommentLoaderStatus.Completed:
                this.StatusText   = "已停止";
                this.IsStopped    = true;
                this.IsEnableStop = false;
                break;

            default:
                break;
            }
        }
예제 #11
0
        public MainWindowVM()
        {
            _cmtLoader        = new CommentLoader();
            _commentColle     = new ObservableCollection <CommentVM>();
            this.CommentColle = CollectionViewSource.GetDefaultView(_commentColle);
            BindingOperations.EnableCollectionSynchronization(_commentColle, _lockCommentColleObj);

            _votingCenterVM = null;
            _puzzleCenterVM = null;
            _authorTable    = new Dictionary <string, string>();
            _isStopped      = true;

            _cmtLoader.OnStatusChanged   += On_CommetLoader_StatusChanged;
            _cmtLoader.OnError           += On_CommentLoader_Error;
            _cmtLoader.OnCommentsReceive += On_CommentLoader_CommentsReceive;

            this.StatusText = "已停止";
        }
예제 #12
0
        public async Task Load()
        {
            IsLoading = true;
            CommentLoader CL = new CommentLoader(
                ThisBook.Id
                , X.Call<XKey[]>( "wenku8.Settings.WRequest, wenku8-protocol", "GetComments", ThisBook.Id )
                , new CommentLoader.CommentXMLParser( GetReviews )
            );
            IList<Comment> FirstLoad = await CL.NextPage();
            IsLoading = false;

            Comments = new Observables<Comment, Comment>( FirstLoad );
            Comments.LoadStart += ( s, e ) => IsLoading = true;
            Comments.LoadEnd += ( se, e ) => IsLoading = false;

            Comments.ConnectLoader( CL );

            NotifyChanged( "Comments" );
            SetControls( "NewComment", "Reload" );
        }
예제 #13
0
        public MainWindowVM()
        {
            _cmtLoader        = new CommentLoader();
            _commentColle     = new ObservableCollection <CommentVM>();
            this.CommentColle = CollectionViewSource.GetDefaultView(_commentColle);
            BindingOperations.EnableCollectionSynchronization(_commentColle, _lockCommentColleObj);

            _authorTable = new Dictionary <string, string>();
            _isStopped   = true;
            _videoUrl    = "";

            _cmtLoader.OnStatusChanged   += On_CommetLoader_StatusChanged;
            _cmtLoader.OnError           += On_CommentLoader_Error;
            _cmtLoader.OnCommentsReceive += On_CommentLoader_CommentsReceive;

            this.CmdStart         = new RelayCommand(Start, CanStart);
            this.CmdStop          = new RelayCommand(Stop, CanStop);
            this.CmdExportComment = new RelayCommand(ExportComment);

            this.StatusText = "已停止";
        }
예제 #14
0
        public async Task SendAddComment(string message)
        {
            //check for emptiness
            if (!string.IsNullOrEmpty(message))
            {
                Comment data = JsonConvert.DeserializeObject <Comment>(message);

                bool isSafe = Logic.CheckSpamFree(data.Body.ToLower());
                if (isSafe)
                {
                    Store.CommentClass.InsertComment(data);
                    Push.SendCommentNotification(data);
                    CommentLoader toReturn = Store.CommentClass.FetchOneCommentLoader(data);
                    await Clients.All.SendAsync("ReceiveAddComment", JsonConvert.SerializeObject(toReturn));
                }
                else
                {
                    Push.NotifyOwnerOFSpam(data.Owner_Guid);
                }
            }
        }
예제 #15
0
        private async void Like_Tapped_Comment(object sender, TappedRoutedEventArgs e)
        {
            if (!Logic.IsInternet())
            {
                await new MessageDialog("No INTERNET connection has been found.").ShowAsync();
                return;
            }
            SymbolIcon    label = (SymbolIcon)sender;;
            string        guid  = label.Tag.ToString();
            CommentLoader load  = new CommentLoader();

            if (loaders.Any(d => d.Guid.Equals(guid)))
            {
                load = loaders.FirstOrDefault(d => d.Guid.Equals(guid));
            }
            //check if this user owns this confession


            if (load.Owner_Guid == Logic.GetKey())
            {
                await new MessageDialog("You can't like your Comment.").ShowAsync();
            }
            else
            {
                //post a new like
                try
                {
                    ConfessSender result = await Online.LikeClass.Post(guid, true, guid);

                    ConfessLoader data = result.Loader;
                    this.DataContext = data;

                    label.Foreground = Logic.GetColorFromHex("#1976D2");
                    LoadData();
                }
                catch (Exception)
                {
                }
            }
        }
예제 #16
0
 internal static void UpdateLoader(CommentLoader replacer)
 {
     Local.CommentLoader.Update(replacer);
 }