Beispiel #1
0
        public void CanSerializeSimpleClass()
        {
            using (MemoryStream s = new MemoryStream())
            {
                SimpleData data = new SimpleData
                {
                    MyInt    = 10,
                    MyString = "Abc"
                };
                new MultipartFormDataSerializer(typeof(SimpleData)).Serialize(s, data, Encoding.UTF8, "xyzq");

                string expected = @"
--xyzq
Content-Disposition: form-data; name=""MyInt""
Content-Type: text/plain; charset=utf-8

10
--xyzq
Content-Disposition: form-data; name=""MyString""
Content-Type: text/plain; charset=utf-8

Abc
--xyzq--";

                s.Seek(0, SeekOrigin.Begin);
                using (StreamReader r = new StreamReader(s))
                {
                    string result = r.ReadToEnd();
                    Assert.AreEqual(expected, result);
                }
            }
        }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        scrollGallery.SetOnItemOpen((aGo, aData) =>
        {
            aGo.GetComponentInChildren <Button>().onClick.AddListener(() =>
            {
                Debug.Log("OnOpen:" + (aData as SimpleData).number.ToString());
                scrollGallery.Select(aData, true);
            });
        });
        scrollGallery.SetOnItemClose((aGo, aData) =>
        {
            aGo.GetComponentInChildren <Button>().onClick.RemoveAllListeners();
        });
        scrollGallery.SetOnItemRefresh((aGo, aData, isSelected) =>
        {
            Debug.Log("OnRefresh:" + (aData as SimpleData).number + " isSelected:" + isSelected);
            aGo.GetComponentInChildren <Text>().text = "number:" + (aData as SimpleData).number + (isSelected ? "√" : "");
        });

        this.datas = new SimpleData[10];

        for (int i = 0; i < 10; i++)
        {
            datas[i] = new SimpleData {
                number = i
            };
            scrollGallery.Add(datas[i]);
        }
        scrollGallery.Select(datas[1]);
    }
 public SimpleData GetSimple([FromBody] SimpleData data)
 {
     return(new SimpleData()
     {
         Name = data.Name, Year = data.Year + 1
     });
 }
        public async Task <ActionResult> Insert()
        {
            var data = new SimpleData().GetCourses();
            await courseStore.InsertCourses(data);

            return(RedirectToAction(nameof(Index)));
        }
        public void CanSerializeSimpleClassWithEncoding(
            [Values("UTF-8|MyInt=10&MyString=Abc+%c3%86%c3%98%c3%85%5e%c3%bc",
            "Windows-1252|MyInt=10&MyString=Abc+%c6%d8%c5%5e%fc",
            "iso-8859-1|MyInt=10&MyString=Abc+%c6%d8%c5%5e%fc")] string charsetData)
        {
            string[] elements = charsetData.Split('|');
              string charset = elements[0];
              string expected = elements[1];

              using (MemoryStream s = new MemoryStream())
              using (StreamWriter w = new StreamWriter(s))
              {
            SimpleData data = new SimpleData
            {
              MyInt = 10,
              MyString = "Abc ÆØÅ^ü"
            };
            ObjectSerializerSettings settings = new ObjectSerializerSettings { Encoding = Encoding.GetEncoding(charset) };
            new FormUrlEncodingSerializer(typeof(SimpleData)).Serialize(w, data, settings);

            w.Flush();
            s.Seek(0, SeekOrigin.Begin);

            // Must always be written in plain old ASCII
            using (StreamReader r = new StreamReader(s, Encoding.ASCII))
            {
              string result = r.ReadToEnd();
              Assert.AreEqual(expected, result);
            }
              }
        }
