コード例 #1
0
        public override string Represent()
        {
            string ret = $"{Delimiter.ToString()}";

            ret += ValueLoop(LocalParameters.Cast <object>().ToList());
            return(ret);
        }
コード例 #2
0
        protected void AddParameter(object value)
        {
            string parameter = $"@val_{ParameterCount++}";

            Parameters.Add(parameter, value);
            LocalParameters.Add(parameter);
        }
コード例 #3
0
        /// <summary>
        /// Calculates the args to be passed to the "next method".
        /// </summary>
        /// <param name="nextLink">The arg to be passed in the "next link" param.</param>
        /// <returns>The params string, e.g. "ctx, foo, nextLink".</returns>
        public string NextMethodInvocationParameters(string nextLink)
        {
            // some next methods take the same params as the "list initial" method plus
            // the next link param.  so if the param counts match assume this is the case.
            // to date, the only place where this appears is in the autorest tests.
            if (NextMethod.LocalParameters.Count() == LocalParameters.Count() + 1)
            {
                return($"{HelperInvocationParameters()}, {nextLink}");
            }

            // attempt to match our local params to that of the next method.
            // by convention ctx is always the first parameter.
            // NOTE: the context param is implicit, i.e. it isn't part of the code model
            var invocationParams = new List <string> {
                "ctx"
            };

            // short-circuit simple case, if the next method takes
            // one parameter then it can only be nextLink
            if (NextMethod.LocalParameters.Count() == 1)
            {
                invocationParams.Add(nextLink);
            }
            else
            {
                // create param lists so we can walk them by ordinal
                var myMethodParams   = LocalParameters.ToList();
                var nextMethodParams = NextMethod.LocalParameters.ToList();

                for (int i = 0; i < nextMethodParams.Count; ++i)
                {
                    if (nextMethodParams[i].Name.EqualsIgnoreCase("nextlink"))
                    {
                        invocationParams.Add(nextLink);
                    }
                    else if (i < myMethodParams.Count && ParameterGo.Match(myMethodParams[i], nextMethodParams[i]))
                    {
                        invocationParams.Add(myMethodParams[i].Name);
                    }
                    else
                    {
                        // try to find a match in our local params
                        var param = myMethodParams
                                    .Where(p => ParameterGo.Match(p, nextMethodParams[i]))
                                    .FirstOrDefault();

                        if (param == null)
                        {
                            throw new Exception("failed to find a matching local parameter");
                        }

                        invocationParams.Add(param.Name);
                    }
                }
            }

            return(string.Join(", ", invocationParams));
        }
コード例 #4
0
        /// <summary>
        /// Get the invocation args for an invocation with an async method
        /// </summary>
        public string GetAsyncMethodInvocationArgs(string customHeaderReference)
        {
            List <string> invocationParams = new List <string>();

            LocalParameters.ForEach(p => invocationParams.Add(p.Name));
            invocationParams.Add(customHeaderReference);
            invocationParams.Add("cancellationToken");
            return(string.Join(", ", invocationParams));
        }
コード例 #5
0
        private void BuildOptionsParameterTemplateModel()
        {
            CompositeType optionsType;

            optionsType = new CompositeType
            {
                Name           = "options",
                SerializedName = "options",
                Documentation  = "Optional Parameters."
            };
            var optionsParmeter = new Parameter
            {
                Name           = "options",
                SerializedName = "options",
                IsRequired     = false,
                Documentation  = "Optional Parameters.",
                Location       = ParameterLocation.None,
                Type           = optionsType
            };

            IEnumerable <ParameterTemplateModel> optionalParameters = LocalParameters.Where(p => !p.IsRequired);

            foreach (ParameterTemplateModel parameter in optionalParameters)
            {
                Property optionalProperty = new Property
                {
                    IsReadOnly     = false,
                    Name           = parameter.Name,
                    IsRequired     = parameter.IsRequired,
                    DefaultValue   = parameter.DefaultValue,
                    Documentation  = parameter.Documentation,
                    Type           = parameter.Type,
                    SerializedName = parameter.SerializedName
                };
                parameter.Constraints.ToList().ForEach(x => optionalProperty.Constraints.Add(x.Key, x.Value));
                parameter.Extensions.ToList().ForEach(x => optionalProperty.Extensions.Add(x.Key, x.Value));
                ((CompositeType)optionsParmeter.Type).Properties.Add(optionalProperty);
            }

            //Adding customHeaders to the options object
            Property customHeaders = new Property
            {
                IsReadOnly     = false,
                Name           = "customHeaders",
                IsRequired     = false,
                Documentation  = "Headers that will be added to the request",
                Type           = new PrimaryType(KnownPrimaryType.Object),
                SerializedName = "customHeaders"
            };

            ((CompositeType)optionsParmeter.Type).Properties.Add(customHeaders);
            OptionsParameterTemplateModel = new ParameterTemplateModel(optionsParmeter);
        }
