Beispiel #1
0
        // constructor
        internal RecordsGetResponse(JObject json)
        {
            rawJson = json.ToString();

            var response = JsonConvert.DeserializeObject <Received>(rawJson);

            ErrorCodeScriptBefore     = Convert.ToInt32(response.Response.ScriptErrorPreRequest);
            ErrorCodeScriptBeforeSort = Convert.ToInt32(response.Response.ScriptErrorPreSort);
            ErrorCodeScriptAfter      = Convert.ToInt32(response.Response.ScriptError);


            SourceInfo          = response.Response.DataInfo;
            FoundRecordCount    = SourceInfo.foundCount;
            totalRecordCount    = SourceInfo.totalRecordCount;
            returnedRecordCount = SourceInfo.returnedCount;

            ErrorCode = (int)json["messages"][0]["code"];
            result    = (string)json["messages"][0]["message"];
            JArray dataArray = (JArray)json["response"]["data"];

            data = new FMData("parent");

            int i = 0;

            // each element in the array here is a record in the found set, a "parent" record
            foreach (JObject record in dataArray)
            {
                // add a row to the DataTable

                string   parentId = (string)record["recordId"];
                string   modId    = (string)record["modId"];
                FMRecord row      = new FMRecord(record.ToString());
                row.setRecordId(parentId);
                row.setModificationId(modId);

                JObject fieldData = (JObject)record["fieldData"];

                // each element here is a field/value pair
                foreach (JProperty field in fieldData.Properties())
                {
                    string fieldName = field.Name;

                    // ==> need to handle here if field name has "::" in it, that it belongs to a related table
                    // that related table may also be set through portal data so check for the name later!

                    string fieldValue = (string)field.Value;
                    row.addFieldAndData(fieldName, fieldValue);
                }


                // check for portalData
                // ==> what if none?

                JObject portalData = (JObject)record["portalData"];
                // each child key here is a portal, not in an array
                // each portal key holds an array of portal records
                foreach (JProperty portal in portalData.Properties())
                {
                    // each property is a relationship/portal

                    // portal name can either be the related TO or the name of the portal object on the layout
                    string      name        = portal.Name;
                    bool        nameHandled = false;
                    FMRecordSet child       = new FMRecordSet(name, name);

                    // now loop through array of related records
                    JArray childRecords = (JArray)portal.Value;
                    int    x            = 0;
                    foreach (JObject childRecord in childRecords)
                    {
                        FMRecord portalRow = new FMRecord(childRecord.ToString());
                        portalRow.setRecordId((string)childRecord["recordId"]);
                        portalRow.setModificationId((string)childRecord["modId"]);
                        foreach (JProperty field in childRecord.Properties())
                        {
                            // get rid of the TO name in the field

                            string fieldName = field.Name;
                            string nameOnly;

                            if (fieldName.Contains("::"))
                            {
                                string[] split  = Regex.Split(fieldName, "::");
                                string   TOname = split[0];
                                nameOnly = split[1];
                                if (nameHandled == false)
                                {
                                    if (TOname == name)
                                    {
                                        child.updateNames(name, null);
                                    }
                                    else
                                    {
                                        child.updateNames(TOname, name);
                                    }

                                    // add the TO name to the list of related tables if we don't have it yet
                                    if (!data.relatedTableNames.Contains(TOname))
                                    {
                                        data.relatedTableNames.Add(TOname);
                                    }

                                    nameHandled = true;
                                }
                            }
                            else
                            {
                                nameOnly = fieldName;
                            }

                            string fieldValue = (string)field.Value;

                            portalRow.addFieldAndData(nameOnly, fieldValue);
                        }

                        // add the row to the record set
                        child.AddRecord(portalRow);
                        x++;
                    }

                    // add the child record set to the overall data
                    row.addRelatedRecords(child);
                }

                // add the row to the data
                data.foundSet.AddRecord(row);

                // increment the record counter for the parent records
                i++;
            }
        }
Beispiel #2
0
 /// <summary>
 /// ?? is referenced but I'll have to figure out why
 /// </summary>
 /// <param name="record"></param>
 public void AddRecord(FMRecord record)
 {
     records.Add(record);
 }