Beispiel #6
0
        public void AddJsonDocumentHandler_ShouldServeJsonDocument()
        {
            //---------------Set up test pack-------------------
            var expected = GetRandomString();
            var data     = new SimpleData {
                SomeProperty = expected
            };
            var route = "api/foo";

            using (var server = Create())
            {
                server.AddJsonDocumentHandler(
                    (p, s) => p.Path == "/" + route
                        ? data
                        : null);
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------

                var stringResult = DownloadResultFrom(server, route, null, out string _).ToUTF8String();

                //---------------Test Result -----------------------
                var resultAsObject = JsonConvert.DeserializeObject <SimpleData>(stringResult);
                Assert.IsNotNull(resultAsObject);
                Assert.AreEqual(expected, resultAsObject.SomeProperty);
            }
        }
        public void CanSerializeSimpleClassWithEncoding(
            [Values("UTF-8|MyInt=10&MyString=Abc+%c3%86%c3%98%c3%85%5e%c3%bc",
                    "Windows-1252|MyInt=10&MyString=Abc+%c6%d8%c5%5e%fc",
                    "iso-8859-1|MyInt=10&MyString=Abc+%c6%d8%c5%5e%fc")] string charsetData)
        {
            string[] elements = charsetData.Split('|');
            string   charset  = elements[0];
            string   expected = elements[1];

            using (MemoryStream s = new MemoryStream())
                using (StreamWriter w = new StreamWriter(s))
                {
                    SimpleData data = new SimpleData
                    {
                        MyInt    = 10,
                        MyString = "Abc ÆØÅ^ü"
                    };
                    ObjectSerializerSettings settings = new ObjectSerializerSettings {
                        Encoding = Encoding.GetEncoding(charset)
                    };
                    new FormUrlEncodingSerializer(typeof(SimpleData)).Serialize(w, data, settings);

                    w.Flush();
                    s.Seek(0, SeekOrigin.Begin);

                    // Must always be written in plain old ASCII
                    using (StreamReader r = new StreamReader(s, Encoding.ASCII))
                    {
                        string result = r.ReadToEnd();
                        Assert.AreEqual(expected, result);
                    }
                }
        }
Beispiel #8
0
 protected override void OnReceive(object message)
 {
     if (message is string)
     {
         string stringMessage = (string)message;
         IncrementAndCheck();
     }
     else if (message is int)
     {
         int intMessage = (int)message;
         IncrementAndCheck();
     }
     else if (message is SimpleData)
     {
         SimpleData simpleDataMessage = (SimpleData)message;
         if (simpleDataMessage.Age > 20)
         {
             IncrementAndCheck();
         }
         else
         {
             IncrementAndCheck();
         }
     }
     else
     {
         IncrementAndCheck();
     }
 }
Beispiel #9
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="simpleData"></param>
        /// <returns></returns>
        public Boolean updSimpleData(SimpleData simpleData)
        {
            simpleData.company = account.company;
            int result = commonModel.comUpd <SimpleData>(simpleData);

            return(result > 0);
        }
        public IEnumerator GetCategories(int id)
        {
            WWWForm form = new WWWForm();

            form.AddField("user_id", id);

            using (UnityWebRequest www = UnityWebRequest.Post(BaseURL + "?action=get_categories", form))
            {
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    categories = new List <SimpleData> ();
                    SimpleJSON.JSONNode data = SimpleJSON.JSON.Parse(www.downloadHandler.text);
                    foreach (SimpleJSON.JSONNode message in data["categories"])
                    {
                        SimpleData f = new SimpleData(message ["category_id"].AsInt, message ["label"].Value, message ["description"].Value);
                        categories.Add(f);
                    }
                }
            }
        }
Beispiel #11
0
        public SafeResponse Check([FromBody] SimpleData simpleData)
        {
            try {
                DA.Check();

                if ((simpleData != null) && (!string.IsNullOrEmpty(simpleData.Data)))
                {
                    apiUser = new ApiUser()
                    {
                        User_ID   = 0,
                        PublicKey = string.IsNullOrEmpty(simpleData.PublicKey) ? Globals.key_public : simpleData.PublicKey
                    };
                    using (SafeData sd = Encrypt_Data(simpleData.Data)) {
                        apiResponse = new SafeResponse(sd, CodeStatus.Ok);
                    }
                }
                else
                {
                    apiResponse = new SafeResponse(CodeStatus.Ok);
                }
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 204; // No content - no connection to DataBase
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 418; // I'm teapot
            }

            return(apiResponse);
        }
        public string addSimpleData(string simpleDataJson)
        {
            try
            {
                //创建service层实例
                simpleDataService = new SimpleDataService();
                //处理json
                SimpleData simpleData = FinanceJson.getFinanceJson().toObject <SimpleData>(simpleDataJson);

                if (simpleDataService.newSimpleData(simpleData))
                {
                    return(FinanceResultData.getFinanceResultData().success(200, null, "新增成功"));
                }
                else
                {
                    return(FinanceResultData.getFinanceResultData().fail(500, null, "新增失败"));
                }
            }
            catch (InvalidOperationException ex)
            {
                //身份验证不通过
                return(FinanceResultData.getFinanceResultData().fail(401, null, ex.Message));
            }
            catch (Exception ex)
            {
                //未知的错误
                return(FinanceResultData.getFinanceResultData().fail(500, null, "未知的错误"));
            }
        }
