Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Class,Spec,itemLevel")] NewApp newApp)
        {
            if (id != newApp.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newApp);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewAppExists(newApp.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newApp));
        }
        public IActionResult CreateApp(NewApp app, string BtnSubmit)
        {
            //AppListDal.Model.ApplicationList appL = app.ConvertToAppList();
            //Create case statement on name of button

            switch (BtnSubmit)
            {
            case "Add":
                app.ConvertToAppList();
                app.SaveData();
                return(RedirectToAction("Index"));

            case "Delete":
                app.ConvertToAppList();
                app.DeleteData();
                return(RedirectToAction("Index"));

            case "Update":
                app.ConvertToAppList();
                app.ChangeData();
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("ID,Name,Class,Spec,itemLevel")] NewApp newApp)
        {
            if (ModelState.IsValid)
            {
                _context.Add(newApp);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(newApp));
        }
Beispiel #4
0
 //检查更新
 private void FindNew(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     string[] version = NewApp.IsNew();
     MessageBox.Show("当前版本为:" + version[0] + "\r\n" +
                     "最新版本为:" + version[1] + "\r\n" +
                     "最后更新时间为:" + version[2]);
     if (version[0] != version[1])
     {
         Process.Start(version[3]);
     }
 }
        public IActionResult AddNew(string ID)
        {
            NewApp newApp = new NewApp();

            if (ID != null)
            {
                newApp.ID = int.Parse(ID);
                GetAnApp gaa = new GetAnApp(ID);
                gaa.FillInNewApp(newApp);
            }
            return(View("AddNew", newApp));
        }
