Beispiel #1
0
    public static bool InvokePostGlobalAsset(GlobalAsset globalAsset)
    {
        if (globalAsset == null)
        {
            return(false);
        }

        try
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(GetRestServiceBaseAddress());

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            var response = client.PostAsJsonAsync("globalassetsapi", globalAsset).Result;

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                throw new Exception(response.ReasonPhrase + " : " + response.Content.ReadAsStringAsync().Result);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
        // GET api/<controller>/5
        //public string Get(int id)
        //{
        //	var existingCounter = db.GlobalAssets.FirstOrDefault(counter => counter.AssetID == id);

        //	if (existingCounter != null)
        //	{
        //		return JsonConvert.SerializeObject(existingCounter);
        //	}

        //	return string.Empty;
        //}

        // POST api/<controller>
        public void Post([FromBody] GlobalAsset asset)
        {
            if (asset == null)
            {
                return;
            }
            using (var tx = db.Database.BeginTransaction())
            {
                try
                {
                    db.GlobalAssets.AddOrUpdate(asset);

                    db.SaveChanges();
                    tx.Commit();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    tx.Rollback();
                    var responseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        Content    = new StringContent(ex.GetDisplayMessage(), System.Text.Encoding.UTF8, "text/plain"),
                        StatusCode = HttpStatusCode.InternalServerError
                    };

                    throw new HttpResponseException(responseMessage);
                }
            }
        }
 // 轉生.
 public void GameRestart()
 {
     Maze.Animal animal = GlobalAsset.LastestAnimalOnLayerColor(Player.position.Z.value, Player.Color);
     AssignPlayer(animal);
     manager.RebindPlayer();
     positionHint.ShowHintAt(manager.PlayerBind.binded.transform.position);
     UI_Skill.SetActive(true);
 }
        public ActionResult DeleteConfirmed(int id)
        {
            GlobalAsset globalAsset = db.GlobalAssets.Find(id);

            db.GlobalAssets.Remove(globalAsset);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
    // 開始遊戲,將現存的生物中的其中一隻變成玩家.
    // 並創造 MapManager 開始畫圖.
    public void GameStart()
    {
        AssignPlayer(GlobalAsset.LastestAnimal());
        manager = new Maze.MapManager(sceneMap, mainCamera, littleMap, GlobalAsset.seenRange);
        positionHint.ShowHintAt(manager.PlayerBind.binded.transform.position);

        statusBar.SetActive(true);
        UI_Skill.SetActive(true);
        rateBar.SetActive(true);
    }
 public ActionResult Edit([Bind(Include = "AssetID,AssetType,AssetSubType,SerialNumber,ClientID,Status,LastServiceDate,NextServiceDate")] GlobalAsset globalAsset)
 {
     if (ModelState.IsValid)
     {
         db.Entry(globalAsset).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(globalAsset));
 }
    // UI 顯示玩家狀態.
    private void UpdataUI()
    {
        if (GlobalAsset.player == null)
        {
            return;
        }

        statusBar.UpdateFor(GlobalAsset.player);
        ability.UpdateByAnimal(GlobalAsset.player);
        rateBar.SetBar(GlobalAsset.PowerOfColorOn(Player.position.Z.value));
    }
        public ActionResult Create([Bind(Include = "AssetID,AssetType,AssetSubType,SerialNumber,ClientID,Status,LastServiceDate,NextServiceDate")] GlobalAsset globalAsset)
        {
            if (ModelState.IsValid)
            {
                db.GlobalAssets.Add(globalAsset);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(globalAsset));
        }
        // GET: GlobalAssets/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GlobalAsset globalAsset = db.GlobalAssets.Find(id);

            if (globalAsset == null)
            {
                return(HttpNotFound());
            }
            return(View(globalAsset));
        }
        // PUT api/<controller>/5
        public void Put(int id, [FromBody] GlobalAsset asset)
        {
            if (asset == null)
            {
                return;
            }

            using (var tx = db.Database.BeginTransaction())
            {
                try
                {
                    db.GlobalAssets.AddOrUpdate(asset);

                    db.SaveChanges();
                    tx.Commit();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    tx.Rollback();
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
        }
Beispiel #11
0
    public static bool InvokePut(GlobalAsset globalAsset)
    {
        try
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(GetRestServiceBaseAddress());

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            var response = client.PutAsJsonAsync("globalassetsapi", globalAsset).Result;

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
        }
        catch (Exception)
        {
        }

        return(false);
    }
Beispiel #12
0
 // 跳轉道開始畫面.
 public void GotoStartScene()
 {
     GlobalAsset.Reset();
     GameStatus.Reset();
     SceneManager.LoadScene(0);
 }
Beispiel #13
0
        static public void Init1(StoryManager manager)
        {
            var ready          = new State();
            var start          = new State();
            var gaming         = new State();
            var waitForRestart = new State();
            var waitForEnd     = new State();
            var end            = new State();

            ready.AddEvent(new Event(
                               () => GameStatus.ready,
                               start,
                               new StoryPlayer().AddMessage("按Enter開始遊戲")
                               ));

            start.AddEvent(new Event(
                               () => TalkBox.end,
                               gaming,
                               new ActionPlayer(
                                   () => {
                GameStatus.pause = false;
                GlobalAsset.controller.GameStart();
            }
                                   )
                               ));

            gaming
            .AddEvent(new Event(
                          () => teachMode,
                          TeachMode(gaming),
                          new ActionPlayer(
                              () => { }
                              )
                          ))
            .AddEvent(new Event(
                          () => GlobalAsset.player.IsDead && GlobalAsset.LastestAnimalOnLayerColor(Player.position.Z.value, Player.Color) == null,
                          waitForEnd,
                          new StoryPlayer().AddMessageWithAction(
                              "物種滅絕...你輸了\n按Enter鍵回主選單",
                              () => {
                GameStatus.pause = true;
                GameStatus.lose  = true;
            }
                              )
                          ))
            .AddEvent(new Event(
                          () => GlobalAsset.player.IsDead && !GameStatus.lose,
                          waitForRestart,
                          new ActionPlayer(() => {
                TalkBox.Show("你已經死了\n按Enter鍵轉生");
            }
                                           )
                          ))
            .AddEvent(new Event(
                          () => GlobalAsset.RateOfColorOn(Player.Color, Player.position.Z.value) == 1f,
                          waitForEnd,
                          new StoryPlayer().AddMessageWithAction(
                              "我方勝利\n按Enter鍵回主選單",
                              () => {
                GameStatus.pause = true;
                GameStatus.win   = true;
            }
                              )
                          ));

            waitForRestart.AddEvent(new Event(
                                        () => TalkBox.end,
                                        gaming,
                                        new ActionPlayer(
                                            () => {
                GameStatus.pause = false;
                GlobalAsset.controller.GameRestart();
            }
                                            )));

            waitForEnd.AddEvent(new Event(
                                    () => TalkBox.end,
                                    end,
                                    new ActionPlayer(
                                        () => GlobalAsset.controller.GotoStartScene()
                                        )));


            manager.currentState = ready;
        }
Beispiel #14
0
    private GlobalAsset GetAssetFromDb(int assetId)
    {
        string        conString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlConnectionString"].ToString();
        SqlConnection sqlConn   = new SqlConnection(conString);

        sqlConn.Open();
        SqlCommand command = new SqlCommand("usp_GetAsset", sqlConn);

        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@AssetID", SqlDbType.Int).Value = assetId;

        SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);
        DataSet        myDataset  = new DataSet();

        sqlAdapter.Fill(myDataset);
        sqlConn.Close();

        if (myDataset.Tables.Count == 0 || myDataset.Tables[0].Rows.Count == 0)
        {
            return(null);
        }

        DataRow dRow = myDataset.Tables[0].Rows[0];

        string assetType          = dRow["AssetTypeInt"].ToString();
        string assetSubType       = dRow["AssetSubTypeInt"].ToString();
        string assetName          = dRow["Name"].ToString();
        string ClientID           = dRow["ClientID"].ToString();
        string statusStr          = dRow["Status"].ToString();
        string LastServiceDateStr = dRow["LastServiceDate"].ToString();
        string NextServiceDateStr = dRow["NextServiceDate"].ToString();

        Nullable <System.DateTime> lastServiceDate = null;
        Nullable <System.DateTime> nextServiceDate = null;

        DateTime dt;

        if (DateTime.TryParse(LastServiceDateStr, out dt))
        {
            lastServiceDate = dt;
        }

        if (DateTime.TryParse(NextServiceDateStr, out dt))
        {
            nextServiceDate = dt;
        }

        var updatedAsset = new GlobalAsset
        {
            AssetID         = assetId,
            AssetType       = int.Parse(assetType),
            AssetSubType    = int.Parse(assetSubType),
            ClientID        = ClientID,
            SerialNumber    = assetName,
            LastServiceDate = lastServiceDate,
            NextServiceDate = nextServiceDate,
            Status          = statusStr
        };

        return(updatedAsset);
    }
