private AssetInstance ProvideAsset(string path, AssetContainer container, Type typ)
        {
            var hash = AssetInstance.GenerateHash(path);

            if (container.TryGetAsset(hash) is AssetInstance asset && asset.IsFinished)
            {
                return(asset);
            }

            asset = typ == typeof(GameObject) ? new PrefabAssetInstance(path) : new AssetInstance(path);
            Object unityObject;

            if (ConvertPath(ref path) || path.StartsWith("Assets"))
            {
                                #if UNITY_EDITOR
                unityObject = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typ);
                                #else
                unityObject = null;
                                #endif
            }
            else
            {
                unityObject = Resources.Load(path, typ);
            }

            asset.SetAsset(unityObject, null);
            return(asset);
        }
Esempio n. 2
0
 public void GetMediaItems(IList <MediaItem> items)
 {
     if (AssetInstance != null)
     {
         AssetInstance.GetMediaItems(items);
     }
 }
Esempio n. 3
0
        private AssetInstance NewAssetInstance(string key, AssetType type, IAssetCore newcore)
        {
            AssetInstance inst = new AssetInstance {
                core = newcore
            };

            newcore.AllocationChanged += OnAssetAllocationChanged;
            _assets[(int)type].Add(key, inst);
            return(inst);
        }
Esempio n. 4
0
        public override async Task <AssetInstance[]> GetInstances()
        {
            // in a non-distributed system we only have one instance (the current one)
            AssetVersion[] versions = await GetUsableVersions();

            string       host = this.httpContextAccessor.HttpContext.Request.Host.Host;
            AssetVersion downloadingVersion = await GetDownloadingVersion();

            AssetInstance instance = new AssetInstance(host, versions, downloadingVersion);

            return(new AssetInstance[] { instance });
        }
Esempio n. 5
0
        public static GameObject InstantiateAsset(
            GameObject prefab,
            AssetInstance assetInstance,
            out GameObject assetObj,
            Transform parent = null,
            bool applyLayout = true,
            bool addCollider = true)
        {
            var gameObj = GameObject.Instantiate(prefab);

            assetObj = gameObj;

            return(ConfigureAsset(gameObj, assetInstance, parent, applyLayout, addCollider));
        }
Esempio n. 6
0
        public int AddAsset(Asset asset)
        {
            ArgumentChecker.IsNotNull(asset, nameof(asset));

            GuidCheck(asset.DatabaseId);

            using (DatabaseConnection conn = new DatabaseConnection(this.databaseConfigs[asset.DatabaseId]))
            {
                // First, find the type of asset.
                AssetType assetType = this.GetAssetType(conn, asset.AssetType);

                // Ensure our asset is compatiable with our type.
                IAssetType fullAssetType = this.GetAssetType(conn, asset.DatabaseId, assetType.Id);
                fullAssetType.ValidateAsset(asset);

                DateTime      timestamp     = DateTime.UtcNow;
                AssetInstance assetInstance = new AssetInstance
                {
                    AssetType    = assetType,
                    CreationDate = timestamp,
                    ModifiedDate = timestamp
                };

                // Next, get all of the attributes that are associated with the asset type.
                IEnumerable <AssetTypeAttributesMap> maps = this.GetAttributesAssociatedWithAssetType(
                    conn,
                    assetType
                    );

                foreach (AssetTypeAttributesMap map in maps)
                {
                    AssetInstanceAttributeValues value = new AssetInstanceAttributeValues
                    {
                        AssetInstance = assetInstance,
                        AttributeKey  = map.AttributeKey,
                        Value         = asset.Attributes[map.AttributeKey.Name].Serialize()
                    };

                    conn.AssetInstanceAttributeValues.Add(value);
                }

                conn.AssetInstances.Add(assetInstance);

                conn.SaveChanges();

                return(assetInstance.Id); // Must come after SaveChanges() so the ID gets updated.
            }
        }
Esempio n. 7
0
        public void Add3dAsset(IVuforiaMarker marker, string objectId, AssetInstance assetInstance, MediaElement fallbackImage)
        {
            var markerAsset = new MarkerAsset
            {
                AssetInstance = assetInstance,
                Marker        = marker,
                ObjectId      = objectId
            };

            if (fallbackImage != null)
            {
                markerAsset.MediaUrl    = fallbackImage.MediaUrl;
                markerAsset.MediaLayout = fallbackImage.Layout;
            }

            Add3dAsset(markerAsset);
        }