コード例 #6
0
        /// <summary>
        /// Generate the method parameter declarations for a method, using TypeScript declaration syntax
        /// <param name="includeOptions">whether the ServiceClientOptions parameter should be included</param>
        /// <param name="isOptionsOptional">whether the ServiceClientOptions parameter should be optional</param>
        /// </summary>
        public string MethodParameterDeclarationTS(bool includeOptions, bool isOptionsOptional = true)
        {
            StringBuilder declarations = new StringBuilder();

            bool first = true;
            IEnumerable <ParameterTS> requiredParameters = LocalParameters.Where(p => p.IsRequired);

            foreach (var parameter in requiredParameters)
            {
                if (!first)
                {
                    declarations.Append(", ");
                }

                declarations.Append(parameter.Name);
                declarations.Append(": ");

                // For date/datetime parameters, use a union type to reflect that they can be passed as a JS Date or a string.
                var type = parameter.ModelType;
                declarations.Append(ProvideParameterType(type));

                first = false;
            }

            if (includeOptions)
            {
                if (!first)
                {
                    declarations.Append(", ");
                }
                if (isOptionsOptional)
                {
                    declarations.Append("options?: ");
                }
                else
                {
                    declarations.Append("options: ");
                }
                if (OptionsParameterModelType.Name.EqualsIgnoreCase("RequestOptionsBase"))
                {
                    declarations.Append("msRest.RequestOptionsBase");
                }
                else
                {
                    declarations.AppendFormat("Models.{0}", OptionsParameterModelType.Name);
                }
            }

            return(declarations.ToString());
        }
コード例 #7
0
ファイル: InValueSyntax.cs プロジェクト: dhq-boiler/Sunctum
        public override string Represent()
        {
            var ret = $"{Delimiter.ToString()}";

            foreach (var parameter in LocalParameters)
            {
                ret += $"{parameter.ToString()}";
                if (!LocalParameters.Last().Equals(parameter))
                {
                    ret += ", ";
                }
            }
            return(ret);
        }
コード例 #8
0
        /// <summary>
        /// Generate the method parameter declaration.
        /// </summary>
        /// <param name="includePkgName">Pass true if the type name should include the package prefix.  Defaults to false.</param>
        public string MethodParametersSignature(bool includePkgName = false)
        {
            var declarations = new List <string> {
                "ctx context.Context"
            };

            LocalParameters
            .ForEach(p => declarations.Add(string.Format(
                                               p.IsRequired || p.ModelType.CanBeEmpty()
                                                        ? "{0} {1}"
                                                        : "{0} *{1}", p.Name, p.ModelType.HasInterface()
                                                            ? p.ModelType.GetInterfaceName(includePkgName)
                                                            : ParameterTypeSig(p.ModelType, includePkgName))));
            return(string.Join(", ", declarations));
        }
コード例 #9
0
        /// <summary>
        /// Gets Get method invocation arguments for Long Running Operations.
        /// </summary>
        /// <param name="getMethod">Get method.</param>
        /// <returns>Invocation arguments.</returns>
        public string GetMethodInvocationArgs(Method getMethod)
        {
            if (getMethod == null)
            {
                throw new ArgumentNullException("getMethod");
            }

            var invocationParams = new List <string>();

            getMethod.Parameters
            .Where(p => LocalParameters.Any(lp => lp.Name == p.Name))
            .ForEach(p => invocationParams.Add(string.Format(CultureInfo.InvariantCulture, "{0}: {0}", p.Name)));
            invocationParams.Add("customHeaders: customHeaders");
            invocationParams.Add("cancellationToken: cancellationToken");
            return(string.Join(", ", invocationParams));
        }
コード例 #10
0
 private void buttonSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         this.Close();
         LocalParameters.username = txtBoxName.Text;
         PDFPrinter pdfPrint = new PDFPrinter();
         pdfPrint.PrintPDF();
         localCon.LocalAddRecord();
         LocalParameters.RestoreParameters();
         LogWriter.LogWrite("Added to SQLite DB.");
     }
     catch (Exception g)
     {
         MessageBox.Show(g.Message);
         LogWriter.LogWrite(g.ToString());
     }
 }
