Example #1
0
        public void TestPropertiesCase()
        {
            JsonDictionary dict = new JsonDictionary();
            string name = "TestName";
            dict.Add("location", "path");
            dict.Add("required", true);
            dict.Add("description", "A string description");
            dict.Add("default", "A default value");
            dict.Add("type", "string");
            dict.Add("repeated", true);
            dict.Add("enum", new List<string> { "atom", "json" });
            dict.Add("enumDescriptions", new List<string> { "atom are small particals", "json is my friend" });
            dict.Add("minimum", "43");
            dict.Add("maximum", "53");
            dict.Add("pattern", "[1-9][0-9]*");
            var impl = new ParameterFactory.BaseParameter(new KeyValuePair<string, object>(name, dict));

            Assert.AreEqual("TestName", impl.Name);
            Assert.AreEqual("path", impl.ParameterType);
            Assert.AreEqual("A string description", impl.Description);
            Assert.AreEqual("string", impl.ValueType);
            Assert.AreEqual(true, impl.IsRequired);
            Assert.AreEqual(true, impl.IsRepeatable);
            Assert.AreEqual("A default value", impl.DefaultValue);
            MoreAsserts.ContentsEqualAndInOrder(new List<string> { "atom", "json" }, impl.EnumValues);
            MoreAsserts.ContentsEqualAndInOrder(
                new List<string> { "atom are small particals", "json is my friend" }, impl.EnumValueDescriptions);
            Assert.AreEqual("53", impl.Maximum);
            Assert.AreEqual("43", impl.Minimum);
            Assert.AreEqual("[1-9][0-9]*", impl.Pattern);
        }
Example #2
0
        /// <summary>
        /// Creates a new parameter with the specified name and value.
        /// </summary>
        public BaseParameter(IServiceFactory factory, string name, JsonDictionary dictionary)
            : base(factory)
        {
            Name = name;
            information = dictionary;
			information.ThrowIfNull("got no valid dictionary");
        }
Example #3
0
 public JsonValue ToJson(IJsonContext context) {
     var dict = new JsonDictionary();
     dict["UserName"] = context.ToJson(UserName);
     dict["ValidTo"] = context.ToJson(ValidTo.ToUnixTime());
     dict["ApiToken"] = context.ToJson(ApiToken);
     return dict;
 }
        public void GetAllvm()
        {
            // Log.Info("Get All Vm");
              try
              {
              int i = 0;
              StringBuilder buildjson=new StringBuilder();
              string jsonstring = string.Empty;
              JsonDictionary<String, Object> result = new JsonDictionary<String, Object>();
             buildjson.Append("[");
              foreach (var vmpsConfig in vmconfiglist)
              {
                  i ++;
                  result["ID"] = vmpsConfig.id;
                  result["OS"] = vmpsConfig.FullyQualifiedOSName;
                  result["FLAVOUR"] = vmpsConfig.flavour;
                  jsonstring = JsonConvert.SerializeObject(result);
                  buildjson.Append(jsonstring);
                  if(vmconfiglist.Count!=i)
                  {
                      buildjson.Append(",");
                  }

              }
              buildjson.Append("]");
              Console.WriteLine(buildjson);

              }
              catch (Exception ex )
              {

              Log.Info("Failed to get All Vm");
              }
        }
Example #5
0
        /// <summary>
        /// Creates a new resource for the specified discovery version with the specified name and json dictionary.
        /// </summary>
        internal Resource(IServiceFactory factory, string name, JsonDictionary dictionary)
            : base(factory)
        {
            name.ThrowIfNull("name");
            dictionary.ThrowIfNull("dictionary");

            logger.Debug("Constructing Resource [{0}]", name);
            Name = name;
            information = dictionary;
            if (information == null)
            {
                throw new ArgumentException("got no valid dictionary");
            }

            // Initialize subresources.
            if (information.ContainsKey("resources"))
            {
                var resourceJson = (JsonDictionary)information["resources"];
                resources = new Dictionary<string, IResource>();
                foreach (KeyValuePair<string, object> pair in resourceJson)
                {
                    // Create the subresource.
                    var subResource = (Resource)Factory.CreateResource(pair.Key, pair.Value as JsonDictionary);
                    subResource.Parent = this;
                    resources.Add(pair.Key, subResource);
                }
            }
        }
Example #6
0
 public BugSenseRequest(BugSenseEx ex, AppEnvironment environment, JsonDictionary<string, string> customData)
 {
     Client = new BugSenseClient();
     Request = new BugSenseInternalRequest() { CustomData = customData };
     //Request.Comment = string.IsNullOrEmpty(ex.Comment) ? ex.Message : ex.Comment;
     Exception = ex;
     AppEnvironment = environment;
 }
Example #7
0
 /// <summary>
 /// Creates a new parameter with the specified name and value.
 /// </summary>
 public BaseParameter(KeyValuePair<string, object> kvp)
 {
     Name = kvp.Key;
     information = kvp.Value as JsonDictionary;
     if (information == null)
     {
         throw new ArgumentException("got no valid dictionary");
     }
 }
        public void ValidateRegexTest()
        {
            IMethod m = new MockMethod();
            var dict = new JsonDictionary { { "name", "test" }, { "pattern", ".+" } };

            var p = ServiceFactory.Default.CreateParameter("test", dict);
            var inputData = new ParameterCollection();
            var validator = new MethodValidator(m, inputData);
            Assert.IsTrue(validator.ValidateRegex(p, "Test"));
        }
