Example #1
0
    public void ConstructorArgumentOneTest()
    {
        string   fileName = "test.txt";
        NCMBFile file     = new NCMBFile(fileName);

        Assert.AreEqual(fileName, file.FileName);
    }
Example #2
0
    public IEnumerator FileDownloadTest()
    {
        byte[]   data = System.Text.Encoding.UTF8.GetBytes("hello");
        NCMBFile file = new NCMBFile("test.txt", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        NCMBTestSettings.CallbackFlag = false;

        NCMBFile getFile = new NCMBFile("test.txt");

        getFile.FetchAsync((byte[] fileData, NCMBException error) => {
            Assert.Null(error);
            Assert.AreEqual("hello", Encoding.UTF8.GetString(fileData));
            NCMBTestSettings.CallbackFlag = true;
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.NotNull(getFile.FileData);
        Assert.AreEqual("hello", Encoding.UTF8.GetString(getFile.FileData));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #3
0
    public IEnumerator FileResponseSignatureTest()
    {
        NCMBSettings.EnableResponseValidation(true);

        byte[]   data = System.Text.Encoding.UTF8.GetBytes("hello");
        NCMBFile file = new NCMBFile("test.txt", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        NCMBTestSettings.CallbackFlag = false;

        NCMBFile getFile = new NCMBFile("test.txt");

        getFile.FetchAsync((byte[] fileData, NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });


        yield return(NCMBTestSettings.AwaitAsync());

        Assert.NotNull(file.CreateDate);
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #4
0
    public IEnumerator FileACLTest()
    {
        byte[]  data = System.Text.Encoding.UTF8.GetBytes("acl test");
        NCMBACL acl  = new NCMBACL();

        acl.PublicReadAccess = true;
        NCMBFile file = new NCMBFile("ACL.txt", data, acl);

        file.SaveAsync((NCMBException error) => {
            NCMBTestSettings.CallbackFlag = true;
        });

        yield return(NCMBTestSettings.AwaitAsync());

        NCMBTestSettings.CallbackFlag = false;

        NCMBQuery <NCMBFile> query = NCMBFile.GetQuery();

        query.WhereEqualTo("fileName", "ACL.txt");
        query.FindAsync((List <NCMBFile> objList, NCMBException error) => {
            Assert.Null(error);
            NCMBFile getFile = objList [0];
            Assert.True(getFile.ACL.PublicReadAccess);
            Assert.False(getFile.ACL.PublicWriteAccess);
            NCMBTestSettings.CallbackFlag = true;
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #5
0
    public void LoadOneImage(int index, Image go)
    {
        NCMBQuery <NCMBFile> query = NCMBFile.GetQuery();

        query.Skip  = index;
        query.Limit = 1;
        query.OrderByDescending("createDate");
        query.FindAsync((List <NCMBFile> objList, NCMBException error) => {
            if (error != null)
            {
                // 検索失敗
            }
            else
            {
                // 検索成功
                foreach (NCMBFile file in objList)
                {
                    file.FetchAsync((byte[] fileData, NCMBException e) => {
                        if (e != null)
                        {
                            // 取得失敗
                        }
                        else
                        {
                            // 取得成功
                            SaveBytes(fileData, go);
                        }
                    });
                }
            }
        });
    }
Example #6
0
    public IEnumerator FileDeleteTest()
    {
        byte[]   data = System.Text.Encoding.UTF8.GetBytes("delete test");
        NCMBFile file = new NCMBFile("delete.txt", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        NCMBTestSettings.CallbackFlag = false;
        Assert.NotNull(file.CreateDate);

        file.DeleteAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        NCMBTestSettings.CallbackFlag = false;

        NCMBQuery <NCMBFile> query = NCMBFile.GetQuery();

        query.WhereEqualTo("fileName", "delete.txt");
        query.FindAsync((List <NCMBFile> objList, NCMBException error) => {
            Assert.Null(error);
            Assert.AreEqual(0, objList.Count);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #7
0
 public void DeleteFile()
 {
     if (lastedFileName != null)
     {
         NCMBFile file = new NCMBFile(lastedFileName);
         file.DeleteAsync();
         lastedFileName = null;
     }
 }
Example #8
0
 public void TestUploadBinary()
 {
     Task.Run(async() =>
     {
         var data = File.ReadAllBytes("../../ncmb.png");
         var file = new NCMBFile("ncmb.png", data, "image/png");
         await file.Save();
         Assert.NotNull(file.Get("fileName"));
     }).GetAwaiter().GetResult();
 }
Example #9
0
    public void ConstructorArgumentTwoTest()
    {
        string fileName = "test.txt";

        byte[]   fileData = System.Text.Encoding.UTF8.GetBytes("hello");
        NCMBFile file     = new NCMBFile(fileName, fileData);

        Assert.AreEqual(fileName, file.FileName);
        Assert.AreEqual(fileData, file.FileData);
    }
Example #10
0
 public void TestUpload()
 {
     Task.Run(async() =>
     {
         var str  = "1,2,3";
         var data = System.Text.Encoding.ASCII.GetBytes(str);
         var file = new NCMBFile("test2.csv", data, "text/csv");
         await file.Save();
         Assert.NotNull(file.Get("fileName"));
     }).GetAwaiter().GetResult();
 }
Example #11
0
 //コンストラクタ
 internal NCMBConnection(String url, ConnectType method, string content, string sessionToken, NCMBFile file, string domain)
 {
     this._method         = method;
     this._content        = content;
     this._url            = url;
     this._sessionToken   = sessionToken;
     this._applicationKey = NCMBSettings.ApplicationKey;
     this._clientKey      = NCMBSettings.ClientKey;
     this._domainUri      = new Uri(domain);
     this._file           = file;
 }
Example #12
0
    public void GetBaseUrlTest()
    {
        // テストデータ作成
        string   fileName = "test.txt";
        NCMBFile file     = new NCMBFile(fileName);

        // internal methodの呼び出し
        MethodInfo method = file.GetType().GetMethod("_getBaseUrl", BindingFlags.NonPublic | BindingFlags.Instance);

        Assert.AreEqual("http://localhost:3000/2013-09-01/files/test.txt", method.Invoke(file, null).ToString());
    }
Example #13
0
    public void ConstructorArgumentThreeTest()
    {
        string fileName = "test.txt";

        byte[]  fileData = System.Text.Encoding.UTF8.GetBytes("hello");
        NCMBACL acl      = new NCMBACL();

        acl.PublicWriteAccess = false;
        NCMBFile file = new NCMBFile(fileName, fileData, acl);

        Assert.AreEqual(fileName, file.FileName);
        Assert.AreEqual(fileData, file.FileData);
        Assert.AreEqual(false, file.ACL.PublicWriteAccess);
    }
Example #14
0
    public void FileUploadTextTest()
    {
        byte[]   data = System.Text.Encoding.UTF8.GetBytes("hello");
        NCMBFile file = new NCMBFile("test.txt", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });

        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(file.CreateDate);
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #15
0
 public void TestUploadWithAcl()
 {
     Task.Run(async() =>
     {
         var str  = "1,2,3";
         var data = System.Text.Encoding.ASCII.GetBytes(str);
         var file = new NCMBFile("test2.csv", data, "text/csv");
         var acl  = new NCMBAcl();
         acl.SetPublicReadAccess(true);
         acl.SetPublicWriteAccess(true);
         file.SetAcl(acl);
         await file.Save();
         Assert.NotNull(file.Get("fileName"));
     }).GetAwaiter().GetResult();
 }
Example #16
0
    public IEnumerator FileUploadFileNameTest()
    {
        byte[]   data = System.Text.Encoding.UTF8.GetBytes("hello");
        NCMBFile file = new NCMBFile("日本語.txt", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.NotNull(file.CreateDate);
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
    void loadOneImageTo(string name, int index)
    {
        NCMBFile file = new NCMBFile(name);

        file.FetchAsync((byte[] fileData, NCMBException error) => {
            if (error != null)
            {
                // 失敗
            }
            else
            {
                SaveBytesTo(fileData, index);
            }
        });
    }
    void saveToCloud(byte[] bytes, string name)
    {
        NCMBFile file = new NCMBFile(name, bytes);

        file.SaveAsync((NCMBException error) => {
            if (error != null)
            {
                Debug.Log("upload error");
                showError(error);
                // 失敗
            }
            else
            {
                saveImageData(name);
            }
        });
    }
Example #19
0
    void saveToCloud(byte[] bytes, string name)
    {
        NCMBFile file = new NCMBFile(name, bytes);

        file.SaveAsync((NCMBException error) => {
            if (error != null)
            {
                // 失敗
                Debug.Log("upload image error");
            }
            else
            {
                //成功
                Debug.Log("upload image success");
                Application.LoadLevel("blackboard");
            }
        });
    }
Example #20
0
    public void FileUploadImageTest()
    {
        FileStream   fileStream = new FileStream("Assets/ncmb_unity/ncmb_unity/Assets/Editor/logo.png", FileMode.Open, FileAccess.Read);
        BinaryReader bin        = new BinaryReader(fileStream);

        byte[] data = bin.ReadBytes((int)bin.BaseStream.Length);
        bin.Close();
        NCMBFile file = new NCMBFile("logo.png", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });

        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(file.CreateDate);
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #21
0
    public IEnumerator FileUploadImageTest()
    {
        FileStream   fileStream = new FileStream("Assets/NCMB/PlayModeTest/Test.png", FileMode.Open, FileAccess.Read);
        BinaryReader bin        = new BinaryReader(fileStream);

        byte[] data = bin.ReadBytes((int)bin.BaseStream.Length);
        bin.Close();
        NCMBFile file = new NCMBFile("Test.png", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.NotNull(file.CreateDate);
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #22
0
 public void GetFile()
 {
     if (lastedFileName != null)
     {
         NCMBFile file = new NCMBFile(lastedFileName);
         file.FetchAsync((byte[] fileData, NCMBException error) => {
             if (error != null)
             {
                 // 失敗
                 Debug.LogError(error);
             }
             else
             {
                 // 成功
                 Debug.Log("Get file success:  " + System.Text.Encoding.Default.GetString(fileData));
             }
         });
     }
 }
Example #23
0
    public void FileQueryTest()
    {
        byte[]   data = System.Text.Encoding.UTF8.GetBytes("hello");
        NCMBFile file = new NCMBFile("test.txt", data);

        file.SaveAsync((NCMBException error) => {
            Assert.Null(error);
        });
        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(file.CreateDate);

        NCMBQuery <NCMBFile> query = NCMBFile.GetQuery();

        query.FindAsync((List <NCMBFile> objList, NCMBException error) => {
            Assert.LessOrEqual(1, objList.Count);
            Assert.Null(error);
            NCMBTestSettings.CallbackFlag = true;
        });
        NCMBTestSettings.AwaitAsync();
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Example #24
0
    public void UploadFile()
    {
        string dateString = DateTime.Now.ToString("yyyy_MM_dd_HHmmss");

        byte[]   data = System.Text.Encoding.UTF8.GetBytes("Content : " + dateString);
        NCMBFile file = new NCMBFile(dateString + ".txt", data);

        file.SaveAsync((NCMBException error) => {
            if (error != null)
            {
                // 失敗
                Debug.LogError(error);
            }
            else
            {
                // 成功
                lastedFileName = dateString + ".txt";
                Debug.Log("Upload file success " + lastedFileName);
            }
        });
    }
Example #25
0
    public void ConstructorTest()
    {
        // テストデータ作成
        string      url          = "http://dummylocalhost/";
        ConnectType connectType  = ConnectType.GET;
        string      content      = "dummyContent";
        string      sessionToken = "dummySessionToken";
        NCMBFile    file         = new NCMBFile();

        // フィールド値の読み込み
        NCMBConnection connection_normal = new NCMBConnection(url, connectType, content, sessionToken);
        Type           type_normal       = connection_normal.GetType();
        FieldInfo      field_normal      = type_normal.GetField("_domainUri", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);

        NCMBConnection connection_file = new NCMBConnection(url, connectType, content, sessionToken, file);
        Type           type_file       = connection_file.GetType();
        FieldInfo      field_file      = type_file.GetField("_domainUri", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);

        Assert.AreEqual("http://localhost:3000/", field_normal.GetValue(connection_normal).ToString());
        Assert.AreEqual("http://localhost:3000/", field_file.GetValue(connection_file).ToString());
    }
Example #26
0
        //y → データ本体。中身は以下の構造になってる。
        //{ { "種類", "名称", "レア度", "数量", "値段", "ユーザ名", "詳細", "ユーザURL"} }
        //{ {      0,      1,       2,     3,      4,         5,      6,          7} }

        public void AddNewOrder()
        {
            NCMBObject obj = new NCMBObject("Orders");

            obj["itemType"] = itemType;
            obj["itemName"] = itemName_UniqueName + " " + itemName_Type + " " + itemName_Enhancement;
            obj["Rarity"]   = Rarity;
            obj["Number"]   = number;
            obj["Price"]    = Price;
            obj["UserID"]   = user_ID;
            obj["Detail"]   = Detail;
            obj["UserURL"]  = user_URL;

            Debug.Log(itemType);
            Debug.Log(itemName_UniqueName);
            Debug.Log(itemName_Type);
            Debug.Log(itemName_Enhancement);
            Debug.Log(Rarity);
            Debug.Log(number + "→" + Number);
            Debug.Log(user_ID);
            Debug.Log(Detail);
            Debug.Log(user_URL);

            obj.SaveAsync();


            //SS保存処理 実質3行だがSS命名のため11行になっている。
            if (ss.GetComponent <AddImage>().texture != null)
            {
                NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("Orders");
                query.Limit = 1;
                query.OrderByDescending("updateDate");
                query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
                {
                    NCMBFile file = new NCMBFile(System.Convert.ToString(objList[0].ObjectId), SS);
                    file.SaveAsync();
                });
            }
        }
Example #27
0
    void saveToCloud(byte[] bytes, string name)
    {
        NCMBFile file = new NCMBFile(name, bytes);

        file.SaveAsync((NCMBException error) => {
            if (error != null)
            {
                // 失敗
                Debug.Log("upload image error");
            }
            else
            {
                //成功
                Debug.Log("upload image success");
#if UNITY_2019_3_OR_NEWER
                SceneManager.LoadScene("blackboard");
#else
                Application.LoadLevel("blackboard");
#endif
            }
        });
    }
Example #28
0
 //コンストラクタ(NCMBFile)
 internal NCMBConnection(String url, ConnectType method, string content, string sessionToken, NCMBFile file)
     : this(url, method, content, sessionToken, file, CommonConstant.DOMAIN_URL)
 {
 }
    //詳細 Buttonが押された時
    //num → OrderIDと同じ。内部的に処理するために、このセクションのみで使う一時変数。
    public void OnDetailButtonPressed(int num, string objectID, int detailPanelPos = 0)
    {
        Debug.Log(num);

        Debug.Log(s6[num]);

        if (detailPanelPos == 0)//検索画面の場合
        {
            detailPanel = DetailPanel;
        }
        else if (detailPanelPos == 1)//出品リスト画面の場合
        {
            detailPanel = DetailPanel_In_MyList;
        }

        //詳細textを代入
        this.detailPanel.transform.GetChild(0).transform.GetChild(1)
        .transform.GetChild(0).transform.GetChild(2)
        .transform.GetChild(0)
        .gameObject.GetComponent <InputField>().text = s6[num];


        //SSの文字をリセット
        this.detailPanel.transform.GetChild(0).transform.GetChild(1)
        .transform.GetChild(0).transform.GetChild(1)
        .transform.GetChild(0).transform.GetChild(0)
        .gameObject.SetActive(true);

        //SSをリセット
        this.detailPanel.transform.GetChild(0).transform.GetChild(1)
        .transform.GetChild(0).transform.GetChild(1)
        .transform.GetChild(0)
        .gameObject.GetComponent <Image>().sprite = null;


        //SSを代入
        //1.SSを取得 2.SS(byte[])をtexture→Spriteに変換
        NCMBQuery <NCMBFile> query = NCMBFile.GetQuery();

        query.WhereEqualTo("fileName", objectID);
        query.FindAsync((List <NCMBFile> objList, NCMBException error) =>
        {
            if (error != null)
            {
                //検索失敗
            }
            else
            {
                //検索成功
                foreach (NCMBFile file in objList)
                {
                    file.FetchAsync((byte[] fileData, NCMBException e) =>
                    {
                        if (e != null)
                        {
                            //取得失敗
                        }
                        else
                        {
                            //取得成功
                            //1.SSの文字を消す。
                            this.detailPanel.transform.GetChild(0).transform.GetChild(1)
                            .transform.GetChild(0).transform.GetChild(1)
                            .transform.GetChild(0).transform.GetChild(0)
                            .gameObject.SetActive(false);

                            //2.SSを代入する。
                            Texture2D texture = new Texture2D(100, 100);
                            texture.LoadImage(fileData);
                            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
                            this.detailPanel.transform.GetChild(0).transform.GetChild(1)
                            .transform.GetChild(0).transform.GetChild(1)
                            .transform.GetChild(0)
                            .gameObject.GetComponent <Image>().sprite = sprite;
                            Resources.UnloadUnusedAssets();
                        }
                    });
                }
            }
        });
        //--SS処理はここまで。

        //ユーザーのLobi URLを代入
        this.detailPanel.transform.GetChild(0).transform.GetChild(1)
        .transform.GetChild(0).transform.GetChild(3)
        .transform.GetChild(0)
        .gameObject.GetComponent <InputField>().text = s7[num];

        //最後に詳細パネルをオンにする
        this.detailPanel.gameObject.SetActive(true);
    }
Example #30
0
 //コンストラクタ(NCMBFile)
 internal NCMBConnection(String url, ConnectType method, string content, string sessionToken, NCMBFile file)
     : this(url, method, content, sessionToken, file, NCMBSettings.DomainURL)
 {
 }