Beispiel #13
0
        public void ThrowExceptionTest1()
        {
            SimpleData data = new SimpleData();
            var        ex1  = Assert.ThrowsException <Exception>(() => data.ThrowException(true));

            Assert.AreEqual(ex1.Message, "YES");
        }
Beispiel #14
0
        private void Chat_Form_Load(object sender, EventArgs e)
        {
            initFont();
            Room_Name.Text = RoomNameProp;
            roomId         = RoomNameProp;
            Debug.WriteLine("CHAT FORM ROOM ID : " + roomId);
            Watcher.roomId = roomId;
            simpleData     = new SimpleData(this);
            connectSocket();
            panel1.AutoScroll = true;
            ChatFormCheck     = true;
            enterRoomCheck.enterRoomformCheck = false;
            powerMode.chatform = this;
            if (Directory.Exists(cloudDirPath))
            {
                Process.Start(cloudDirPath);

                FirstConnectSync(); //채티방 처음 입장 시 업로드, 다운로드, 삭제 동기화

                Watcher.roomId = roomId;
                //Watcher watcher = new Watcher();
                //new Thread(watcher.FolderWatcher).Start();
                Watcher watcher = new Watcher(this);
                watcher.FolderWatcher();
            }
            else
            {
                MessageBox.Show("폴더 경로가 없습니다.");
            }
        }
Beispiel #15
0
 public static void recordParams()
 {
     SimpleData.WriteStringToFile("LeapData.txt", "The swipeMinVeloctiy is :" + swipeMinVelocity + ".");
     SimpleData.WriteStringToFile("LeapData.txt", "The swipeMinDistance is :" + swipeMinDistance + ".");
     SimpleData.WriteStringToFile("LeapData.txt", "The dragVelocity is :" + dragVelocity + ".");
     SimpleData.WriteStringToFile("LeapData.txt", "The grabViewFactor is :" + grabViewFactor + ".");
     SimpleData.WriteStringToFile("LeapData.txt", "The connectTimeLimited is :" + connectTimeLimited + ".");
 }
        public void WhenDataIsNullItIsNotSendAsEmptyString()
        {
            // Arrange
              SimpleData d = new SimpleData { };

              // Act
              CheckSerialization("MyInt=0", d);
        }
 private void sendSimpleMessage(string msg)
 {
     sd                = new SimpleData(this);
     sd.ObjectId       = ObjId;
     sd.AgentInfo      = ScenePrivate.FindAgent(sd.ObjectId)?.AgentInfo;
     sd.SourceObjectId = ObjectPrivate.ObjectId;
     SendToAll(msg, sd);
 }
    private void sendSimpleMessage(string msg)
    {
        SimpleData sd = new SimpleData();

        sd.AgentInfo = AgentName;
        sd.ObjectId  = ComponentID;
        SendToAll(msg, sd);
    }
Beispiel #19
0
 private void sendSimpleMessage(string msg, CollisionData data)
 {
     SimpleData sd = new SimpleData(this);
     sd.AgentInfo = Hitman.AgentInfo;
     sd.ObjectId = data.HitObject.ObjectId;
     sd.SourceObjectId = ObjectPrivate.ObjectId;
     SendToAll(msg, sd);
 }
