Exemple #1
0
        public async Task<Update> CheckForUpdate(string url)
        {
            var response = await this.Client.GetAsync(url);
            asapJson.JsonNode responseNode = new asapJson.JsonNode(await response.Content.ReadAsStringAsync(), true);
            response.Dispose();

            try
            {
                if (responseNode.getValue_Object()["success"].getValue_Boolean())
                {
                    var version = new Version(responseNode.getValue_Object()["content"].getValue_Object()["version"].getValue_String());
                    var curVersion = this.AppVersion;

                    if(!(version.Major > curVersion.Major || version.Minor > curVersion.Minor || version.Build > curVersion.Build || version.Revision > curVersion.Revision))
                    {
                        return new Update(url, false);
                    }

                    string downloadInfo_Name = string.Empty;
                    string downloadInfo_Url = string.Empty;
                    foreach (var node in responseNode.getValue_Object()["content"].getValue_Object()["download"].getValue_Array())
                    {
                        downloadInfo_Name = node.getValue_Object()["name"].getValue_String();
                        downloadInfo_Url = node.getValue_Object()["link"].getValue_String();
                        break;
                    }
                    return new Update(url, true, downloadInfo_Name, downloadInfo_Url, version);
                }
            }
            catch(Exception ex)
            {
                Logger.Error(ex.Message);
            }
            return new Update(url, false);
        }
Exemple #2
0
        private ItemInfo(asapJson.JsonNode sourceNode, ItemsGetterUtil.Image owner)
        {
            this.Tags = new List <Tag>();
            foreach (var node in sourceNode.getValue_Object()["tags"].getValue_Array())
            {
                this.Tags.Add(new Tag(node));
            }

            this.Comments = new List <Comment>();
            var tmpComments = new List <Comment>();

            foreach (var node in sourceNode.getValue_Object()["comments"].getValue_Array())
            {
                tmpComments.Add(new Comment(node, this));
            }
            foreach (var it in tmpComments)
            {
                if (it.Parent == 0)
                {
                    this.Comments.Add(it);
                }
                else
                {
                    tmpComments.Find((obj) => obj.Id == it.Parent).Children.Add(it);
                }
            }

            this.Timestamp = ApiProvider.UnixTimestamp0.AddSeconds(sourceNode.getValue_Object()["ts"].getValue_Number());
            this.Cache     = sourceNode.getValue_Object()["cache"].getValue_String();
            this.Rt        = (long)sourceNode.getValue_Object()["rt"].getValue_Number();
            this.Qc        = (long)sourceNode.getValue_Object()["qc"].getValue_Number();

            this.Owner = owner;
        }
Exemple #3
0
 public Badge(asapJson.JsonNode sourceNode)
 {
     this.Link        = sourceNode.getValue_Object()["link"].getValue_String();
     this.Image       = sourceNode.getValue_Object()["image"].getValue_String();
     this.Description = sourceNode.getValue_Object()["description"].getValue_String();
     this.Created     = ApiProvider.UnixTimestamp0.AddSeconds(sourceNode.getValue_Object()["created"].getValue_Number());
 }
Exemple #4
0
        public IEnumerable <Variable> GetVariablesByName(IEnumerable <string> names, EVariableNamespace scope = EVariableNamespace.MissionNamespace)
        {
            var command = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());

            command.GetValue_Object()["command"] = new asapJson.JsonNode((int)ESendCommands.GetVariable);
            var data = command.GetValue_Object()["data"];

            data.GetValue_Object()["name"]  = new asapJson.JsonNode(new List <asapJson.JsonNode>(names.Select(name => new asapJson.JsonNode(name))));
            data.GetValue_Object()["scope"] = new asapJson.JsonNode((int)scope);
            this.WriteMessage(command);

            //have to wait for response now. which will be command 3

            throw new NotImplementedException();
            //command should be the returned packet
            var variables = command.GetValue_Object()["data"];

            foreach (var variable in variables.GetValue_Array())
            {
                var name  = variable.GetValue_Object()["name"].GetValue_String();
                var type  = variable.GetValue_Object()["type"].GetValue_String();
                var value = "";
                if (type != "void")
                {
                    value = variable.GetValue_Object()["value"].GetValue_String();
                    var ns = (EVariableNamespace)variable.GetValue_Object()["ns"].GetValue_Number();//Namespace the variable comes from
                }
                yield return(new Variable()
                {
                    Name = name, Value = value, VariableType = Variable.ValueType.Parse(type)
                });
            }
        }
