Example #1
0
        public async Task <object> DeleteCourse(int iCourseId)
        {
            List <KeyValuePair <string, string> > lstCommands = new List <KeyValuePair <string, string> >();

            lstCommands.Add(new KeyValuePair <string, string>("event", "delete"));
            this.CommandToExecute = CanvasCommand.DELETE_COURSE;
            string sUrl = await CommandUrl();

            sUrl = string.Format(sUrl, iCourseId);
            if (lstCommands != null && lstCommands.Count > 0)
            {
                if (sUrl.EndsWith("/"))
                {
                    sUrl = sUrl.Substring(0, sUrl.Length - 1);
                }
                sUrl = string.Concat(sUrl, "?1=1");
                foreach (KeyValuePair <string, string> aCommand in lstCommands)
                {
                    string sParamName  = aCommand.Key;
                    string sParamValue = aCommand.Value;
                    if ((!string.IsNullOrEmpty(sParamName) && (!string.IsNullOrEmpty(sParamValue))))
                    {
                        sUrl = string.Concat(sUrl, "&", sParamName, "=", sParamValue);
                    }
                }
            }
            return(await Execute(sUrl));
        }
Example #2
0
        public async Task <object> MarkEntryAsRead(int iCourseId, int iDiscussionTopicId, int iEntryId)
        {
            this.CommandToExecute = CanvasCommand.MARK_ENTRY_AS_READ;
            string sUrl = string.Format(await CommandUrl(), iCourseId, iDiscussionTopicId, iEntryId);

            return(await Execute(sUrl));
        }
Example #3
0
        public async Task <object> GetCourseDiscussionEntries(int iCourseId, int iDiscussionTopicId)
        {
            this.CommandToExecute = CanvasCommand.GET_COURSE_DISCUSSION_ENTRIES;
            string sUrl = string.Format(await CommandUrl(), iCourseId, iDiscussionTopicId);

            return(await Execute(sUrl));
        }
Example #4
0
        public async Task <object> GetCourseDiscussionsTopics(int iCourseId)
        {
            this.CommandToExecute = CanvasCommand.GET_COURSE_DISCUSSIONS_TOPICS;
            string sUrl = string.Format(await CommandUrl(), iCourseId);

            return(await Execute(sUrl));
        }
Example #5
0
        public async Task <object> GetCourseDetail(int iCourseId)
        {
            this.CommandToExecute = CanvasCommand.GET_COURSE_DETAIL;
            string sUrl = string.Concat(await CommandUrl(), "/", iCourseId);

            return(await Execute(sUrl));
        }
Example #6
0
        public async Task <object> ReplyToTopicEntry(int iCourseId, int iDiscussionTopicId, int iEntryId, string sReply)
        {
            this.CommandToExecute = CanvasCommand.REPLY_TO_DISCUSSION_ENTRY;
            string sUrl = string.Format(await CommandUrl(), iCourseId, iDiscussionTopicId, iEntryId);

            sUrl = string.Concat(sUrl, "?1=1&message=", HttpUtility.UrlEncode(sReply));
            return(await Execute(sUrl));
        }
