public Resource FindOrCreateResource(int objectId, int resourceId, int tier)
        {
            if (objectIdToResourceMap.ContainsKey(objectId))
            {
                return(objectIdToResourceMap[objectId]);
            }

            if (resourceDictionary.ContainsKey(resourceId))
            {
                ResourceType resType     = resourceDictionary[resourceId];
                Resource     newResource = new Resource()
                {
                    ResourceId = resourceId, Name = resType.Name, Type = resType.Type, Tier = tier
                };
                objectIdToResourceMap.Add(objectId, newResource);

                if (ResourceAdded != null)
                {
                    ResourceEventArgs m = new ResourceEventArgs(newResource);
                    foreach (System.EventHandler <ResourceEventArgs> e in ResourceAdded?.GetInvocationList())
                    {
                        e.BeginInvoke(this, m, e.EndInvoke, null);
                    }
                }

                return(newResource);
            }

            return(null);
        }
示例#2
0
 /// <summary>
 /// Adds a resource to this resource manager.
 /// </summary>
 /// <param name="resource">The resource to be added.</param>
 public void Add(IResource resource)
 {
     if (s_diagnostics)
     {
         _Debug.WriteLine("Resource manager " + Name + " added resource " + resource.Name + ". It now holds " + (m_resources.Count + 1) + " resources.");
     }
     m_resources.Add(resource);
     resource.Manager = this;
     ResourceAdded?.Invoke(this, resource);
 }
        private async void SubscriptionAddedInManager(object sender, SubscriptionAddedEventArgs e)
        {
            var resource = await this.FhirRepository.ReadResourceAsync(e.ResourceId);

            if (resource is Patient)
            {
                await this.SeedManager.AddReferenceAsync($"did:iota:{resource.Id}", e.Seed);
            }

            await this.SearchRepository.AddResourceAsync(resource);

            ResourceAdded?.Invoke(this, new ResourceAddedEventArgs(resource));
        }
示例#4
0
        public void ResouceAdd2()
        {
            TaskElement("Idle>10 Minutes").WaitUntil(); TaskElement("Idle>10 Minutes").Clicks();

            AddResource.Clicks();

            ResourceType.WaitUntil();

            ResourceType.SelectDropdown("eMOSUser");

            SelectResource("Barger").WaitUntil();

            SelectResource("Barger").Clicks();

            ResourceAdded.Clicks(); WaitforIt(Properties.InactivePhase);
        }
示例#5
0
        public void ResourceAdd4()

        {
            TaskElementUnplanned("Idle").WaitUntil(); TaskElementUnplanned("Idle").Clicks();

            AddResource.Clicks();

            ResourceType.WaitUntil();

            ResourceType.SelectDropdown("eMOSUser");

            SelectResource("Baker").WaitUntil();

            SelectResource("Baker").Clicks();

            ResourceAdded.Clicks();
        }
示例#6
0
        public void AddSameResource()

        {
            TaskElement("Non-Working GPS").WaitUntil(); TaskElement("Non-Working GPS").Clicks();

            AddResource.WaitUntil();

            AddResource.Clicks();

            ResourceType.WaitUntil();

            ResourceType.SelectDropdown("eMOSUser");

            SelectResource("Arroyo").WaitUntil();

            SelectResource("Arroyo").Clicks();

            SelectResource("Sandra").Clicks();

            ResourceAdded.Clicks();
        }
示例#7
0
        public void AddMultipleResource()

        {
            TaskElement("Total Tasks Completed").WaitUntil(); TaskElement("Total Tasks Completed").Clicks();

            AddResource.Clicks();

            ResourceType.WaitUntil();

            ResourceType.SelectDropdown("eMOSUser");

            SelectResource("Wondez").WaitUntil();

            SelectResource("Wondez").Clicks();

            SelectResource("Arroyo").Clicks();

            SelectResource("Sandra").Clicks();

            ResourceAdded.Clicks();
        }