Beispiel #6
0
        internal string Launch(string InstanceSize, ZAwsSecGroup SecGroup, ZAwsKeyPair KeyPair, string Name, string StartupScript, NewApp[] AppsToInstall, decimal MaxBid)
        {
            //Prepare the StartupScript, using SETTINGS and FILE features.
            //Now search for all SETTINGS and replace with settings
            int settings_location = -1;
            while ((settings_location = StartupScript.IndexOf("{SETTING=")) != -1)
            {
                string keyname = StartupScript.Substring(settings_location + "{SETTING=".Length, StartupScript.IndexOf("}", settings_location) - settings_location - "{SETTING=".Length);

                string s = StartupScript.Substring(0, settings_location);
                s += System.Configuration.ConfigurationManager.AppSettings[keyname];
                s += StartupScript.Substring(StartupScript.IndexOf("}", settings_location) + 1);
                StartupScript = s;
            }
            settings_location = -1;
            while ((settings_location = StartupScript.IndexOf("{FILE=")) != -1)
            {
                string keyname = StartupScript.Substring(settings_location + "{FILE=".Length, StartupScript.IndexOf("}", settings_location) - settings_location - "{FILE=".Length);

                StreamReader streamReader = new StreamReader(System.Configuration.ConfigurationManager.AppSettings[keyname]);
                string svalue = streamReader.ReadToEnd();
                streamReader.Close();

                string s = StartupScript.Substring(0, settings_location);
                s += svalue;
                s += StartupScript.Substring(StartupScript.IndexOf("}", settings_location) + 1);
                StartupScript = s;
            }

            //Input the project downlaod scripts

            /*
            if (AppsToInstall != null && AppsToInstall.Length > 0)
            {
                StreamReader streamReader = new StreamReader("app_addscript");
                string appLoadScript = streamReader.ReadToEnd();
                streamReader.Close();

                string sApps = "";
                foreach (var app in AppsToInstall)
                {
                    sApps += string.Format(appLoadScript,
                                    app.AppName,
                                    app.AppLocation,
                                    app.AppUrl,
                                    app.TypeIsRails ? "/public" : "",
                                    app.DefaultServerApp ? "_" : "");
                }

                //Now insert
                int startLoc = StartupScript.IndexOf("#{INSTALL_APP_START}") + "#{INSTALL_APP_START}".Length;

                string s = StartupScript.Substring(0, startLoc) + "\n";
                s += sApps + "\n";
                s += StartupScript.Substring(startLoc);
                StartupScript = s;
            }
            */
            // {0} = app name and directory, for example b1
            // {1} = git repository URL, for example [email protected]:zmilojko/b1.git
            // {2} = app URL, for example b1.z-ware.fi
            // {3} = for rails application, "/public", otherwise ""
            // {4} = for default application, "_", toherwise ""

            //Copy the script to the clipboard - to help debugging
            Clipboard.SetText(StartupScript);

            string NewInstanceId = "";

            lock (myController.MonitoringThreadLock)
            {

                if (MaxBid > 0)
                {

                    //For spot instances
                    var req2 = new Amazon.EC2.Model.RequestSpotInstancesRequest()
                        .WithSpotPrice(MaxBid.ToString(CultureInfo.InvariantCulture))
                        .WithLaunchSpecification(new Amazon.EC2.Model.LaunchSpecification()
                            .WithImageId(this.ResponseData.ImageId)
                            .WithInstanceType(InstanceSize)
                            .WithKeyName(KeyPair.Name)
                            .WithSecurityGroupId(SecGroup.ResponseData.GroupId)
                            .WithPlacement(new Amazon.EC2.Model.Placement().WithAvailabilityZone("eu-west-1a"))
                            .WithUserData(Convert.ToBase64String(Encoding.UTF8.GetBytes(StartupScript.Replace("\r", "")))));

                    Amazon.EC2.Model.RequestSpotInstancesResponse resp2 = myController.ec2.RequestSpotInstances(req2);

                    NewInstanceId = resp2.RequestSpotInstancesResult.SpotInstanceRequest[0].SpotInstanceRequestId;
                    myController.myTaskQueue.AddTask(new ZAwsTaskNewSpotRequestHandling(this.myController, resp2.RequestSpotInstancesResult.SpotInstanceRequest[0].SpotInstanceRequestId, Name));
                    //myController.RememberNameForSpotInstance(NewInstanceId, Name);
                }
                else
                {
                    var req = new Amazon.EC2.Model.RunInstancesRequest()
                      .WithImageId(this.ResponseData.ImageId)
                      .WithInstanceType(InstanceSize)
                      .WithKeyName(KeyPair.Name)
                      .WithSecurityGroupId(SecGroup.ResponseData.GroupId)
                      .WithMinCount(1)
                      .WithMaxCount(1)
                      .WithPlacement(new Amazon.EC2.Model.Placement().WithAvailabilityZone("eu-west-1a"))
                      .WithUserData(Convert.ToBase64String(Encoding.UTF8.GetBytes(StartupScript.Replace("\r", ""))));

                    Amazon.EC2.Model.RunInstancesResponse response = myController.ec2.RunInstances(req);

                    NewInstanceId = response.RunInstancesResult.Reservation.RunningInstance[0].InstanceId;

                    int errCounter = 0;
                    while (true)
                    {
                        try
                        {
                            Amazon.EC2.Model.CreateTagsResponse response2 = myController.ec2.CreateTags(new Amazon.EC2.Model.CreateTagsRequest()
                                                                .WithResourceId(NewInstanceId)
                                                                .WithTag(new Amazon.EC2.Model.Tag().WithKey("Name").WithValue(Name)));
                            break;
                        }
                        catch(Exception ex)
                        {
                            errCounter++;
                            if (errCounter > 2)
                            {
                                Program.TraceLine("Run Instance request sent OK, but cannot set instance name.", ex);
                                break;
                            }
                            Thread.Sleep(errCounter * 2000);
                        }
                    }

                }

                if (AppsToInstall != null && AppsToInstall.Length > 0)
                {
                    /*
                    foreach (var appToInstall in AppsToInstall)
                    {
                        appToInstall.DeployedOnInstanceId = NewInstanceId;
                    }
                    myController.RegisterNewApps(AppsToInstall);
                     */
                    myController.myTaskQueue.AddTask(new ZAwsTaskInstallApps(myController, Name, AppsToInstall));
                }
            }
            return NewInstanceId;
        }