Esempio n. 1
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);
    }
Esempio n. 2
0
    public void ACLObject()
    {
        //NCMBACLオブジェクトを作成
        NCMBACL acl = new NCMBACL();

        //読み込み権限を全開放
        acl.PublicReadAccess = true;

        //書き込み権限を全開放
        acl.PublicWriteAccess = true;

        NCMBObject obj = new NCMBObject("TestClass");

        obj.Add("Name", "Unity");
        obj.Add("message", "ACL");
        obj.ACL = acl;
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理
                Debug.LogError(e);
            }
            else
            {
                //成功時の処理
                lastedObjectID = obj.ObjectId;
                Debug.Log("Save object with ACL success " + lastedObjectID);
            }
        });
    }
Esempio n. 3
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);
    }
Esempio n. 4
0
        /// <summary>
        /// NCMBObjectに、フィールドとACLの設定を追加する
        /// </summary>
        /// <returns>設定を追加したNCMBObject</returns>
        /// <param name="obj">設定を追加したいNCMBObjectのインスタンス</param>
        /// <typeparam name="T">NCMBObjectとその派生クラス</typeparam>
        private T objectSettings <T>(T obj) where T : NCMBObject
        {
            if (UseFieldSettings)
            {
                obj = addKeyValues <T>(obj);
            }

            if (UseAclSettings)
            {
                NCMBACL acl = SetACL();
                if (acl != null)
                {
                    obj.ACL = acl;
                }
            }

            return(obj);
        }
Esempio n. 5
0
        /// <summary>
        /// 設定したACLを返す
        /// デフォルトのACL使用時や、設定数が0の時はnullを返す
        /// </summary>
        /// <returns>ACL</returns>
        private NCMBACL SetACL()
        {
            if (UseDefaultPermission || AclDataList.Count == 0)
            {
                return(null);
            }

            NCMBACL acl = new NCMBACL();

            bool settingFlag = false;

            foreach (NCMBUTACLData data in AclDataList)
            {
                if (!settingFlag && (data.IsRead || data.IsWrite))
                {
                    settingFlag = true;
                }

                switch (data.Type)
                {
                case NCMBUTACLType.All:
                    acl.PublicReadAccess  = data.IsRead;
                    acl.PublicWriteAccess = data.IsWrite;
                    break;

                case NCMBUTACLType.Member:
                    acl.SetReadAccess(data.ObjectId, data.IsRead);
                    acl.SetWriteAccess(data.ObjectId, data.IsWrite);
                    break;
                }
            }

            if (!settingFlag)
            {
                return(null);
            }

            return(acl);
        }
Esempio n. 6
0
        //estimatedDataのvalueの値がオブジェクト型の場合はここで変換
        private static IDictionary <string, object> _encodeJSONObject(object value, bool allowNCMBObjects)
        {
            //日付型をNifty仕様に変更してクラウドに保存
            if (value is DateTime)
            {
                DateTime dt = (DateTime)value;
                Dictionary <string, object> Datedic = new Dictionary <string, object> ();
                string iso = dt.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
                Datedic.Add("__type", "Date");
                Datedic.Add("iso", iso);
                return(Datedic);
            }
            if (value is NCMBObject)
            {
                NCMBObject obj = (NCMBObject)value;
                if (!allowNCMBObjects)
                {
                    throw new ArgumentException("NCMBObjects not allowed here.");
                }
                //GetRelationなどしたオブジェクトが未保存の場合はエラー
                if (obj.ObjectId == null)
                {
                    throw new ArgumentException("Cannot create a pointer to an object without an objectId.");
                }
                Dictionary <string, object> NCMBDic = new Dictionary <string, object> ();
                NCMBDic.Add("__type", "Pointer");
                NCMBDic.Add("className", obj.ClassName);
                NCMBDic.Add("objectId", obj.ObjectId);
                return(NCMBDic);
            }
            if (value is NCMBGeoPoint)
            {
                NCMBGeoPoint point = (NCMBGeoPoint)value;
                Dictionary <string, object> GeoDic = new Dictionary <string, object> ();
                GeoDic.Add("__type", "GeoPoint");
                GeoDic.Add("latitude", point.Latitude);
                GeoDic.Add("longitude", point.Longitude);
                return(GeoDic);
            }


            if (value is IDictionary)
            {
                Dictionary <string, object> beforeDictionary = new Dictionary <string, object> ();
                IDictionary afterDictionary = (IDictionary)value;
                foreach (object key in afterDictionary.Keys)
                {
                    if (key is string)
                    {
                        beforeDictionary [(string)key] = _maybeEncodeJSONObject(afterDictionary [key], allowNCMBObjects);
                    }
                    else
                    {
                        throw new NCMBException(new ArgumentException("Invalid type for key: " + key.GetType().ToString() + ".key type string only."));
                    }
                }

                return(beforeDictionary);
            }

            if (value is NCMBRelation <NCMBObject> )
            {
                NCMBRelation <NCMBObject> relation = (NCMBRelation <NCMBObject>)value;
                return(relation._encodeToJSON());
            }

            if (value is NCMBACL)
            {
                NCMBACL acl = (NCMBACL)value;
                return(acl._toJSONObject());
            }
            return(null);
        }