/// <summary> /// Gets operation name. /// This method will be a little faster than <see cref="Enum.ToString()"/> /// </summary> /// <param name="operation">Operation of Webex Teams.</param> /// <returns>Name of the operation.</returns> public static string GetOperationName(TeamsOperation operation) { string name; // This will be a tiny little bit faster than refrection base operation.ToString(). switch (operation) { case TeamsOperation.Unknown: name = "Unknown"; break; case TeamsOperation.Create: name = "Create"; break; case TeamsOperation.Get: name = "Get"; break; case TeamsOperation.List: name = "List"; break; case TeamsOperation.Update: name = "Update"; break; case TeamsOperation.Delete: name = "Delete"; break; case TeamsOperation.GetHeader: name = "GetHeader"; break; default: name = operation.ToString(); break; } return(name); }
/// <summary> /// Parse the request into <see cref="TeamsResourceOperation"/>. /// </summary> /// <returns><see cref="TeamsResourceOperation"/> of the result.</returns> public TeamsResourceOperation ParseResourceOperation() { TeamsResource resource = TeamsResource.Unknown; TeamsOperation operation = TeamsOperation.Unknown; if (this.RequestInfo != null) { var method = this.RequestInfo.HttpMethod; if (method != null) { if (method == HttpMethod.Post) { operation = TeamsOperation.Create; } else if (method == HttpMethod.Get) { operation = TeamsOperation.Get; } else if (method == HttpMethod.Put) { operation = TeamsOperation.Update; } else if (method == HttpMethod.Delete) { operation = TeamsOperation.Delete; } else if (method == HttpMethod.Head) { operation = TeamsOperation.GetHeader; } } string path = this.RequestInfo.Uri?.AbsolutePath; if (!String.IsNullOrEmpty(path)) { foreach (var item in PATH_AND_RESOURCES) { if (path.StartsWith(item.Path)) { resource = item.Resouce; if (resource == TeamsResource.AccessToken && operation == TeamsOperation.Create) { operation = TeamsOperation.Get; } else if (operation == TeamsOperation.Get && path.EndsWith(item.Path)) { operation = TeamsOperation.List; } break; } } } if (resource == TeamsResource.FileData && operation == TeamsOperation.GetHeader) { operation = TeamsOperation.Get; resource = TeamsResource.FileInfo; } } return(new TeamsResourceOperation(resource, operation)); }
/// <summary> /// Creates TeamsResourceOperation. /// </summary> /// <param name="resource">Resouce of Webex Teams.</param> /// <param name="operation">Operation of Webex Teams.</param> internal TeamsResourceOperation(TeamsResource resource, TeamsOperation operation) { this.Resource = resource; this.Operation = operation; }