示例#8
0
        public Resource FindOrCreateResource(int objectId, int resourceId, int tier)
        {
            if (objectIdToResourceMap.ContainsKey(objectId))
            {
                return(objectIdToResourceMap[objectId]);
            }

            if (resourceDictionary.ContainsKey(resourceId))
            {
                ResourceType resType     = resourceDictionary[resourceId];
                Resource     newResource = new Resource()
                {
                    ResourceId = resourceId, Name = resType.Name, Type = resType.Type, Tier = tier
                };
                objectIdToResourceMap.Add(objectId, newResource);
                ResourceAdded?.Invoke(this, new ResourceEventArgs(newResource));
                return(newResource);
            }

            return(null);
        }
 private void OnResourceAdded(object sender, IPublicResource publicResource)
 {
     ResourceAdded?.Invoke(this, publicResource.Proxify(TypeController));
 }
示例#10
0
    public async AsyncReply <bool> Put(IResource resource)
    {
        try
        {
            if (resource == this)
            {
                return(true);
            }

            var attrs = resource.Instance.GetAttributes();

            foreach (var kv in resources)
            {
                if (kv.Value.Target == resource)
                {
                    resource.Instance.Variables.Add("objectId", kv.Key);
                    return(true);
                }
            }

            count++;

            Instance.Modified("Count");

            var type = ResourceProxy.GetBaseType(resource);

            // insert the document
            var document = new BsonDocument
            {
                { "classname", type.FullName + "," + type.GetTypeInfo().Assembly.GetName().Name },
                { "name", resource.Instance.Name },
            };

            resourcesCollection.InsertOne(document);
            resource.Instance.Variables["objectId"] = document["_id"].ToString();


            // now update the document
            // * insert first to get the object id, update values, attributes, children and parents after in case the same resource has a property references self

            var parents  = new BsonArray();
            var children = new BsonArray();

            var template = resource.Instance.Template;

            // setup attributes
            resource.Instance.Variables["children"] = new string[0];
            resource.Instance.Variables["parents"]  = new string[] { this.Instance.Link };

            // copy old children (in case we are moving a resource from a store to another.
            if (resource.Instance.Store != this)
            {
                var resourceChildren = await resource.Instance.Children <IResource>();

                if (resourceChildren != null)
                {
                    foreach (IResource c in resourceChildren)
                    {
                        children.Add(c.Instance.Link);
                    }
                }

                var resourceParents = await resource.Instance.Parents <IResource>();

                if (resourceParents == null)
                {
                    parents.Add(this.Instance.Link);
                }
                else
                {
                    foreach (IResource p in resourceParents)
                    {
                        parents.Add(p.Instance.Link);
                    }
                }
            }
            else
            {
                // just add self
                parents.Add(this.Instance.Link);
            }


            var attrsDoc = ComposeStructure(attrs);


            var values = new BsonDocument();

            foreach (var pt in template.Properties)
            {
                var rt = pt.PropertyInfo.GetValue(resource, null);

                values.Add(pt.Name,
                           new BsonDocument {
                    { "age", BsonValue.Create(resource.Instance.GetAge(pt.Index)) },
                    { "modification", resource.Instance.GetModificationDate(pt.Index) },
                    { "value", Compose(rt) }
                });
            }


            var filter = Builders <BsonDocument> .Filter.Eq("_id", document["_id"]);

            var update = Builders <BsonDocument> .Update
                         .Set("values", values).Set("parents", parents).Set("children", children).Set("attributes", attrsDoc);

            resourcesCollection.UpdateOne(filter, update);


            resources.Add(document["_id"].AsObjectId.ToString(), new WeakReference(resource));

            //resource.Instance.Variables["objectId"] = document["_id"].ToString();

            ResourceAdded?.Invoke(resource);

            return(true);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return(false);
        }
    }
示例#11
0
 private void RaiseResourceAdded(IPublicResource newResource)
 {
     ResourceAdded?.Invoke(this, newResource);
 }
示例#12
0
 protected virtual void OnResourceAdded(ResourceAddedEventArgs e)
 {
     ResourceAdded?.Invoke(this, e);
 }
示例#13
0
 private void Register(Resource resource)
 {
     resources.Add(resource);
     ResourceAdded?.Invoke(resource);
     resource.Deleted += OnResourceDeleted;
 }
示例#14
0
 private void OnResourceAdded(IResource resource) =>
 ResourceAdded?.Invoke(this, new ResourceEventArgs(resource));