Exemplo n.º 1
0
        // GET: UUID/Validar/5
        public ActionResult Validar()
        {
            UUIDModel model = new UUIDModel();
            ResultSet res   = model.validar();

            string UUID = "";

            while (res.Next())
            {
                string fileName = res.Get("XML");
                long   pk       = res.GetLong("ID_ESTADODECUENTA");
                try
                {
                    string xml = Load(fileName);

                    string etiqueta = "UUID=\"";
                    int    index    = xml.IndexOf(etiqueta);
                    if (0 < index)
                    {
                        index += etiqueta.Length;
                        int index_2 = xml.IndexOf("\"", index);
                        if (index_2 > 0)
                        {
                            UUID = xml.Substring(index, index_2 - index);
                            model.save_UUID(pk, UUID);
                        }
                    }
                }
                catch (Exception) { }
            }


            return(Content("-1"));
        }
        public async Task <OperationResult <UploadMediaStatusModel> > GetMediaStatus(UUIDModel uuid, CancellationToken ct)
        {
            if (!EnableRead)
            {
                return(null);
            }

            var endpoint = $"{BaseUrl}/{GatewayVersion.V1P1}/media/{uuid.Uuid}/status";

            return(await HttpClient.Get <UploadMediaStatusModel>(endpoint, ct));
        }
        public async Task <OperationResult <MediaModel> > GetMediaResult(UUIDModel model, CancellationToken ct)
        {
            if (!EnableRead)
            {
                return(null);
            }

            var endpoint = $"{BaseUrl}/{GatewayVersion.V1P1}/media/{model.Uuid}/result";

            return(await HttpClient.Get <MediaModel>(endpoint, ct));
        }
Exemplo n.º 4
0
        public ActionResult <ResponseModel> PostRegister([FromBody] RequestModel req)
        {
            var user = new UserModel
            {
                uuid     = UUIDModel.GetUUID(),
                name     = (string)req.data["name"],
                password = (string)req.data["password"],
                datetime = DateTime.Now
            };

            _context.User.Add(user);
            _context.SaveChanges();

            return(new ResponseModel
            {
                status = 200,
                statusText = "success"
            });
        }
Exemplo n.º 5
0
        public ActionResult <ResponseModel> PostSignIn([FromBody] RequestModel req)
        {
            var user  = new UserModel();
            var data  = new Newtonsoft.Json.Linq.JObject();
            var token = new Newtonsoft.Json.Linq.JObject();
            var auth  = new AuthModel();
            var _auth = new AuthModel();

            try
            {
                user          = _context.User.Single(u => u.name == (string)req.data["name"] && u.password == (string)req.data["password"]);
                auth.uuid     = user.uuid;
                auth.token    = UUIDModel.GetUUID("N") + UUIDModel.GetUUID("N");
                auth.datetime = DateTime.Now;
                _context.Auth.Add(auth);
                _context.SaveChanges();

                _auth = _context.Auth.Single(a => a.token == auth.token);
            }
            catch (Exception ex)
            {
                data["msg"] = ex.Message;
                return(new ResponseModel
                {
                    status = 404,
                    statusText = "failure",
                    data = data
                });
            }
            data["uuid"]   = user.uuid;
            data["name"]   = user.name;
            token["id"]    = _auth.id;
            token["token"] = _auth.token;
            data["token"]  = token;
            HttpContext.Session.SetString("token", _auth.token);
            return(new ResponseModel
            {
                status = 200,
                statusText = "success",
                data = data
            });
        }
