Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// 构造函数,由CloudSearchApi对象调用,请点击以下链接来获取CloudSearchApi的
        /// getIndex方法详情。
        /// 
        /// </summary>
        /// <param name="api">用于管理索引的API对象</param>
        /// <param name="indexName">索引名称。</param>
        public CloudSearchIndex(CloudSearchApi api, string indexName)
        {
            this._api = api;
            this._indexName = indexName;

            this._indexURL = api.indexURL(this._indexName);
            this._docURL = api.docURL(this._indexName);
            this._topURL = api.topURL(this._indexName);
            this._metaURL = api.statusURL(this._indexName);
            this._errorURL = api.errorURL(this._indexName);
            this._searchURL = api.searchURL(this._indexName);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string a = @"$%^";
            Console.WriteLine(HttpUtility.HtmlEncode(a));
            Console.WriteLine(HttpUtility.UrlEncode(a,
                Encoding.UTF8));
            Console.WriteLine(HttpUtility.UrlEncodeUnicode(a));

            //var ja = new JArray(new string[] { "a", "b" });
            //JObject joo = JObject.Parse("{\"a\":\"b\"}");
            //Console.WriteLine(joo.ToString(Newtonsoft.Json.Formatting.None));

            //Console.ReadKey();

            //JObject resultDoc = new JObject();
            //resultDoc.Add("cmd", "action");
            //resultDoc["field"] = "asd";

            //NameValueCollection col = new NameValueCollection();
            //col.Add("a", "aa");
            //col.Add("b", "bb");

            //var jt = JToken.FromObject(col);

            //Console.WriteLine(jt.ToString());

            //CloudSearchHttpException testing = new CloudSearchHttpException("sdf", 4401);

            string clientId = "6100004160758124";
            string secretKey = "0007e8ebc3fefec7bd42d4d984db1cb5";
            string apiUrl = @"http://css.aliyun.com/v1/api";

            CloudSearchApi api = new CloudSearchApi(apiUrl, clientId, secretKey);
            var index = api.getIndex("testIndex");
            Console.WriteLine(index.getDocument("id_2"));

            JObject addingDocs = new JObject();
            addingDocs["cmd"] = "add";
            addingDocs["fields"] = generateDoc();

            index.addDocuments(addingDocs.ToString(Formatting.None));
            //int docCount = index.getTotalDocCount();
            //Console.WriteLine(docCount);

            //index.deleteDocuments("id_6");

            //string s = "abc";
            //string url = @"http://ali.contoso.com/xx/v1/api/";
            //Console.WriteLine(url.RTrim(@"/v1/api/"));

            //Console.WriteLine(Utilities.CalcMd5(s));
            //Console.WriteLine(DateTime.MinValue);
            //Console.WriteLine((DateTime.Now - DateTime.MinValue).TotalSeconds);
            //CloudSearchApi api = new CloudSearchApi("", "", "");
            //Console.WriteLine(CloudSearchApi.time());
            //var webReq = WebRequest.Create(@"http://css.aliyun.com/v1/api/index?nonce=89141b020411c061cf8545c50aa5c7df.1352443204&client_id=6100004160758124&sign=f77c35b25f19c60d3c0b074ec7390080");
            //webReq.Method = "GET";
            //var response = webReq.GetResponse();
            //StreamReader sr = new StreamReader(response.GetResponseStream());
            //var result = sr.ReadToEnd();

            //JObject jObj = JObject.Parse(result);
            //JToken errorMessage = null;
            //if (jObj.TryGetValue("errors", out errorMessage))
            //{
            //    Console.WriteLine(errorMessage[0]["code"]);
            //}
            //Console.WriteLine(result);
            Console.ReadKey();
        }