Example #9
0
 internal BaseMethod(IServiceFactory factory, string name, JsonDictionary dictionary)
     : base(factory)
 {
     Name = name;
     information = dictionary;
     if (information == null)
     {
         throw new ArgumentException("got no valid dictionary");
     }
 }
Example #10
0
 internal BaseMethod(DiscoveryVersion version, KeyValuePair<string, object> kvp)
 {
     discoveryVersion = version;
     Name = kvp.Key;
     information = kvp.Value as JsonDictionary;
     if (information == null)
     {
         throw new ArgumentException("got no valid dictionary");
     }
 }
        public void ValidateRegexTest()
        {
            IMethod m = new MockMethod();
            var dict = new JsonDictionary { { "name", "test" }, { "pattern", ".+" } };

            var jsonObj = new KeyValuePair<string, object>("test", dict);

            var p = new ParameterFactory.BaseParameter(jsonObj);
            var inputData = new ParameterCollection();
            var validator = new MethodValidator(m, inputData);
            Assert.IsTrue(validator.ValidateRegex(p, "Test"));
        }
Example #12
0
        public void ConstuctorArgumentValidationTest()
        {
            var param = new FactoryParameterV0_3("http://server/");
            var js = new JsonDictionary();
            js["name"] = "TestName";
            js["version"] = "v1";
            js["restBasePath"] = "test/path";

            Assert.Throws(typeof(ArgumentNullException), () => new ServiceV0_3(null, js));
            Assert.Throws(typeof(ArgumentNullException), () => new ServiceV0_3(param, null));

            new ServiceV0_3(param, js);
        }
Example #13
0
        /// <summary>
        /// Initialize a new MediaUpload object from a JsonDictionary describing its configuration.
        /// </summary>
        /// <param name="dict"></param>
        public MediaUpload(JsonDictionary dict)
        {
            if (dict == null)
                throw new ArgumentNullException("dict");
            information = dict;

            accepts = new LazyResult<string[]>(() =>
            {
                var acceptList = information[AcceptsPath] as IEnumerable<object>;
                return acceptList == null ?
                    new string[] { } : acceptList.Select(x => x as string).ToArray();
            });

            var protocols = information[ProtocolsPath] as JsonDictionary;
        }
Example #14
0
        public void ConstuctorArgumentValidationTest()
        {
            var param = new FactoryParameters("http://server/");
            var js = new JsonDictionary();
            js["name"] = "TestName";
            js["version"] = "v1";
            js["restBasePath"] = "test/path";

            var factory = ServiceFactoryDiscoveryV0_3.GetInstance();

            Assert.DoesNotThrow(() => factory.CreateService(js, null));
            Assert.Throws(typeof(ArgumentNullException), () => factory.CreateService(null, param));

            factory.CreateService(js, param);
        }