Exemplo n.º 6
0
        public ActionResult <ResponseModel> PostInsert([FromBody] UserModel _user)
        {
            _user.uuid     = UUIDModel.GetUUID();
            _user.datetime = DateTime.Now;
            _context.User.Add(_user);
            _context.SaveChanges();
            return(new ResponseModel
            {
                status = 200,
                statusText = "success",

                /*
                 * data = new UserModel
                 * {
                 *  id = _user.id,
                 *  uuid = _user.uuid,
                 *  name = _user.name,
                 * }
                 */
            });
        }
 public async Task <OperationResult <MediaModel> > TryGetMediaResult(UUIDModel uuid)
 {
     return(await TryRunTask <UUIDModel, MediaModel>(GetMediaResult, OnDisposeCts.Token, uuid));
 }
 private async Task <OperationResult <MediaModel> > GetMediaResult(UUIDModel uuid, CancellationToken ct)
 {
     return(await Api.GetMediaResult(uuid, ct));
 }
 private async Task <OperationResult <UploadMediaStatusModel> > GetMediaStatus(UUIDModel uuid, CancellationToken ct)
 {
     return(await Api.GetMediaStatus(uuid, ct));
 }
 public async Task <OperationResult <UploadMediaStatusModel> > TryGetMediaStatus(UUIDModel uuid)
 {
     return(await TryRunTask <UUIDModel, UploadMediaStatusModel>(GetMediaStatus, OnDisposeCts.Token, uuid));
 }
Exemplo n.º 11
0
 private void switchToNewModel(IContainerRootMarshalled c)
 {
     ContainerRoot cc = CloneContainerRoot(c);
     if (!c.isReadOnly())
     {
         cc = (ContainerRoot)kevoreeFactory.createModelCloner().clone(cc, true);
     }
     // current model is backed-up
     UUIDModel previousModel = model;
     if (previousModel != null)
     {
         models.AddLast(previousModel);
     }
     // TODO : MAGIC NUMBER ;-) , ONLY KEEP 10 PREVIOUS MODEL
     if (models.Count > 15)
     {
         models.RemoveFirst();
     }
     // Changes the current model by the new model
     if (cc != null)
     {
         UUIDModel uuidModel = new UUIDModelImpl(Guid.NewGuid(), new ContainerRootMarshalled(cc));
         this.model = uuidModel;
         // Fires the update to listeners
         modelListeners.notifyAllListener();
     }
 }
