Exemple #1
0
        public void ODRTagsAreCreatedAsExpected()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "ODRTags1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "ODRTags1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    dataset     = catalog.OpenDataSet("data1");

            dataset.AddVariant(new DeviceRequirement(), testFiles.CreateFile("data1.dat", "data1"), null);
            dataset.AddOnDemandResourceTag("tag1");
            dataset.AddOnDemandResourceTag("tag2");

            catalog.Write();

            string datasetPath = Path.Combine(catalogPath, "data1.dataset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(datasetPath));
            AssertFileExistsAndHasContents(Path.Combine(datasetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "ODRTags1.data1.dataset.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(datasetPath, "data1.dat"), "data1");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Exemple #2
0
        public void ImageSetCanBeCreatedWithDuplicateFiles()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Imageset1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Imageset-duplicate.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    imageset    = catalog.OpenImageSet("img1");

            var filePath = testFiles.CreateFile("data1.png", "img1");

            imageset.AddVariant(new DeviceRequirement().AddWidthClass(SizeClassRequirement.Regular),
                                filePath);

            imageset.AddVariant(new DeviceRequirement().AddHeightClass(SizeClassRequirement.Compact),
                                filePath);

            catalog.Write();

            string imagesetPath = Path.Combine(catalogPath, "img1.imageset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(imagesetPath));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Imageset-duplicate.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1.png"), "img1");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1-1.png"), "img1");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Exemple #3
0
        public AssetStoreViewModel()
        {
            IsInstallingAsset = false;
            DisplayMaps       = true;
            SetSelectedCategoriesFromAppSettings();
            FetchAllPreviewImages = AppSettingsUtil.GetAppSetting(SettingKey.FetchAllPreviewImages).Equals("true", StringComparison.OrdinalIgnoreCase);

            if (AppSettingsUtil.GetAppSetting(SettingKey.DeleteDownloadAfterAssetInstall) == "")
            {
                DeleteDownloadAfterInstall = true; // default to true if does not exist in app config
            }
            else
            {
                DeleteDownloadAfterInstall = AppSettingsUtil.GetAppSetting(SettingKey.DeleteDownloadAfterAssetInstall).Equals("true", StringComparison.OrdinalIgnoreCase);
            }

            InstallStatusList = new List <string>()
            {
                defaultInstallStatusValue, "Installed", "Not Installed"
            };
            SelectedInstallStatus = defaultInstallStatusValue;

            AuthorList = new List <AuthorDropdownViewModel>()
            {
                new AuthorDropdownViewModel(defaultAuthorValue, 0)
            };
            AuthorToFilterBy = AuthorList[0];

            _catalogCache = GetCurrentCatalog();
            ReloadAllAssets();
            CheckForCatalogUpdatesAsync(clearCache: false);
        }
Exemple #4
0
        public void BrandAssetCreationWorks()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "BrandAsset11Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "BrandAsset1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    brandAssets = catalog.OpenBrandAssetGroup("brand1");

            var icon1 = brandAssets.OpenImageSet("icon1", "tv", "primary-app-icon", 128, 256);

            icon1.AddVariant(new DeviceRequirement(), testFiles.CreateFile("data1.png", "img1"));
            catalog.Write();

            string brandAssetsPath = Path.Combine(catalogPath, "brand1.brandassets");
            string icon1Path       = Path.Combine(brandAssetsPath, "icon1.imageset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(brandAssetsPath));
            Assert.IsTrue(Directory.Exists(icon1Path));

            AssertFileExistsAndHasContents(Path.Combine(brandAssetsPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "BrandAssets1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(icon1Path, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "BrandAssets1.icon1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(icon1Path, "data1.png"), "img1");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Exemple #5
0
        public void DataSetCreationWorks()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Dataset1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Dataset1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    dataset     = catalog.OpenDataSet("data1");

            dataset.AddVariant(new DeviceRequirement().AddDevice(DeviceTypeRequirement.iPad),
                               testFiles.CreateFile("data1.dat", "data1"), null);

            dataset.AddVariant(new DeviceRequirement().AddMemory(MemoryRequirement.Mem1GB),
                               testFiles.CreateFile("data2.dat", "data2"), "testtype1");

            dataset.AddVariant(new DeviceRequirement().AddMemory(MemoryRequirement.Mem2GB).AddGraphics(GraphicsRequirement.Metal1v2),
                               testFiles.CreateFile("data3", "data3"), "testtype2");

            catalog.Write();

            string datasetPath = Path.Combine(catalogPath, "data1.dataset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(datasetPath));
            AssertFileExistsAndHasContents(Path.Combine(datasetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Dataset1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(datasetPath, "data1.dat"), "data1");
            AssertFileExistsAndHasContents(Path.Combine(datasetPath, "data2.dat"), "data2");
            AssertFileExistsAndHasContents(Path.Combine(datasetPath, "data3"), "data3");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Exemple #6
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            batch   = new SpriteBatch(GraphicsDevice);
            Assets  = new AssetCatalog(Content, lua);
            TheGame = new GameManager();

            primitives = new Primitives(GraphicsDevice, batch);


#if DEVELOPMENT_BUILD
            console = new DevelopmentConsole(this, batch, primitives, lua, this.Window);
            Components.Add(console);
#endif

            world = new World(32, 32);
            world.Register(new SpriteRenderer());
            world.Register(new PlayerController(camera, primitives));
            world.Register(new CharacterController(primitives));
            world.Register(new IlluminationSystem(penumbra));
            world.Register(new AnimationSystem());
            var physics = (PhysicsSystem)world.Register(new PhysicsSystem(primitives));

            // Goto the menu level
            gsm.Goto(new GameLevel(world, penumbra, camera));
            //gsm.Goto(new Menu(world));
        }
        public BoolWithMessage AddAsset()
        {
            string errorMessage = ValidateAssetInfo(null);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                return(BoolWithMessage.False($"The following errors were found:\n\n{errorMessage}"));
            }

            Asset newAsset = new Asset()
            {
                ID           = $"{SelectedAssetID}{SelectedIDExtension}",
                Author       = SelectedAssetAuthor,
                Category     = SelectedAssetCategory,
                Description  = SelectedAssetDescription,
                Name         = SelectedAssetName,
                PreviewImage = SelectedAssetImageUrl,
                UpdatedDate  = DateTime.UtcNow,
                Version      = 1,
            };


            if (!string.IsNullOrWhiteSpace(SelectedAssetUpdatedDate))
            {
                DateTime.TryParse(SelectedAssetUpdatedDate, out DateTime updateDate);
                if (updateDate != null && updateDate != DateTime.MinValue)
                {
                    newAsset.UpdatedDate = updateDate;
                }
            }

            double.TryParse(SelectedAssetVersion, out double version);

            if (version <= 0)
            {
                newAsset.Version = version;
            }

            if (SelectedAssetDownloadType == "Url")
            {
                newAsset.DownloadLink = AssetCatalog.FormatUrl(SelectedAssetDownloadUrl);
            }
            else if (SelectedAssetDownloadType == "Google Drive")
            {
                newAsset.DownloadLink = $"rsmm://GDrive/{SelectedAssetDownloadUrl}";
            }


            AssetViewModel viewModel = new AssetViewModel(newAsset);

            AssetList.Add(viewModel);

            AssetToEdit   = null;
            SelectedAsset = null;
            SelectedAsset = AssetList[AssetList.Count - 1];

            return(BoolWithMessage.True());
        }
Exemple #8
0
        public void ImageSetCreationWorks()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Imageset1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Imageset1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    imageset    = catalog.OpenImageSet("img1");

            imageset.AddVariant(new DeviceRequirement().AddWidthClass(SizeClassRequirement.Regular),
                                testFiles.CreateFile("data1.png", "img1"));

            imageset.AddVariant(new DeviceRequirement().AddHeightClass(SizeClassRequirement.Compact),
                                testFiles.CreateFile("data2.png", "img2"));

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X1),
                                testFiles.CreateFile("data3.png", "img3"));

            var alignment = new ImageAlignment();

            alignment.top    = 1;
            alignment.bottom = 2;
            alignment.left   = 3;
            alignment.right  = 4;

            var resizing = new ImageResizing();

            resizing.type             = ImageResizing.SlicingType.HorizontalAndVertical;
            resizing.top              = 1;
            resizing.bottom           = 2;
            resizing.left             = 3;
            resizing.right            = 4;
            resizing.centerResizeMode = ImageResizing.ResizeMode.Stretch;
            resizing.centerWidth      = 2;
            resizing.centerHeight     = 4;

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X3),
                                testFiles.CreateFile("data4.png", "img4"), alignment, resizing);
            catalog.Write();

            string imagesetPath = Path.Combine(catalogPath, "img1.imageset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(imagesetPath));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Imageset1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1.png"), "img1");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data2.png"), "img2");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data3.png"), "img3");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data4.png"), "img4");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Exemple #9