Esempio n. 8
0
        public static GameObject ConfigureAsset(
            GameObject gameObj,
            AssetInstance assetInstance,
            Transform parent = null,
            bool applyLayout = true,
            bool addCollider = true)
        {
            var layoutObj = new GameObject("Layout");

            layoutObj.transform.localPosition = Vector3.zero;
            layoutObj.transform.localRotation = Quaternion.identity;
            layoutObj.transform.localScale    = Vector3.one;

            var animationObj = new GameObject("Scripted Animation");

            animationObj.transform.localPosition = Vector3.zero;
            animationObj.transform.localRotation = Quaternion.identity;
            animationObj.transform.localScale    = Vector3.one;

            animationObj.transform.SetParent(layoutObj.transform);

            gameObj.transform.localPosition = Vector3.zero;
            gameObj.transform.localRotation = Quaternion.identity;

            gameObj.transform.SetParent(animationObj.transform);

            if (assetInstance.Layout != null)
            {
                LayoutHelper.Apply(layoutObj.transform, assetInstance.Layout);
            }

            var collider = gameObj.GetComponent <Collider>();

            if (!collider)
            {
                gameObj.AddComponent <SphereCollider>();
            }

            if (parent)
            {
                layoutObj.transform.SetParent(parent.transform, false);
            }

            return(layoutObj);
        }
Esempio n. 9
0
        public Asset GetAsset(Guid databaseId, int assetId)
        {
            GuidCheck(databaseId);
            using (DatabaseConnection conn = new DatabaseConnection(this.databaseConfigs[databaseId]))
            {
                AssetInstance assetInstance = conn.AssetInstances
                                              .Include(nameof(AssetInstance.AssetType))
                                              .FirstOrDefault(i => i.Id == assetId);

                if (assetInstance == null)
                {
                    throw new ArgumentException(
                              "Can not find asset id " + assetId + " in database " + databaseId,
                              nameof(assetId)
                              );
                }

                return(CreateAsset(conn, databaseId, assetInstance.AssetType.Name, assetInstance));
            }
        }
Esempio n. 10
0
        public void GetMediaItems(IList <MediaItem> items)
        {
            if (Markers != null)
            {
                foreach (var marker in Markers)
                {
                    var mp = marker as IMediaItemProvider;

                    if (mp != null)
                    {
                        mp.GetMediaItems(items);
                    }
                }
            }

            if (AssetInstance != null)
            {
                AssetInstance.GetMediaItems(items);
            }
        }
Esempio n. 11
0
        public void UpdateAsset(int id, Asset asset)
        {
            ArgumentChecker.IsNotNull(asset, nameof(asset));

            GuidCheck(asset.DatabaseId);

            using (DatabaseConnection conn = new DatabaseConnection(this.databaseConfigs[asset.DatabaseId]))
            {
                // First, find the type of asset.
                AssetType assetType = this.GetAssetType(conn, asset.AssetType);

                // Ensure our asset is compatiable with our type.
                IAssetType fullAssetType = this.GetAssetType(conn, asset.DatabaseId, assetType.Id);
                fullAssetType.ValidateAsset(asset);

                // Get the asset instance currently in the database.
                AssetInstance assetInstance = conn.AssetInstances.FirstOrDefault(i => i.Id == id);
                if (assetInstance == null)
                {
                    throw new ArgumentException("Can not find asset of ID " + id + " in database " + asset.DatabaseId);
                }

                // Update all values of attributes.
                IEnumerable <AssetInstanceAttributeValues> values = conn.AssetInstanceAttributeValues
                                                                    .Include(nameof(AssetInstanceAttributeValues.AttributeKey))
                                                                    .Where(v => v.AssetInstance.Id == assetInstance.Id);

                foreach (AssetInstanceAttributeValues value in values)
                {
                    value.Value = asset.Attributes[value.AttributeKey.Name].Serialize();
                    conn.AssetInstanceAttributeValues.Update(value);
                }

                // Update modified timestamp in the database.
                DateTime timestamp = DateTime.UtcNow;
                assetInstance.ModifiedDate = timestamp;
                conn.AssetInstances.Update(assetInstance);

                conn.SaveChanges();
            }
        }
        private AssetInstance ProvideAsset(string path, AssetContainer container, Type typ)
        {
            var hash = AssetInstance.GenerateHash(path);

            if (container.TryGetAsset(hash) is AssetInstance asset)
            {
                return(asset);
            }

            if (!TryGetABContext(path, out var abPathContext))
            {
                Debug.LogWarning($"Can not get ab context : {path}");
                return(null);
            }

            asset = typ == typeof(GameObject) ? new PrefabAssetInstance(path) : new AssetInstance(path);
            var abInstance = FindOrCreateABInstance(abPathContext.ABName, container);

            asset.SetAsset(abInstance.LoadAsset(abPathContext.Path, typ), abInstance);
            return(asset);
        }