Exemple #5
0
 public void UpdateBreakpoint(Breakpoint b)
 {
     {
         var command = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());
         command.GetValue_Object()["command"] = new asapJson.JsonNode((int)ESendCommands.AddBreakpoint);
         command.GetValue_Object()["data"]    = b.Serialize();
         this.WriteMessage(command);
     }
 }
Exemple #6
0
        public void WriteMessage(asapJson.JsonNode node)
        {
            var str = node.ToString();

            Logger.Log(NLog.LogLevel.Info, string.Format("SEND {0}", str));
            var bytes = ASCIIEncoding.UTF8.GetBytes(str);

            this.Pipe.Write(bytes, 0, bytes.Length);
        }
Exemple #7
0
        public static async Task <ItemsGetter> Fetch(ApiProvider apiProvider, ViewSource vs)
        {
            string fetchUrl = apiProvider.Api + vs.RequestPath;
            var    response = await apiProvider.Client.GetAsync(new Uri(fetchUrl));

            asapJson.JsonNode responseNode = new asapJson.JsonNode(await response.Content.ReadAsStringAsync(), true);
            response.Dispose();
            return(new ItemsGetter(responseNode, vs, apiProvider));
        }
Exemple #8
0
        public static async Task <Sync> Fetch(ApiProvider apiProvider, DateTime?lastSync = null)
        {
            string url = apiProvider.Api;

            url += "user/sync?lastId=" + (lastSync.HasValue ? lastSync.Value.Subtract(ApiProvider.UnixTimestamp0).TotalSeconds : 0);
            var response = await apiProvider.Client.GetAsync(new Uri(url));

            asapJson.JsonNode responseNode = new asapJson.JsonNode(await response.Content.ReadAsStringAsync(), true);
            response.Dispose();
            return(new Sync(responseNode));
        }
Exemple #9
0
        public static async Task <ItemInfo> Fetch(ItemsGetterUtil.Image img, ApiProvider apiProvider)
        {
            string url = apiProvider.Api;

            url += "items/info?itemId=" + img.Id;

            var response = await apiProvider.Client.GetAsync(new Uri(url));

            asapJson.JsonNode responseNode = new asapJson.JsonNode(await response.Content.ReadAsStringAsync(), true);
            response.Dispose();
            return(new ItemInfo(responseNode, img));
        }
Exemple #10
0
        //https://github.com/dedmen/ArmaDebugEngine/blob/master/BIDebugEngine/BIDebugEngine/breakPoint.cpp#L12 void BreakPoint::Serialize(JsonArchive& ar)

        /*
         *  {
         *      "action": {
         *          "code": "string",
         *          "basePath" : "string",
         *          "type": 0
         *      },
         *      "condition":  {
         *          "code": "string",
         *          "type": 0
         *      },
         *      "filename": "string",
         *      "line": 0
         *  }
         */
        public static asapJson.JsonNode Serialize(this ArmA.Studio.Debugger.Breakpoint b)
        {
            var data   = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());
            var action = data.GetValue_Object()["action"] = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());

            action.GetValue_Object()["code"]     = new asapJson.JsonNode();
            action.GetValue_Object()["basePath"] = new asapJson.JsonNode();
            action.GetValue_Object()["type"]     = new asapJson.JsonNode(2); //https://github.com/dedmen/ArmaDebugEngine/blob/master/BIDebugEngine/BIDebugEngine/breakPoint.h#L82
            data.GetValue_Object()["condition"]  = new asapJson.JsonNode();
            data.GetValue_Object()["filename"]   = new asapJson.JsonNode(b.ArmAPath);
            data.GetValue_Object()["line"]       = new asapJson.JsonNode(b.Line);
            return(data);
        }
