public JObject GenerateReport( JObject source, string outgoingNum = "...", string date = "...", string uniqueNum = "", string caseManagement = "", string directorName = "[ДИРЕКТОР]", string coordinatorName = "", string coordinatorPosition = "", string madeByName = "", string madeByPosition = "" ) { var json = new { outgoingNum = outgoingNum, date = date, uniqueNum = uniqueNum, caseManagement = caseManagement, paragraph1 = this.GetParagraph1(source.Get<JObject>("paragraph1")), paragraph2 = this.GetParagraph2(source.Get<JObject>("paragraph2")), paragraph3 = this.GetParagraph3(source.Get<JObject>("paragraph3")), paragraph4 = this.GetParagraph4(source.Get<JObject>("paragraph4")), paragraph6 = this.GetParagraph6(source.Get<JObject>("paragraph6")), paragraph7 = this.GetParagraph7(source.Get<JObject>("paragraph7")), paragraph8 = this.GetParagraph8(source.Get<JObject>("paragraph8")), director = new { name = directorName }, coordinators = new object[] { new { name = coordinatorName, position = coordinatorPosition } }, madeBy = new { name = madeByName, position = madeByPosition } }; return JObject.FromObject(json); }
public JObject GenerateNote( JObject source, string outgoingNum = "...", string date = "...", string secretaryName = "[СЕКРЕТАР]", string secretaryPosition = "/Определен със Заповед № .................../", string coordinatorName = "", string coordinatorPosition = "", string madeByName = "", string madeByPosition = "" ) { var json = new { outgoingNum = outgoingNum, date = date, paragraph1 = this.GetParagraph1(source.Get<JObject>("paragraph1")), paragraph2 = this.GetParagraph2(source.Get<JObject>("paragraph2")), paragraph3 = this.GetParagraph3(source.Get<JObject>("paragraph3")), paragraph4 = this.GetParagraph4(source.Get<JObject>("paragraph4")), paragraph6 = this.GetParagraph6(source.Get<JObject>("paragraph6")), paragraph7 = this.GetParagraph7(source.Get<JObject>("paragraph7")), paragraph8 = this.GetParagraph8(source.Get<JObject>("paragraph8")), secretary = new { name = secretaryName, position = secretaryPosition }, coordinators = new object[] { new { name = coordinatorName, position = coordinatorPosition } }, madeBy = new { name = madeByName, position = madeByPosition } }; return JObject.FromObject(json); }
private ServiceConfiguration CreateServiceConfiguration(JObject jConfig) { var configuration = ServiceConfiguration.CreateSilently( jConfig.Get("Name"), jConfig.Get("BaseUri"), _navigationService, _invokerFactory); var actionGroups = jConfig.GetJArray("ActionGroups").Select(j => CreateActionGroup(j, configuration)); configuration.ActionGroups.AddRange(actionGroups); return configuration; }
/// <summary> /// Get a uri fragment representing the resource corresponding to the /// given instance in the table. /// </summary> /// <param name="tableName">The name of the table.</param> /// <param name="instance">The instance.</param> /// <returns>A URI fragment representing the resource.</returns> private static string GetUriFragment(string tableName, JObject instance) { Debug.Assert(!string.IsNullOrEmpty(tableName), "tableName should not be null or empty!"); // Get the value of the object (as a primitive JSON type) object id = null; if (!instance.Get(IdPropertyName).TryConvert(out id) || id == null) { throw new ArgumentException( string.Format( CultureInfo.InvariantCulture, Resources.IdNotFoundExceptionMessage, IdPropertyName), "instance"); } return GetUriFragment(tableName, id); }
/// <summary> /// Insert a new object into a table. /// </summary> /// <param name="instance"> /// The instance to insert into the table. /// </param> /// <returns> /// A task that will complete when the insert finishes. /// </returns> internal async Task<JToken> SendInsertAsync(JObject instance) { if (instance == null) { throw new ArgumentNullException("instance"); } // Make sure the instance doesn't have its ID set for an insertion if (instance.Get(IdPropertyName) != null) { throw new ArgumentException( string.Format( CultureInfo.InvariantCulture, Resources.CannotInsertWithExistingIdMessage, IdPropertyName), "instance"); } string url = GetUriFragment(this.TableName); JToken response = await this.MobileServiceClient.RequestAsync("POST", url, instance); JToken patched = Patch(instance, response); return patched; }
public void TrySet() { JObject obj = null; Assert.IsFalse(obj.TrySet("fail", null)); obj = new JObject(); Assert.IsTrue(obj.TrySet("x", null)); Assert.IsTrue(obj.Get("x").IsNull()); Assert.IsTrue(obj.TrySet("x", true)); Assert.AreEqual(true, obj.Get("x").AsBool()); Assert.IsTrue(obj.TrySet("x", 1)); Assert.AreEqual(1.0, obj.Get("x").AsNumber()); Assert.IsTrue(obj.TrySet("x", 1.0)); Assert.AreEqual(1.0, obj.Get("x").AsNumber()); Assert.IsTrue(obj.TrySet("x", 1.0f)); Assert.AreEqual(1.0, obj.Get("x").AsNumber()); Assert.IsTrue(obj.TrySet("x", 'x')); Assert.AreEqual("x", obj.Get("x").AsString()); Assert.IsTrue(obj.TrySet("x", "abc")); Assert.AreEqual("abc", obj.Get("x").AsString()); DateTime now = DateTime.Now; Assert.IsTrue(obj.TrySet("x", now)); Assert.AreEqual( now.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK", CultureInfo.InvariantCulture), obj.Get("x").AsString()); DateTimeOffset offset = DateTimeOffset.Now; Assert.IsTrue(obj.TrySet("x", offset)); Assert.AreEqual( offset.DateTime.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK", CultureInfo.InvariantCulture), obj.Get("x").AsString()); Assert.IsFalse(obj.TrySet("x", new Uri("http://www.microsoft.com"))); }
public void Set() { JObject value = null; value.Set("silent", "fail"); value = new JObject(); value.Set("b", true); Assert.AreEqual(true, value.Get("b").AsBool()); value.Set("c", 12); Assert.AreEqual(12, value.Get("c").AsInteger()); value.Set("d", 12.2); Assert.AreEqual(12.2, value.Get("d").AsNumber()); Assert.AreEqual(12, value.Get("d").AsInteger()); value.Set("e", "abc"); Assert.AreEqual("abc", value.Get("e").AsString()); value.Set("f", new JObject()); Assert.IsNotNull(value.Get("f")); }
public async Task InsertAsync() { string appUrl = "http://www.test.com"; string appKey = "secret..."; string collection = "tests"; TestServiceFilter hijack = new TestServiceFilter(); MobileServiceClient service = new MobileServiceClient(appUrl, appKey) .WithFilter(hijack); JObject obj = new JObject().Set("value", "new") as JObject; hijack.Response.Content = new JObject().Set("id", 12).Set("value", "new").ToString(); await service.GetTable(collection).InsertAsync(obj); Assert.AreEqual(12, obj.Get("id").AsInteger()); Assert.Contains(hijack.Request.Uri.ToString(), collection); ThrowsAsync<ArgumentNullException>( async () => await service.GetTable(collection).InsertAsync(null)); // Verify we throw if ID is set on both JSON and strongly typed // instances ThrowsAsync<ArgumentException>( async () => await service.GetTable(collection).InsertAsync( new JObject().Set("id", 15) as JObject)); ThrowsAsync<ArgumentException>( async () => await service.GetTable<Person>().InsertAsync( new Person() { Id = 15 })); }
private object GetParagraph8(JObject paragraph8) { if (paragraph8 == null) { return null; } return new { additionalInfo = new { text = paragraph8.Get<string>("additionalInfo") } }; }
private object GetParagraph6(JObject paragraph6) { if (paragraph6 == null) { return null; } var table1Text = paragraph6.Get<string>("deadline.table1.findings"); var table2Text = paragraph6.Get<string>("deadline.table2.findings"); if (string.IsNullOrEmpty(table1Text) && string.IsNullOrEmpty(table2Text)) { return null; } return new { deadline = new { table1 = string.IsNullOrEmpty(table1Text) ? null : new { findings = table1Text }, table2 = string.IsNullOrEmpty(table2Text) ? null : new { findings = table2Text } } }; }
private object GetParagraph4(JObject paragraph4) { if (paragraph4 == null) { return null; } var techniqueText = paragraph4.Get<string>("technique.table1.findings"); if (string.IsNullOrEmpty(techniqueText)) { return null; } return new { technique = new { findings = techniqueText } }; }
private object GetParagraph3(JObject paragraph3) { if (paragraph3 == null) { return null; } var decisionText = paragraph3.Get<string>("decision.table1.findings"); if (string.IsNullOrEmpty(decisionText)) { return null; } return new { decision = new { findings = decisionText } }; }
private object GetParagraph2(JObject paragraph2) { if (paragraph2 == null) { return null; } var notice = this.GetNotice(paragraph2.Get<JObject>("notice")); if (notice == null) { return null; } return new { notice = notice }; }
private object GetParagraph1(JObject paragraph1) { var emplJObj = paragraph1 == null ? new JObject() : paragraph1.Get<JObject>("employer.table1"); var procJObj = paragraph1 == null ? new JObject() : paragraph1.Get<JObject>("proc"); return new { employer = this.GetEmployer(emplJObj), procedure = this.GetProcedure(procJObj) }; }
private ActionGroup CreateActionGroup(JObject jActionGroup, ServiceConfiguration configuration) { var actionGroup = ActionGroup.CreateSilently(jActionGroup.Get("Name"), configuration, _navigationService); actionGroup.Actions.AddRange(jActionGroup.GetJArray("Actions").Select(j => CreateAction(j, configuration))); return actionGroup; }
private ServiceAction CreateAction(JObject jAction, ServiceConfiguration configuration) { return ServiceAction.CreateSilently( jAction.Get("Name"), jAction.Get("UriPath"), jAction.Get("Method"), jAction.Get("Body"), jAction.Get("MediaType"), () => configuration.BaseUri); }
public void Get() { JObject obj = null; Assert.IsNull(obj.Get("fail")); obj = new JObject() .Set("a", "apple") .Set("b", "banana") .Set("c", "cherry") as JObject; Assert.AreEqual("apple", obj.Get("a").AsString()); Assert.AreEqual("banana", obj.Get("b").AsString()); Assert.AreEqual("cherry", obj.Get("c").AsString()); Assert.IsNull(obj.Get("d")); }
public async Task UpdateAsync() { string appUrl = "http://www.test.com"; string appKey = "secret..."; string collection = "tests"; TestServiceFilter hijack = new TestServiceFilter(); MobileServiceClient service = new MobileServiceClient(appUrl, appKey) .WithFilter(hijack); JObject obj = new JObject().Set("id", 12).Set("value", "new") as JObject; hijack.Response.Content = new JObject() .Set("id", 12) .Set("value", "new") .Set("other", "123") .ToString(); IMobileServiceTable table = service.GetTable(collection); await table.UpdateAsync(obj); Assert.AreEqual("123", obj.Get("other").AsString()); Assert.Contains(hijack.Request.Uri.ToString(), collection); ThrowsAsync<ArgumentNullException>(async () => await table.UpdateAsync(null)); ThrowsAsync<ArgumentException>(async () => await table.UpdateAsync(new JObject())); }
private object GetNotice(JObject notice) { string conclusionText = notice.Get<string>("table1.findings"), orderSubjText = notice.Get<string>("table2.findings"), quantityVolumeText = notice.Get<string>("table3.findings"), deadlineText = notice.Get<string>("table4.findings"), depositsAndGuaranteeText = notice.Get<string>("table5.findings"), procurementConditionsText = notice.Get<string>("table6.findings"), economicalOpText = notice.Get<string>("table7.findings"), economicalAndFinancialOppText = notice.Get<string>("table8.findings"), technicalOppText = notice.Get<string>("table9.findings"), othersText = notice.Get<string>("table10.findings"), procedureText = notice.Get<string>("table11.findings"), criteriaAssignmentText = notice.Get<string>("table12.findings"), administrativeInfoText = notice.Get<string>("table13.findings"), appealProcText = notice.Get<string>("table14.findings"), appendixBText = notice.Get<string>("table15.findings"); if (string.IsNullOrEmpty(conclusionText) && string.IsNullOrEmpty(orderSubjText) && string.IsNullOrEmpty(quantityVolumeText) && string.IsNullOrEmpty(deadlineText) && string.IsNullOrEmpty(depositsAndGuaranteeText) && string.IsNullOrEmpty(procurementConditionsText) && string.IsNullOrEmpty(economicalOpText) && string.IsNullOrEmpty(economicalAndFinancialOppText) && string.IsNullOrEmpty(technicalOppText) && string.IsNullOrEmpty(othersText) && string.IsNullOrEmpty(procedureText) && string.IsNullOrEmpty(criteriaAssignmentText) && string.IsNullOrEmpty(administrativeInfoText) && string.IsNullOrEmpty(appealProcText) && string.IsNullOrEmpty(appendixBText)) { return null; } return new { conclusion = string.IsNullOrEmpty(conclusionText) ? null : new { findings = conclusionText }, orderSubj = string.IsNullOrEmpty(orderSubjText) ? null : new { findings = orderSubjText }, quantityVolume = string.IsNullOrEmpty(quantityVolumeText) ? null : new { findings = quantityVolumeText }, deadline = string.IsNullOrEmpty(deadlineText) ? null : new { findings = deadlineText }, depositsAndGuarantee = string.IsNullOrEmpty(depositsAndGuaranteeText) ? null : new { findings = depositsAndGuaranteeText }, procurementConditions = string.IsNullOrEmpty(procurementConditionsText) ? null : new { findings = procurementConditionsText }, economicalOp = string.IsNullOrEmpty(economicalOpText) ? null : new { findings = economicalOpText }, economicalAndFinancialOpp = string.IsNullOrEmpty(economicalAndFinancialOppText) ? null : new { findings = economicalAndFinancialOppText }, technicalOpp = string.IsNullOrEmpty(technicalOppText) ? null : new { findings = technicalOppText }, others = string.IsNullOrEmpty(othersText) ? null : new { findings = othersText }, procedure = string.IsNullOrEmpty(procedureText) ? null : new { findings = procedureText }, criteriaAssignment = string.IsNullOrEmpty(criteriaAssignmentText) ? null : new { findings = procedureText }, administrativeInfo = string.IsNullOrEmpty(administrativeInfoText) ? null : new { findings = administrativeInfoText }, appealProc = string.IsNullOrEmpty(appealProcText) ? null : new { findings = appealProcText }, appendixB = string.IsNullOrEmpty(appendixBText) ? null : new { findings = appendixBText } }; }