Beispiel #1
0
        public int SetMapping(String jsonBody, Dictionary <int, string> Header)
        {
            MappingPayload tmp = JsonConvert.DeserializeObject <MappingPayload>(jsonBody);

            ParentObject = tmp.parent;

            Dictionary <int, MappingPayload.Mapping> mapping = new Dictionary <int, MappingPayload.Mapping>();

            foreach (KeyValuePair <int, String> entry in Header)
            {
                MappingPayload.Mapping map = tmp.find(entry.Value);
                Mapping.Add(entry.Key, map);
                if (!Meta.ContainsKey(map.toObject))
                {
                    RetrieveMetadata(map.toObject);
                }
            }

            BatchSize = (int)this.maxRecords / tmp.size;

            return(BatchSize);
        }
Beispiel #2
0
        public void PreparePayload(String[] data, int line)
        {
            Dictionary <string, Dictionary <string, object> > body = new Dictionary <string, Dictionary <string, object> >();
            Record parent = new Record();

            int i = 0;

            foreach (String value in data)
            {
                //only if field was mapped
                if (Mapping.ContainsKey(i))
                {
                    MappingPayload.Mapping map = Mapping[i];

                    Dictionary <string, object> dataset = new Dictionary <string, object>();
                    dataset.Add(map.toColumn, value);

                    if (body.ContainsKey(map.toObject))
                    {
                        body[map.toObject].Add(map.toColumn, value);
                    }
                    else
                    {
                        body.Add(map.toObject, dataset);
                    }
                }
                i++;
            }

            parent.attributes.Add("type", ParentObject);
            parent.attributes.Add("referenceId", ParentObject + line.ToString());

            RestSharp.Serialization.Json.JsonSerializer serializer = new RestSharp.Serialization.Json.JsonSerializer();

            parent.fields = body[ParentObject];

            List <Record>  records  = new List <Record>();
            SalesforceBody children = new SalesforceBody();

            foreach (KeyValuePair <string, Dictionary <string, object> > entry in body)
            {
                if (entry.Key == ParentObject)
                {
                    continue;
                }

                Record child = new Record();

                child.attributes.Add("type", entry.Key);
                child.attributes.Add("referenceId", entry.Key + line.ToString());
                child.fields = entry.Value;

                children.records = records;
                parent.children.Add(Meta[entry.Key].labelPlural, new SalesforceBody(child));
            }

            this.body.records.Add(parent);

            if (this.body.records.Count >= BatchSize)
            {
                flush();
            }
        }