Esempio n. 1
0
        /// <summary>Loads the collection asynchronously from a DataServiceQuery instance.</summary>
        /// <param name="query">A query of type DataServiceQuery.</param>
        /// <remarks>This method uses the event-based async pattern.
        /// The method returns immediately without waiting for the query to complete. Then it calls the handler of the
        /// <see cref="LoadCompleted"/> event exactly once on the UI thread. The event will be raised regradless
        /// if the query succeeded or not.
        /// This class only support one asynchronous operation in flight.</remarks>
        public void LoadAsync(IQueryable <T> query)
        {
            Util.CheckArgumentNull(query, "query");
            DataServiceQuery <T> dsq = query as DataServiceQuery <T>;

            if (dsq == null)
            {
                throw new ArgumentException(Strings.DataServiceCollection_LoadAsyncRequiresDataServiceQuery, "query");
            }

            if (this.asyncOperationInProgress)
            {
                throw new InvalidOperationException(Strings.DataServiceCollection_MultipleLoadAsyncOperationsAtTheSameTime);
            }

            if (this.trackingOnLoad)
            {
                this.StartTracking(((DataServiceQueryProvider)dsq.Provider).Context,
                                   null,
                                   this.entitySetName,
                                   this.entityChangedCallback,
                                   this.collectionChangedCallback);
                this.trackingOnLoad = false;
            }

            BeginLoadAsyncOperation(
                asyncCallback => dsq.BeginExecute(asyncCallback, null),
                asyncResult =>
            {
                QueryOperationResponse <T> response = (QueryOperationResponse <T>)dsq.EndExecute(asyncResult);
                this.Load(response);
                return(response);
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            course = e.Parameter as Course;
            globalRate = 0;

            attendDsq = (DataServiceQuery<ATTEND>)(from attend in ctx.ATTEND
                                                   where attend.COURSE_ID == course.ID && attend.CUSTOMER_ID == Constants.User.ID
                                                   select attend);

            try
            {
                TaskFactory<IEnumerable<ATTEND>> tf = new TaskFactory<IEnumerable<ATTEND>>();
                IEnumerable<ATTEND> attends = await tf.FromAsync(attendDsq.BeginExecute(null, null), iar => attendDsq.EndExecute(iar));
                if (attends.Count() != 0)
                {
                    enterCommentStackPanel.Visibility = Visibility.Visible;
                }
            }
            catch
            {
                ShowMessageDialog();
            }

            commentDsq = (DataServiceQuery<COMMENT_DET>)(from comment in ctx.COMMENT_DET
                                                         where comment.COURSE_ID == course.ID
                                                         orderby comment.TIME ascending
                                                         select comment);
            commentDsq.BeginExecute(OnCommentComplete, null);
        }
Esempio n. 3
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {

            try
            {
                teachDsq = (DataServiceQuery<COURSE_AVAIL>)(from course in ctx.COURSE_AVAIL
                                                            where course.TEACHER_NAME == Constants.User.NAME
                                                            select course);

                TaskFactory<IEnumerable<COURSE_AVAIL>> tf = new TaskFactory<IEnumerable<COURSE_AVAIL>>();


                IEnumerable<COURSE_AVAIL> attends = await tf.FromAsync(ctx.BeginExecute<COURSE_AVAIL>(
                    new Uri("/GetAllCoursesAttendedByCustomer?customer_id=" + Constants.User.ID, UriKind.Relative), null, null),
                    iar => ctx.EndExecute<COURSE_AVAIL>(iar));
                IEnumerable<COURSE_AVAIL> teaches = await tf.FromAsync(teachDsq.BeginExecute(null, null), iar => teachDsq.EndExecute(iar));


                courseData = new StoreData();
                foreach (var c in attends)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    tmpCourse.IsBuy = true;
                    tmpCourse.IsTeach = false;
                    courseData.AddCourse(tmpCourse);
                }
                foreach (var c in teaches)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    tmpCourse.IsTeach = true;
                    tmpCourse.IsBuy = false;
                    courseData.AddCourse(tmpCourse);
                }

                dataCategory = courseData.GetGroupsByAttendingOrTeaching();
                cvs1.Source = dataCategory;
                UserProfileBt.DataContext = Constants.User;

            }
            catch
            {
                ShowMessageDialog("on navi to");
            }
            
        }