Exemple #11
0
        //https://github.com/dedmen/ArmaDebugEngine/blob/master/BIDebugEngine/BIDebugEngine/breakPoint.cpp#L12 void BreakPoint::Serialize(JsonArchive& ar)

        /*
         *  {
         *      "action": {
         *          "code": "string",
         *          "basePath" : "string",
         *          "type": 0
         *      },
         *      "condition": "string",
         *      "filename": "string",
         *      "line": 0
         *  }
         */
        public static asapJson.JsonNode Serialize(this ArmA.Studio.Data.BreakpointInfo b)
        {
            var data   = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());
            var action = data.GetValue_Object()["action"] = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());

            action.GetValue_Object()["code"]     = new asapJson.JsonNode();
            action.GetValue_Object()["basePath"] = new asapJson.JsonNode();
            action.GetValue_Object()["type"]     = new asapJson.JsonNode(2); //https://github.com/dedmen/ArmaDebugEngine/blob/master/BIDebugEngine/BIDebugEngine/breakPoint.h#L82
            data.GetValue_Object()["condition"]  = string.IsNullOrWhiteSpace(b.SqfCondition) ? new asapJson.JsonNode() : new asapJson.JsonNode(b.SqfCondition);
            data.GetValue_Object()["filename"]   = new asapJson.JsonNode(b.FileRef.ArmAPath.Replace('/', '\\').Replace(@"\\", @"\"));
            data.GetValue_Object()["line"]       = new asapJson.JsonNode(b.Line);
            return(data);
        }
Exemple #12
0
 private Sync(asapJson.JsonNode node)
 {
     this.InboxCount = (int)node.getValue_Object()["inboxCount"].getValue_Number();
     this.Log        = new List <int>();
     foreach (var it in node.getValue_Object()["log"].getValue_Array())
     {
         this.Log.Add((int)it.getValue_Number());
     }
     this.LastId    = (int)node.getValue_Object()["lastId"].getValue_Number();
     this.Timestamp = ApiProvider.UnixTimestamp0.AddSeconds(node.getValue_Object()["ts"].getValue_Number());
     //this.Cache = node.getValue_Object()["cache"];
     this.Rt = (long)node.getValue_Object()["rt"].getValue_Number();
     this.Qc = (long)node.getValue_Object()["qc"].getValue_Number();
 }
Exemple #13
0
        public Image(asapJson.JsonNode sourceNode)
        {
            this.Id        = (long)sourceNode.getValue_Object()["id"].getValue_Number();
            this.Promoted  = (long)sourceNode.getValue_Object()["promoted"].getValue_Number();
            this.Up        = (long)sourceNode.getValue_Object()["up"].getValue_Number();
            this.Down      = (long)sourceNode.getValue_Object()["down"].getValue_Number();
            this.Created   = ApiProvider.UnixTimestamp0.AddSeconds(sourceNode.getValue_Object()["created"].getValue_Number());
            this.ImagePath = sourceNode.getValue_Object()["image"].getValue_String();
            this.Thumb     = sourceNode.getValue_Object()["thumb"].getValue_String();
            this.Fullsize  = sourceNode.getValue_Object()["fullsize"].getValue_String();
            this.Source    = sourceNode.getValue_Object()["source"].getValue_String();
            this.Flags     = (long)sourceNode.getValue_Object()["flags"].getValue_Number();
            this.User      = sourceNode.getValue_Object()["user"].getValue_String();

            this.UserMark = new API.ProfileUtil.Mark((int)sourceNode.getValue_Object()["mark"].getValue_Number());
        }
Exemple #14
0
 private ItemsGetter(asapJson.JsonNode node, ViewSource vs, ApiProvider apiProvider)
 {
     this.View    = vs;
     this.AtEnd   = node.getValue_Object()["atEnd"].getValue_Boolean();
     this.AtStart = node.getValue_Object()["atStart"].getValue_Boolean();
     this.Items   = new List <Image>();
     foreach (var it in node.getValue_Object()["items"].getValue_Array())
     {
         this.Items.Add(new Image(it));
     }
     this.Timestamp = ApiProvider.UnixTimestamp0.AddSeconds(node.getValue_Object()["ts"].getValue_Number());
     this.Cache     = node.getValue_Object()["cache"].getValue_String();
     this.Rt        = (long)node.getValue_Object()["rt"].getValue_Number();
     this.Qc        = (long)node.getValue_Object()["qc"].getValue_Number();
     this.Provider  = apiProvider;
 }
Exemple #15
0
        public bool Perform(EOperation op)
        {
            switch (op)
            {
            case EOperation.Continue:
            {
                var node = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());
                node.GetValue_Object()["command"] = new asapJson.JsonNode((int)ESendCommands.ContinueExecution);
                node.GetValue_Object()["data"]    = new asapJson.JsonNode((int)EStepType.Continue);
                this.WriteMessage(node);
                return(true);
            }

            case EOperation.StepInto:
            {
                var node = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());
                node.GetValue_Object()["command"] = new asapJson.JsonNode((int)ESendCommands.ContinueExecution);
                node.GetValue_Object()["data"]    = new asapJson.JsonNode((int)EStepType.StepInto);
                this.WriteMessage(node);
                return(true);
            }

            case EOperation.StepOver:
            {
                var node = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());
                node.GetValue_Object()["command"] = new asapJson.JsonNode((int)ESendCommands.ContinueExecution);
                node.GetValue_Object()["data"]    = new asapJson.JsonNode((int)EStepType.StepOver);
                this.WriteMessage(node);
                return(true);
            }

            case EOperation.StepOut:
            {
                var node = new asapJson.JsonNode(new Dictionary <string, asapJson.JsonNode>());
                node.GetValue_Object()["command"] = new asapJson.JsonNode((int)ESendCommands.ContinueExecution);
                node.GetValue_Object()["data"]    = new asapJson.JsonNode((int)EStepType.StepOut);
                this.WriteMessage(node);
                return(true);
            }

            default:
                this.LastError = "Not Implemented";
                return(false);
            }
        }