Exemplo n.º 12
0
        private bool internalUpdateModel(IContainerRootMarshalled proposedNewModel, string callerPath)
        {
            if (proposedNewModel.findNodesByID(this.nodeName) == null)
            {
                return false;
            }
            try
            {
                var readOnlyNewModel = CloneContainerRoot(proposedNewModel);
                if (readOnlyNewModel.isReadOnly())
                {
                    readOnlyNewModel = (ContainerRoot)kevoreeFactory.createModelCloner().clone(readOnlyNewModel, false);
                    readOnlyNewModel.setGenerated_KMF_ID(nodeName + "@" + callerPath + "#" + java.lang.System.nanoTime());
                    readOnlyNewModel = (ContainerRoot)kevoreeFactory.createModelCloner().clone(readOnlyNewModel, true);
                }
                else
                {
                    readOnlyNewModel.setGenerated_KMF_ID(nodeName + "@" + callerPath + "#" + java.lang.System.nanoTime());
                }
                pending = proposedNewModel;
                // Model check is OK.
                ContainerRoot currentModel;
                if (this.model != null)
                {

                    var serialized = this.model.getModel().serialize();
                    var kf = new org.kevoree.factory.DefaultKevoreeFactory();
                    currentModel = (ContainerRoot)kf.createJSONLoader().loadModelFromString(serialized).get(0);
                }
                else
                {
                    currentModel = null;
                }
                UpdateContext updateContext = new UpdateContext(new ContainerRootMarshalled(currentModel), new ContainerRootMarshalled(readOnlyNewModel), callerPath);
                bool preCheckResult = modelListeners.preUpdate(updateContext);
                bool initUpdateResult = modelListeners.initUpdate(updateContext);
                if (preCheckResult && initUpdateResult)
                {
                    IContainerRootMarshalled newmodel = new ContainerRootMarshalled(readOnlyNewModel);
                    // CHECK FOR HARA KIRI
                    IContainerRootMarshalled previousHaraKiriModel = null;
                    // Checks and bootstrap the node
                    checkBootstrapNode(newmodel);
                    if (this.model != null)
                    {
                        var serialized = this.model.getModel().serialize();
                        var kf = new org.kevoree.factory.DefaultKevoreeFactory();
                        currentModel = (ContainerRoot)kf.createJSONLoader().loadModelFromString(serialized).get(0);
                    }
                    else
                    {
                        currentModel = null;
                    }
                    long milli = java.lang.System.currentTimeMillis();

                    bool deployResult;
                    try
                    {
                        if (nodeInstance != null)
                        {
                            // Compare the two models and plan the adaptation
                            // Log.info("Comparing models and planning
                            // adaptation.")

                            var dkf = new DefaultKevoreeFactory();
                            var modelCompare = dkf.createModelCompare();

                            // TODO : clean up -> cloned
                            var newmodel2 = CloneContainerRoot(newmodel);

                            var traces = modelCompare.diff(currentModel, newmodel2);
                            AdaptationModel adaptationModel = nodeInstance.plan(new ContainerRootMarshalled(currentModel), newmodel, new TracesMarshalled(traces));
                            // Execution of the adaptation
                            updateContext = new UpdateContext(new ContainerRootMarshalled(currentModel), new ContainerRootMarshalled(newmodel2), callerPath);

                            UpdateContext final_updateContext = updateContext;
                            Func<bool> afterUpdateTest = () => { return modelListeners.afterUpdate(final_updateContext); };
                            Func<bool> postRollbackTest = () =>
                            {
                                modelListeners.postRollback(final_updateContext);
                                return true;
                            };

                            Func<bool> preCmdPreRollbackTest = getPreCmdPreRollbackTest(updateContext, modelListeners);

                            IContainerNodeMarshalled rootNode = newmodel.findNodesByID(getNodeName());
                            deployResult = PrimitiveCommandExecutionHelper.execute(this, rootNode,
                                    adaptationModel, nodeInstance, afterUpdateTest, preCmdPreRollbackTest,
                                    postRollbackTest);

                            if (deployResult)
                            {
                                this.model = new UUIDModelImpl(Guid.NewGuid(), newmodel);
                            }
                        }
                        else
                        {
                            deployResult = false;
                        }
                    }
                    catch (Exception e)
                    {
                        loggerMaster.Error(e.StackTrace);
                        deployResult = false;
                    }
                    if (deployResult)
                    {
                        switchToNewModel(newmodel);
                    }
                    else
                    {
                        // KEEP FAIL MODEL, TODO
                        // IF HARAKIRI
                        if (previousHaraKiriModel != null)
                        {
                            internalUpdateModel(previousHaraKiriModel, callerPath);
                            previousHaraKiriModel = null; // CLEAR
                        }
                    }
                    long milliEnd = java.lang.System.currentTimeMillis() - milli;
                    //pending = null;
                    return deployResult;

                }
                else
                {
                    return false;
                }

            }
            catch (java.lang.Throwable)
            {
                return false;
            }
        }
Exemplo n.º 13
0
        private void checkBootstrapNode(IContainerRootMarshalled currentModel)
        {
            try
            {
                if (nodeInstance == null)
                {
                    IContainerNodeMarshalled foundNode = currentModel.findNodesByID(getNodeName());
                    if (foundNode != null)
                    {
                        nodeInstance = bootstrapNodeType(currentModel, getNodeName());
                        if (nodeInstance != null)
                        {
                            nodeInstance.Start();

                            UUIDModelImpl uuidModel = new UUIDModelImpl(Guid.NewGuid(), new ContainerRootMarshalled(kevoreeFactory.createContainerRoot()));

                            // TODO : check for concurrency problems here.
                            this.model = uuidModel;
                        }
                    }
                }
            }
            catch (java.lang.Throwable)
            {
                // TODO is it possible to display the following log ?
                try
                {
                    if (nodeInstance != null)
                    {
                        // TODO : Mieux gérer les erreurs
                        /*Method met = resolver.resolve(org.kevoree.annotation.Stop.class);
                        met.invoke(nodeInstance);
                         */
                    }
                }
                catch (java.lang.Throwable)
                {
                }
                finally
                {
                }
                nodeInstance = null;
               // resolver = null;
            }
        }