Beispiel #15
0
    private GlobalAsset GetAssetFromDb()
    {
        var assetIdstr = Request.QueryString["ID"];
        int assetId    = 0;

        if (string.IsNullOrEmpty(assetIdstr) || !int.TryParse(assetIdstr, out assetId))
        {
            return(null);
        }

        try
        {
            string        conString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlConnectionString"].ToString();
            SqlConnection sqlConn   = new SqlConnection(conString);
            sqlConn.Open();
            SqlCommand command = new SqlCommand("usp_GetAsset", sqlConn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@AssetID", SqlDbType.Int).Value = assetId;

            SqlDataAdapter sqlAdapter = new SqlDataAdapter(command);
            DataSet        myDataset  = new DataSet();
            sqlAdapter.Fill(myDataset);
            sqlConn.Close();

            DataRow dRow = myDataset.Tables[0].Rows[0];

            string assetType          = dRow["AssetTypeInt"].ToString();
            string assetSubType       = dRow["AssetSubTypeInt"].ToString();
            string assetName          = dRow["Name"].ToString();
            string ClientID           = dRow["ClientID"].ToString();
            string statusStr          = dRow["Status"].ToString();
            string LastServiceDateStr = dRow["LastServiceDate"].ToString();
            string NextServiceDateStr = dRow["NextServiceDate"].ToString();

            Nullable <System.DateTime> lastServiceDate = null;
            Nullable <System.DateTime> nextServiceDate = null;

            DateTime dt;
            if (DateTime.TryParse(LastServiceDateStr, out dt))
            {
                lastServiceDate = dt;
            }

            if (DateTime.TryParse(NextServiceDateStr, out dt))
            {
                nextServiceDate = dt;
            }

            var updatedAsset = new GlobalAsset
            {
                AssetID         = assetId,
                AssetType       = int.Parse(assetType),
                AssetSubType    = int.Parse(assetSubType),
                ClientID        = ClientID,
                SerialNumber    = assetName,
                LastServiceDate = lastServiceDate,
                NextServiceDate = nextServiceDate,
                Status          = statusStr
            };
            return(updatedAsset);
        }
        catch (Exception exception)
        {
            Debug.WriteLine(exception);
            ErrorMsg.Text = "Asset Updated. Failed to update Global Asset Service." + exception.GetDisplayMessage();
        }

        return(null);
    }
Beispiel #16
0
 protected void SqlAsset_OnUpdating(object sender, SqlDataSourceCommandEventArgs e)
 {
     this.editedAsset = GetAssetFromDb();
 }