public void Run(ResponeCode code, FileInfo file, bool fileoption = false) { try { HeaderOption option = HeaderOption.Create(); if (fileoption) { option.AddOption("Content-Type", "multipart/formed-data"); option.AddOption("Content-Disposition", "attachment; filename=" + file.Name); option.AddOption("Length", file.Length.ToString()); } else { option.AddOption("Content-Type", "text/html"); } byte[] header = BuildHeader(code, option); client.Send(header); if (file != null && file.Exists) { byte[] data = GetFile(file); client.Send(data); } } catch (Exception e) { LastException = e; client.Send(BuildHeader(ResponeCode.CODE500)); } finally { client.Close(); } }
public async Task <IActionResult> CalendarView( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "calendarView")] HttpRequest req) { try { var graphClient = GetGraphClient(configuration.GraphV1); var user = req.Query["user"]; var startDateTime = new QueryOption("startDateTime", req.Query["start"]); var endDateTime = new QueryOption("endDateTime", req.Query["end"]); var options = new List <Option> { startDateTime, endDateTime }; if (!string.IsNullOrWhiteSpace(req.Query["timeZone"])) { var timeZone = new HeaderOption("Prefer", $"outlook.timezone=\"{req.Query["timeZone"]}\""); options.Add(timeZone); } var result = await graphClient.Users[user].CalendarView.Request(options).GetAsync(); var events = result.Select(e => e.ToEvent(ChangeType.None, user)).ToList(); return(new OkObjectResult(Result.Ok(events))); } catch (Exception e) { var error = $"{e.Message}\n\r{e.StackTrace}"; log.Error(error); return(new OkObjectResult(Result.Fail <List <Event> >(error))); } }
public IHttpMultiClient AddHeader(Action <HeaderOption> action) { if (Client != null) { throw new Exception("Client已初始化,不能再添加头"); } HeaderOption Option = new HeaderOption(); action(Option); Option.SetHeader(); return(this); }
public AddToAlbumViewModel(long ownerId, long vid) { this._ownerId = ownerId; this._vid = vid; this._myAlbumsOption = new HeaderOption() { ID = AppGlobalStateManager.Current.LoggedInUserId, Name = CommonResources.VideoCatalog_MyAlbums }; this._selectedOption = this._myAlbumsOption; this._headerOptions.Add(this._selectedOption); this._albumsVM = new GenericCollectionViewModel <VKList <VideoAlbum>, AlbumHeader>((ICollectionDataProvider <VKList <VideoAlbum>, AlbumHeader>) this); EventAggregator.Current.Subscribe((object)this); }
private byte[] BuildHeader(ResponeCode code, HeaderOption option = null) { String2 ret = new String2(Encoding.UTF8); if (object.Equals(code, ResponeCode.CODE200)) { ret += "HTTP/1.1 200 OK" + String2.CRLF; } else { ret += "HTTP/1.1 " + ((int)code) + " NG" + String2.CRLF; } if (option != null) { foreach (String key in option.ToResult().Keys) { ret += key + ": " + option.ToResult()[key] + String2.CRLF; } } ret += "Keep-Alive: timeout=15, max=93" + String2.CRLF; ret += "Connection: Keep-Alive" + String2.CRLF + String2.CRLF; return(ret.ToBytes()); }
public async Task GroupDeltaLink() { // Get our first delta page. var groupDeltaCollectionPage = await graphClient.Groups.Delta().Request().GetAsync(); // Go through all of the delta pages so that we can get the delta link on the last page. while (groupDeltaCollectionPage.NextPageRequest != null) { groupDeltaCollectionPage = await groupDeltaCollectionPage.NextPageRequest.GetAsync(); } // At this point we're up to date. groupDeltaCollectionPage now has a deltalink. object deltaLink; // Now let's use the deltalink to make sure there aren't any changes. if (groupDeltaCollectionPage.AdditionalData.TryGetValue(Constants.OdataInstanceAnnotations.DeltaLink, out deltaLink)) { groupDeltaCollectionPage.InitializeNextPageRequest(graphClient, deltaLink.ToString()); groupDeltaCollectionPage = await groupDeltaCollectionPage.NextPageRequest.GetAsync(); // This could be false in case a change has occurred to a group since the last deltapage. Assert.True((groupDeltaCollectionPage.Count == 0), "groupDeltaCollectionPage has unexpected entry."); } Assert.NotNull(deltaLink); // Let's test what happens when we add a group. // Create a group. There can only be a single planner plan per group. var myGroup = new Group(); myGroup.Description = "A temporary group."; myGroup.DisplayName = "Test group"; myGroup.GroupTypes = new List <string>() { "Unified" }; myGroup.MailEnabled = true; myGroup.MailNickname = "BobTestGroup"; myGroup.SecurityEnabled = false; // Call Graph service API to create the new group. var syncdGroup = await graphClient.Groups.Request().AddAsync(myGroup); // Lets add a member to the group. var userToAddToGroup = new User(); userToAddToGroup.Id = "ff1fa027-1a7a-4041-aac7-77bd88af7c9f"; await graphClient.Groups[syncdGroup.Id].Members.References.Request().AddAsync(userToAddToGroup); // Call with the deltalink. We have to wait since there is some latency between the time that the // group is created and the time when the delta is registered. await Task.Delay(10000); groupDeltaCollectionPage.InitializeNextPageRequest(graphClient, deltaLink.ToString()); groupDeltaCollectionPage = await groupDeltaCollectionPage.NextPageRequest.GetAsync(); Assert.True((groupDeltaCollectionPage.Count == 1)); // Clean up the group we created. var headers = new HeaderOption("Content-type", "application/json"); // Need this due to bug. Can't delete without this. await graphClient.Groups[syncdGroup.Id].Request().DeleteAsync(); }
public async Async.Task SchemaExtensionTest() { // Create a schema extension on a contact. // TODO: a tool that creates an object based on a schemaExtension definition. SchemaExtension extensionDefinition = new SchemaExtension() { Description = "This extension correlates a group with a foreign database.", Id = $"crmForeignKey", // Microsoft Graph will prepend 8 chars Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty() { Name = "fid", Type = "Integer" } }, TargetTypes = new List <string>() { "Group" } }; // Create the schema extension. This results in a call to Microsoft Graph. SchemaExtension schemaExtension = await graphClient.SchemaExtensions.Request().AddAsync(extensionDefinition); Assert.NotNull(schemaExtension); Assert.Equal(schemaExtension.Status, "InDevelopment"); Assert.Contains(extensionDefinition.Id, schemaExtension.Id); Assert.NotNull(schemaExtension.Owner); // List all of the schema extensions available to this application. IGraphServiceSchemaExtensionsCollectionPage schemaExtensions = await graphClient.SchemaExtensions.Request().GetAsync(); Assert.True(schemaExtensions.Count > 0); Assert.NotNull(schemaExtensions[0].Properties); Assert.True(schemaExtensions[0].Description.Length > 0); Assert.NotNull(schemaExtensions[0].TargetTypes); Assert.NotNull(schemaExtensions[0].Id); // Get a specific schema extension. SchemaExtension extensionFromGet = await graphClient.SchemaExtensions[schemaExtension.Id].Request().GetAsync(); Assert.NotNull(extensionFromGet); // Add header so we get back a representation of the updated schema extension. List <HeaderOption> headers = new List <HeaderOption>(); HeaderOption preferHeader = new HeaderOption("Prefer", "return=representation"); headers.Add(preferHeader); // Update a specific schema extension. extensionFromGet.Description = "This extension will be deleted"; // Potential bug: state transition from deprecated to available is not working. // Potential bug here as the service is not returning the SchemaExtension on update. Must delete test until this is fixed. 5/30/2017 // SchemaExtension extensionFromUpdate = await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); // Enable or re-write test when we learn expected behavior. //Assert.Equal(extensionFromGet.Status, extensionFromUpdate.Status, "Expected: the patch object status property matches the returned status property; Actual: they don't match."); // Create a group with the schema extension defined earlier. IDictionary <string, object> extensionInstance = new Dictionary <string, object>(); extensionInstance.Add(schemaExtension.Id, new MyDBExtensionClass(123123)); Group group = new Group() { DisplayName = $"Test group - {Guid.NewGuid().ToString()}", Description = "This group was created with a schema extension", MailEnabled = false, MailNickname = "nickname", // silly requirement since this isn't mail enabled. SecurityEnabled = false, GroupTypes = new List <string>() { "Unified" }, AdditionalData = extensionInstance }; await Async.Task.Delay(15000); // It takes some time for the schema extension def to be available for the creation of a group. group = await graphClient.Groups.Request().AddAsync(group); // Delete a specific schema extension. await graphClient.SchemaExtensions[extensionFromGet.Id].Request().DeleteAsync(); try { var deletedSchemaExtension = await graphClient.SchemaExtensions[extensionFromGet.Id].Request().GetAsync(); Assert.False(true, "Expected: ServiceException since the schema extension ws deleted; Actual: the GET on the supposedly deleted schema extension returned successfully."); } catch (ServiceException e) { Assert.Equal(e.StatusCode, System.Net.HttpStatusCode.NotFound); } // Delete the group. try { await graphClient.Groups[group.Id].Request().DeleteAsync(); } catch (ServiceException e) { Assert.False(true, ($"Error: {e.Error.ToString()}")); } }
public NotesController(INoteRepository repository, IOptions <HeaderOption> opt) { _repository = repository; _option = opt.Value; }
public async Async.Task CreateSchemaExtension() { // Create a schema extension on a contact. SchemaExtension extensionPayload = new SchemaExtension() { Description = "This extension correlates a group with a foreign database.", Id = $"crmForeignKey", // Microsoft Graph will prepend 8 chars Properties = new List <ExtensionSchemaProperty>() { new ExtensionSchemaProperty() { Name = "fid", Type = "Integer" } }, TargetTypes = new List <string>() { "Group" } }; // Create the schema extension. This results in a call to Microsoft Graph. SchemaExtension schemaExtension = await graphClient.SchemaExtensions.Request().AddAsync(extensionPayload); Assert.IsNotNull(schemaExtension, "Expected: schemaExtension is not null; Actual: it returned null"); Assert.AreEqual(schemaExtension.Status, "InDevelopment", $"Expected: a new schem extension has a status as InDevelopment; Actual: {schemaExtension.Status}"); StringAssert.Contains(schemaExtension.Id, extensionPayload.Id, "Expected: the payload identifier is contained in the schema extension returned by the service; Actual: it is not returned"); Assert.IsNotNull(schemaExtension.Owner, "Expected: the owner value is set by the service; Actual: it wasn't set by the service."); // List all of the schema extensions available to this application. IGraphServiceSchemaExtensionsCollectionPage schemaExtensions = await graphClient.SchemaExtensions.Request().GetAsync(); Assert.IsTrue(schemaExtensions.Count > 0, "Expected: at least one schema extension; Actual: 0"); Assert.IsNotNull(schemaExtensions[0].Properties, "Expected: the extension properties are set; Actual: extension properties are not set."); Assert.IsTrue(schemaExtensions[0].Description.Length > 0, "Expected: the description has at least one character; Actual: the description was not set"); Assert.IsNotNull(schemaExtensions[0].TargetTypes, "Expected: the extension targets are set; Actual: extension targets are not set."); Assert.IsNotNull(schemaExtensions[0].Id, "Expected: the Id property is set; Actual: Id property is not set."); // Get a specific schema extension. SchemaExtension extensionFromGet = await graphClient.SchemaExtensions[schemaExtension.Id].Request().GetAsync(); Assert.IsNotNull(extensionFromGet, "Expected: returned a schema extension object; Actual: an object wasn't returned."); // Add header so we get back a representation of the updated schema extension. List <HeaderOption> headers = new List <HeaderOption>(); HeaderOption preferHeader = new HeaderOption("Prefer", "return=representation"); headers.Add(preferHeader); // Update a specific schema extension. extensionFromGet.Description = "This extension will be deleted"; // Potential bug: state transition from deprecated to available is not working. // Potential bug here as the service is not returning the SchemaExtension on update. Must delete test until this is fixed. 5/30/2017 // SchemaExtension extensionFromUpdate = await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); await graphClient.SchemaExtensions[extensionFromGet.Id].Request(headers).UpdateAsync(extensionFromGet); // Enable or re-write test when we learn expected behavior. //Assert.AreEqual(extensionFromGet.Status, extensionFromUpdate.Status, "Expected: the patch object status property matches the returned status property; Actual: they don't match."); // Delete a specific scheam extension. await graphClient.SchemaExtensions[extensionFromGet.Id].Request().DeleteAsync(); try { var deletedSchemaExtension = await graphClient.SchemaExtensions[extensionFromGet.Id].Request().GetAsync(); Assert.Fail("Expected: ServiceException since the schema extension ws deleted; Actual: the GET on the supposedly deleted schema extension returned successfully."); } catch (ServiceException e) { Assert.AreEqual(e.StatusCode, System.Net.HttpStatusCode.NotFound, $"Expected: {System.Net.HttpStatusCode.NotFound}; Actual: {e.StatusCode}"); } }