Example #7
0
        //public void DrawAt ()
        //{
        //    if (Width > 0 && Height > 0)
        //    {
        //        int origX = Console.CursorLeft;
        //        int origY = Console.CursorTop;
        //        int endX = origX + Width + 2;
        //        int endY = origY + Height + 2;

        //        // Draw outer canvas
        //        for (int i = 0; i < Width + 2; i++)
        //        {
        //            // Top border
        //            Point.DrawAt(H_BORDER, origX + i, origY);
        //            // Bottom Border
        //            Point.DrawAt(H_BORDER, origX + i, origY + Height + 1);
        //        }

        //        for (int i = 0; i < Height; i++)
        //        {
        //            // Left Border
        //            Point.DrawAt(V_BORDER, origX, origY + i + 1);
        //            // Rigth Border
        //            Point.DrawAt(V_BORDER, origX + Width + 2, origY + i + 1);
        //        }

        //        // Draw inner canvas
        //        for (int x = 0; x < Width; x++)
        //        {
        //            for(int y = 0; y < Height; y++)
        //            {
        //                if (CanvasArray[x,y] != '\0')
        //                {
        //                    Point.DrawAt(CanvasArray[x, y], origX + x + 1, origY + y + 1);
        //                }
        //            }
        //        }

        //        // reset the cursor to end of last line
        //        Console.SetCursorPosition(endX, endY);
        //    }
        //    else
        //    {
        //        throw new Exception("Width and Height must be positive integers. Width: " + Width + " x Height: " + Height + " is not valid. Please specify a valid width and height.");
        //    }
        //}

        #endregion

        public static Canvas CreateCanvas(
            CommandEntity command
            )
        {
            CanvasCommand canvasCommand = (CanvasCommand)command;

            return(new Canvas(
                       canvasCommand.Width,
                       canvasCommand.Height
                       ));
        }
        public void TestCanvasCreateCanvas()
        {
            int width  = 10;
            int height = 10;

            CommandEntity command = new CanvasCommand(width, height);

            Canvas canvas = Canvas.CreateCanvas(command);

            Assert.AreEqual(width, canvas.Width);
            Assert.AreEqual(height, canvas.Height);
        }
        /// <summary>
        /// Creates the command.
        /// </summary>
        /// <param name="input">The input command.</param>
        /// <returns></returns>
        public static ICommand CreateCommand(string input)
        {
            ICommand command = null;

            try
            {
                var inputSplit = input.Split(' ');
                switch (inputSplit[0])
                {
                case "C":
                    command = new CanvasCommand(inputSplit[1], inputSplit[2]);
                    break;

                case "L":
                    command = new LineCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "R":
                    command = new RectCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "B":
                    command = new FillCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3]);
                    break;

                case "Q":
                    command = new QuitCommand();
                    break;

                default:
                    break;
                }

                if (command != null && !command.IsValid)
                {
                    command = null;
                }
            }
            catch (System.Exception)
            {
                command = null;
            }
            return(command);
        }
Example #10
0
        public async Task <object> UpdateCourse(Courses.Add Update, int iCourseId)
        {
            if (Update != null)
            {
                List <KeyValuePair <string, string> > lstCommands = new List <KeyValuePair <string, string> >();
                lstCommands.Add(new KeyValuePair <string, string>("course[name]", Update.CourseName));
                lstCommands.Add(new KeyValuePair <string, string>("course[public_description]", Update.CourseDescription));
                if (Update.StartDate != null)
                {
                    lstCommands.Add(new KeyValuePair <string, string>("course[start_at]", Update.StartDate.Value.ToString("o")));
                }
                if (Update.EndDate != null)
                {
                    lstCommands.Add(new KeyValuePair <string, string>("course[end_at]", Update.EndDate.Value.ToString("o")));
                }
                lstCommands.Add(new KeyValuePair <string, string>("enroll_me", true.ToString().ToLower()));
                lstCommands.Add(new KeyValuePair <string, string>("course[is_public]", true.ToString().ToLower()));
                lstCommands.Add(new KeyValuePair <string, string>("course[self_enrollment]", true.ToString().ToLower()));

                this.CommandToExecute = CanvasCommand.UPDATE_COURSE;
                string sUrl = await CommandUrl();

                sUrl = string.Format(sUrl, iCourseId);
                if (lstCommands != null && lstCommands.Count > 0)
                {
                    if (sUrl.EndsWith("/"))
                    {
                        sUrl = sUrl.Substring(0, sUrl.Length - 1);
                    }
                    sUrl = string.Concat(sUrl, "?1=1");
                    foreach (KeyValuePair <string, string> aCommand in lstCommands)
                    {
                        string sParamName  = aCommand.Key;
                        string sParamValue = aCommand.Value;
                        if ((!string.IsNullOrEmpty(sParamName) && (!string.IsNullOrEmpty(sParamValue))))
                        {
                            sUrl = string.Concat(sUrl, "&", sParamName, "=", sParamValue);
                        }
                    }
                }
                return(await Execute(sUrl));
            }

            return(null);
        }