Exemple #16
0
        public async Task <List <Image> > GetOlder()
        {
            if (this.AtEnd)
            {
                return(new List <Image>());
            }
            string fetchUrl = this.Provider.Api + this.View.RequestPath + "&older=" + this.Items.Last().Id;
            var    response = await Provider.Client.GetAsync(new Uri(fetchUrl));

            asapJson.JsonNode responseNode = new asapJson.JsonNode(await response.Content.ReadAsStringAsync(), true);
            response.Dispose();
            this.AtEnd = responseNode.getValue_Object()["atEnd"].getValue_Boolean();
            var newItems = new List <Image>();

            foreach (var it in responseNode.getValue_Object()["items"].getValue_Array())
            {
                newItems.Add(new Image(it));
            }
            this.Items.AddRange(newItems);
            return(newItems);
        }
        public async Task <Update> CheckForUpdate(string url)
        {
            var response = await this.Client.GetAsync(url);

            asapJson.JsonNode responseNode = new asapJson.JsonNode(await response.Content.ReadAsStringAsync(), true);
            response.Dispose();

            try
            {
                if (responseNode.getValue_Object()["success"].getValue_Boolean())
                {
                    var version    = new Version(responseNode.getValue_Object()["content"].getValue_Object()["version"].getValue_String());
                    var curVersion = this.AppVersion;

                    if (!(version.Major > curVersion.Major || version.Minor > curVersion.Minor || version.Build > curVersion.Build || version.Revision > curVersion.Revision))
                    {
                        return(new Update(url, false));
                    }

                    string downloadInfo_Name = string.Empty;
                    string downloadInfo_Url  = string.Empty;
                    foreach (var node in responseNode.getValue_Object()["content"].getValue_Object()["download"].getValue_Array())
                    {
                        downloadInfo_Name = node.getValue_Object()["name"].getValue_String();
                        downloadInfo_Url  = node.getValue_Object()["link"].getValue_String();
                        break;
                    }
                    return(new Update(url, true, downloadInfo_Name, downloadInfo_Url, version));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
            return(new Update(url, false));
        }
Exemple #18
0
        public Message(asapJson.JsonNode souceNode)
        {
            //api call profile/info has a bug for messages which causes all numbers to be strings ...
            //that is why this weirdo casting has to happen for the generic message object

            asapJson.JsonNode tmpNode;
            double            tmpVal;

            tmpNode = souceNode.getValue_Object()["id"];
            if (tmpNode.Type == asapJson.JsonNode.EJType.Number)
            {
                this.Id = (long)tmpNode.getValue_Number();
            }
            else if (tmpNode.Type == asapJson.JsonNode.EJType.String)
            {
                if (double.TryParse(tmpNode.getValue_String(), out tmpVal))
                {
                    this.Id = (long)tmpVal;
                }
                else
                {
                    this.Id = -1;
                }
            }
            tmpNode = souceNode.getValue_Object()["up"];
            if (tmpNode.Type == asapJson.JsonNode.EJType.Number)
            {
                this.Up = (long)tmpNode.getValue_Number();
            }
            else if (tmpNode.Type == asapJson.JsonNode.EJType.String)
            {
                if (double.TryParse(tmpNode.getValue_String(), out tmpVal))
                {
                    this.Up = (long)tmpVal;
                }
                else
                {
                    this.Up = -1;
                }
            }
            tmpNode = souceNode.getValue_Object()["down"];
            if (tmpNode.Type == asapJson.JsonNode.EJType.Number)
            {
                this.Down = (long)tmpNode.getValue_Number();
            }
            else if (tmpNode.Type == asapJson.JsonNode.EJType.String)
            {
                if (double.TryParse(tmpNode.getValue_String(), out tmpVal))
                {
                    this.Down = (long)tmpVal;
                }
                else
                {
                    this.Down = -1;
                }
            }
            this.Content = souceNode.getValue_Object()["content"].getValue_String();
            tmpNode      = souceNode.getValue_Object()["created"];
            if (tmpNode.Type == asapJson.JsonNode.EJType.Number)
            {
                this.Created = ApiProvider.UnixTimestamp0.AddSeconds(tmpNode.getValue_Number());
            }
            else if (tmpNode.Type == asapJson.JsonNode.EJType.String)
            {
                if (double.TryParse(tmpNode.getValue_String(), out tmpVal))
                {
                    this.Created = ApiProvider.UnixTimestamp0.AddSeconds(tmpVal);
                }
                else
                {
                    this.Created = ApiProvider.UnixTimestamp0;
                }
            }

            //Only for ItemInfo messages
            this.Parent     = souceNode.getValue_Object().ContainsKey("parent") ? (long)souceNode.getValue_Object()["parent"].getValue_Number() : 0;
            this.Confidence = souceNode.getValue_Object().ContainsKey("confidence") ? (long)souceNode.getValue_Object()["confidence"].getValue_Number() : 0;
            this.Author     = souceNode.getValue_Object().ContainsKey("name") ? souceNode.getValue_Object()["name"].getValue_String() : "";
            this.Mark       = souceNode.getValue_Object().ContainsKey("mark") ? (long)souceNode.getValue_Object()["mark"].getValue_Number() : 0;

            //Only for Profile messages
            this.Thumb = souceNode.getValue_Object().ContainsKey("thumb") ? souceNode.getValue_Object()["thumb"].getValue_String() : "";
            if (souceNode.getValue_Object().ContainsKey("itemId"))
            {
                tmpNode = souceNode.getValue_Object()["itemId"];
                if (tmpNode.Type == asapJson.JsonNode.EJType.Number)
                {
                    this.ItemId = (long)tmpNode.getValue_Number();
                }
                else if (tmpNode.Type == asapJson.JsonNode.EJType.String)
                {
                    if (double.TryParse(tmpNode.getValue_String(), out tmpVal))
                    {
                        this.ItemId = (long)tmpVal;
                    }
                    else
                    {
                        this.ItemId = -1;
                    }
                }
            }
            else
            {
                this.ItemId = 0;
            }
        }
Exemple #19
0
 public ImgLink(asapJson.JsonNode sourceNode)
 {
     this.ID    = sourceNode.getValue_Object()["id"].getValue_String();
     this.Thumb = sourceNode.getValue_Object()["thumb"].getValue_String();
 }
Exemple #20
0
        private void Thread_ReadPipeMessage()
        {
            try
            {
                var buffer = new byte[2048];
                while (this.Pipe.IsConnected)
                {
                    var builder = new StringBuilder();
                    do
                    {
                        var ammount = this.Pipe.Read(buffer, 0, buffer.Length);
                        for (int i = 0; i < ammount; i++)
                        {
                            builder.Append((char)buffer[i]);
                        }
                    } while (!this.Pipe.IsMessageComplete);
                    if (builder.Length > 0)
                    {
                        var node = new asapJson.JsonNode(builder.ToString(), true);
                        Logger.Log(NLog.LogLevel.Info, string.Format("RECV {0}", node.ToString()));
                        if (node.GetValue_Object().ContainsKey("exception"))
                        {
                            this.OnError?.Invoke(this, new OnErrorEventArgs()
                            {
                                Message = node.GetValue_Object()["exception"].GetValue_String()
                            });
                        }
                        else
                        {
                            switch ((int)node.GetValue_Object()["command"].GetValue_Number())
                            {
                            case (int)ERecvCommands.Halt:
                            {
                                var callstack      = this.LastCallstack = node.GetValue_Object()["callstack"];
                                var instruction    = node.GetValue_Object()["instruction"];
                                var fileOffsetNode = instruction.GetValue_Object()["fileOffset"];
                                var line           = (int)fileOffsetNode.GetValue_Array()[0].GetValue_Number();
                                var col            = (int)fileOffsetNode.GetValue_Array()[2].GetValue_Number();
                                this.OnHalt?.Invoke(this, new OnHaltEventArgs()
                                    {
                                        DocumentPath = instruction.GetValue_Object()["filename"].GetValue_String(), Col = col, Line = line
                                    });
                            }
                            break;

                            case (int)ERecvCommands.ContinueExecution:
                            {
                                this.OnContinue?.Invoke(this, new OnContinueEventArgs()
                                    {
                                    });
                            }
                            break;


                            default:
                                this.Messages.Add(node);
                                break;
                            }
                        }
                    }
                    Thread.Sleep(10);
                }
            }
            catch (ObjectDisposedException) { }
        }
Exemple #21
0
 public Comment(asapJson.JsonNode souceNode, ItemInfo owner)
 {
     this._msg     = new Util.Message(souceNode);
     this.Children = new List <Comment>();
     this.Owner    = owner;
 }
Exemple #22
0
 public Tag(asapJson.JsonNode sourceNode)
 {
     this.Id         = (long)sourceNode.getValue_Object()["id"].getValue_Number();
     this.Confidence = (long)sourceNode.getValue_Object()["confidence"].getValue_Number();
     this.Text       = sourceNode.getValue_Object()["tag"].getValue_String();
 }