Beispiel #20
0
 public static SimpleData getInstance()
 {
     if (data == null)
     {
         data = new SimpleData();
     }
     return(data);
 }
    // Init() is where the script is setup and is run when the script starts.
    public override void Init()
    {
        // initialize simple data object to send events to other scripts
        _simpleData = new SimpleData(this);

        // Subscribe to interaction events to do something when the object is clicked.
        InteractionPrompt.Subscribe(OnClick);
    }
Beispiel #22
0
    public SimpleData GenerateSimpleData()
    {
        var returnData = new SimpleData {
            index = global_index++
        };

        createdDatas.Add(returnData);
        return(returnData);
    }
        public void WhenDataIsNullItIsNotSendAsEmptyString()
        {
            // Arrange
            SimpleData d = new SimpleData {
            };

            // Act
            CheckSerialization("MyInt=0", d);
        }
    private void sendSimpleMessage(string msg)
    {
        Log.Write("Sending Msg: " + msg);
        SimpleData sd = new SimpleData(this);

        sd.AgentInfo      = AgentName;
        sd.ObjectId       = ComponentID;
        sd.SourceObjectId = ObjectPrivate.ObjectId;
        SendToAll(msg, sd);
    }
Beispiel #25
0
    private void ExecuteInteraction(InteractionData idata)
    {
        SimpleData sd = new SimpleData(this);

        sd.SourceObjectId = ObjectPrivate.ObjectId;
        sd.AgentInfo      = ScenePrivate.FindAgent(idata.AgentId)?.AgentInfo;
        sd.ObjectId       = sd.AgentInfo != null ? sd.AgentInfo.ObjectId : ObjectId.Invalid;
        //string VoteEvent = "Score" + Button.ToString();
        SendScore(1);
    }
Beispiel #26
0
    private void ExecuteInteraction(InteractionData idata)
    {
        SimpleData sd = new SimpleData(this);

        sd.SourceObjectId = ObjectPrivate.ObjectId;
        sd.AgentInfo      = ScenePrivate.FindAgent(idata.AgentId)?.AgentInfo;
        sd.ObjectId       = sd.AgentInfo != null ? sd.AgentInfo.ObjectId : ObjectId.Invalid;
        SendToAll(EventNames[index], sd);
        index = (index + 1) % EventNames.Count;
    }
Beispiel #27
0
        public void StupidSearchTest()
        {
            SearchAlgorithm algorithm = new SearchAlgorithm();

            int[] numbers = new SimpleData().GetOrderedArray(1000);
            int   number  = 333;
            int   index   = algorithm.BinarySearch(numbers, number);

            Assert.AreEqual(333, index);
        }
Beispiel #28
0
        public void GetOrderedArrayTest()
        {
            SimpleData simpleData = new SimpleData();
            var        result     = simpleData.GetOrderedArray(10);

            Assert.AreEqual(10, result.Length);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, result[i]);
            }
        }
Beispiel #29
0
    private void sendSimpleMessage(string msg, InteractionData data)
    {
        SimpleData sd = new SimpleData(this);

        //SimpleDataExt thisObjectDataExt = new SimpleDataExt(this);
        sd.AgentInfo      = ScenePrivate.FindAgent(data.AgentId)?.AgentInfo;
        sd.ObjectId       = sd.AgentInfo.ObjectId;
        sd.SourceObjectId = ObjectPrivate.ObjectId;
        // assign our data to reflective data field
        SendToAll(msg, sd);
    }
Beispiel #30
0
 public PulseData()
 {
     IPulse        = new SimpleData(Properties.Settings.Default.I, 0x01);
     IIPulse       = new SimpleData(Properties.Settings.Default.II, 0x02);
     IIIPulse      = new SimpleData(Properties.Settings.Default.III, 0x03);
     I_IIDistance  = new SimpleData(Properties.Settings.Default.I_II, 0x04);
     I_IIIDistance = new SimpleData(Properties.Settings.Default.I_III, 0x05);
     Period        = new PeriodData(Properties.Settings.Default.T, 0x06, 0x07);
     Strobe        = new SimpleData(Properties.Settings.Default.St, 0x09);
     StrobePos     = new SimpleData(Properties.Settings.Default.I_St, 0x08);
 }
		public void SoapMethodTest()
		{
			SvcOpDef.AddressDef.RequestMethod = WfServiceRequestMethod.Soap;
			SimpleData paraValue = new SimpleData()
			{
				DateTimeField = DateTime.Now,
				IntField = 1000,
				EnumField = SimpleEnum.S1
			};//StringField = "aaaaaaa",
			InvokeComplexService(paraValue);
		}