Example #15
0
        public JsonResult DeleteBanks(string id)
        {
            string errmsg = "";
            var    result = UserBanksBusiness.UpdateStatus(id, 9);

            JsonDictionary.Add("result", result);
            if (!result)
            {
                JsonDictionary.Add("ErrMsg", "操作失败!");
            }
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #16
0
        public JsonResult GetLotteryRecord(string cpcode, int status, string lcode, string issuenum, string type, int selfrange, int winType, string btime, string etime, int pageIndex)
        {
            int total     = 0;
            int pageTotal = 0;
            var items     = LotteryOrderBusiness.GetLotteryOrder("", cpcode, CurrentUser.UserID, lcode, issuenum, type, status, winType, PageSize, pageIndex, ref total,
                                                                 ref pageTotal, selfrange, btime, etime);

            JsonDictionary.Add("items", items);
            JsonDictionary.Add("totalCount", total);
            JsonDictionary.Add("pageCount", pageTotal);
            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #17
0
        public JsonResult AuditApplyReturnProduct(string orderid, string wareid)
        {
            int    result  = 0;
            string errinfo = "";

            var bl = AgentOrderBusiness.BaseBusiness.AuditApplyReturnProduct(orderid, wareid, CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID, ref result, ref errinfo);

            JsonDictionary.Add("status", bl);
            JsonDictionary.Add("result", result);
            JsonDictionary.Add("errinfo", errinfo);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #18
0
        public JsonResult AuditReturnIn(string docid)
        {
            int    result  = 0;
            string errinfo = "";

            var bl = StockBusiness.BaseBusiness.AuditReturnIn(docid, CurrentUser.UserID, CurrentUser.ClientID, ref result, ref errinfo);

            JsonDictionary.Add("status", bl);
            JsonDictionary.Add("result", result);
            JsonDictionary.Add("errinfo", errinfo);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #19
0
        /// <summary>
        /// 加入到购物车
        /// </summary>
        /// <param name="productid"></param>
        /// <param name="detailsid"></param>
        /// <param name="quantity"></param>
        /// <param name="ordertype"></param>
        /// <returns></returns>
        public JsonResult AddShoppingCart(EnumDocType ordertype, string productid, string detailsid, decimal quantity, string unitid, string depotid, string taskid, string remark = "", string guid = "", string attrid = "")
        {
            if (string.IsNullOrEmpty(guid))
            {
                guid = CurrentUser.UserID;
            }
            var bl = ShoppingCartBusiness.AddShoppingCart(ordertype, productid, detailsid, quantity, unitid, depotid, taskid,
                                                          remark, guid, attrid, CurrentUser.UserID, OperateIP);

            JsonDictionary.Add("Status", bl);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public void ValidateRegexTest()
        {
            IMethod m    = new MockMethod();
            var     dict = new JsonDictionary {
                { "name", "test" }, { "pattern", ".+" }
            };

            var jsonObj = new KeyValuePair <string, object>("test", dict);


            var p         = new ParameterFactory.BaseParameter(jsonObj);
            var inputData = new ParameterCollection();
            var validator = new MethodValidator(m, inputData);

            Assert.IsTrue(validator.ValidateRegex(p, "Test"));
        }
Example #21
0
        public JsonResult GetProductUseLogs(string productid, int pageindex)
        {
            int totalCount = 0;
            int pageCount  = 0;

            var list = new ProductsBusiness().GetProductUseLogs(productid, 20, pageindex, ref totalCount, ref pageCount);

            JsonDictionary.Add("items", list);
            JsonDictionary.Add("totalCount", totalCount);
            JsonDictionary.Add("pageCount", pageCount);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #22
0
        /// <summary>
        /// 保存采购单
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public JsonResult SubmitPurchase(string doc)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var model = serializer.Deserialize <CloudSalesEntity.StorageDoc>(doc);

            model.DocType = (int)EnumDocType.RK;

            var id = OrdersBusiness.CreateStorageDoc(model, CurrentUser.UserID, OperateIP, CurrentUser.ClientID);

            JsonDictionary.Add("ID", id);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #23
0
        public JsonResult ConfirmLoginPwd(string loginName, string loginPwd)
        {
            if (string.IsNullOrEmpty(loginName))
            {
                loginName = CurrentUser.LoginName;
            }
            bool bl = OrganizationBusiness.ConfirmLoginPwd(loginName, loginPwd);

            JsonDictionary.Add("Result", bl);

            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #24
0
        public JsonResult GetActiveList(string keywords, int pageIndex, int pageSize, string btime = "",
                                        string etime = "", int type = -1)
        {
            int totalCount = 0, pageCount = 0;

            JsonDictionary.Add("items",
                               WebSetBusiness.GetActiveList(keywords, pageIndex, pageSize, ref totalCount, ref pageCount, btime, etime,
                                                            type));
            JsonDictionary.Add("TotalCount", totalCount);
            JsonDictionary.Add("PageCount", pageCount);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #25
0
        public JsonResult OrdersList(int paytype, int status, string keywords, string userID, string beginTime,
                                     string endTime, int pageIndex, int pageSize)
        {
            int totalCount = 0;
            int pageCount  = 0;
            var result     = UserOrdersBusiness.GetUserOrders(keywords, userID, -1, status, paytype, pageSize, pageIndex, ref totalCount, ref pageCount, beginTime, endTime);

            JsonDictionary.Add("totalCount", totalCount);
            JsonDictionary.Add("pageCount", pageCount);
            JsonDictionary.Add("items", result);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #26
0
        public JsonResult ConfirmAgentOrderSend(string orderid, string expressid, string expresscode)
        {
            int    result  = 0;
            string errinfo = "";

            var bl = AgentOrderBusiness.BaseBusiness.ConfirmAgentOrderSend(orderid, expressid, expresscode, CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID, ref result, ref errinfo);

            JsonDictionary.Add("status", bl);
            JsonDictionary.Add("result", result);
            JsonDictionary.Add("errinfo", errinfo);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #27
0
        /// <summary>
        /// 获取购物车产品
        /// </summary>
        /// <param name="ordertype"></param>
        /// <returns></returns>
        public JsonResult GetShoppingCart(EnumDocType ordertype, string guid = "")
        {
            if (string.IsNullOrEmpty(guid))
            {
                guid = CurrentUser.UserID;
            }

            var list = ShoppingCartBusiness.GetShoppingCart(ordertype, guid, "");

            JsonDictionary.Add("Items", list);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #28
0
        public JsonResult GetProductStocks(string Keywords, int PageIndex, int PageSize)
        {
            int totalCount = 0;
            int pageCount  = 0;

            var list = StockBusiness.BaseBusiness.GetProductStocks(Keywords, PageSize, PageIndex, ref totalCount, ref pageCount, CurrentUser.ClientID);

            JsonDictionary.Add("items", list);
            JsonDictionary.Add("totalCount", totalCount);
            JsonDictionary.Add("pageCount", pageCount);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #29
0
        //
        // GET: /FeedBack/

        #region ajax
        public ActionResult InsertFeedBack(string entity)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            FeedBack             model      = serializer.Deserialize <FeedBack>(entity);

            model.CreateUserID = CurrentUser.UserID;

            bool flag = FeedBackBusiness.InsertFeedBack(model);

            JsonDictionary.Add("Result", flag?1:0);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #30
0
        public JsonResult ImgList(int Status, string Keywords, string BeginTime, string EndTime, int PageIndex, int PageSize)
        {
            int totalCount = 0;
            int pageCount  = 0;
            var result     = UserImgsBusiness.GetUserImgList(Keywords, Status, BeginTime, EndTime, PageIndex, PageSize,
                                                             ref totalCount, ref pageCount);

            JsonDictionary.Add("totalCount", totalCount);
            JsonDictionary.Add("pageCount", pageCount);
            JsonDictionary.Add("items", result);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #31
0
        //获取订单列表根据二当家客户端编码
        public JsonResult GetOrdersByYXClientCode(int pageSize, int pageIndex, string clientID = "", string keywords = "",
                                                  string categoryID = "", string orderby = "", string beginPrice = "", string endPrice = "")
        {
            int totalCount = 0, pageCount = 0;
            var list = OrdersBusiness.BaseBusiness.GetOrdersByYXCode(clientID, keywords, pageSize, pageIndex, ref totalCount, ref pageCount,
                                                                     categoryID, orderby, beginPrice, endPrice);
            var objs = new List <Dictionary <string, object> >();

            foreach (var item in list)
            {
                Dictionary <string, object> obj = new Dictionary <string, object>();
                obj.Add("orderID", item.OrderID);
                obj.Add("goodsName", item.GoodsName);
                obj.Add("categoryID", item.CategoryID);
                obj.Add("categoryName", item.CategoryName);
                obj.Add("processCategoryName", item.ProcessCategoryName);
                obj.Add("intGoodsCode", item.IntGoodsCode);
                obj.Add("finalPrice", item.FinalPrice);
                obj.Add("orderImage", item.OrderImage);
                obj.Add("orderImages", item.OrderImages);
                obj.Add("createTime", item.CreateTime);
                obj.Add("endTime", item.EndTime);
                obj.Add("clientID", item.ClientID);
                obj.Add("goodsID", item.GoodsID);
                //obj.Add("logo", item.Client.Logo);
                //obj.Add("clientName", item.Client.CompanyName);
                //obj.Add("clientContactName", item.Client.ContactName);
                //obj.Add("clientCode", item.Client.ClientCode);
                //obj.Add("clientMobile", item.Client.MobilePhone);
                //obj.Add("clientAddress", item.Client.Address);
                //obj.Add("clientCityCode", item.Client.CityCode);
                //obj.Add("clientUserNum", "0-50人");
                //obj.Add("clientUserLables", "金牌工厂,深度验厂,交期保障");
                //obj.Add("clientCity", item.Client.City != null ? item.Client.City.City + item.Client.City.Counties : "");
                //obj.Add("orderAttrs", OrdersBusiness.BaseBusiness.GetOrderArrrsByOrderID(item.OrderID));
                objs.Add(obj);
            }
            JsonDictionary.Add("orders", objs);
            JsonDictionary.Add("totalCount", totalCount);
            JsonDictionary.Add("pageCount", pageCount);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #32
0
        public JsonResult SavaProduct(string product)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Products             model      = serializer.Deserialize <Products>(product);
            int result = 0;

            if (!string.IsNullOrEmpty(model.AttrList))
            {
                model.AttrList = model.AttrList.Substring(0, model.AttrList.Length - 1);
            }
            if (!string.IsNullOrEmpty(model.ValueList))
            {
                model.ValueList = model.ValueList.Substring(0, model.ValueList.Length - 1);
            }
            if (!string.IsNullOrEmpty(model.AttrValueList))
            {
                model.AttrValueList = model.AttrValueList.Substring(0, model.AttrValueList.Length - 1);
            }

            string id = "";

            if (string.IsNullOrEmpty(model.ProductID))
            {
                id = new ProductsBusiness().AddProduct(model.ProductCode, model.ProductName, model.GeneralName, model.ProviderID, model.UnitID,
                                                       model.CategoryID, model.Status.Value, model.IsPublic, model.AttrList, model.ValueList, model.AttrValueList,
                                                       model.CommonPrice.Value, model.Price, model.Weight.Value, model.IsAllow,
                                                       model.DiscountValue.Value, model.ProductImage, model.ShapeCode, model.Description, model.ProductDetails, CurrentUser.UserID, CurrentUser.ClientID, ref result);
            }
            else
            {
                bool bl = new ProductsBusiness().UpdateProduct(model.ProductID, model.ProductCode, model.ProductName, model.GeneralName, model.ProviderID, model.UnitID,
                                                               model.Status.Value, model.IsPublic, model.CategoryID, model.AttrList, model.ValueList, model.AttrValueList,
                                                               model.CommonPrice.Value, model.Price, model.Weight.Value, model.IsAllow,
                                                               model.DiscountValue.Value, model.ProductImage, model.ShapeCode, model.Description, CurrentUser.UserID, CurrentUser.ClientID, ref result);
                if (bl)
                {
                    id = model.ProductID;
                }
            }
            JsonDictionary.Add("ID", id);
            JsonDictionary.Add("result", result);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public void GenerateCommonParameterPropertyTest()
        {
            var method = new MockMethod()
            {
                Name       = "Method",
                Parameters = new Dictionary <string, IDiscoveryParameter>()
            };
            var resource = new MockResource();

            resource.Methods.Add("Method", method);
            var resourceDecl = new CodeTypeDeclaration();
            var requestDecl  = new CodeTypeDeclaration();

            #region Create common Parameters
            IDictionary <string, IDiscoveryParameter> commonParameters = new Dictionary <string, IDiscoveryParameter>();
            var dict = new JsonDictionary {
                { "name", "alt" }, { "location", "query" }, { "type", "string" }, { "default", "json" }
            };
            var p = ServiceFactory.Default.CreateParameter("alt", dict);
            commonParameters["alt"] = p;
            #endregion

            // Confirm that two properties and two fields are generated.
            var decorator = new CommonParameterRequestDecorator(commonParameters);
            decorator.DecorateClass(resource, method, requestDecl, resourceDecl);

            Assert.AreEqual(2, requestDecl.Members.Count); // Property  + field.
            Assert.AreEqual(0, resourceDecl.Members.Count);

            CodeTypeMemberCollection newMembers = requestDecl.Members;

            // Check the generated field.
            Assert.IsInstanceOf <CodeMemberField>(newMembers[0]);
            Assert.AreEqual("_alt", newMembers[0].Name);

            // Check the generated property.
            Assert.IsInstanceOf <CodeMemberProperty>(newMembers[1]);
            CodeMemberProperty property = (CodeMemberProperty)newMembers[1];
            Assert.AreEqual("Alt", property.Name);

            // Check that the property has a Key attribute.
            Assert.AreEqual(1, property.CustomAttributes.Count);
            Assert.AreEqual(
                typeof(RequestParameterAttribute).FullName, property.CustomAttributes[0].AttributeType.BaseType);
            Assert.AreEqual(
                "alt", ((CodePrimitiveExpression)property.CustomAttributes[0].Arguments[0].Value).Value);
        }
Example #34
0
        static public bool Store(string path, JsonDictionary map, bool overwrite = true)
        {
            MemoryStream        stream    = new MemoryStream();
            XmlDictionaryWriter xmlWriter = JsonReaderWriterFactory.CreateJsonWriter(stream);

            // 取得したXmlDictionaryWriterに対して、xmlを構築
            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("root");
            xmlWriter.WriteAttributeString("type", "object");

            // mapのkeyをタグ名、valueを値としてnodeを作成
            foreach (KeyValuePair <string, string> pair in map)
            {
                // mapのキー名でタグを作成
                xmlWriter.WriteStartElement(pair.Key);
                // これはなくてもOKだった
                //xmlWriter.WriteAttributeString("type", "string");
                xmlWriter.WriteValue(pair.Value);
                xmlWriter.WriteEndElement();
            }

            // rootノードの閉じタグ
            xmlWriter.WriteEndElement();

            xmlWriter.Flush();

            // JSON形式の文字列を得る
            stream.Position = 0;

            // 上書きしない場合は存在チェック
            if (!overwrite)
            {
                if (File.Exists(path))
                {
                    MessageBox.Show("指定したファイル[" + path + "]は既に存在します。", "ファイル書き込みエラー");
                }
                return(false);
            }

            // 書き込み
            var writer = new StreamWriter(path);

            writer.Write(new StreamReader(stream).ReadToEnd());

            stream.Close();
            return(true);
        }
        public void ValidateEnumNullTest()
        {
            IMethod m = new MockMethod();
            var dict = new JsonDictionary { { "name", "test" } };

            // Create the parameter.
            var p = ServiceFactory.Default.CreateParameter("test", dict);
            var inputData = new ParameterCollection();
            var validator = new MethodValidator(m, inputData);

            // Confirm that the method validates enumerations correctly.
            Assert.IsTrue(validator.ValidateEnum(p, "one"));
            Assert.IsTrue(validator.ValidateEnum(p, "two"));
            Assert.IsTrue(validator.ValidateEnum(p, "three"));
            Assert.IsTrue(validator.ValidateEnum(p, "One"));
            Assert.IsTrue(validator.ValidateEnum(p, ""));
        }
Example #36
0
        public JsonResult SaveReply(string entity)
        {
            var       result = false;
            string    msg    = "提交失败,请稍后再试!";
            UserReply model  = JsonConvert.DeserializeObject <UserReply>(entity);

            model.FromReplyID     = string.IsNullOrEmpty(model.FromReplyID) ? "" : model.FromReplyID;
            model.FromReplyUserID = string.IsNullOrEmpty(model.FromReplyUserID) ? "" : model.FromReplyUserID;
            result = UserReplyBusiness.CreateUserReply(model.GUID.Replace("ZSXJ,", ""), model.Content, model.Title, CurrentUser.UserID, model.FromReplyID, model.FromReplyUserID, model.Type, model.GUID.IndexOf("ZSXJ,"), ref msg);
            JsonDictionary.Add("result", result);
            JsonDictionary.Add("ErrMsg", msg);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public void RootResourceTest()
        {
            var subJson = new JsonDictionary();
            subJson.Add("resources", new JsonDictionary { { "Grandchild", new JsonDictionary() } });
            var topJson = new JsonDictionary();
            topJson.Add("resources", new JsonDictionary { { "Sub", subJson } });

            // Create the resource hierachy.
            var topResource = new Resource(ServiceFactory.Default, "", topJson);
            var subResource = topResource.Resources["Sub"];
            var grandchildResource = subResource.Resources["Grandchild"];

            // Check the generated full name.
            Assert.AreEqual("", topResource.Path);
            Assert.AreEqual("Sub", subResource.Path);
            Assert.AreEqual("Sub.Grandchild", grandchildResource.Path);
        }
Example #38
0
        /// <summary>
        /// 根据订单clientID获取订单
        /// </summary>
        public JsonResult GetClientOrders(string keyWords, string clientID, int status, int type, string beginDate, string endDate, int pageSize, int pageIndex, int userType = 0)
        {
            int pageCount  = 0;
            int totalCount = 0;

            List <ClientOrder> list = ClientOrderBusiness.GetBase(keyWords.Trim(), status, type, beginDate, endDate, clientID, userType, pageSize, pageIndex, ref totalCount, ref pageCount);

            JsonDictionary.Add("Items", list);
            JsonDictionary.Add("TotalCount", totalCount);
            JsonDictionary.Add("PageCount", pageCount);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #39
0
        public JsonResult FinishInitSetting()
        {
            bool bl = ClientBusiness.FinishInitSetting(CurrentUser.ClientID);

            JsonDictionary.Add("result", bl);
            if (bl)
            {
                CurrentUser.Client.GuideStep = 0;
                Session["ClientManager"]     = CurrentUser;
            }

            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #40
0
        public JsonResult SaveStorageBillingInvoice(string entity)
        {
            JavaScriptSerializer  serializer = new JavaScriptSerializer();
            StorageBillingInvoice model      = serializer.Deserialize <StorageBillingInvoice>(entity);

            var id = FinanceBusiness.BaseBusiness.CreateStorageBillingInvoice(model.BillingID, model.Type, model.InvoiceMoney, model.InvoiceCode, model.Remark, CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID);

            model.InvoiceID  = id;
            model.CreateUser = CurrentUser;
            JsonDictionary.Add("item", model);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #41
0
        public JsonResult UpdPwd(int type, string oldpwd, string newpwd)
        {
            var    result = false;
            var    model  = CurrentUser;
            string msg    = "";

            if (type == 0 && Encrypt.GetEncryptPwd(oldpwd, CurrentUser.LoginName).ToLower() != CurrentUser.LoginPwd.ToLower())
            {
                msg = "旧密码错误,操作失败";
            }
            else if (type == 1 && !string.IsNullOrEmpty(CurrentUser.AccountPwd) &&
                     CurrentUser.AccountPwd.ToLower() != Encrypt.GetEncryptPwd(newpwd, CurrentUser.LoginName).ToLower())
            {
                msg = "资金密码错误,操作失败";
            }
            else if (type == 1 && string.IsNullOrEmpty(CurrentUser.AccountPwd) &&
                     CurrentUser.LoginPwd.ToLower() == Encrypt.GetEncryptPwd(newpwd, CurrentUser.LoginName).ToLower())
            {
                msg = "资金密码不能喝登陆密码一致,操作失败";
            }
            else
            {
                if (type == 0)
                {
                    result = M_UsersBusiness.SetAdminAccount(CurrentUser.UserID, CurrentUser.LoginName, newpwd);
                    if (result)
                    {
                        model.LoginPwd    = Encrypt.GetEncryptPwd(newpwd, CurrentUser.LoginName);
                        Session["Manage"] = model;
                    }
                }
                else
                {
                    result            = M_UsersBusiness.UpdateAccountPwd(CurrentUser.UserID, CurrentUser.LoginName, newpwd);
                    model.AccountPwd  = Encrypt.GetEncryptPwd(newpwd, CurrentUser.LoginName);
                    Session["Manage"] = model;
                }
            }
            JsonDictionary.Add("result", result);
            JsonDictionary.Add("ErrMsg", msg);
            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #42
0
        /// <summary>
        /// 获取活动讨论列表
        /// </summary>
        public JsonResult GetActivityReplys(string activityID, int pageSize, int pageIndex)
        {
            int pageCount  = 0;
            int totalCount = 0;

            List <ActivityReplyEntity> list = ActivityBusiness.GetActivityReplys(activityID, pageSize, pageIndex, ref totalCount, ref pageCount);

            JsonDictionary.Add("Items", list);
            JsonDictionary.Add("TotalCount", totalCount);
            JsonDictionary.Add("PageCount", pageCount);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #43
0
 /// <summary>
 /// 获取属性详情
 /// </summary>
 /// <param name="attr"></param>
 /// <returns></returns>
 public JsonResult GetAttrByID(string attrID = "")
 {
     if (string.IsNullOrEmpty(attrID))
     {
         JsonDictionary.Add("Item", null);
     }
     else
     {
         var model = new ProductsBusiness().GetProductAttrByID(attrID, CurrentUser.ClientID);
         JsonDictionary.Add("Item", model);
     }
     return(new JsonResult
     {
         Data = JsonDictionary,
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     });
 }
Example #44
0
        public void RootResourceTest()
        {
            var subJson = new JsonDictionary();
            subJson.Add("resources", new JsonDictionary { { "Grandchild", new JsonDictionary() } });
            var topJson = new JsonDictionary();
            topJson.Add("resources", new JsonDictionary { { "Sub", subJson } });

            // Create the resource hierachy.
            var topResource = new ResourceV1_0(new KeyValuePair<string, object>("", topJson));
            var subResource = topResource.Resources["Sub"];
            var grandchildResource = subResource.Resources["Grandchild"];

            // Check the generated full name.
            Assert.AreEqual("", topResource.Path);
            Assert.AreEqual("Sub", subResource.Path);
            Assert.AreEqual("Sub.Grandchild", grandchildResource.Path);
        }
Example #45
0
        public JsonResult SaveBillingInvoice(string entity)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            BillingInvoice       model      = serializer.Deserialize <BillingInvoice>(entity);

            var id = FinanceBusiness.BaseBusiness.CreateBillingInvoice(model.BillingID, model.Type, model.CustomerType, model.InvoiceMoney, model.InvoiceTitle, model.CityCode, model.Address, model.PostalCode, model.ContactName, model.ContactPhone, model.Remark, CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID);

            model.InvoiceID  = id;
            model.CreateUser = CurrentUser;
            JsonDictionary.Add("item", model);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #46
0
        public JsonResult GetLotteryOrderReportList(string btime, string etime, int playtype, string cpcode,
                                                    string lcode, string issuenum, string type, string state, int winType, int pageIndex, int selfrange = 0)
        {
            int total     = 0;
            int pageTotal = 0;
            var list      = UserReportBussiness.GetLotteryOrderReportList(btime, etime, playtype, cpcode, CurrentUser.UserID, lcode, issuenum, type, state, winType, pageIndex, PageSize,
                                                                          ref total, ref pageTotal, selfrange);

            JsonDictionary.Add("items", list);
            JsonDictionary.Add("totalCount", total);
            JsonDictionary.Add("pageCount", pageTotal);
            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #47
0
        /// <summary>
        /// 获取举报反馈信息
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="type"></param>
        /// <param name="status"></param>
        /// <param name="keyWords"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public JsonResult GetFeedBacks(int pageIndex, int type, int status, string keyWords, string beginDate,
                                       string endDate)
        {
            int totalCount = 0, pageCount = 0;
            var list = FeedBackBusiness.GetFeedBacks(keyWords, beginDate, endDate, type, status, "", PageSize, pageIndex,
                                                     out totalCount, out pageCount);

            JsonDictionary.Add("Items", list);
            JsonDictionary.Add("TotalCount", totalCount);
            JsonDictionary.Add("PageCount", pageCount);

            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public void ValidateEnumNullTest()
        {
            IMethod m = new MockMethod();
            var dict = new JsonDictionary { { "name", "test" } };

            // Create the parameter.
            var jsonObj = new KeyValuePair<string, object>("test", dict);
            var p = new ParameterFactory.BaseParameter(jsonObj);
            var inputData = new ParameterCollection();
            var validator = new MethodValidator(m, inputData);

            // Confirm that the method validates enumerations correctly.
            Assert.IsTrue(validator.ValidateEnum(p, "one"));
            Assert.IsTrue(validator.ValidateEnum(p, "two"));
            Assert.IsTrue(validator.ValidateEnum(p, "three"));
            Assert.IsTrue(validator.ValidateEnum(p, "One"));
            Assert.IsTrue(validator.ValidateEnum(p, ""));
        }
        public void DecorateClassSubresourceTest()
        {
            // Create a top and a sub resource.
            var subJson = new JsonDictionary();
            var topJson = new JsonDictionary();
            var topResource = new ResourceV1_0(new KeyValuePair<string, object>("Top", topJson));
            var subResource = new ResourceV1_0(new KeyValuePair<string, object>("Sub", subJson));
            subResource.Parent = topResource;

            var decorator = new StandardResourceNameResourceDecorator();
            var decoratedClass = new CodeTypeDeclaration { Name = "Sub" };
            decorator.DecorateClass(
                subResource, "Sub", decoratedClass, null, ServiceClassName, new IResourceDecorator[0]);

            Assert.AreEqual(1, decoratedClass.Members.Count);
            Assert.IsInstanceOf(typeof(CodeMemberField), decoratedClass.Members[0]);
            var resourceField = (CodeMemberField) decoratedClass.Members[0];
            Assert.AreEqual("Top.Sub", ((CodePrimitiveExpression) resourceField.InitExpression).Value);

            CheckCompile(decoratedClass, false, "Failed To Compile StandardResourceNameResourceDecorator");
        }
        public void DecorateClassSubresourceTest()
        {
            // Create a top and a sub resource.
            var subJson = new JsonDictionary();
            var topJson = new JsonDictionary();
            var factory = ServiceFactory.Get(DiscoveryVersion.Version_1_0);
            var topResource = factory.CreateResource("Top", topJson);
            var subResource = factory.CreateResource("Sub", subJson);
            ((Resource)subResource).Parent = topResource;

            var decorator = new StandardResourceNameResourceDecorator();
            var decoratedClass = new CodeTypeDeclaration { Name = "Sub" };
            decorator.DecorateClass(
                subResource, "Sub", decoratedClass, null, ServiceClassName, new IResourceDecorator[0]);

            Assert.AreEqual(1, decoratedClass.Members.Count);
            Assert.IsInstanceOf(typeof(CodeMemberField), decoratedClass.Members[0]);
            var resourceField = (CodeMemberField) decoratedClass.Members[0];
            Assert.AreEqual("Top.Sub", ((CodePrimitiveExpression) resourceField.InitExpression).Value);

            CheckCompile(decoratedClass, false, "Failed To Compile StandardResourceNameResourceDecorator");
        }
Example #51
0
 public JsonValue ToJson(IJsonContext context) {
     var dict = new JsonDictionary();
     dict.Set("id", SetID);
     dict.Set("url", Uri.ToString());
     dict.Set("title", Title);
     dict.Set("created_by", Author);
     if (Description != null)
         dict.Set("description",Description);
     dict.Set("term_count", TermCount);
     dict.Set("created_date", Created.ToUnixTime());
     dict.Set("modified_date", Modified.ToUnixTime());
     dict["subjects"] = context.ToJson(Subjects);
     dict.Set("visibility", Visibility.ToApiString());
     dict.Set("editable", EditPermissions.ToApiString());
     dict.Set("has_access", HasAccess);
     dict.Set("has_discussion", HasDiscussion);
     dict.Set("lang_terms", TermLanguageCode);
     dict.Set("lang_definitions", DefinitionLanguageCode);
     if (Terms != null)
         dict["terms"] = context.ToJson(Terms);
     return dict;
 }
Example #52
0
        public void SubresourceTest()
        {
            var topJson = new JsonDictionary();
            topJson.Add("resources", new JsonDictionary() { { "Sub", new JsonDictionary() } });

            // Create the resource hierachy and confirm results.
            var topResource = new ResourceV1_0(new KeyValuePair<string, object>("Top", topJson));
            Assert.IsNotNull(topResource.Resources);
            Assert.AreEqual(1, topResource.Resources.Count);
            Assert.AreEqual("Sub", topResource.Resources["Sub"].Name);
            Assert.AreEqual(topResource, topResource.Resources["Sub"].Parent);
        }
        public void SubresourceTest()
        {
            var topJson = new JsonDictionary();
            topJson.Add("resources", new JsonDictionary() { { "Sub", new JsonDictionary() } });

            // Create the resource hierachy and confirm results.
            var topResource = new Resource(ServiceFactory.Default, "Top", topJson);
            Assert.IsNotNull(topResource.Resources);
            Assert.AreEqual(1, topResource.Resources.Count);
            Assert.AreEqual("Sub", topResource.Resources["Sub"].Name);
            Assert.AreEqual(topResource, topResource.Resources["Sub"].Parent);
        }
Example #54
0
        /// <summary>
        /// Creates a new resource for the specified discovery version with the specified name and json dictionary.
        /// </summary>
        internal BaseResource(DiscoveryVersion version, KeyValuePair<string, object> kvp)
        {
            kvp.ThrowIfNull("kvp");
            kvp.Key.ThrowIfNull("kvp");

            DiscoveryVersion = version;
            logger.Debug("Constructing Resource [{0}]", kvp.Key);
            Name = kvp.Key;
            information = kvp.Value as JsonDictionary;
            if (information == null)
            {
                throw new ArgumentException("got no valid dictionary");
            }

            // Initialize subresources.
            if (information.ContainsKey("resources"))
            {
                var resourceJson = (JsonDictionary)information["resources"];
                resources = new Dictionary<string, IResource>();
                foreach (KeyValuePair<string, object> pair in resourceJson)
                {
                    // Create the subresource.
                    var subResource = (BaseResource)CreateResource(pair);
                    subResource.Parent = this;
                    resources.Add(pair.Key, subResource);
                }
            }
        }
Example #55
0
        private static JsonDictionary ParseObject(TokenStream ts)
        {
            // to parse an object, you get the object name, and then parse the value
            JsonToken token = ts.GetNextToken();

            if (token.Type != JsonToken.TokenType.String && token.Type != JsonToken.TokenType.ObjectEnd)
            {
                throw new ArgumentException(
                    "Unable to parse object. Found object " + token +
                    " while looking for property name or object end.");
            }

            JsonDictionary dict = new JsonDictionary();
            if (token.Type != JsonToken.TokenType.ObjectEnd)
            {
                for (JsonToken cur = ts.GetNextToken(); cur != null; cur = ts.GetNextToken())
                {
                    switch (cur.Type)
                    {
                        case JsonToken.TokenType.ObjectEnd:
                            logger.Debug("Found object end");
                            return dict;
                        case JsonToken.TokenType.MemberSeperator:
                            token = ts.GetNextToken();
                            break;
                        case JsonToken.TokenType.NameSeperator:
                            object value = ParseExpression(null, ts);
                            if (dict.ContainsKey(token.Value))
                            {
                                throw new ArgumentException(
                                    "JsonObject contains duplicate definition for [" + token.Value + "]");
                            }
                            dict.Add(token.Value, value);
                            break;
                        default:
                            throw new ArgumentException(
                                "Found invalid Json was expecting } or , or : found " + cur);
                    }
                }
            }
            return dict;
        }
        private void ListAllVm(VMWareVirtualHost virtualHost)
        {
            try
               {
              Log.Info("List All Vm");
              StringBuilder builderjson=new StringBuilder();
              string jsonstring = string.Empty;
              var crap = virtualHost.RunningVirtualMachines;
              if (crap.Count() > 0)
              {
              JsonDictionary<String, Object> result = new JsonDictionary<String, Object>();
              foreach (var machine in crap)
              {
                  Dictionary<string, string> dictos = GetIdOsDetails(machine.PathName);

                  foreach (var dicto in dictos)
                  {
                      result[dicto.Key] = dicto.Value;
                      jsonstring = JsonConvert.SerializeObject(result);

                  }
                  builderjson.Append(jsonstring);

              }

              Console.WriteLine(builderjson.ToString());
              }
              else
              {
              Console.WriteLine("There is no  Vm is Up..");
              }

               }
               catch (Exception ex)
               {

               Log.Info("Failed to List All Vm"+ex);
               }
        }
Example #57
0
 public MethodV1_0(IServiceFactory factory, string name, JsonDictionary dictionary)
     : base(factory, name, dictionary)
 {
 }
Example #58
0
 private IService CreateV1Service()
 {
     var dict = new JsonDictionary();
     dict.Add("name", "TestName");
     dict.Add("version", "v1");
     return new ConcreteClass(dict);
 }
Example #59
0
 public void ParseSchemasEmptyTest()
 {
     JsonDictionary js = new JsonDictionary();
     var dict = BaseService.ParseSchemas(js);
     Assert.AreEqual(0, dict.Count);
 }
Example #60
0
 public ParameterV1_0(IServiceFactory factory, string name, JsonDictionary dictionary)
     : base(factory, name, dictionary) { }