Exemplo n.º 1
0
        public static AssetCatalog Merge(AssetCatalog c1, AssetCatalog c2)
        {
            Dictionary <string, Asset> assets = c1.Assets.ToDictionary(m => m.ID, m => m);

            foreach (var otherAsset in c2.Assets)
            {
                Asset m;
                if (assets.TryGetValue(otherAsset.ID, out m))
                {
                    if (otherAsset.Version > m.Version || otherAsset.UpdatedDate > m.UpdatedDate)
                    {
                        assets[otherAsset.ID] = otherAsset;
                    }
                }
                else
                {
                    assets[otherAsset.ID] = otherAsset;
                }
            }

            return(new AssetCatalog()
            {
                Name = "Merged Catalog",
                Assets = assets.Values.ToList()
            });
        }
        public void Download(DownloadItemViewModel newDownload)
        {
            if (!AssetCatalog.TryParseDownloadUrl(newDownload.DownloadUrl, out DownloadLocationType type, out string location))
            {
                return;
            }

            switch (type)
            {
            case DownloadLocationType.Url:
                DownloadFileFromUrl(newDownload, location);
                break;


            case DownloadLocationType.GDrive:
                DownloadFileFromGDrive(newDownload, location);
                break;


            case DownloadLocationType.MegaFile:
                DownloadFileFromMega(newDownload, location);

                break;
            }

            newDownload.IsStarted = true;
        }
Exemplo n.º 3
0
        public DownloadItemViewModel Download(string link, string saveFilePath, string description, Action onCancel, Action onComplete)
        {
            DownloadLocationType type;
            string location;

            if (!AssetCatalog.TryParseDownloadUrl(link, out type, out location))
            {
                return(null);
            }

            Action onError = () =>
            {
            };


            DownloadItemViewModel newDownload = new DownloadItemViewModel()
            {
                ItemName      = description,
                OnCancel      = onCancel,
                OnError       = onError,
                OnComplete    = onComplete,
                DownloadSpeed = "Calculating ...",
                DownloadType  = DownloadType.Asset
            };

            switch (type)
            {
            case DownloadLocationType.Url:
                using (var wc = new System.Net.WebClient())
                {
                    newDownload.PerformCancel = () =>
                    {
                        wc.CancelAsync();
                        newDownload.OnCancel?.Invoke();
                    };
                    wc.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                    wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                    wc.DownloadFileAsync(new Uri(location), saveFilePath, newDownload);
                }

                break;

            case DownloadLocationType.GDrive:
                var gd = new GDrive();
                newDownload.PerformCancel = () =>
                {
                    gd.CancelAsync();
                    newDownload.OnCancel?.Invoke();
                };
                gd.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                gd.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                gd.Download(location, saveFilePath, newDownload);
                break;
            }

            newDownload.IsStarted = true;
            return(newDownload);
        }
Exemplo n.º 4
0
        internal static string GetNameFromAssetCatalog(string url)
        {
            string name = "";

            try
            {
                string       catalogStr = DownloadUtils.GetTextResponseFromUrl(url, 5);
                AssetCatalog newCatalog = JsonConvert.DeserializeObject <AssetCatalog>(catalogStr);
                name = newCatalog.Name ?? "";
            }
            catch (Exception e)
            {
                Logger.Error(e);
                Logger.Warn($"Failed to get catalog name from url {url}");
            }

            return(name);
        }
Exemplo n.º 5
0
        public void Download(DownloadItemViewModel newDownload)
        {
            DownloadLocationType type;
            string location;

            if (!AssetCatalog.TryParseDownloadUrl(newDownload.DownloadUrl, out type, out location))
            {
                return;
            }

            switch (type)
            {
            case DownloadLocationType.Url:
                using (var wc = new System.Net.WebClient())
                {
                    newDownload.PerformCancel = () =>
                    {
                        wc.CancelAsync();
                        newDownload.OnCancel?.Invoke();
                    };
                    wc.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                    wc.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                    wc.DownloadFileAsync(new Uri(location), newDownload.SaveFilePath, newDownload);
                }

                break;

            case DownloadLocationType.GDrive:
                var gd = new GDrive();
                newDownload.PerformCancel = () =>
                {
                    gd.CancelAsync();
                    newDownload.OnCancel?.Invoke();
                };
                gd.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(_wc_DownloadProgressChanged);
                gd.DownloadFileCompleted   += new AsyncCompletedEventHandler(_wc_DownloadFileCompleted);
                gd.Download(location, newDownload.SaveFilePath, newDownload);
                break;
            }

            newDownload.IsStarted = true;
        }