// May have do a bunch of these to be able to send correctly
    public RequestCreate spawnThis()
    {
        RequestCreate spawn = new RequestCreate();

        spawn.send();
        return(spawn);
    }
Ejemplo n.º 2
0
        public void TestRequestUid()
        {
            var request1 = new RequestCreate(path: "/", data: null, acl: null, createMode: CreateMode.Persistent);
            var request2 = new RequestExists(path: "/", watcher: null);

            var batch1 = new RequestMulti(
                new List <Op>
            {
                Op.Check("/", 1),
                Op.Delete("/a", -1)
            },
                completeSynchronously: false);

            var batch2 = new RequestMulti(
                new List <Op>
            {
                Op.GetChildren("/"),
                Op.Delete("/a", -1)
            },
                completeSynchronously: true);

            Assert.IsTrue(request2.Uid > request1.Uid);
            Assert.IsTrue(batch1.Requests[0].Uid > request2.Uid);
            Assert.IsTrue(batch1.Requests[1].Uid > batch1.Requests[0].Uid);
            Assert.IsTrue(batch1.Uid > batch1.Requests[1].Uid);
            Assert.IsTrue(batch2.Uid > batch1.Uid);
        }
        public static Domain.Customer MapToDomain(RequestCreate @new)
        {
            var customer = new Domain.Customer
            {
                Forename     = @new.Forename,
                Surname      = @new.Surname,
                EmailAddress = @new.EmailAddress,
                Password     = @new.Password
            };

            return(customer);
        }
Ejemplo n.º 4
0
        public IHttpActionResult CreateRequest(RequestCreate request)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            var service = CreateRequestService();

            if (!service.CreateRequest(request))
                return InternalServerError();

            return Ok();
        }
        public async Task <ApiResult <bool> > Create(RequestCreate request)
        {
            var makeMoney = new MakeMoney()
            {
                Name        = request.Name,
                Description = request.Description,
                Img         = request.Name,
                Status      = true,
            };

            _context.MakeMoneys.Add(makeMoney);
            await _context.SaveChangesAsync();

            return(new ApiSuccessResult <bool>());
        }
Ejemplo n.º 6
0
        public async Task <ApiResult <bool> > Create(RequestCreate request)
        {
            var spend = new Spend()
            {
                Name        = request.Name,
                Description = request.Description,
                Img         = request.Img,
                Status      = true,
            };

            _context.Spends.Add(spend);
            await _context.SaveChangesAsync();

            return(new ApiSuccessResult <bool>());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create([FromBody] RequestCreate request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _serviceSpend.Create(request);

            if (!result.IsSuccessed)
            {
                return(BadRequest(result.Message));
            }
            return(Ok(result));
        }
Ejemplo n.º 8
0
        public bool CreatesRequest(RequestCreate model)
        {
            var entity =
                new Request()
            {
                OwnerId   = _userId,
                Content   = model.Content,
                RequestId = model.RequestId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Requests.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 9
0
        public bool CreateRequest(RequestCreate model)
        {
            var entity =
                new Request()
            {
                OwnerId                = _userId,
                EquipmentId            = model.EquipmentId,
                BeginningDateRequested = model.BeginningDateRequested,
                EndingDateRequested    = model.EndingDateRequested
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Requests.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 10
0
        public ActionResult Create(RequestCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateRequestService();

            if (service.CreatesRequest(model))
            {
                TempData["SaveResult"] = "Your note was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Request could not be created.");

            return(View(model));
        }
Ejemplo n.º 11
0
        private static MetaserverResponse Create(MetaRequest request)
        {
            RequestCreate      createRequest = (RequestCreate)request;
            MetaserverResponse response;

            //Invoca o servidor
            try
            {
                MetadataEntry entry = core.Create(createRequest.FileName, createRequest.NbDataServer, createRequest.ReadQuorum,
                                                  createRequest.WriteQuorum, request.ClientId);
                response           = new MetaserverResponse(ResponseStatus.Success, request, ThisMetaserverId);
                response.MetaEntry = entry;
            }
            catch (Exception ex)
            {
                response           = new MetaserverResponse(ResponseStatus.Exception, request, ThisMetaserverId);
                response.Exception = new PadiException(PadiExceptiontType.CreateFile, ex.Message);
            }
            return(response);
        }
Ejemplo n.º 12
0
        private static void TestCreate(
            Action <string> log,
            int numberOfThreads,
            RingMasterBackendCore backendCore,
            ClientSession clientSession)
        {
            var sw   = new Stopwatch();
            var data = new byte[PayloadLength];

            var countPerThread = TotalNodeCount / numberOfThreads;
            var threads        = Enumerable.Range(0, numberOfThreads)
                                 .Select(n => new Thread(() =>
            {
                for (int i = 0; i < countPerThread; i++)
                {
                    var createReq = new RequestCreate(
                        $"/test/{n}/{i}",
                        null,
                        data,
                        null,
                        CreateMode.PersistentSequentialAllowPathCreation,
                        null);

                    backendCore.ProcessMessage(createReq, clientSession, null);
                }
            }))
                                 .ToArray();

            int gen0 = GC.CollectionCount(0), gen1 = GC.CollectionCount(1), gen2 = GC.CollectionCount(2);

            sw.Start();

            Parallel.ForEach(threads, t => t.Start());
            Parallel.ForEach(threads, t => t.Join());
            sw.Stop();

            var rate = countPerThread * numberOfThreads / sw.Elapsed.TotalSeconds;

            log($"Create nodes: {sw.Elapsed} QPS={rate:G3}");
            log($"  Gen0={GC.CollectionCount(0) - gen0} Gen1={GC.CollectionCount(1) - gen1} Gen2={GC.CollectionCount(2) - gen2}\n");
        }
Ejemplo n.º 13
0
        //////////////////////////////////// CLient Interface //////////////////////////////////
        public String Create(String filename, int nbDataServers, int readQuorum, int writeQuorum)
        {
            log.Debug(DateTime.Now.Ticks + " Create: " + filename);

            Console.WriteLine("#CREATE Create file: " + filename + " nbDataServer: " + nbDataServers + " readQuorum: " + readQuorum + " writeQuorum: " + writeQuorum);
            RequestCreate createRequest = new RequestCreate(filename, nbDataServers, readQuorum, writeQuorum);

            log.Debug(DateTime.Now.Ticks + " [M] Send Create: " + filename);
            MetaserverResponse response = MetaserverClient.SendRequestToMetaserver(createRequest);
            //Processar a resposta
            MetadataEntry metaEntry = response.MetaEntry;

            if (metaEntry != null)
            {
                Console.WriteLine("#CREATE Create Successeful");
                log.Debug(DateTime.Now.Ticks + " Create Done: " + filename);
                return(metaEntry.ToString( ));
            }
            else
            {
                throw new PadiException(PadiExceptiontType.CreateFile, "Response without entry");
            }
        }
Ejemplo n.º 14
0
        public ActionResult Create(RequestCreate model, HttpPostedFileBase file)
        {
            Boolean isValid = true;

            ViewBag.ErrorMessageSouvenirName = null;
            ViewBag.ErrorMessageCountry      = null;
            ViewBag.ErrorMessageAmount       = null;
            ViewBag.ErrorMessagePrice        = null;
            ViewBag.ErrorMessageCurrency     = null;
            ViewBag.ErrorMessageDescription  = null;

            if (model.souvenirName == null || model.souvenirName.Length < 3 || model.souvenirName.Length > 30)
            {
                ViewBag.ErrorMessageSouvenirName = "The name of your souvenir should have between 3 and 30 characters.";
                isValid = false;
            }
            if (model.countrySouv == null)
            {
                ViewBag.ErrorMessageCountry = "Please select a country.";
                isValid = false;
            }
            //Fehlermeldung von amount wird noch nicht angezeigt
            if (model.amount < 1 || model.amount > 1000)
            {
                ViewBag.ErrorMessageAmount = "Please enter a quantity between 1 and 1000.";
                isValid = false;
            }
            if (model.price == null)
            {
                ViewBag.ErrorMessagePrice = "Please enter a price";
                isValid = false;
            }
            else
            {
                string tmp = model.price.Replace(",", "");
                tmp = tmp.Replace(".", "");
                if (model.price == null || model.price.Length > 10)
                {
                    ViewBag.ErrorMessagePrice = "Please enter a price under 10 digits.";
                    isValid = false;
                }
                if ((model.price.Length - tmp.Length) > 1)
                {
                    ViewBag.ErrorMessagePrice = "Maximum one ',' or '.' !";
                    isValid = false;
                }
            }
            if (model.currency == null)
            {
                ViewBag.ErrorMessageCurrency = "Please select a currency.";
                isValid = false;
            }
            if (model.descriptionSouv == null || model.descriptionSouv.Length > 300 || model.descriptionSouv.Length < 5)
            {
                ViewBag.ErrorMessageDescription = "Please enter a description of your souvenir, it should be more than 5 and less than 300 characters.";
                isValid = false;
            }

            if (isValid == true)
            {
                SouvenirInfo souvenirInfo = new SouvenirInfo();
                if (model.price.Contains(","))
                {
                    model.price = model.price.Replace(",", ".");
                }
                NumberStyles style   = NumberStyles.AllowDecimalPoint;
                CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-US");
                double       d;
                double.TryParse(model.price, style, culture, out d);
                souvenirInfo.price           = Math.Round(d, 2);
                souvenirInfo.currency        = model.currency;
                souvenirInfo.descriptionSouv = model.descriptionSouv;


                db.souvenirInfos.Add(souvenirInfo);
                db.SaveChanges();

                Souvenir souvenir = new Souvenir();

                try
                {
                    string fileName  = souvenirInfo.souvenirInfoID.ToString();
                    string extension = Path.GetExtension(file.FileName);
                    fileName += extension;
                    souvenir.selectedPictureSouvenir = "~/Content/" + fileName;
                    fileName = Path.Combine(Server.MapPath("~/Content/"), fileName);
                    file.SaveAs(fileName);
                }
                catch (Exception)
                {
                    souvenir.selectedPictureSouvenir = "~/Content/defaultSouvenir.png";
                }
                souvenir.souvenirID   = souvenirInfo.souvenirInfoID;
                souvenir.souvenirName = model.souvenirName;
                souvenir.countrySouv  = model.countrySouv;
                souvenir.souvenirInfo = souvenirInfo;

                db.souvenirs.Add(souvenir);
                db.SaveChanges();

                Customer customer = db.customers.Find(Session["userName"]);

                Request request = new Request();
                request.souvenir  = souvenir;
                request.customer  = customer;
                request.amount    = model.amount;
                request.reward    = (double)(request.amount * request.souvenir.souvenirInfo.price * rewardpercent) / 100;
                request.reward    = Math.Round(request.reward, 2);
                request.status    = "new";
                request.requestID = souvenirInfo.souvenirInfoID;

                db.requests.Add(request);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            else
            {
                return(View("Create", model));
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Deserialize <see cref="IZooKeeperRequest"/>
        /// </summary>
        /// <param name="xid">the callid</param>
        /// <param name="type">type of the call</param>
        /// <param name="sessionState">The PerSession State</param>
        /// <param name="ringMasterRequest">The ring master request.</param>
        /// <exception cref="System.ArgumentException">unknown type  + type</exception>
        /// <returns>The Zookeeper Request</returns>
        private IZooKeeperRequest DeserializeZooKeeperRequest(int xid, ZooKeeperRequestType type, ZkprPerSessionState sessionState, out IRingMasterRequest ringMasterRequest)
        {
            ringMasterRequest = null;
            switch (type)
            {
            case ZooKeeperRequestType.Notification:     // "0" for Createing a session
                ringMasterRequest = null;
                return(this.DeserializeNotification(xid));

            case ZooKeeperRequestType.CreateSession:
                ZkprProtocolMessages.CreateSession cs = this.DeserializeCreateSession();
                ringMasterRequest            = new RequestInit((ulong)cs.SessionId, cs.IsNullPassword ? string.Empty : cs.Password);
                sessionState.ConnectRecieved = true;
                return(cs);

            case ZooKeeperRequestType.Exists:
                ZkprProtocolMessages.Exists ex = this.DeserializeExists(xid);
                ringMasterRequest = new RequestExists(ex.Path, ex.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse));
                return(ex);

            case ZooKeeperRequestType.GetChildren:
                ZkprProtocolMessages.GetChildren gc = this.DeserializeGetChildren(xid);
                ringMasterRequest = new RequestGetChildren(gc.Path, gc.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse), null);
                return(gc);

            case ZooKeeperRequestType.GetChildren2:
                ZkprProtocolMessages.GetChildren2 gc2 = this.DeserializeGetChildren2(xid);
                ringMasterRequest = new RequestGetChildren(gc2.Path, gc2.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse), null);
                return(gc2);

            case ZooKeeperRequestType.GetData:
                ZkprProtocolMessages.GetData gd = this.DeserializeGetData(xid);
                ringMasterRequest = new RequestGetData(gd.Path, RequestGetData.GetDataOptions.None, gd.Watch == false ? null : new Watcher((ulong)xid, WatcherKind.OneUse));
                return(gd);

            case ZooKeeperRequestType.Create:
                ZkprProtocolMessages.Create cr   = this.DeserializeCreate(xid);
                IReadOnlyList <Acl>         acls = this.TranslateZkprAclListToRMAclList(cr.Acls);
                CreateMode cm = this.TranslateZkprCreatFlagsToRmCreateMode(cr.Flags);
                ringMasterRequest = new RequestCreate(cr.Path, cr.Data, acls, cm);
                return(cr);

            case ZooKeeperRequestType.Create2:
                ZkprProtocolMessages.Create2 cr2   = this.DeserializeCreate2(xid);
                IReadOnlyList <Acl>          acls2 = this.TranslateZkprAclListToRMAclList(cr2.Acls);
                CreateMode cm2 = this.TranslateZkprCreatFlagsToRmCreateMode(cr2.Flags);
                ringMasterRequest = new RequestCreate(cr2.Path, cr2.Data, acls2, cm2);
                return(cr2);

            case ZooKeeperRequestType.SetData:
                ZkprProtocolMessages.SetData sd = this.DeserializeSetData(xid);
                ringMasterRequest = new RequestSetData(sd.Path, sd.Data, sd.Version);
                return(sd);

            case ZooKeeperRequestType.Delete:
                ZkprProtocolMessages.Delete dl = this.DeserializeDelete(xid);
                ringMasterRequest = new RequestDelete(dl.Path, dl.Version, false);
                return(dl);

            case ZooKeeperRequestType.Ping:
                ringMasterRequest = null;
                return(this.DeserializePing(xid));

            case ZooKeeperRequestType.CloseSession:
                ringMasterRequest            = null;
                sessionState.ConnectRecieved = false;     // Renegotiate the CreateSession
                return(this.DeserializeCloseSession(xid));

            case ZooKeeperRequestType.GetACL:
                ZkprProtocolMessages.GetACL ga = this.DeserializeGetACL(xid);
                ringMasterRequest = new RequestGetAcl(ga.Path, null);
                return(ga);

            case ZooKeeperRequestType.SetACL:
                ZkprProtocolMessages.SetACL sa      = this.DeserializeSetACL(xid);
                IReadOnlyList <Acl>         sa_acls = this.TranslateZkprAclListToRMAclList(sa.Acls);
                ringMasterRequest = new RequestSetAcl(sa.Path, sa_acls, sa.Version);
                return(sa);

            case ZooKeeperRequestType.Multi:
                ZkprProtocolMessages.Multi mu    = this.DeserializeMulti(xid);
                IReadOnlyList <Op>         rmOps = this.TranslateZkprOpsListToRmOpsList(mu.Ops);
                ringMasterRequest = new RequestMulti(rmOps, false);
                return(mu);

            case ZooKeeperRequestType.Auth:
                ZkprProtocolMessages.Auth au = this.DeserializeAuth(xid);
                ringMasterRequest = new RequestSetAuth(au.RmAuthId);
                return(au);

            case ZooKeeperRequestType.Check:
            case ZooKeeperRequestType.Sync:
            case ZooKeeperRequestType.Reconfig:
            case ZooKeeperRequestType.SetWatches:
            case ZooKeeperRequestType.RemoveWatches:
            case ZooKeeperRequestType.CreateContainer:
            case ZooKeeperRequestType.DeleteContainer:
            case ZooKeeperRequestType.Sasl:
            case ZooKeeperRequestType.Error:
            default:
                break;
            }

            return(null);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Serialize <see cref="RequestCreate"/>.
 /// </summary>
 /// <param name="request">Request to serialize</param>
 private void SerializeRequestCreate(RequestCreate request)
 {
     this.binaryWriter.Write((ushort)request.CreateMode);
     this.SerializeData((byte[])request.Data);
     this.SerializeAclList(request.Acl);
 }
Ejemplo n.º 17
0
 protected virtual void OnRequestCreate(DataEventArgs e) => RequestCreate?.Invoke(this, e);