Esempio n. 1
0
        internal async static Task <bool> CreateRelative(Func <Task <string> > tagRetriever, Func <object, Task <string[]> > terminalParametersRetriever, object owner, IDialogService dialogService, INeuronQueryService neuronQueryService, INeuronApplicationService neuronApplicationService, ITerminalApplicationService terminalApplicationService, IStatusService statusService, string avatarUrl, string regionId, string targetNeuronId, RelativeType relativeType)
        {
            bool result = false;
            await Neurons.Helper.SetStatusOnComplete(async() =>
            {
                bool stat = false;
                var tag   = await tagRetriever();

                if (!string.IsNullOrEmpty(tag) &&
                    await Neurons.Helper.PromptSimilarExists(neuronQueryService, dialogService, avatarUrl, owner, tag))
                {
                    string[] tps             = await terminalParametersRetriever(owner);
                    var presynapticNeuronId  = string.Empty;
                    var postsynapticNeuronId = string.Empty;
                    var newNeuronId          = string.Empty;

                    if (relativeType == RelativeType.Presynaptic)
                    {
                        newNeuronId          = presynapticNeuronId = Guid.NewGuid().ToString();
                        postsynapticNeuronId = targetNeuronId;
                    }
                    else if (relativeType == RelativeType.Postsynaptic)
                    {
                        presynapticNeuronId = targetNeuronId;
                        newNeuronId         = postsynapticNeuronId = Guid.NewGuid().ToString();
                    }

                    await neuronApplicationService.CreateNeuron(
                        avatarUrl,
                        newNeuronId,
                        tag,
                        regionId
                        );
                    await terminalApplicationService.CreateTerminal(
                        avatarUrl,
                        Guid.NewGuid().ToString(),
                        presynapticNeuronId,
                        postsynapticNeuronId,
                        (neurUL.Cortex.Common.NeurotransmitterEffect) int.Parse(tps[0]),
                        float.Parse(tps[1])
                        );
                    result = true;
                    stat   = true;
                }
                return(stat);
            },
                                                     $"{relativeType.ToString()} created successfully.",
                                                     statusService,
                                                     $"{relativeType.ToString()} creation cancelled."
                                                     );

            return(result);
        }
Esempio n. 2
0
        internal async static Task <Neuron> CreateNeuron(Func <Task <string> > tagRetriever, object owner, IDialogService dialogService, INeuronQueryService neuronQueryService, INeuronApplicationService neuronApplicationService, INotificationApplicationService notificationApplicationService, IStatusService statusService, string avatarUrl, string regionId)
        {
            Neuron result = null;
            await Neurons.Helper.SetStatusOnComplete(async() =>
            {
                bool stat          = false;
                bool addingOwner   = false;
                var shouldAddOwner = (await notificationApplicationService.GetNotificationLog(avatarUrl, string.Empty)).NotificationList.Count == 0;
                if (shouldAddOwner && (await dialogService.ShowDialogYesNo("This Avatar needs to be initialized with an Owner Neuron. Do you wish to continue by creating one?", owner, out DialogResult yesno)).GetValueOrDefault())
                {
                    addingOwner = true;
                }

                if (!shouldAddOwner || addingOwner)
                {
                    string tag = await tagRetriever();
                    if (!string.IsNullOrEmpty(tag) &&
                        await Neurons.Helper.PromptSimilarExists(neuronQueryService, dialogService, avatarUrl, owner, tag)
                        )
                    {
                        Neuron n = new Neuron
                        {
                            Tag     = tag,
                            UIId    = Guid.NewGuid().GetHashCode(),
                            Id      = Guid.NewGuid().ToString(),
                            Version = 1,
                        };

                        await neuronApplicationService.CreateNeuron(
                            avatarUrl,
                            n.Id,
                            n.Tag,
                            regionId
                            );
                        result = n;
                        stat   = true;
                    }
                }
                return(stat);
            },
                                                     "Neuron created successfully.",
                                                     statusService,
                                                     "Neuron creation cancelled."
                                                     );

            return(result);
        }