コード例 #11
0
        /// <summary>
        /// Generate the method parameter declaration for sync methods and extensions
        /// </summary>
        /// <param name="addCustomHeaderParameters">If true add the customHeader to the parameters</param>
        /// <returns>Generated string of parameters</returns>
        public virtual string GetSyncMethodParameterDeclaration(bool addCustomHeaderParameters)
        {
            var declarations = new List <string>();

            foreach (var parameter in LocalParameters.Where(x => x.Location != ParameterLocation.Header))
            {
                var format = (parameter.IsRequired ? "{0} {1}" : "{0} {1} = {2}");

                var defaultValue = $"default({parameter.ModelTypeName})";
                if (!string.IsNullOrEmpty(parameter.DefaultValue) && parameter.ModelType is PrimaryType)
                {
                    defaultValue = parameter.DefaultValue;
                }
                declarations.Add(string.Format(CultureInfo.InvariantCulture,
                                               format, parameter.ModelTypeName, parameter.Name, defaultValue));
            }

            return(string.Join(", ", declarations));
        }
コード例 #12
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    foreach (var relay in Relay)
                    {
                        relay.Dispose();
                    }
                    Relay.Clear();
                    Relay = null;
                    Parameters.Clear();
                    Parameters = null;
                    LocalParameters.Clear();
                    LocalParameters = null;
                }

                _disposedValue = true;
            }
        }
コード例 #13
0
        /// <summary>
        /// Generate the method parameter declarations for a method, using TypeScript declaration syntax
        /// <param name="includeOptions">whether the ServiceClientOptions parameter should be included</param>
        /// <param name="isOptionsOptional">whether the ServiceClientOptions parameter should be optional</param>
        /// </summary>
        public string MethodParameterDeclarationTS(bool includeOptions, bool isOptionsOptional = true)
        {
            TSBuilder       builder       = new TSBuilder();
            TSParameterList parameterList = new TSParameterList(builder);

            parameterList.Parameters(LocalParameters.Where(p => p.IsRequired).Select(AutoRestParameterToTSParameter));

            if (includeOptions)
            {
                string optionsParameterType;
                if (OptionsParameterModelType.Name.EqualsIgnoreCase("RequestOptionsBase"))
                {
                    optionsParameterType = "msRest.RequestOptionsBase";
                }
                else
                {
                    optionsParameterType = $"Models.{OptionsParameterModelType.Name}";
                }
                parameterList.Parameter("options", optionsParameterType, isOptionsOptional);
            }

            return(builder.ToString());
        }
コード例 #14
0
 public override string Represent()
 {
     return($"= {LocalParameters.First()}");
 }
コード例 #15
0
        /// <summary>
        /// Generate the method parameter declarations for a method, using TypeScript declaration syntax
        /// <param name="includeOptions">whether the ServiceClientOptions parameter should be included</param>
        /// </summary>
        public string MethodParameterDeclarationTS(bool includeOptions)
        {
            StringBuilder declarations = new StringBuilder();

            bool first = true;
            IEnumerable <ParameterTemplateModel> requiredParameters = LocalParameters.Where(p => p.IsRequired);

            foreach (var parameter in requiredParameters)
            {
                if (!first)
                {
                    declarations.Append(", ");
                }

                declarations.Append(parameter.Name);
                declarations.Append(": ");

                // For date/datetime parameters, use a union type to reflect that they can be passed as a JS Date or a string.
                var type = parameter.Type;
                if (type == PrimaryType.Date || type == PrimaryType.DateTime)
                {
                    declarations.Append("Date|string");
                }
                else
                {
                    declarations.Append(type.TSType(false));
                }

                first = false;
            }

            if (includeOptions)
            {
                if (!first)
                {
                    declarations.Append(", ");
                }
                declarations.Append("options: { ");
                var optionalParameters = ((CompositeType)OptionsParameterTemplateModel.Type).Properties;
                for (int i = 0; i < optionalParameters.Count; i++)
                {
                    if (i != 0)
                    {
                        declarations.Append(", ");
                    }
                    declarations.Append(optionalParameters[i].Name);
                    declarations.Append("? : ");
                    if (optionalParameters[i].Name.Equals("customHeaders", StringComparison.OrdinalIgnoreCase))
                    {
                        declarations.Append("{ [headerName: string]: string; }");
                    }
                    else
                    {
                        declarations.Append(optionalParameters[i].Type.TSType(false));
                    }
                }
                declarations.Append(" }");
            }

            return(declarations.ToString());
        }