Esempio n. 13
0
        public void Add3DAsset(IVisualMarker marker, string objectId, AssetInstance assetInstance, MediaElement fallbackImage)
        {
            if (!CheckAdapter())
            {
                return;
            }

            var markerAsset = new MarkerAsset
            {
                AssetInstance = assetInstance,
                Marker        = marker,
                ObjectId      = objectId
            };

            if (fallbackImage != null)
            {
                markerAsset.MediaUrl    = fallbackImage.MediaUrl;
                markerAsset.MediaLayout = fallbackImage.Layout;
            }

            Add3DAsset(markerAsset);
        }
Esempio n. 14
0
        public void DeleteAsset(Guid databaseId, int assetTypeId, int assetId)
        {
            this.GuidCheck(databaseId);

            using (DatabaseConnection conn = new DatabaseConnection(this.databaseConfigs[databaseId]))
            {
                AssetType assetType = this.GetAssetType(conn, assetTypeId);

                AssetInstance asset = conn.AssetInstances.FirstOrDefault(a => a.Id == assetId);
                if (asset == null)
                {
                    throw new ArgumentException("Could not find asset with ID " + assetId + " in database " + this.DatabaseNames[databaseId]);
                }

                // First, we need to delete all values that are related to the asset from the database.
                IEnumerable <AssetInstanceAttributeValues> values = conn.AssetInstanceAttributeValues.Where(v => v.AssetInstance.Id == asset.Id);
                conn.AssetInstanceAttributeValues.RemoveRange(values);

                // Lastly, delete the asset itself.
                conn.AssetInstances.Remove(asset);

                conn.SaveChanges();
            }
        }
Esempio n. 15
0
        private Asset CreateAsset(DatabaseConnection conn, Guid databaseId, string assetType, AssetInstance assetInstance)
        {
            // Next, get all of the attributes and their values associated with the asset instance.
            IEnumerable <AssetInstanceAttributeValues> attributeValues = conn.AssetInstanceAttributeValues
                                                                         .Include(nameof(AssetInstanceAttributeValues.AssetInstance))
                                                                         .Include(nameof(AssetInstanceAttributeValues.AttributeKey))
                                                                         .Where(i => i.AssetInstance.Id == assetInstance.Id);

            // Create the asset.
            Asset asset = new Asset(databaseId)
            {
                AssetType = assetType
            };

            foreach (AssetInstanceAttributeValues value in attributeValues)
            {
                IAttribute attr = AttributeFactory.CreateAttribute(value.AttributeKey.AttributeType);
                attr.Deserialize(value.Value);

                asset.AddEmptyAttribute(value.AttributeKey.Name, attr.AttributeType);
                asset.SetAttribute(value.AttributeKey.Name, attr);
            }

            return(asset);
        }
Esempio n. 16
0
 public AssetVersion[] GetInstalledVersions(AssetInstance instance)
 {
     return(instance.InstalledVersions);
 }
