Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="dp"></param>
        public void InitializeD(string strategy, params object[] dp)
        {
            //StrategyValidationCheck(strategy, dp);

            string querystr = "";

            if (strategy == "SeeParams_Single")
            {
                if (dp != null && dp.Length > 0)
                {
                    //resolve querystring
                    var attrs = GetType().GetCustomAttributes(typeof(QueryStringProvider), false);
                    if (attrs != null && attrs.Length > 0)
                    {
                        querystr    = QueryStringResolver.GetQueryString(((QueryStringProvider)attrs[0]).ProviderName, Config["destination"]["querystring"].ToString(), dp);
                        Destination = destinationq.GetData(querystr);
                    }
                    else
                    {
                        //throw error
                    }
                }
            }
            //other strategy
            else
            {
                //no params
                Destination = destinationq.GetData("");
            }

            if (Destination == null)
            {
                // add log and throw exception
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="extras"></param>
        /// <returns></returns>
        public void UpdateData(JObject ds, params string[] extras)
        {
            //need extras to thell httpclient the exact address of update
            //and this method has the knowledge of msg body format

            //opertaion of HttpClient
            using (var client = new HttpClient())
            {
                try
                {
                    var changeset = ds["_changeset"];

                    if (changeset != null)
                    {
                        foreach (var rd in changeset)
                        {
                            var querystring = "";

                            if (rd["_rdstatus"].ToString() == "update")
                            {
                                ((JObject)rd).Remove("_rdstatus");
                                querystring = QueryStringResolver.GetQueryString("CommonRegex", extras[0], new JValue[] { (JValue)rd["_id"] });
                                ((JObject)rd).Remove("_id");
                            }
                            else if (rd["_rdstatus"].ToString() == "add")
                            {
                                ((JObject)rd).Remove("_rdstatus");
                                querystring = extras[1];
                            }

                            AddMetaData(client, "update");
                            var updatetask = client.PostAsync(querystring, new StringContent(((JObject)rd).ToString(), Encoding.UTF8, "application/json"));
                            updatetask.Wait();
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            } //end of using
        }     //end of method