Beispiel #32
0
        public void Run2()
        {
            SimpleData simple = new SimpleData();
            var        data   = simple.GetOrderedArray(10);

            simple.Shuffle(data);
            foreach (var item in data)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #33
0
    private void sendSimpleMessage(string msg, InteractionData data)
    {
        SimpleData sd = new SimpleData();

        sd.AgentInfo = ScenePrivate.FindAgent(data.AgentId)?.AgentInfo;
        sd.ObjectId  = sd.AgentInfo.ObjectId;
        SendToAll(msg, sd);

        Wait(TimeSpan.FromMilliseconds((int)OffTimer * 1000));
        SendToAll(msg + "Off", sd);
    }
    public override object Unpack(object ob, object Data)
    {
        if (ob is string == false) throw new System.ArgumentException("Invalid Type");

        object obj = new SimpleData();
        ((SimpleData)obj).Value = float.Parse((string)ob);
        ((SimpleData)Data).Value = ((SimpleData)obj).Value;

        ((SimpleData)Data).Value = ((SimpleData)Data).Value;

        return obj;
    }
        public void TestDosFile()
        {
            var testdata = new SimpleData() {
                Record = "one record only"
            };

            var engine = new DelimitedFileEngine<SimpleData>();
            using (var filename = new TempFileFactory()) {
                String twoRecords = testdata.Record + StringHelper.NewLine + testdata.Record + StringHelper.NewLine;

                ProcessAppend(testdata, engine, filename, twoRecords, "\r\n\r\n", "Dos");
                ProcessAppend(testdata, engine, filename, twoRecords, "\n\n\n", "Unix");
                ProcessAppend(testdata, engine, filename, twoRecords, "\r\r\r", "Macintosh");

                GC.Collect(); //  Clean up the loose file stream from the testing
            }
        }
        private static void ProcessAppend(SimpleData testdata, DelimitedFileEngine<SimpleData> engine, String filename, String twoRecords,
            string LineEnds, string testname)
        {
            using (var fs = new StreamWriter(filename))
                {
                    fs.Write(testdata.Record);
                    fs.Write(LineEnds);  // lots of blanks lines to trim
                    fs.Close();
                }

                engine.AppendToFile(filename, testdata);

                using (var input = new StreamReader(filename))
                {
                    String result = input.ReadToEnd();
                    result.AssertEqualTo<String>(twoRecords, testname + ": Expected two records only on output");
                    input.Close();
                }
        }
        private static void ProcessAppend(SimpleData testdata,
            DelimitedFileEngine<SimpleData> engine,
            String filename,
            String twoRecords,
            string LineEnds,
            string testname)
        {
            using (var fs = new StreamWriter(filename)) {
                fs.Write(testdata.Record);
                fs.Write(LineEnds); // lots of blanks lines to trim
                fs.Close();
            }

            engine.AppendToFile(filename, testdata);

            using (var input = new StreamReader(filename)) {
                String result = input.ReadToEnd();
                Check.That(result).IsEqualTo(twoRecords);
                input.Close();
            }
        }
        public void CanSerializeSimpleClass()
        {
            using (MemoryStream s = new MemoryStream())
              {
            SimpleData data = new SimpleData
            {
              MyInt = 10,
              MyString = "Abc"
            };
            new MultipartFormDataSerializer(typeof(SimpleData)).Serialize(s, data, Encoding.UTF8, "xyzq");

            string expected = @"
            --xyzq
            Content-Disposition: form-data; name=""MyInt""
            Content-Type: text/plain; charset=utf-8

            10
            --xyzq
            Content-Disposition: form-data; name=""MyString""
            Content-Type: text/plain; charset=utf-8

            Abc";

            s.Seek(0, SeekOrigin.Begin);
            using (StreamReader r = new StreamReader(s))
            {
              string result = r.ReadToEnd();
              Assert.AreEqual(expected, result);
            }
              }
        }