コード例 #16
0
        private void btOk_Click(object sender, EventArgs e)
        {
            if (tbLogin.Text == "" || tbPassword.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("Имя пользователя и пароль должны быть заполнены.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("login", tbLogin.Text);

            string encrypted_data;

            try
            {
                encrypted_data = (string)DBFunctions.ReadScalarFromDB("SELECT encrypted_credentials FROM auth_user WHERE login = @login", parameters);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Передайте администратору следующее:" + Environment.NewLine + ex.Message, "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            if (encrypted_data == null)
            {
                System.Windows.Forms.MessageBox.Show("Вход не удался.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                tbPassword.Text = "";
                tbPassword.Focus();
                return;
            }

            string credentials;

            try
            {
                credentials = Encryption.Decrypt(encrypted_data, tbPassword.Text);
            } catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show("Вход не удался.", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                tbPassword.Text = "";
                tbPassword.Focus();
                return;
            }

            string[] cred_array = credentials.Split('%');

            DBFunctions.login    = cred_array[0];
            DBFunctions.password = cred_array[1];

            DBFunctions.login_from_parameters = false;
            DBFunctions.Init();

            if (!DBFunctions.TestConnecion())
            {
                DBFunctions.login = DBFunctions.password = "";
                DBFunctions.login_from_parameters = true;
                DBFunctions.Init();
                System.Windows.Forms.MessageBox.Show("Вход прошел удачно, но не удается установить соединение с БД. Обратитесь к администратору", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            try
            {
                AuthModule.user_id = (int)DBFunctions.ReadScalarFromDB("SELECT id FROM auth_user WHERE login = @login", parameters);
                object ob_rigths = DBFunctions.ReadScalarFromDB("SELECT rights FROM auth_user LEFT JOIN auth_roles ON role_id = auth_roles.id WHERE login = @login", parameters);
                if (ob_rigths != DBNull.Value)
                {
                    AuthModule.rights.Deserialize((string)ob_rigths);
                }
                else
                {
                    AuthModule.rights.Deserialize("");
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Передайте администратору следующее:" + Environment.NewLine + ex.Message, "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            LocalParameters.Login = tbLogin.Text;
            LocalParameters.SaveParameters();

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
コード例 #17
0
 protected TSParameter[] GetRequiredParameters()
 {
     return(LocalParameters.Where(parameter => parameter.IsRequired).Select(AutoRestParameterToTSParameter).ToArray());
 }
コード例 #18
0
        /// <summary>
        /// Generate the method parameter declarations for a method, using TypeScript declaration syntax
        /// <param name="includeOptions">whether the ServiceClientOptions parameter should be included</param>
        /// <param name="isOptionsOptional">whether the ServiceClientOptions parameter should be optional</param>
        /// </summary>
        public string MethodParameterDeclarationTS(bool includeOptions, bool isOptionsOptional = true)
        {
            StringBuilder declarations = new StringBuilder();

            bool first = true;
            IEnumerable <ParameterJs> requiredParameters = LocalParameters.Where(p => p.IsRequired);

            foreach (var parameter in requiredParameters)
            {
                if (!first)
                {
                    declarations.Append(", ");
                }

                declarations.Append(parameter.Name);
                declarations.Append(": ");

                // For date/datetime parameters, use a union type to reflect that they can be passed as a JS Date or a string.
                var type = parameter.ModelType;
                if (type.IsPrimaryType(KnownPrimaryType.Date) || type.IsPrimaryType(KnownPrimaryType.DateTime))
                {
                    declarations.Append("Date|string");
                }
                else
                {
                    declarations.Append(type.TSType(false));
                }

                first = false;
            }

            if (includeOptions)
            {
                if (!first)
                {
                    declarations.Append(", ");
                }
                if (isOptionsOptional)
                {
                    declarations.Append("options?: { ");
                }
                else
                {
                    declarations.Append("options: { ");
                }
                var optionalParameters = ((CompositeType)OptionsParameterTemplateModel.ModelType).Properties.OrderBy(each => each.Name == "customHeaders" ? 1 : 0).ToArray();
                for (int i = 0; i < optionalParameters.Length; i++)
                {
                    if (i != 0)
                    {
                        declarations.Append(", ");
                    }
                    declarations.Append(optionalParameters[i].Name);
                    declarations.Append("? : ");
                    if (optionalParameters[i].Name.EqualsIgnoreCase("customHeaders"))
                    {
                        declarations.Append("{ [headerName: string]: string; }");
                    }
                    else
                    {
                        declarations.Append(optionalParameters[i].ModelType.TSType(false));
                    }
                }
                declarations.Append(" }");
            }

            return(declarations.ToString());
        }
コード例 #19
0
 private void buttonExit_Click(object sender, RoutedEventArgs e)
 {
     this.Close();
     LocalParameters.RestoreParameters();
 }
コード例 #20
0
 /// <summary>
 /// Get the invocation args for an invocation with an async method
 /// </summary>
 public string GetAsyncMethodInvocationArgs(string customHeaderReference, string cancellationTokenReference = "cancellationToken") =>
 string.Join(", ", LocalParameters.Select(each => (string)each.Name).Concat(new[] { customHeaderReference, cancellationTokenReference }));
コード例 #21
0
 private void btnChangeParams_Click(object sender, EventArgs e)
 {
     LocalParameters.EditParameters();
     this.DialogResult = System.Windows.Forms.DialogResult.Yes;
     Close();
 }