0
        public void ImageStackCreationWorks()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "ImageStack1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "ImageStack1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    imageStack  = catalog.OpenImageStack("stack1");

            var layer    = imageStack.AddLayer("layer1");
            var imageset = layer.GetImageSet();

            imageset.AddVariant(new DeviceRequirement().AddWidthClass(SizeClassRequirement.Regular),
                                testFiles.CreateFile("data1.png", "img1"));

            imageset.AddVariant(new DeviceRequirement().AddHeightClass(SizeClassRequirement.Compact),
                                testFiles.CreateFile("data2.png", "img2"));

            layer = imageStack.AddLayer("layer2");
            layer.SetReference("Image1");
            catalog.Write();

            string imageStackPath     = Path.Combine(catalogPath, "stack1.imagestack");
            string layer1Path         = Path.Combine(imageStackPath, "layer1.imagestacklayer");
            string layer1ImageSetPath = Path.Combine(layer1Path, "Content.imageset");
            string layer2Path         = Path.Combine(imageStackPath, "layer2.imagestacklayer");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(imageStackPath));
            Assert.IsTrue(Directory.Exists(layer1Path));
            Assert.IsTrue(Directory.Exists(layer1ImageSetPath));
            Assert.IsTrue(Directory.Exists(layer2Path));

            AssertFileExistsAndHasContents(Path.Combine(imageStackPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "ImageStack1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(layer1Path, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "ImageStack1.layer1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(layer1ImageSetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "ImageStack1.layer1.Content.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(layer2Path, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "ImageStack1.layer2.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(layer1ImageSetPath, "data1.png"), "img1");
            AssertFileExistsAndHasContents(Path.Combine(layer1ImageSetPath, "data2.png"), "img2");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Exemple #10
0
 IEnumerator Init()
 {
     return(LoadValue(
                string.Format("http://{0}/api/assetcatalogs", assetServerAddress),
                data => {
         if (data as DataArray != null)
         {
             CoreLogger.LogInfo(_loggerModule, string.Format("received catalog: {0}", data));
             _catalog = new AssetCatalog(data[0]);
         }
         else
         {
             CoreLogger.LogWarning(_loggerModule, "response is not a json array - no catalog will be available");
             _catalog = new AssetCatalog();
         }
     }
                ));
 }
        public BoolWithMessage ImportCatalog(string pathToCatalog)
        {
            try
            {
                AssetCatalog catalog = JsonConvert.DeserializeObject <AssetCatalog>(File.ReadAllText(pathToCatalog));

                AssetList = new ObservableCollection <AssetViewModel>(catalog.Assets.Select(a => new AssetViewModel(a)).ToList());
                ClearSelectedAsset();

                CatalogName = catalog.Name;

                return(BoolWithMessage.True());
            }
            catch (Exception e)
            {
                return(BoolWithMessage.False($"Failed to import catalog: {e.Message}"));
            }
        }
Exemple #12
0
        public void FoldersAreCreatedAsExpected()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Folder1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Folder1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    dataset     = catalog.OpenDataSet("test/test/test2/data1");

            dataset.AddVariant(new DeviceRequirement().AddDevice(DeviceTypeRequirement.iPad),
                               testFiles.CreateFile("data1.dat", "data1"), null);

            var folder = catalog.OpenFolder("test/test2");

            folder.providesNamespace = true;
            dataset = catalog.OpenDataSet("test/test2/data2");
            dataset.AddVariant(new DeviceRequirement().AddDevice(DeviceTypeRequirement.iPad),
                               testFiles.CreateFile("data2.dat", "data2"), null);

            catalog.Write();

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsFalse(File.Exists(Path.Combine(catalogPath, "Contents.json")));
            Assert.IsTrue(Directory.Exists(Path.Combine(catalogPath, "test")));
            Assert.IsFalse(File.Exists(Path.Combine(catalogPath, "test/Contents.json")));
            Assert.IsTrue(Directory.Exists(Path.Combine(catalogPath, "test/test")));
            Assert.IsFalse(File.Exists(Path.Combine(catalogPath, "test/test/Contents.json")));
            Assert.IsTrue(Directory.Exists(Path.Combine(catalogPath, "test/test/test2")));
            Assert.IsFalse(File.Exists(Path.Combine(catalogPath, "test/test/test2/Contents.json")));
            Assert.IsTrue(Directory.Exists(Path.Combine(catalogPath, "test/test/test2/data1.dataset")));
            Assert.IsTrue(Directory.Exists(Path.Combine(catalogPath, "test/test2")));
            AssertFileExistsAndHasContents(Path.Combine(catalogPath, "test/test2/Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Folder1.test2.Contents.json")));
            Assert.IsTrue(Directory.Exists(Path.Combine(catalogPath, "test/test2/data2.dataset")));
            AssertFileExistsAndHasContents(Path.Combine(catalogPath, "test/test/test2/data1.dataset/Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Folder1.data1.dataset.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(catalogPath, "test/test2/data2.dataset/Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Folder1.data2.dataset.Contents.json")));

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
        public static void Build()
        {
            BuildTarget             buildTarget = EditorUserBuildSettings.activeBuildTarget;
            BuildAssetBundleOptions options     = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.StrictMode;

            string        folder    = EditorUtility.OpenFolderPanel("Build AssetBundles", Application.streamingAssetsPath, "");
            DirectoryInfo directory = new DirectoryInfo(folder);

            if (!directory.Exists)
            {
                Debug.LogError($"Directory '{folder}' does not exist!");
                return;
            }

            directory.Delete(true);
            directory.Create(); // clear it

            try
            {
                BuildPipeline.BuildAssetBundles(directory.FullName, options, buildTarget);

                foreach (var manifest in directory.GetFiles("*.manifest", SearchOption.AllDirectories))
                {
                    manifest.Delete();
                }

                string manifestBundlePath = Path.Combine(directory.FullName, directory.Name);
                File.Delete(manifestBundlePath);

                AssetCatalog catalog     = AssetUtility.CreateEditorAssetCatalog();
                string       catalogJson = JsonConvert.SerializeObject(catalog);
                File.WriteAllText(Path.Combine(directory.FullName, AssetCatalog.FileName), catalogJson);

                AssetDatabase.Refresh();
                Debug.Log("Build Successfully");
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Debug.Log("Build Failed");
            }
        }
        public BoolWithMessage ExportCatalog(string savePath)
        {
            try
            {
                UpdateAsset(SelectedAsset); // ensure the currently selected asset is updated before writing to file

                AssetCatalog catalog = new AssetCatalog()
                {
                    Name   = CatalogName,
                    Assets = AssetList.Select(a => a.Asset).ToList()
                };

                string fileContents = JsonConvert.SerializeObject(catalog, Formatting.Indented);
                File.WriteAllText(savePath, fileContents);

                return(BoolWithMessage.True());
            }
            catch (Exception e)
            {
                return(BoolWithMessage.False($"Failed to export catalog: {e.Message}"));
            }
        }
        private BoolWithMessage UpdateAsset(AssetViewModel assetToUpdate)
        {
            if (assetToUpdate == null)
            {
                return(BoolWithMessage.False("assetToUpdate is null"));
            }

            string validationMsg = ValidateAssetInfo(assetToUpdate);

            if (!string.IsNullOrEmpty(validationMsg))
            {
                UpdatedAssetInvalid?.Invoke(validationMsg);
                return(BoolWithMessage.False(validationMsg));
            }

            if (SelectedAssetDownloadType == "Url")
            {
                assetToUpdate.Asset.DownloadLink = AssetCatalog.FormatUrl(SelectedAssetDownloadUrl);
            }
            else if (SelectedAssetDownloadType == "Google Drive")
            {
                assetToUpdate.Asset.DownloadLink = $"rsmm://GDrive/{SelectedAssetDownloadUrl}";
            }
            else if (SelectedAssetDownloadType == "Mega")
            {
                assetToUpdate.Asset.DownloadLink = $"rsmm://MegaFile/{SelectedAssetDownloadUrl}";
            }
            assetToUpdate.Asset.ID           = $"{SelectedAssetID}{SelectedIDExtension}";
            assetToUpdate.Asset.Name         = SelectedAssetName;
            assetToUpdate.Asset.Author       = SelectedAssetAuthor;
            assetToUpdate.Asset.Category     = SelectedAssetCategory;
            assetToUpdate.Asset.Description  = SelectedAssetDescription;
            assetToUpdate.Asset.PreviewImage = SelectedAssetImageUrl;

            double.TryParse(SelectedAssetVersion, out double version);

            if (version <= 0)
            {
                assetToUpdate.Asset.Version = 1;
            }
            else
            {
                assetToUpdate.Asset.Version = version;
            }

            DateTime.TryParse(SelectedAssetUpdatedDate, out DateTime updateDate);

            if (updateDate != DateTime.MinValue)
            {
                assetToUpdate.Asset.UpdatedDate = updateDate.ToUniversalTime();
            }
            else if (string.IsNullOrWhiteSpace(SelectedAssetUpdatedDate))
            {
                assetToUpdate.Asset.UpdatedDate = DateTime.UtcNow;
            }

            assetToUpdate.Name          = assetToUpdate.Asset.Name;
            assetToUpdate.Author        = assetToUpdate.Asset.Author;
            assetToUpdate.AssetCategory = assetToUpdate.Asset.Category;
            assetToUpdate.Version       = assetToUpdate.Asset.Version.ToString();
            assetToUpdate.UpdatedDate   = assetToUpdate.Asset.UpdatedDate.ToLocalTime().ToString(AssetViewModel.dateTimeFormat);
            assetToUpdate.Description   = assetToUpdate.Asset.Description;

            return(BoolWithMessage.True());
        }
        //**********DeleteAsset**************************************************
        //NAME           : DeleteAsset
        //PURPOSE        : Function to delete assets from product catalog.
        //PARAMETERS     : AssetPID,Language,Mode(Add,Update,Delete),isClone,DeleteAll
        //RETURN VALUE   : boolean
        //USAGE		     :
        //CREATED ON	 : 11-02-2006
        //CHANGE HISTORY :Auth           Date	     Description
        //***********************************************************************
        public bool DeleteAsset(string AssetPID, string Language, string Mode, bool isClone, bool DeleteAll)
        {
            try
            {
                Product objAsset;
                int     lngCnt;
                string  AssetCatalog;

                objAsset = new Product(Convert.ToInt32(AssetPID));
                ArrayList LocalArray;
                //LocalArray=GetLocales(Language.Substring(0,2));
                LocalArray = GetLocales(Language);

                try
                {
                    if ((Mode == "U") || (DeleteAll == true))
                    {
                        foreach (Product Assetparent in  objAsset.ParentProducts)
                        {
                            Assetparent.Assets.Remove(objAsset);
                            //objAsset.ParentProducts.Remove(Assetparent,DanaherTM.ProductEngine.DBUtils.DataStructures.RelationshipTypes.Products.Asset);
                            //objAsset.ParentProducts.Remove(
                        }
                    }
                }
                catch (Exception Ex)
                {
                    //Do nothing
                }


                for (lngCnt = 0; lngCnt < LocalArray.Count; lngCnt++)
                {
                    try
                    {
                        ProductLocalized LocalProduct = new ProductLocalized(objAsset, Convert.ToString(LocalArray[lngCnt].ToString().Trim()));
                        LocalProduct.Delete();
                    }
                    catch (Exception ex)
                    {
                        //Do Nothing
                    }
                }

                for (lngCnt = 0; lngCnt < LocalArray.Count; lngCnt++)
                {
                    try
                    {
                        AssetCatalog = Convert.ToString(LocalArray[lngCnt]);
                        AssetCatalog = AssetCatalog.Trim().Substring(AssetCatalog.Trim().Length - 2, 2);
                        Catalog ProductCatalog = new Catalog("Fnet-" + AssetCatalog.ToUpper());
                        ProductCatalog.Assets.Remove(objAsset);
                    }
                    catch (Exception ex)
                    {
                        //Do Nothing
                    }
                }

                try
                {
                    if ((Mode == "U") || (DeleteAll == true))
                    {
                        //						foreach(Category AssetCat in  objAsset.Categories)
                        //						{
                        //							//objAsset.Categories.Remove(AssetCat);
                        //							Deletecategory(AssetCat.ID,objAsset.ID);
                        //						}
                        objAsset.Categories.Remove(DanaherTM.ProductEngine.DBUtils.DataStructures.RelationshipTypes.Products.Asset);
                    }
                }
                catch (Exception Ex)
                {
                    //Do nothing
                }

                if (((Mode != "U") && (Mode != "A")) || DeleteAll == true)
                //if(DeleteAll==true)
                {
                    objAsset.Delete();
                }
                return(true);
            }
            catch (Exception ex)
            {
                //Code for error handling
                return(false);
            }
        }
Exemple #17
0
        public Task CheckForCatalogUpdatesAsync(bool clearCache = true)
        {
            object countLock = new object();

            Task t = Task.Factory.StartNew(() =>
            {
                string catFile = AbsolutePathToCatalogSettingsJson;

                Directory.CreateDirectory(AbsolutePathToTempDownloads);

                CatalogSettings currentSettings = new CatalogSettings();

                if (File.Exists(catFile))
                {
                    currentSettings = JsonConvert.DeserializeObject <CatalogSettings>(File.ReadAllText(catFile));
                    currentSettings.CatalogUrls.RemoveAll(s => string.IsNullOrWhiteSpace(s.Url));
                }
                else
                {
                    CatalogSettings.AddDefaults(currentSettings);
                }


                if (currentSettings.CatalogUrls.Count == 0)
                {
                    if (File.Exists(catFile))
                    {
                        File.Delete(catFile);
                    }

                    _catalogCache = new AssetCatalog();
                    ReloadAllAssets();
                    RefreshFilteredAssetList();
                    return;
                }

                if (clearCache)
                {
                    lock (catalogCacheLock)
                    {
                        _catalogCache = new AssetCatalog();
                    }
                }

                foreach (CatalogSubscription sub in currentSettings.CatalogUrls.Where(c => c.IsActive).ToArray())
                {
                    Logger.Info($"Checking catalog {sub.Url}");

                    string uniqueFileName = $"cattemp{Path.GetRandomFileName()}.xml"; // save temp catalog update to unique filename so multiple catalog updates can download async
                    string path           = Path.Combine(AbsolutePathToTempDownloads, uniqueFileName);

                    Guid downloadId = Guid.NewGuid();

                    Action onCancel = () =>
                    {
                        RemoveFromDownloads(downloadId);
                    };

                    Action onError = () =>
                    {
                        RemoveFromDownloads(downloadId);
                    };

                    Action onComplete = () =>
                    {
                        RemoveFromDownloads(downloadId);

                        try
                        {
                            AssetCatalog c = JsonConvert.DeserializeObject <AssetCatalog>(File.ReadAllText(path));

                            lock (catalogCacheLock) // put a lock on the Catalog so multiple threads can only merge one at a time
                            {
                                _catalogCache = AssetCatalog.Merge(_catalogCache, c);
                                File.WriteAllText(AbsolutePathToCatalogJson, JsonConvert.SerializeObject(_catalogCache, Formatting.Indented));
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }
                        finally
                        {
                            // delete temp catalog
                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }

                            ReloadAllAssets();
                            RefreshFilteredAssetList();
                        }
                    };

                    DownloadItemViewModel catalogDownload = new DownloadItemViewModel()
                    {
                        UniqueId     = downloadId,
                        DownloadType = DownloadType.Catalog,
                        ItemName     = $"Checking catalog {sub.Url}",
                        DownloadUrl  = AssetCatalog.FormatUrl(sub.Url),
                        SaveFilePath = path,
                        OnComplete   = onComplete,
                        OnError      = onError,
                        OnCancel     = onCancel
                    };

                    AddToDownloads(catalogDownload);
                }
            });

            return(t);
        }