예제 #1
0
        public async Task <IEnumerable <ProjectItem> > GetProjects(string url = null)
        {
            try
            {
                if (url == null)
                {
                    url = this.MarketUrl;
                }
                string username = null;
                string project  = null;
                string target   = null;
                if (!this.GetRepoInfo(url, out username, out project, out target))
                {
                    XLogSys.Print.Error(GlobalHelper.Get("market_url_check"));
                    return(null);
                }

                IReadOnlyList <RepositoryContent> result = null;

                result = await client.Repository.Content.GetAllContents(username, project, target);

                var items = result?.Where(d => d.Type == ContentType.File && (d.Name.EndsWith(".xml", true, null) || d.Name.EndsWith(".hproj", true, null))).Select(
                    d =>
                {
                    var projectItem = new ProjectItem()
                    {
                        IsRemote = true,
                        SavePath = d.DownloadUrl
                    };
                    var suffix       = d.Name.Split('.').Last();
                    var name         = d.Name.Replace("." + suffix, "");
                    projectItem.Name = name;
                    var meta         = name + ".meta";
                    var metafile     = result.FirstOrDefault(d2 => d2.Name == meta);
                    if (metafile != null)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            var response = WebRequest.Create(metafile.DownloadUrl).GetResponse().GetResponseStream();
                            using (StreamReader reader = new StreamReader(response, Encoding.UTF8))
                            {
                                var item     = reader.ReadToEnd();
                                var metainfo = ParameterItem.GetParameters(item);
                                ControlExtended.UIInvoke(() =>
                                {
                                    projectItem.DictDeserialize(metainfo.ToDictionary(d2 => d2.Key, d2 => (object)d2.Value));
                                });
                            }
                        });
                    }
                    return(projectItem);
                });
                return(items);
            }
            catch (Exception ex)
            {
                XLogSys.Print.Error(ex.Message);
                return(new List <ProjectItem>());
            }
        }
예제 #2
0
        public override void DictDeserialize(IDictionary<string, object> dicts, Scenario scenario = Scenario.Database)
        {
            base.DictDeserialize(dicts, scenario);
            var doc = dicts as FreeDocument;
            if (doc == null || doc.Children == null) return;
            foreach (FreeDocument child in doc.Children)
            {
                var project = new ProjectItem();

                project.DictDeserialize(child);
                Projects.Add(project);
            }
        }