public IAction CreateNewCopy()
        {
            MethodAction a = (MethodAction)Activator.CreateInstance(this.GetType(), Owner);

            a.MemberId    = (UInt32)(Guid.NewGuid().GetHashCode());
            a.Description = this.Description;
            if (string.IsNullOrEmpty(MethodName))
            {
                a.MethodName = "Action" + Guid.NewGuid().GetHashCode().ToString("x");
            }
            else
            {
                if (MethodName.Length > 30)
                {
                    a.MethodName = MethodName.Substring(0, 30) + Guid.NewGuid().GetHashCode().ToString("x");
                }
                else
                {
                    a.MethodName = MethodName + "_" + Guid.NewGuid().GetHashCode().ToString("x");
                }
            }
            if (_returnReceiver != null)
            {
                a._returnReceiver = (IObjectPointer)_returnReceiver.Clone();
            }
            if (_condition != null)
            {
                a._condition = (ExpressionValue)_condition.Clone();
            }
            return(a);
        }
Example #2
0
        public CodeMemberMethod CreateApiFunction(WebApiDescription description, IPoco2Client poco2TsGen, bool stringAsString)
        {
            this.Description    = description;
            this.Poco2TsGen     = poco2TsGen;
            this.StringAsString = stringAsString;

            MethodName = TsCodeGenerationOptions.Instance.CamelCase ? Fonlow.Text.StringExtensions.ToCamelCase(description.ActionDescriptor.ActionName) : description.ActionDescriptor.ActionName;
            if (MethodName.EndsWith("Async"))
            {
                MethodName = MethodName.Substring(0, MethodName.Length - 5);                //HTTP does not care about the server side async.
            }
            ReturnType = description.ResponseDescription?.ResponseType ?? description.ActionDescriptor.ReturnType;

            //create method
            Method = CreateMethodName();

            CreateDocComments();

            switch (description.HttpMethod)
            {
            case "GET":
            case "DELETE":
            case "POST":
            case "PUT":
                RenderImplementation();
                break;

            default:
                Trace.TraceWarning("This HTTP method {0} is not yet supported", description.HttpMethod);
                break;
            }

            return(Method);
        }
Example #3
0
        private void ProcessCallbackBinding()
        {
            // Trying to roughly follow http://msdn.microsoft.com/en-us/library/ms228974(v=vs.110).aspx
            // "Event-based async pattern"

            if (InputObject == null)
            {
                throw new PSArgumentNullException("InputObject", "InputObject may not be null.");
            }

            bool isStatic = false;
            Type targetType;

            if ((_baseObject as Type) != null)
            {
                targetType = (Type)_baseObject;
                isStatic   = true;
                this.WriteVerbose("InputObject is a Type: " + targetType.Name);
            }
            else
            {
                targetType = _baseObject.GetType();
                this.WriteVerbose("InputObject is an instance of " + targetType.Name);
            }

            // Func<T1, Tn..., AsyncCallback, object, IAsyncResult> begin,
            // Func<IAsyncResult, dynamic> end)
            // begin/end?
            if (MethodName.StartsWith("Begin",
                                      StringComparison.OrdinalIgnoreCase))
            {
                WriteVerbose("Method is AsyncCallback Begin/End pairing style.");

                string     verb          = MethodName.Substring(5);
                string     endMethodName = "End" + verb;
                MethodInfo endMethod     = targetType.GetMethod(endMethodName, new[] { typeof(IAsyncResult) });

                if (endMethod == null)
                {
                    throw new PSArgumentException(String.Format(
                                                      "No matching '{0}(IAsyncResult)' method found for APM call '{1}'.",
                                                      endMethodName, MethodName));

                    // TODO: throw proper terminating error
                    //this.ThrowTerminatingError(new ErrorRecord());
                }
                //BindBeginEndStyleMethod(targetType, isStatic);
            }
            else if (MethodName.EndsWith("Async", StringComparison.OrdinalIgnoreCase))
            {
                // determine if EAP or TAP mode call
                string verb = MethodName.Substring(0, MethodName.Length - 5); // e.g. "[Read]Async"

                this.WriteWarning("*Async method handling not implemented, yet.");
            }
            // winrt / task?

            //
        }
Example #4
0
        protected override string GetSourceObjectEventName()
        {
            string eventName = String.Format("{0}Completed", MethodName.Substring(5)); // trim "Begin"

            // subscription is unique per instance/event combo (this might be too restrictive?)
            Guid id = this.GetBindingInfo(_baseObject).Id;

            this.SourceIdentifier = (id + "_" + eventName);

            this.WriteVerbose("GetSourceObjectEventName(): " + this.SourceIdentifier);

            return("Completed"); // fixed-name event for PSPromise
        }
 private bool MatchesMethod(AssemblyItem item)
 {
     if (MethodName == null)
     {
         return(true);
     }
     else if (MethodName.EndsWith('*'))
     {
         return(item.Method.Name.StartsWith(
                    MethodName.Substring(0, MethodName.Length - 1),
                    StringComparison.Ordinal));
     }
     else
     {
         return(string.Equals(item.Method.Name, MethodName, StringComparison.Ordinal));
     }
 }
 protected string GetMethodName()
 {
     return(char.ToLowerInvariant(MethodName.First()) + MethodName.Substring(1));
 }