Пример #1
0
 /// <summary>
 /// An object association is a directional relationship between two object identifiers. For example, Application Installation: user id => installed application ids; Marriage: husband => wife; Friendship: user id => friend user id; Gift: giver => receiver 
 /// Each association has at least 3 names that are required to describe it: name of the association itself: "installation", "marriage", "friendship", "gift". alias1, name of the first object identifier: "user id", "husband", "giver". alias2, name of the second object identifier: "application id", "wife", "friend user id", "receiver". 
 /// For some associations, we also need reverse direction for a lookup by the second object identifier. For examples, in "marriage" case, not only may we need to look up wife ids by husband ids, but we may also need to look up husband ids by wife ids. We call this a two-way association. Since "husband to wife" is not the same as "wife to husband", we call this a two-way asymmetric association.
 /// In some other two-way associations, backward association has the same meaning of forward association. For example, in "friendship", if "A is B's friend" then "B is A's friend" as well. We call these types of two-way associations symmetric. For a symmetric association, when "A to B" is added, we also add "B to A", so that a reverse lookup can find out exactly the same information. 
 /// </summary>
 /// <param name="name">Name of forward association to create. This name needs to be unique among all object types and associations defined for this application. This name also needs to be a valid identifier, which is no longer than 32 characters, starting with a letter (a-z) and consisting of only small letters (a-z), numbers (0-9) and/or underscores. </param>
 /// <param name="assoc_type">Type of this association:
 /// 1: one-way association, where reverse lookup is not needed;
 /// 2: two-way symmetric association, where a backward association (B to A) is always created when a forward association (A to B) is created.
 /// 3: two-way asymmetric association, where a backward association (B to A) has different meaning than a forward association (A to B). </param>
 /// <param name="assoc_info1">Describes object identifier 1 in an association. This is a data structure that has:
 /// alias: name of object identifier 1. This alias needs to be a valid identifier, which is no longer than 32 characters, starting with a letter (a-z) and consisting of only small letters (a-z), numbers (0-9) and/or underscores.
 /// object_type: Optional - object type of object identifier 1.
 /// unique: Optional - Default to false. Whether each unique object identifier 1 can only appear once in all associations of this type. </param>
 /// <param name="assoc_info2">Describes object identifier 2 in an association. This is a data structure that has:
 /// alias: name of object identifier 2. This alias needs to be a valid identifier, which is no longer than 32 characters, starting with a letter (a-z) and consisting of only small letters (a-z), numbers (0-9) and/or underscores.
 /// object_type: Optional - object type of object identifier 2.
 /// unique: Optional - Default to false. Whether each unique object identifier 2 can only appear once in all associations of this type. </param>
 /// <param name="inverse">Optional - name of backward association, if it is two-way asymmetric. This name needs to be unique among all object types and associations defined for this application. This name also needs to be a valid identifier, which is no longer than 32 characters, starting with a letter (a-z) and consisting of only small letters (a-z), numbers (0-9) and/or underscores. </param>
 /// <returns>Empty response if succesful, error otherwise.</returns>
 public void defineAssociation(string name, int assoc_type, assoc_object_type assoc_info1, assoc_object_type assoc_info2, bool? inverse)
 {
     var parameterList = new Dictionary<string, string> { { "method", "facebook.data.defineAssociation" } };
     _api.AddRequiredParameter(parameterList, "name", name);
     _api.AddRequiredParameter(parameterList, "assoc_type", assoc_type);
     _api.AddRequiredParameter(parameterList, "assoc_info1", assoc_info1);
     _api.AddRequiredParameter(parameterList, "assoc_info2", assoc_info2);
     if (inverse!=null)
         _api.AddParameter(parameterList, "inverse", (bool)inverse);
     _api.SendRequest(parameterList);
 }
Пример #2
0
 public void defineAssociationTest()
 {
     DropAssociations();
     createObjectTypeTest();
     API parent = _api;
     data target = new data(parent);
     string name = Constants.TestAssociationDefName;
     int assoc_type = 2;
     assoc_object_type assoc_info1 = new assoc_object_type
                                         {
                                             alias = Constants.TestAssociationDefAlias1,
                                             object_type = Constants.TestType
                                         };
     assoc_object_type assoc_info2 = new assoc_object_type
                                         {
                                             alias = Constants.TestAssociationDefAlias2,
                                             object_type = Constants.TestType
                                         };
     bool? inverse = null;
     target.defineAssociation(name, assoc_type, assoc_info1, assoc_info2, inverse);
 }
Пример #3
0
 internal void AddRequiredParameter(IDictionary<string, string> dict, string key, assoc_object_type assoc_info)
 {
     if (!(assoc_info ==null))
     {
         var assoc = new Dictionary<string, string>
                         {
                             {"alias" , assoc_info.alias},
                             {"object_type" , assoc_info.object_type},
                             {"unique" , assoc_info.unique.ToString()}
                         };
         AddJSONAssociativeArray(dict,key,assoc);
     }
     else
     {
         throw new Exception(string.Format("Error: Parameter '{0}' is required.", key));
     }
 }