Esempio n. 1
0
        private void OnProvision(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnProvisionRequestDebugLogMessage, ServiceDescription(), msg, reply);
            ProvisionResponse response      = new ProvisionResponse();
            ProvisionRequest  provision_req = new ProvisionRequest();

            provision_req.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(msg));

            ProvisionedServicePlanType plan        = provision_req.Plan;
            ServiceCredentials         credentials = provision_req.Credentials;

            if (credentials == null)
            {
                credentials = GenerateCredentials();
            }

            credentials.ServiceWorkFactory.StartNew(
                () =>
            {
                try
                {
                    ServiceCredentials credential = Provision(plan, credentials);

                    credential.NodeId = this.nodeId;

                    response.Credentials = credential;

                    Logger.Debug(
                        Strings.OnProvisionSuccessDebugLogMessage,
                        ServiceDescription(),
                        msg,
                        response.SerializeToJson());

                    NodeNats.Publish(reply, null, EncodeSuccess(response));
                }
                catch (Exception ex)
                {
                    Logger.Warning(ex.ToString());
                    NodeNats.Publish(reply, null, EncodeFailure(response));
                }
            });
        }
Esempio n. 2
0
        private void OnProvision(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnProvisionRequestDebugLogMessage, ServiceDescription(), msg, reply);
            ProvisionResponse response = new ProvisionResponse();
            ProvisionRequest provision_req = new ProvisionRequest();

            provision_req.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(msg));

            string plan = provision_req.Plan;
            string version = provision_req.Version;
            ServiceCredentials credentials = provision_req.Credentials;

            if (credentials == null)
            {
                credentials = GenerateCredentials();
            }

            //// For backwards compatibility. TODO: Remove when version support is final.
            if (version == null)
            {
                Logger.Debug(Strings.ProvisionBackwardsCompatibilityModeInfoMessage);
                version = this.defaultVersion;
            }

            credentials.ServiceWorkFactory.StartNew(
                () =>
                {
                    try
                    {
                        ServiceCredentials credential = Provision(plan, credentials, version);

                        credential.NodeId = this.nodeId;

                        response.Credentials = credential;

                        this.capacity -= CapacityUnit();
                        Logger.Debug(
                            Strings.OnProvisionSuccessDebugLogMessage,
                            ServiceDescription(),
                            msg,
                            response.SerializeToJson());

                        nodeNats.Publish(reply, null, EncodeSuccess(response));
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning(ex.ToString());
                        nodeNats.Publish(reply, null, EncodeFailure(response));
                    }
                });
        }
Esempio n. 3
0
        private void OnProvision(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnProvisionRequestDebugLogMessage, ServiceDescription(), msg, reply);
            ProvisionResponse response = new ProvisionResponse();
            ProvisionRequest provision_req = new ProvisionRequest();

            provision_req.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(msg));

            ProvisionedServicePlanType plan = provision_req.Plan;
            ServiceCredentials credentials = provision_req.Credentials;

            if (credentials == null)
            {
                credentials = GenerateCredentials();
            }

            credentials.ServiceWorkFactory.StartNew(
                () =>
                {
                    try
                    {
                        ServiceCredentials credential = Provision(plan, credentials);

                        credential.NodeId = this.nodeId;

                        response.Credentials = credential;

                        Logger.Debug(
                            Strings.OnProvisionSuccessDebugLogMessage,
                            ServiceDescription(),
                            msg,
                            response.SerializeToJson());

                        NodeNats.Publish(reply, null, EncodeSuccess(response));
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning(ex.ToString());
                        NodeNats.Publish(reply, null, EncodeFailure(response));
                    }
                });
        }