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 <bool> LinkRelative(Func <Task <IEnumerable <Neuron> > > linkCandidatesRetriever, Func <object, Task <string[]> > terminalParametersRetriever, object owner, ITerminalApplicationService terminalApplicationService, IStatusService statusService, string avatarUrl, string targetNeuronId, RelativeType relativeType)
        {
            bool result = false;
            await Neurons.Helper.SetStatusOnComplete(async() =>
            {
                bool stat      = false;
                var candidates = await linkCandidatesRetriever();

                if (candidates != null && candidates.Count() > 0)
                {
                    string[] tps = await terminalParametersRetriever(owner);

                    foreach (var n in candidates)
                    {
                        await terminalApplicationService.CreateTerminal(
                            avatarUrl,
                            Guid.NewGuid().ToString(),
                            relativeType == RelativeType.Presynaptic ? n.Id : targetNeuronId,
                            relativeType == RelativeType.Presynaptic ? targetNeuronId : n.Id,
                            (neurUL.Cortex.Common.NeurotransmitterEffect) int.Parse(tps[0]),
                            float.Parse(tps[1])
                            );
                    }
                    result = true;
                    stat   = true;
                }

                return(stat);
            },
                                                     $"{relativeType.ToString()} linked successfully.",
                                                     statusService,
                                                     $"{relativeType.ToString()} linking cancelled."
                                                     );

            return(result);
        }