Esempio n. 17
0
        private void ExecuteSaveCommand()
        {
            if (this.transactionType == TransactionUiType.Deposit)
            {
                this.model.CashTransactions.Add(
                    new CashTransaction
                {
                    TransactionDate = this.CashTransactionDate,
                    SettlementDate  = this.CashSettlementDate,
                    Description     = this.CashTransationDescription,
                    Comment         = this.CashTransactionComment,
                    Amount          = decimal.Parse(this.CashTransactionAmount)
                });
                this.entityModel.SaveChanges();
            }
            else if (this.transactionType == TransactionUiType.Withdraw)
            {
                this.model.CashTransactions.Add(
                    new CashTransaction
                {
                    TransactionDate = this.CashTransactionDate,
                    SettlementDate  = this.CashSettlementDate,
                    Description     = this.CashTransationDescription,
                    Comment         = this.CashTransactionComment,
                    Amount          = -Convert.ToDecimal(this.CashTransactionAmount)
                });
                this.entityModel.SaveChanges();
            }
            else if (this.transactionType == TransactionUiType.Buy)
            {
                var asset = this.entityModel.Assets.FirstOrDefault(a => a.Ticker == this.AssetTickerSymbol);
                if (asset == null)
                {
                    asset = new Asset()
                    {
                        Ticker             = this.AssetTickerSymbol,
                        Desciption         = this.AssetName,
                        AssetCurrency      = CurrencyCode.CAD,
                        Quantity           = 0,
                        LastPrice          = Convert.ToDecimal(this.AssetPrice),
                        LastPriceTimestamp = this.AssetTransactionDate,
                        Yield = 0
                    };
                    this.entityModel.Assets.Add(asset);
                }

                var cashTransaction = new CashTransaction
                {
                    TransactionDate = this.CashTransactionDate,
                    SettlementDate  = this.CashSettlementDate,
                    Description     = this.CashTransationDescription,
                    Comment         = this.CashTransactionComment,
                    Amount          = -Convert.ToDecimal(this.CashTransactionAmount)
                };
                this.model.CashTransactions.Add(cashTransaction);

                var assetInstance = new AssetInstance
                {
                    Asset    = asset,
                    BookCost = Convert.ToDecimal(this.AssetTransactionAmount)
                };
                this.model.Assets.Add(assetInstance);
                this.model.AssetTransactions.Add(
                    new AssetTransaction()
                {
                    TransactionType = Ipm.Model.TransactionType.BuySell,
                    TransactionDate = this.AssetTransactionDate,
                    SettlementDate  = this.AssetSettlementDate,
                    TickerSymbol    = this.AssetTickerSymbol,
                    AssetName       = this.AssetName,
                    Description     = this.AssetTransactionDescription,
                    Comment         = this.AssetTransactionComment,
                    Quantity        = Convert.ToDecimal(this.AssetQuantity),
                    Price           = Convert.ToDecimal(this.AssetPrice),
                    Commission      = Convert.ToDecimal(this.AssetTransactionCommission),
                    Amount          = Convert.ToDecimal(this.AssetTransactionAmount),
                    CashTransaction = cashTransaction,
                    AssetInstance   = assetInstance
                });
                this.entityModel.SaveChanges();
            }
        }
Esempio n. 18
0
        public void Add3dAsset(ResourceActivationContext ctxt, IVuforiaMarker marker, string mediaId, AssetInstance assetInstance, string fallbackImageUrl = null, Layout layout = null, Action onOpen = null, Action onSelect = null)
        {
            if (DoesObjectExist(marker.Identifier, mediaId))
            {
                return;
            }

            var markerAsset = new MarkerAsset
            {
                ActivationContext = ctxt,
                AssetInstance     = assetInstance,
                Marker            = marker,
                MediaType         = MediaType.Image,
                MediaUrl          = fallbackImageUrl,
                MediaLayout       = layout,
                ObjectId          = mediaId,
                OnSelect          = onSelect,
                OnOpen            = onOpen
            };

            Add3dAsset(markerAsset);
        }
Esempio n. 19
0
 private AssetInstance NewAssetInstance(string key, AssetType type, IAssetCore newcore)
 {
   AssetInstance inst = new AssetInstance { core = newcore };
   newcore.AllocationChanged += OnAssetAllocationChanged;
   _assets[(int) type].Add(key, inst);
   return inst;
 }
Esempio n. 20
0
 public string GetAddress(AssetInstance instance)
 {
     return(instance.Address);
 }
Esempio n. 21
0
 public AssetVersion GetDownloadingVersion(AssetInstance instance)
 {
     return(instance.DownloadingVersion);
 }