Example #11
0
        private static void Record(CanvasCommand canvasCommand, AvaloniaPicture avaloniaPicture)
        {
            if (avaloniaPicture is null || avaloniaPicture._commands is null)
            {
                return;
            }

            switch (canvasCommand)
            {
            case ClipPathCanvasCommand clipPathCanvasCommand:
            {
                var path = clipPathCanvasCommand.ClipPath.ToGeometry(false);
                if (path is { })
                {
                    // TODO: clipPathCanvasCommand.Operation;
                    // TODO: clipPathCanvasCommand.Antialias;
                    avaloniaPicture._commands.Add(new GeometryClipDrawCommand(path));
                }
            }
Example #12
0
        private async Task <List <CanvasAccountModel> > AccountList()
        {
            if (_AccountList == null)
            {
                this.CommandToExecute = CanvasCommand.GET_ACCOUNT_LIST;
                string sUrl = await this.CommandUrl();

                object oResponse = await Execute(sUrl);

                if (oResponse != null)
                {
                    string sJson = oResponse as string;
                    if (sJson != null)
                    {
                        _AccountList = sJson.FromJson <List <CanvasAccountModel> >();
                    }
                }
            }
            return(_AccountList);
        }
Example #13
0
        public async Task <object> Execute(CanvasCommand cmd, List <KeyValuePair <string, string> > lstCommands)
        {
            this.CommandToExecute = cmd;
            string sUrl = await CommandUrl();

            if (lstCommands != null && lstCommands.Count > 0)
            {
                if (sUrl.EndsWith("/"))
                {
                    sUrl = sUrl.Substring(0, sUrl.Length - 1);
                }
                sUrl = string.Concat(sUrl, "?1=1");
                foreach (KeyValuePair <string, string> aCommand in lstCommands)
                {
                    string sParamName  = aCommand.Key;
                    string sParamValue = aCommand.Value;
                    if ((!string.IsNullOrEmpty(sParamName) && (!string.IsNullOrEmpty(sParamValue))))
                    {
                        sUrl = string.Concat(sUrl, "&", sParamName, "=", sParamValue);
                    }
                }
            }
            return(await Execute(sUrl));
        }
Example #14
0
        private static void Record(CanvasCommand canvasCommand, AvaloniaPicture avaloniaPicture)
        {
            if (avaloniaPicture == null || avaloniaPicture._commands == null)
            {
                return;
            }

            switch (canvasCommand)
            {
            case ClipPathCanvasCommand clipPathCanvasCommand:
            {
                var path = clipPathCanvasCommand.ClipPath.ToGeometry(false);
                if (path != null)
                {
                    // TODO: clipPathCanvasCommand.Operation;
                    // TODO: clipPathCanvasCommand.Antialias;
                    avaloniaPicture._commands.Add(new GeometryClipDrawCommand(path));
                }
            }
            break;

            case ClipRectCanvasCommand clipRectCanvasCommand:
            {
                var rect = clipRectCanvasCommand.Rect.ToSKRect();
                // TODO: clipRectCanvasCommand.Operation;
                // TODO: clipRectCanvasCommand.Antialias;
                avaloniaPicture._commands.Add(new ClipDrawCommand(rect));
            }
            break;

            case SaveCanvasCommand _:
            {
                // TODO:
                avaloniaPicture._commands.Add(new SaveDrawCommand());
            }
            break;

            case RestoreCanvasCommand _:
            {
                // TODO:
                avaloniaPicture._commands.Add(new RestoreDrawCommand());
            }
            break;

            case SetMatrixCanvasCommand setMatrixCanvasCommand:
            {
                var matrix = setMatrixCanvasCommand.Matrix.ToMatrix();
                avaloniaPicture._commands.Add(new SetTransformDrawCommand(matrix));
            }
            break;

            case SaveLayerCanvasCommand saveLayerCanvasCommand:
            {
                // TODO:
                avaloniaPicture._commands.Add(new SaveLayerDrawCommand());
            }
            break;

            case DrawImageCanvasCommand drawImageCanvasCommand:
            {
                if (drawImageCanvasCommand.Image != null)
                {
                    var image = drawImageCanvasCommand.Image.ToBitmap();
                    if (image != null)
                    {
                        var source = drawImageCanvasCommand.Source.ToSKRect();
                        var dest   = drawImageCanvasCommand.Dest.ToSKRect();
                        var bitmapInterpolationMode = drawImageCanvasCommand.Paint?.FilterQuality.ToBitmapInterpolationMode() ?? AVMI.BitmapInterpolationMode.Default;
                        avaloniaPicture._commands.Add(new ImageDrawCommand(image, source, dest, bitmapInterpolationMode));
                    }
                }
            }
            break;

            case DrawPathCanvasCommand drawPathCanvasCommand:
            {
                if (drawPathCanvasCommand.Path != null && drawPathCanvasCommand.Paint != null)
                {
                    (var brush, var pen) = drawPathCanvasCommand.Paint.ToBrushAndPen();

                    if (drawPathCanvasCommand.Path.Commands?.Count == 1)
                    {
                        var pathCommand = drawPathCanvasCommand.Path.Commands[0];
                        var success     = false;

                        switch (pathCommand)
                        {
                        case AddRectPathCommand addRectPathCommand:
                        {
                            var rect = addRectPathCommand.Rect.ToSKRect();
                            avaloniaPicture._commands.Add(new RectangleDrawCommand(brush, pen, rect, 0, 0));
                            success = true;
                        }
                        break;

                        case AddRoundRectPathCommand addRoundRectPathCommand:
                        {
                            var rect = addRoundRectPathCommand.Rect.ToSKRect();
                            var rx   = addRoundRectPathCommand.Rx;
                            var ry   = addRoundRectPathCommand.Ry;
                            avaloniaPicture._commands.Add(new RectangleDrawCommand(brush, pen, rect, rx, ry));
                            success = true;
                        }
                        break;

                        case AddOvalPathCommand addOvalPathCommand:
                        {
                            var rect            = addOvalPathCommand.Rect.ToSKRect();
                            var ellipseGeometry = new AM.EllipseGeometry(rect);
                            avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, ellipseGeometry));
                            success = true;
                        }
                        break;

                        case AddCirclePathCommand addCirclePathCommand:
                        {
                            var x               = addCirclePathCommand.X;
                            var y               = addCirclePathCommand.Y;
                            var radius          = addCirclePathCommand.Radius;
                            var rect            = new A.Rect(x - radius, y - radius, radius + radius, radius + radius);
                            var ellipseGeometry = new AM.EllipseGeometry(rect);
                            avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, ellipseGeometry));
                            success = true;
                        }
                        break;

                        case AddPolyPathCommand addPolyPathCommand:
                        {
                            if (addPolyPathCommand.Points != null)
                            {
                                var points           = addPolyPathCommand.Points.ToPoints();
                                var close            = addPolyPathCommand.Close;
                                var polylineGeometry = new AM.PolylineGeometry(points, close);
                                avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, polylineGeometry));
                                success = true;
                            }
                        }
                        break;
                        }

                        if (success)
                        {
                            break;
                        }
                    }

                    if (drawPathCanvasCommand.Path.Commands?.Count == 2)
                    {
                        var pathCommand1 = drawPathCanvasCommand.Path.Commands[0];
                        var pathCommand2 = drawPathCanvasCommand.Path.Commands[1];

                        if (pathCommand1 is MoveToPathCommand moveTo && pathCommand2 is LineToPathCommand lineTo)
                        {
                            var p1 = new A.Point(moveTo.X, moveTo.Y);
                            var p2 = new A.Point(lineTo.X, lineTo.Y);
                            avaloniaPicture._commands.Add(new LineDrawCommand(pen, p1, p2));
                            break;
                        }
                    }

                    var geometry = drawPathCanvasCommand.Path.ToGeometry(brush != null);
                    if (geometry != null)
                    {
                        avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, geometry));
                    }
                }
            }
            break;

            case DrawTextBlobCanvasCommand drawPositionedTextCanvasCommand:
            {
                // TODO:
            }
            break;

            case DrawTextCanvasCommand drawTextCanvasCommand:
            {
                if (drawTextCanvasCommand.Paint != null)
                {
                    (var brush, _) = drawTextCanvasCommand.Paint.ToBrushAndPen();
                    var text   = drawTextCanvasCommand.Paint.ToFormattedText(drawTextCanvasCommand.Text);
                    var x      = drawTextCanvasCommand.X;
                    var y      = drawTextCanvasCommand.Y;
                    var origin = new A.Point(x, y - drawTextCanvasCommand.Paint.TextSize);
                    avaloniaPicture._commands.Add(new TextDrawCommand(brush, origin, text));
                }
            }
            break;

            case DrawTextOnPathCanvasCommand drawTextOnPathCanvasCommand:
            {
                // TODO:
            }
            break;

            default:
                break;
            }
        }
Example #15
0
 public async Task <object> Execute(CanvasCommand cmd)
 {
     return(await Execute(cmd, null));
 }