Esempio n. 4
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            course = e.Parameter as Course;


            sharedNoteDsq = (DataServiceQuery<NOTE_AVAIL>)(from selectNote in ctx.NOTE_AVAIL
                                                           where selectNote.COURSE_ID == course.ID.Value && selectNote.SHARE == true
                                                           orderby selectNote.DATE descending
                                                           select selectNote);
            switchButton.Content = "Mine";
            TaskFactory<IEnumerable<NOTE_AVAIL>> tf = new TaskFactory<IEnumerable<NOTE_AVAIL>>();
            IEnumerable<NOTE_AVAIL> nas = await tf.FromAsync(sharedNoteDsq.BeginExecute(null, null), iar => sharedNoteDsq.EndExecute(iar));
            sharedNotesList = nas.ToList();
            foreach (var n in sharedNotesList)
            {
                allSharedNotesStackPanel.Children.Add(GenerateSharedNoteItem(n.ID, n.TITLE, n.CONTENT, n.CUSTOMER_NAME, n.DATE, n.LESSON_NUMBER, n.CUSTOMER_ID.Value));
            }
        }
Esempio n. 5
0
 public async void SetAttendTeachNumber()
 {
     try
     {
         ctx = new CloudEDUEntities(new Uri(Constants.DataServiceURI));
         teachDsq = (DataServiceQuery<COURSE_AVAIL>)(from course in ctx.COURSE_AVAIL
                                                     where course.TEACHER_NAME == this.NAME
                                                     select course);
         TaskFactory<IEnumerable<COURSE_AVAIL>> tf = new TaskFactory<IEnumerable<COURSE_AVAIL>>();
         IEnumerable<COURSE_AVAIL> attends = await tf.FromAsync(ctx.BeginExecute<COURSE_AVAIL>(
             new Uri("/GetAllCoursesAttendedByCustomer?customer_id=" + this.ID, UriKind.Relative), null, null),
             iar => ctx.EndExecute<COURSE_AVAIL>(iar));
         ATTEND_COUNT = attends.Count();
         IEnumerable<COURSE_AVAIL> teaches = await tf.FromAsync(teachDsq.BeginExecute(null, null), iar => teachDsq.EndExecute(iar));
         TEACH_COUNT = teaches.Count();
     }
     catch
     {
         ShowMessageDialog("Set Attend Teach Number ");
     }
 }
        private async void LoginButton_Click(object sende, RoutedEventArgs e)
        {

            bool isLogined = false;

            if (InputPassword.Password.Equals(string.Empty))
            {
                var messageDialog = new MessageDialog("Please Check your input!");
                await messageDialog.ShowAsync();
                return;
            }


            
            try
            {
                TaskFactory<IEnumerable<CUSTOMER>> tf = new TaskFactory<IEnumerable<CUSTOMER>>();
                customerDsq = (DataServiceQuery<CUSTOMER>)(from user in ctx.CUSTOMER where user.NAME.Equals(Constants.User.NAME) select user);
                IEnumerable<CUSTOMER> cs = await tf.FromAsync(customerDsq.BeginExecute(null, null), iar => customerDsq.EndExecute(iar));
                csl = new List<CUSTOMER>(cs);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                ShowMessageDialog("customerdsq error!");
            }
            

            foreach (CUSTOMER c in csl)
            {
                if (c.NAME.Equals(Constants.User.NAME))
                {
                    if (c.PASSWORD == Constants.ComputeMD5(InputPassword.Password))
                    {
                        if (!c.ALLOW)
                        {
                            ShowMessageDialog("The User is forbidden");
                        }
                        Constants.User = new User(c);
                        isLogined = true;
                        Frame.Navigate(typeof(CourseStore.Courstore));

                    }
                }
            }

            /*

            bool isLogined = false;
            try
            {
                foreach (CUSTOMER c in csl)
                {
                    if (c.NAME.Equals(Constants.User.NAME))
                    {
                        if (c.PASSWORD == Constants.ComputeMD5(InputPassword.Password))
                        {
                            if (!c.ALLOW)
                            {
                                var notAllowed = new MessageDialog("The User is forbidden!");
                                await notAllowed.ShowAsync();
                                return;
                            }
                            Constants.User = new User(c);
                            //login success
                            Constants.Save<bool>("AutoLog", (bool)CheckAutoLogin.IsChecked);

                            System.Diagnostics.Debug.WriteLine("login success");
                            string courseUplaodUri = "/AddDBLog?opr='Login'&msg='" + Constants.User.NAME + "'";

                            try
                            {
                                TaskFactory<IEnumerable<bool>> tf = new TaskFactory<IEnumerable<bool>>();
                                IEnumerable<bool> result = await tf.FromAsync(ctx.BeginExecute<bool>(new Uri(courseUplaodUri, UriKind.Relative), null, null), iar => ctx.EndExecute<bool>(iar));
                            }
                            catch
                            {
                            }
                            isLogined = true;
                            Frame.Navigate(typeof(CourseStore.Courstore));
                            // navigate 
                        }
                    }
                }
                
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine("Msg: {0}\nInnerExp:{1}\nStackTrace: {2} ",
                    exp.Message, exp.InnerException, exp.StackTrace);
                ShowMessageDialog();
            }
            */
            if (!isLogined)
            {
                ShowMessageDialog("Username or password is wrong!");
            }
            
        }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            course = e.Parameter as Course;

            try
            {
                DataServiceQuery<COURSE_AVAIL> cDsq = (DataServiceQuery<COURSE_AVAIL>)(from kc in ctx.COURSE_AVAIL
                                                                                       where course.ID == kc.ID
                                                                                       select kc);
                TaskFactory<IEnumerable<COURSE_AVAIL>> tf = new TaskFactory<IEnumerable<COURSE_AVAIL>>();
                COURSE_AVAIL tmpCourse = (await tf.FromAsync(cDsq.BeginExecute(null, null), iar => cDsq.EndExecute(iar))).FirstOrDefault();
                course = Constants.CourseAvail2Course(tmpCourse);
            }
            catch
            {
                ShowMessageDialog("Network connection error2!");
                Frame.GoBack();
            }

            UserProfileBt.DataContext = Constants.User;
            DataContext = course;
            introGrid.DataContext = course;

            frame.Navigate(typeof(CourseDetail.Overview), course);

            isTeach = false;
            isBuy = false;

            try
            {
                teachCourses = (DataServiceQuery<COURSE_AVAIL>)(from teachC in ctx.COURSE_AVAIL
                                                                where teachC.TEACHER_NAME == Constants.User.NAME
                                                                select teachC);
                TaskFactory<IEnumerable<COURSE_AVAIL>> teachTF = new TaskFactory<IEnumerable<COURSE_AVAIL>>();
                IEnumerable<COURSE_AVAIL> tcs = await teachTF.FromAsync(teachCourses.BeginExecute(null, null), iar => teachCourses.EndExecute(iar));

                buyCourses = (DataServiceQuery<ATTEND>)(from buyC in ctx.ATTEND
                                                        where buyC.CUSTOMER_ID == Constants.User.ID
                                                        select buyC);
                TaskFactory<IEnumerable<ATTEND>> buyCF = new TaskFactory<IEnumerable<ATTEND>>();
                IEnumerable<ATTEND> bcs = await buyCF.FromAsync(buyCourses.BeginExecute(null, null), iar => buyCourses.EndExecute(iar));


                foreach (var t in tcs)
                {
                    if (t.ID == course.ID)
                    {
                        isTeach = true;
                        break;
                    }
                }

                foreach (var b in bcs)
                {
                    if (b.COURSE_ID == course.ID)
                    {
                        isBuy = true;
                        break;
                    }
                }
            }
            catch
            {
                ShowMessageDialog("Network connection error3!");
                Frame.GoBack();
            }

            if (course.Price == null || course.Price.Value == 0)
            {
                PriceTextBlock.Text = "Free";
            }
            else
            {
                PriceTextBlock.Text = "$ " + Math.Round(course.Price.Value, 2);
            }
            System.Diagnostics.Debug.WriteLine(course.Rate);
            SetStarsStackPanel(course.Rate ?? 0);

            if (isTeach)
            {
                courseButton.Content = "Teach";
            }
            else if (isBuy)
            {
                courseButton.Content = "Attend";
            }
            else
            {
                courseButton.Content = "Buy";
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Handles the Click event of the SwitchButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private async void SwitchButton_Click(object sender, RoutedEventArgs e)
        {
            Button bt = sender as Button;
            sharedNoteDsq = (DataServiceQuery<NOTE_AVAIL>)(from selectNote in ctx.NOTE_AVAIL
                                                           where selectNote.COURSE_ID == course.ID.Value && selectNote.SHARE == true
                                                           orderby selectNote.DATE descending
                                                           select selectNote);
            myNoteDsq = (DataServiceQuery<NOTE_AVAIL>)(from myNote in ctx.NOTE_AVAIL
                                                       where myNote.COURSE_ID == course.ID.Value && myNote.CUSTOMER_ID == Constants.User.ID
                                                       orderby myNote.DATE descending
                                                       select myNote);

            try
            {
                if (bt.Content.ToString() == "Mine")
                {
                    bt.Content = "Shared";
                    myNotesStackPanel.Visibility = Visibility.Visible;
                    allSharedNotesStackPanel.Visibility = Visibility.Collapsed;
                    myNotesStackPanel.Children.Clear();
                    TaskFactory<IEnumerable<NOTE_AVAIL>> tf = new TaskFactory<IEnumerable<NOTE_AVAIL>>();
                    IEnumerable<NOTE_AVAIL> nas = await tf.FromAsync(myNoteDsq.BeginExecute(null, null), iar => myNoteDsq.EndExecute(iar));
                    mySharedNotesList = nas.ToList();
                    foreach (var n in mySharedNotesList)
                    {
                        myNotesStackPanel.Children.Add(GenerateMySharedNoteItem(n.ID, n.TITLE, n.CONTENT, n.CUSTOMER_NAME, n.DATE, n.LESSON_NUMBER));
                    }
                }
                else if (bt.Content.ToString() == "Shared")
                {
                    bt.Content = "Mine";
                    myNotesStackPanel.Visibility = Visibility.Collapsed;
                    allSharedNotesStackPanel.Visibility = Visibility.Visible;
                    allSharedNotesStackPanel.Children.Clear();
                    TaskFactory<IEnumerable<NOTE_AVAIL>> tf = new TaskFactory<IEnumerable<NOTE_AVAIL>>();
                    IEnumerable<NOTE_AVAIL> nas = await tf.FromAsync(sharedNoteDsq.BeginExecute(null, null), iar => sharedNoteDsq.EndExecute(iar));
                    sharedNotesList = nas.ToList();
                    foreach (var n in sharedNotesList)
                    {
                        allSharedNotesStackPanel.Children.Add(GenerateSharedNoteItem(n.ID, n.TITLE, n.CONTENT, n.CUSTOMER_NAME, n.DATE, n.LESSON_NUMBER, n.CUSTOMER_ID.Value));
                    }
                }
            }
            catch
            {
                ShowMessageDialog("Network connection error38!");
            }
        }
        private async Task<QueryOperationResponse<FeedPackage>> ExecuteQuery(DataServiceQuery<FeedPackage> query)
        {
            var retrievePackagesTask = Task.Factory.FromAsync(query.BeginExecute, result => query.EndExecute(result), TaskCreationOptions.None);

            var queryOperation = await retrievePackagesTask as QueryOperationResponse<FeedPackage>;

            return queryOperation;
        }
Esempio n. 10
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            SetAllTextBlock();
            allCourses = new List<Course>();
            loadingProgressRing.IsActive = true;

            var borders = from b in topograph.Children.OfType<Border>()
                          select b;

            List<string> courseNameList = new List<string>();
            List<CloudEDU.Common.Constants.CourseAvaiStates> courseStatesList = new List<Constants.CourseAvaiStates>();
            foreach (Border border in borders)
            {
                TextBlock textBlock = border.Child as TextBlock;
                string courseShowName = textBlock.Text.Replace("\n", " ");
                courseNameList.Add(textBlock.Text);
                courseStatesList.Add(Constants.DepCourse.GetCourseLearnedState(courseShowName));
            }
            SetAllCoursesStates(courseNameList, courseStatesList);


            SetCourseState("Compute\nArchitecture", Constants.CourseAvaiStates.NotLearnedDisable);

            try
            {
                teachDsq = (DataServiceQuery<COURSE_AVAIL>)(from course in ctx.COURSE_AVAIL
                                                            where course.TEACHER_NAME == Constants.User.NAME
                                                            select course);

                TaskFactory<IEnumerable<COURSE_AVAIL>> tf = new TaskFactory<IEnumerable<COURSE_AVAIL>>();

                IEnumerable<COURSE_AVAIL> attends = await tf.FromAsync(ctx.BeginExecute<COURSE_AVAIL>(
                    new Uri("/GetAllCoursesAttendedByCustomer?customer_id=" + Constants.User.ID, UriKind.Relative), null, null),
                    iar => ctx.EndExecute<COURSE_AVAIL>(iar));
                IEnumerable<COURSE_AVAIL> teaches = await tf.FromAsync(teachDsq.BeginExecute(null, null), iar => teachDsq.EndExecute(iar));

                DataServiceQuery<COURSE_AVAIL> allCoursesDsq = (DataServiceQuery<COURSE_AVAIL>)(from c in ctx.COURSE_AVAIL
                                                                                                select c);
                IEnumerable<COURSE_AVAIL> allCoursesEnum = await tf.FromAsync(allCoursesDsq.BeginExecute(null, null), iar => allCoursesDsq.EndExecute(iar));
                foreach (var c in allCoursesEnum)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    allCourses.Add(tmpCourse);
                }

                courseData = new StoreData();
                foreach (var c in attends)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    tmpCourse.IsBuy = true;
                    tmpCourse.IsTeach = false;
                    courseData.AddCourse(tmpCourse);
                }
                foreach (var c in teaches)
                {
                    Course tmpCourse = Constants.CourseAvail2Course(c);
                    tmpCourse.IsTeach = true;
                    tmpCourse.IsBuy = false;
                    courseData.AddCourse(tmpCourse);
                }

                dataCategory = courseData.GetGroupsByAttendingOrTeaching();
                cvs1.Source = dataCategory;
                UserProfileBt.DataContext = Constants.User;

            }
            catch
            {
                ShowMessageDialog("on navi to");
            }

            loadingProgressRing.IsActive = false;
        }