Exemplo n.º 1
0
        private async Task DeleteBlockchainPolicy(I2B_Request request)
        {
            BigInteger?nonce = null;

            if (_blockchain_settings.transaction_fire_and_forget)
            {
                nonce = _web3geth_service.BlockchainManager.GetMainAccountNonceForRawTransaction;
            }

            DeletePolicy delete_policy = JsonConvert.DeserializeObject <DeletePolicy>(request.task.payload);

            string tx_hash = await _web3geth_service.Policy.SetPolicyAllAttributes(
                contract_address : delete_policy.contract_address,
                task_uuid : request.task_uuid,
                start_date_time : delete_policy.start_date_time.ToString(),
                end_date_time : delete_policy.end_date_time.ToString(),
                start_date_time_local : delete_policy.start_date_time_local,
                end_date_time_local : delete_policy.end_date_time_local,
                status : delete_policy.status,
                deleted : delete_policy.deleted.ToString(),
                nonce : nonce);

            if (_blockchain_settings.transaction_fire_and_forget)
            {
                // check transaction is pending
                await MakeSureTransactionIsPending(tx_hash);

                var fire_and_forget = BackgroundWaitTransactionResult(tx_hash, request);
            }
            else
            {
                await BackgroundWaitTransactionResult(tx_hash, request);
            }
        }
        void obradi()
        {
            try
            {
                int operacija = 0;
                while (operacija != (int)Operacije.Kraj)
                {
                    TransferKlasa transfer = formater.Deserialize(tok) as TransferKlasa;
                    switch (transfer.Operacija)
                    {
                    case Operacije.Login:
                        FindAgent fa = new FindAgent();
                        transfer.Rezultat = fa.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.AddClient:
                        AddClient ac = new AddClient();
                        transfer.Rezultat = ac.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.GetListClients:
                        GetLIstClients glc = new GetLIstClients();
                        transfer.Rezultat = glc.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.SearchClients:
                        SearchClients sc = new SearchClients();
                        transfer.Rezultat = sc.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.SelectClient:
                        SelectClient scl = new SelectClient();
                        transfer.Rezultat = scl.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.UpdateClient:
                        UpdateClient uc = new UpdateClient();
                        transfer.Rezultat = uc.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.AddPolicy:
                        AddPolicy ap = new AddPolicy();
                        transfer.Rezultat = ap.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.UpdatePolicy:
                        UpdatePolicy up = new UpdatePolicy();
                        transfer.Rezultat = up.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.DeletePolicy:
                        DeletePolicy dp = new DeletePolicy();
                        transfer.Rezultat = dp.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.SearchPolicy:
                        SearchPolicy sp = new SearchPolicy();
                        transfer.Rezultat = sp.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.SelectPolicy:
                        SelectPolicy spo = new SelectPolicy();
                        transfer.Rezultat = spo.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.GetListInsTypes:
                        GetListInsuranceTypes git = new GetListInsuranceTypes();
                        transfer.Rezultat = git.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.DeleteClient:
                        DeleteClient dc = new DeleteClient();
                        transfer.Rezultat = dc.IzvrsiSO(transfer.TransferObjekat as OpstiDomenskiObjekat);
                        formater.Serialize(tok, transfer);
                        break;

                    case Operacije.Kraj:
                        operacija = 1;
                        Server.listaTokova.Remove(tok);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception)
            {
                Server.listaTokova.Remove(tok);
            }
        }
Exemplo n.º 3
0
            /// <remarks>Runs <see cref="Keybase.API.Environment.EnsureInitialization"/>.</remarks>
            public static void Listen([NotNull] IListener listener)
            {
                Process process;

                if (null == (process = CreateProcess(kListenArguments)))
                {
                    listener.OnError();

                    return;
                }

                process.OutputDataReceived += (sender, arguments) =>
                {
                    if (null == process || null == arguments.Data)
                    {
                        return;
                    }

                    Log.Debug(typeof(Chat), Log.Type.Message, "Incoming: {0}", arguments.Data);

                    Incoming incoming = JsonSerializer.Deserialize <Incoming> (
                        arguments.Data,
                        StandardResolver.AllowPrivateCamelCase
                        );

                    Incoming.Content.Type type = incoming.GetContentType();
                    switch (type)
                    {
                    case Incoming.Content.Type.Text:
                        if (!incoming.MarkReceipt())
                        {
                            Log.Error("API.Chat.Listen MarkReceipt failed. Incoming contained no message structure?");
                            return;
                        }

                        Message message = incoming.ToMessage();

                        if (message.Valid)
                        {
#if DEBUG_API_LISTEN
                            Log.Message("API.Chat.Listen invoking OnIncoming: {0}", message);
#endif

                            listener.OnIncoming(message);
                        }
                        else
                        {
                            Log.Error("API.Chat.Listen failed to log an incoming message. Keeping busy?");
                        }
                        break;

                    case Incoming.Content.Type.Reaction:
                        if (!incoming.MarkReceipt())
                        {
                            Log.Error("API.Chat.Listen MarkReceipt failed. Incoming contained no message structure?");
                            return;
                        }

                        Reaction reaction = incoming.ToReaction();

                        if (reaction.Valid)
                        {
#if DEBUG_API_LISTEN
                            Log.Message("API.Chat.Listen invoking OnReaction: {0}", reaction);
#endif

                            listener.OnReaction(reaction);
                        }
                        else
                        {
                            Log.Error("API.Chat.Listen failed to log an incoming reaction. Keeping busy?");
                        }
                        break;

                    case Incoming.Content.Type.Delete:
                        DeletePolicy policy = listener.DeletePolicy;

                        using (PooledList <Message.ID> targets = incoming.ToDeleteList())
                        {
                            if (null == targets)
                            {
                                Log.Error("API.Chat.Listen received delete with an invalid targets list");

                                return;
                            }

#if DEBUG_API_LISTEN
                            Log.Message("API.Chat.Listen handling delete of {0} messages", targets.Value.Count);
#endif

                            if (policy.HasFlag(DeletePolicy.Callback))
                            {
                                foreach (Message.ID target in targets.Value)
                                {
                                    listener.OnDelete(target);
                                }
                            }

                            if (policy.HasFlag(DeletePolicy.Remove))
                            {
                                foreach (Message.ID target in targets.Value)
                                {
                                    TryRemoveFromLog(target);
                                }
                            }
                        }
                        break;

                    case Incoming.Content.Type.Unknown:
                        Log.Error("API.Chat.Listen received unknown content type. Incomplete API spec? Data:\n{0}", arguments.Data);
                        return;

                    default:
                        Log.Warning("API.Chat.Listen received unhandled content type: {0}", type);
                        break;
                    }
                };

                bool receivedStartMessage = false;

                process.ErrorDataReceived += (sender, arguments) =>
                {
                    if (null == process || null == arguments.Data)
                    {
                        return;
                    }

                    if (!receivedStartMessage && arguments.Data.StartsWith(kListenOutputStart))
                    {
                        receivedStartMessage = true;
                        return;
                    }

                    Log.Error("API.Chat.Listen process received error output: {0}", arguments.Data);
                };

                process.Exited += (sender, arguments) =>
                {
                    if (null == process)
                    {
                        return;
                    }

                    Log.Debug(typeof(Chat), Log.Type.Message, "API.Chat.Listen process exit");

                    listener.OnError();

                    process.EnableRaisingEvents = false;
                    process.Dispose();
                    process = null;
                };

                if (!process.Start())
                {
                    Log.Error("API.Chat.Listen process failed to start");

                    listener.OnError();

                    return;
                }

                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }