public ActionResult UploadDomain(String domainName, HttpPostedFileBase domainXmlFile, IEnumerable <HttpPostedFileBase> variantFiles)
        {
            if (domainName == null || domainXmlFile == null || variantFiles == null)
            {
                return(RedirectToAction("NegotiationDomainConfiguration"));
            }

            String domainXml;

            if (domainXmlFile.ContentLength == 0)
            {
                return(RedirectToAction("NegotiationDomainConfiguration"));
            }

            using (StreamReader reader = new StreamReader(domainXmlFile.InputStream))
            {
                domainXml = reader.ReadToEnd();
            }

            var variants = variantFiles.Select(x =>
            {
                using (StreamReader reader = new StreamReader(x.InputStream))
                {
                    return(new XmlFile(x.FileName, reader.ReadToEnd()));
                }
            });

            NegotiationManager.CreateDomain(domainName, domainXml, variants);

            return(RedirectToAction("NegotiationDomainConfiguration"));
        }
 public ActionResult NegotiationStrategyConfiguration()
 {
     return(View(new NegotiationConfigurationModel <Strategy>()
     {
         ActiveId = NegotiationManager.GetAiConfig().StrategyId,
         Items = NegotiationManager.GetStrategies()
     }));
 }
        public ActionResult NewActiveDomain(int newActiveDomain)
        {
            if (NegotiationManager.GameDomain == null || NegotiationManager.GameDomain.Id != newActiveDomain)
            {
                NegotiationManager.SetNewDomain(newActiveDomain);
            }

            return(RedirectToAction("NegotiationDomainConfiguration"));
        }
 public ActionResult NegotiationDomainConfiguration()
 {
     return(View(new NegotiationDomainConfig()
     {
         ActiveId = NegotiationManager.GameDomain != null ? NegotiationManager.GameDomain.Id : 0,
         Items = NegotiationManager.GetDomains(),
         HumanSide = NegotiationManager.GameDomain != null ? NegotiationManager.Config.HumanSide : null,
         HumanVariant = NegotiationManager.GameDomain != null ? NegotiationManager.Config.HumanVariant : null,
         AiVariant = NegotiationManager.GameDomain != null ? NegotiationManager.Config.AiVariant : null,
     }));
 }
        public ActionResult SaveUserOptionChange(String negotiationId, String topic, String option)
        {
            NegotiationEngine engine;

            if (negotiationId == null || !NegotiationManager.OnGoingNegotiations.TryGetValue(negotiationId, out engine))
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }

            NegotiationManager.SaveUserOptionChange(engine, topic, option);

            return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK));
        }
        public ActionResult NewActiveStrategy(int newActiveStrategy)
        {
            if (newActiveStrategy == 0)
            {
                return(RedirectToAction("NegotiationStrategyConfiguration"));
            }

            if (NegotiationManager.GetAiConfig().StrategyId != newActiveStrategy)
            {
                NegotiationManager.SetNewStrategy(newActiveStrategy);
            }

            return(RedirectToAction("NegotiationStrategyConfiguration"));
        }
        private string CreateNewNegotiation(PreNegotiationQuestionnaireViewModel model)
        {
            string            id     = this.Request.UserHostAddress + ";" + DateTime.Now.ToUniversalTime().ToString(CultureInfo.InvariantCulture);
            NegotiationEngine engine =
                new NegotiationEngine(
                    id,
                    NegotiationManager.Domain,
                    model,
                    NegotiationManager.GetHumanConfig(),
                    NegotiationManager.GetAiConfig());

            NegotiationManager.SaveNewNegotiation(engine, model);
            NegotiationManager.OnGoingNegotiations.TryAdd(id, engine);

            return(id);
        }
        public ActionResult UserSummary(string userId)
        {
            if (String.IsNullOrEmpty(userId))
            {
                return(RedirectToAction("Negotiation"));
            }

            var user = NegotiationManager.GetUser(userId);

            if (user == null)
            {
                return(RedirectToAction("Negotiation"));
            }

            return(View("UserSummaryView", user));
        }
        public ActionResult GameSummary(string gameId)
        {
            if (String.IsNullOrEmpty(gameId))
            {
                return(RedirectToAction("Negotiation"));
            }

            var game = NegotiationManager.GetGame(gameId);

            if (game == null)
            {
                return(RedirectToAction("Negotiation"));
            }

            return(View("GameSummaryView", game));
        }
        public ActionResult UploadStrategy(String strategyName, HttpPostedFileBase strategyDll, IEnumerable <HttpPostedFileBase> dependencyDlls)
        {
            if (strategyName == null || strategyDll == null)
            {
                return(RedirectToAction("NegotiationStrategyConfiguration"));
            }

            if (strategyDll.ContentLength == 0)
            {
                return(RedirectToAction("NegotiationStrategyConfiguration"));
            }

            String virtualDirPath = Path.Combine("~/Dlls", DateTime.Now.ToString("yyyyMMdd.hh.mm.ss.") + strategyDll.FileName);
            String virtualDllPath = Path.Combine(virtualDirPath, strategyDll.FileName);

            String DllDirPath = System.Web.HttpContext.Current.Server.MapPath(virtualDirPath);

            Directory.CreateDirectory(DllDirPath);

            String DllPath = Path.Combine(DllDirPath, strategyDll.FileName);

            using (FileStream fs = new FileStream(DllPath, FileMode.CreateNew))
            {
                strategyDll.InputStream.CopyTo(fs);
            }

            if (dependencyDlls != null && dependencyDlls.Any())
            {
                foreach (var dll in dependencyDlls.Where(x => x != null))
                {
                    String dependencyDllPath = Path.Combine(DllDirPath, dll.FileName);

                    using (FileStream fs = new FileStream(dependencyDllPath, FileMode.CreateNew))
                    {
                        dll.InputStream.CopyTo(fs);
                    }
                }
            }

            NegotiationManager.CreateStrategy(strategyName, virtualDllPath);

            return(RedirectToAction("NegotiationStrategyConfiguration"));
        }
 public ActionResult AllGameView()
 {
     return(View("AllGameView", NegotiationManager.GetGames()));
 }
        public ActionResult SetDomainVariants(string humanSide, string humanVariant, string aiVariant)
        {
            NegotiationManager.SetDomainVariants(humanSide, humanVariant, aiVariant);

            return(RedirectToAction("NegotiationDomainConfiguration"));
        }