public void Cast_ConvertsDecimalParamCorrectly()
        {
            var parameters = new Hashtable {{"NetFramework", "4.5"}};
            var sut = parameters.Cast<SingleDecimalParameter>();

            Assert.Equal(4.5M, sut.NetFramework);
        }
        public void Cast_CastsParametersWithDotNotation()
        {
            var parameters = new Hashtable { { "Octopus.Machine.Name", "some machine name" } };
            var sut = parameters.Cast<DotNotationParameter>();

            Assert.Equal("some machine name", sut.OctopusMachineName);
        }
Ejemplo n.º 3
0
        private string Download(string uri, Hashtable vars)
        {
            // 1. format query string
            if (vars != null)
            {
                var query = vars.Cast<DictionaryEntry>().Aggregate("", (current, d) => current + ("&" + d.Key.ToString() + "=" + d.Value.ToString()));
                if (query.Length > 0)
                {
                    uri = uri + "?" + query.Substring(1);
                }
            }

            // 2. setup basic authenication
            var authstring = Convert.ToBase64String(
                Encoding.ASCII.GetBytes(String.Format("{0}:{1}",
                                                      _id, _token)));

            // 3. perform GET using WebClient
            var client = new WebClient();
            client.Headers.Add("Authorization",
                               String.Format("Basic {0}", authstring));
            var resp = client.DownloadData(uri);

            return Encoding.ASCII.GetString(resp);
        }
        public void Cast_DoesNotThrowWhenNotRequiredParamNotGiven()
        {
            var parameters = new Hashtable {{"SiteName", "MySite"}};
            var sut = parameters.Cast<RequiredParameters>();

            Assert.Equal("MySite", sut.SiteName);
        }
        public void Cast_ConvertsShortParamCorrectly()
        {
            var parameters = new Hashtable {{"Port", "80"}};

            var sut = parameters.Cast<SingleShortParameter>();

            Assert.Equal(80, sut.Port);
        }
Ejemplo n.º 6
0
 public static Dictionary<string, object> HashtableToDict(Hashtable hashtable)
 {
     if (hashtable == null)
     {
         return new Dictionary<string, object>();
     }
     return hashtable.Cast<DictionaryEntry>().ToDictionary(
         kvp => (string) kvp.Key.ToString(), kvp => (object) kvp.Value
     );
 }
        public Model.Webhook CreateWebhook(
            string resourceGroupName,
            string automationAccountName,
            string name,
            string runbookName,
            bool isEnabled,
            DateTimeOffset expiryTime,
            Hashtable runbookParameters)
        {
            Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
            Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
            using (var request = new RequestSettings(this.automationManagementClient))
            {
                var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName };
                var createOrUpdateProperties = new WebhookCreateOrUpdateProperties
                                                   {
                                                       IsEnabled = isEnabled,
                                                       ExpiryTime = expiryTime,
                                                       Runbook = rbAssociationProperty,
                                                       Uri =
                                                           this.automationManagementClient
                                                           .Webhooks.GenerateUri(
                                                               resourceGroupName,
                                                               automationAccountName).Uri
                                                   };
                if (runbookParameters != null)
                {
                    createOrUpdateProperties.Parameters =
                        runbookParameters.Cast<DictionaryEntry>()
                            .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
                }

                var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters(
                    name,
                    createOrUpdateProperties);

                var webhook =
                    this.automationManagementClient.Webhooks.CreateOrUpdate(
                        resourceGroupName,
                        automationAccountName,
                        webhookCreateOrUpdateParameters).Webhook;

                return new Model.Webhook(
                    resourceGroupName,
                    automationAccountName,
                    webhook,
                    webhookCreateOrUpdateParameters.Properties.Uri);
            }
        }
Ejemplo n.º 8
0
        private string Upload(string uri, string method, Hashtable vars)
        {
            // 1. format body data
            var data = "";
            if (vars != null)
            {
                data = vars.Cast<DictionaryEntry>().Aggregate(data, (current, d) => current + (d.Key.ToString() + "=" + d.Value.ToString() + "&"));
            }

            // 2. setup basic authenication
            var authstring = Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", _id, _token)));

            // 3. perform POST/PUT/DELETE using WebClient
            ServicePointManager.Expect100Continue = false;
            var postbytes = Encoding.ASCII.GetBytes(data);
            var client = new WebClient();

            client.Headers.Add("Authorization", String.Format("Basic {0}", authstring));
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            var resp = client.UploadData(uri, method, postbytes);

            return Encoding.ASCII.GetString(resp);
        }
        private static void GeraSoluction(ParametrosCriarProjetos parametros, string guidProjTO, string guidProjDAL, string guidProjInterface, string guidProjBLL, string guidProjWcf)
        {
            var trocasSolution = new Hashtable
            {
                {"[guid]", Guid.NewGuid().ToString().ToUpper().ToUpper()},
                {"[namespace]", parametros.NameSpace},
                {"[guidTO]", guidProjTO},
                {"[guidDAL]", guidProjDAL},
                {"[guidInterface]", guidProjInterface},
                {"[guidBLL]", guidProjBLL}
            };

            var projSolution = Gerador.RetornaTextoBase("noituloS");

            if (parametros.MapWcf)
            {
                projSolution = projSolution.Replace("[guidWcf]", string.Format("Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{0}Wcf\", \"{0}Wcf\\{0}Wcf.csproj\", \"{{53034ACE-081D-4CDA-8075-D3B158C7DAF9}}\"{1}EndProject", parametros.NameSpace, Environment.NewLine));
                projSolution = projSolution.Replace("[guidGlobalWcf]", string.Format("{{{0}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU{1}{{{0}}}.Debug|Any CPU.Build.0 = Debug|Any CPU{1}{{{0}}}.Release|Any CPU.ActiveCfg = Release|Any CPU{1}{{{0}}}.Release|Any CPU.Build.0 = Release|Any CPU", guidProjWcf, Environment.NewLine));
            }
            else
            {
                projSolution = projSolution.Replace("[guidWcf]", "");
                projSolution = projSolution.Replace("[guidGlobalWcf]", "");
            }

            switch (parametros.VersaoFramework)
            {
                case "v2.0":
                    projSolution = projSolution.Replace("2010", "2008");
                    projSolution = projSolution.Replace("11.00", "10.00");
                    break;
                case "v4.5":
                    projSolution = projSolution.Replace("2010", "2012");
                    projSolution = projSolution.Replace("11.00", "12.00");
                    break;
            }

            projSolution = trocasSolution.Cast<DictionaryEntry>().Aggregate(projSolution, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));

            File.WriteAllText(string.Format("{0}\\{1}.sln", parametros.CaminhoDestino, parametros.NameSpace), projSolution);
        }
        private static void GeraProjetoInterface(ParametrosCriarProjetos parametros, string guidProjInterface, List<string> arquivosInterface, string templateAssembly)
        {
            var trocasInterface = new Hashtable
            {
                {"[guid]", guidProjInterface},
                {"[namespace]", parametros.NameSpace},
                {"[arquivos]", string.Join("\n", arquivosInterface.ToArray())}
            };

            var projInterface = Gerador.RetornaTextoBase("secafretnIetalpmeT");
            projInterface = trocasInterface.Cast<DictionaryEntry>().Aggregate(projInterface, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
            projInterface = projInterface.Replace("[versao]", parametros.VersaoFramework);

            var assemblyInterface = templateAssembly.Replace("[log]", "");
            assemblyInterface = assemblyInterface.Replace("[namespace]", parametros.NameSpace);
            assemblyInterface = assemblyInterface.Replace("[guid]", guidProjInterface);

            File.WriteAllText(string.Format("{0}\\Interfaces\\{1}Interfaces.csproj", parametros.CaminhoDestino, parametros.NameSpace), projInterface);
            File.WriteAllText(string.Format("{0}\\Interfaces\\Properties\\AssemblyInfo.cs", parametros.CaminhoDestino), assemblyInterface);
        }
        private static void GeraProjetoDal(ParametrosCriarProjetos parametros, string provider, string guidProjDAL, string guidProjInterface, string guidProjTO, List<string> arquivosDAL, StringBuilder sbLog4Net, string templateAssembly)
        {
            var trocasDAL = new Hashtable
            {
                {"[guid]", guidProjDAL},
                {"[namespace]", parametros.NameSpace},
                {"[guidInterface]", guidProjInterface},
                {"[guidTO]", guidProjTO},
                {"[provider]", string.Format("<Compile Include=\"DataDrain\\Factories\\{0}.cs\" />", provider)},
                {"[arquivos]", string.Join("\n", arquivosDAL.ToArray())},
            };

            var projDAL = Gerador.RetornaTextoBase("SSLADetalpmet").Replace("[log]", "");

            projDAL = trocasDAL.Cast<DictionaryEntry>().Aggregate(projDAL, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
            projDAL = projDAL.Replace("[versao]", parametros.VersaoFramework);


            var assemblyDAL = templateAssembly.Replace("[camada]", "DAL").Replace("[log]", "");
            
            assemblyDAL = assemblyDAL.Replace("[namespace]", parametros.NameSpace);
            assemblyDAL = assemblyDAL.Replace("[guid]", guidProjDAL);


            File.WriteAllText(string.Format("{0}\\DAL\\{1}DAL.csproj", parametros.CaminhoDestino, parametros.NameSpace), projDAL);
            File.WriteAllText(string.Format("{0}\\DAL\\Properties\\AssemblyInfo.cs", parametros.CaminhoDestino), assemblyDAL);
        }
        private static void GeraProjetoBll(ParametrosCriarProjetos parametros, string guidProjBLL, string guidProjInterface, string guidProjTO, string guidProjDAL, List<string> arquivosBLL, StringBuilder sbLog4Net, string templateAssembly)
        {
            var trocasBLL = new Hashtable
            {
                {"[guid]", guidProjBLL},
                {"[namespace]", parametros.NameSpace},
                {"[guidInterface]", guidProjInterface},
                {"[guidTO]", guidProjTO},
                {"[guidDAL]", guidProjDAL},
                {"[arquivos]", string.Join("\n", arquivosBLL.ToArray())},
            };

            var projBLL = Gerador.RetornaTextoBase("LLBetalpmet").Replace("[log]", "");
            projBLL = trocasBLL.Cast<DictionaryEntry>().Aggregate(projBLL, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
            projBLL = projBLL.Replace("[versao]", parametros.VersaoFramework);

            var assemblyBLL = templateAssembly.Replace("[camada]", "bll").Replace("[log]", "");
            assemblyBLL = assemblyBLL.Replace("[namespace]", parametros.NameSpace);
            assemblyBLL = assemblyBLL.Replace("[guid]", guidProjBLL);


            File.WriteAllText(string.Format("{0}\\BLL\\{1}BLL.csproj", parametros.CaminhoDestino, parametros.NameSpace), projBLL);
            File.WriteAllText(string.Format("{0}\\BLL\\Properties\\AssemblyInfo.cs", parametros.CaminhoDestino), assemblyBLL);
        }
        public void Cast_IgnoresExtraNotRequiredParameters()
        {
            var parameters = new Hashtable {{"SiteName", "MySite"}, {"ApplicationPoolName", "AppPool1"}};

            var sut = parameters.Cast<InstallerContextTests.SingleStringParameter>();

            Assert.Equal("MySite", sut.SiteName);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// VHSoft: Add function to handle complex searching; converting the json object from jqgrid to workable sql where string
        /// </summary>
        private void ConvertComplexSearchObjectToSQL(Hashtable searchObject, ref string where, ref string additionalSQL)
        {
            Dictionary<string, object> value2 = searchObject.Cast<DictionaryEntry> ().ToDictionary(kvp => (string)kvp.Key, kvp => (object)kvp.Value);

            this.ConvertComplexSearchObjectToSQL(value2, ref where, ref additionalSQL);
        }
Ejemplo n.º 15
0
 public static Dictionary<string, object> HashtableToDictionary(Hashtable table)
 {
     return table
       .Cast<DictionaryEntry>()
       .ToDictionary(kvp => (string)kvp.Key, kvp => kvp.Value);
 }
Ejemplo n.º 16
0
        public string Request(string path, string method, Hashtable vars)
        {
            string response;

            if (path == null || path.Length <= 0)
                throw (new ArgumentException("Invalid path parameter"));

            method = method.ToUpper();
            if (method == null || (method != "GET" && method != "POST" && method != "PUT" && method != "DELETE"))
            {
                throw (new ArgumentException("Invalid method parameter"));
            }

            if (method != "GET" && vars.Count <= 0)
            {
                throw (new ArgumentException("No vars parameters"));
            }

            var url = _build_uri(path);
            try
            {
                response = method == "GET" ? Download(url, vars) : Upload(url, method, vars);
            }
            catch (WebException e)
            {
                var message = e.Message;

                switch (e.Status)
                {
                    case WebExceptionStatus.TrustFailure:
                        message = "You do not trust the people who issued the certificate being used by twiliorest.dll.";
                        break;
                }

                var varList = vars.Cast<DictionaryEntry>().Aggregate("", (current, d) => current + ("&" + d.Key.ToString() + "=" + d.Value.ToString()));


                var responseStr = "";
                Stream responseStream = null;
                if (e.Response != null)
                    responseStream = e.Response.GetResponseStream();
                if (responseStream != null)
                    using (var sr = new StreamReader(responseStream))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            responseStr += line;
                        }
                    }


                message = String.Format("TwilioRestException occurred in the request you sent: \n{0}\n\tURLL: {1}\n\tMETHOD:{2}\n\tVARS:{3}\n\tRESPONSE:{4}",
                                        message,
                                        url,
                                        method,
                                        varList,
                                        responseStr);

                throw new TwilioRestException(message, e);
            }

            return response;
        }
        public void Cast_ThrowsWhenTypeNotCompatibleWithShort()
        {
            var parameters = new Hashtable {{"Port", "blah"}};

            Exception sut = Catch.Exception(() => parameters.Cast<SingleShortParameter>());

            Assert.IsType<ParameterCastException>(sut);
            Assert.Equal("Cannot cast to type System.Int16 for parameter name Port", sut.Message);
        }
        public void Cast_ThrowsWhenTypeNotCompatibleWithFloat()
        {
            var parameters = new Hashtable {{"NetFramework", "blah"}};

            Exception sut = Catch.Exception(() => parameters.Cast<SingleFloatParameter>());

            Assert.IsType<ParameterCastException>(sut);
            Assert.Equal("Cannot cast to type System.Single for parameter name NetFramework", sut.Message);
        }
        public void Cast_ThrowsWhenRequiredParameterIsNotGiven()
        {
            var parameters = new Hashtable {{"Port", "80"}};

            Exception sut = Catch.Exception(() => parameters.Cast<RequiredParameters>());

            Assert.IsType<RequiredParameterNotGivenException>(sut);
            Assert.Equal("Parameter SiteName is required please specify it.", sut.Message);
        }
        public void Cast_SetsAllParameters()
        {
            var parameters = new Hashtable {{"Port", "80"}, {"SiteName", "MySite"}, {"AppPoolName", "AppPool1"}};

            var sut = parameters.Cast<MultipleParameters>();

            Assert.Equal(80, sut.Port);
            Assert.Equal("MySite", sut.SiteName);
            Assert.Equal("AppPool1", sut.AppPoolName);
        }
        public Model.Webhook UpdateWebhook(
            string resourceGroupName,
            string automationAccountName,
            string name,
            Hashtable parameters,
            bool? isEnabled)
        {
            Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
            Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
            using (var request = new RequestSettings(this.automationManagementClient))
            {
                var webhookModel =
                    this.automationManagementClient.Webhooks.Get(resourceGroupName, automationAccountName, name).Webhook;
                var webhookPatchProperties = new WebhookPatchProperties();
                if (webhookModel != null)
                {
                    if (isEnabled != null)
                    {
                        webhookPatchProperties.IsEnabled = isEnabled.Value;
                    }
                    if (parameters != null)
                    {
                        webhookPatchProperties.Parameters =
                            parameters.Cast<DictionaryEntry>()
                                .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
                    }
                }

                var webhookPatchParameters = new WebhookPatchParameters(name) { Properties = webhookPatchProperties };
                var webhook =
                    this.automationManagementClient.Webhooks.Patch(
                        resourceGroupName,
                        automationAccountName,
                        webhookPatchParameters).Webhook;

                return new Model.Webhook(resourceGroupName, automationAccountName, webhook);
            }
        }
        public static void SetTemplateMetadata(ProvisioningTemplate template, string templateDisplayName, string templateImagePreviewUrl, Hashtable templateProperties)
        {
            if (!String.IsNullOrEmpty(templateDisplayName))
            {
                template.DisplayName = templateDisplayName;
            }

            if (!String.IsNullOrEmpty(templateImagePreviewUrl))
            {
                template.ImagePreviewUrl = templateImagePreviewUrl;
            }

            if (templateProperties != null && templateProperties.Count > 0)
            {
                var properties = templateProperties
                    .Cast<DictionaryEntry>()
                    .ToDictionary(i => (String)i.Key, i => (String)i.Value);

                foreach (var key in properties.Keys)
                {
                    if (!String.IsNullOrEmpty(key))
                    {
                        template.Properties[key] = properties[key];
                    }
                }
            }
        }
        private static void GeraProjetoTo(Configuration parametros, string guidProjTO, string guidProjInterface, List<string> arquivosTO, string templateAssembly)
        {
            var trocasTo = new Hashtable
            {
                {"[guid]", guidProjTO},
                {"[namespace]", parametros.NameSpace},
                {"[guidInterface]", guidProjInterface},
                {"[arquivos]", string.Join("\n", arquivosTO.ToArray())}
            };

            var projTO = FileFactory.RetornaTextoBase("OTetalpmet");
            projTO = trocasTo.Cast<DictionaryEntry>().Aggregate(projTO, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
            projTO = projTO.Replace("[versao]", parametros.VersaoFramework);

            var assemblyTO = templateAssembly.Replace("[camada]", "TO").Replace("[log]", "");
            assemblyTO = assemblyTO.Replace("[namespace]", parametros.NameSpace);
            assemblyTO = assemblyTO.Replace("[guid]", guidProjTO);


            File.WriteAllText(string.Format("{0}\\TO\\{1}TO.csproj", parametros.DestinationPath, parametros.NameSpace), projTO);
            File.WriteAllText(string.Format("{0}\\TO\\Properties\\AssemblyInfo.cs", parametros.DestinationPath), assemblyTO);
        }
Ejemplo n.º 24
0
        private static List<Hashtable> GenerateList(DocumentCollection oldDc)
        {
            var ds =
                from d in _client.CreateDocumentQuery<PostMessage>(oldDc.DocumentsLink)
                where d.Type == "Post"
                select d;

            Hashtable hs = new Hashtable();
            Hashtable newList = new Hashtable();
            Hashtable oldList = new Hashtable();

            var n = ds.ToList().Count;
            foreach (var d in ds)
            {
                if (!hs.ContainsKey(d.Path.District))
                {
                    hs.Add(d.Path.District, 1);
                }
                else
                {
                    hs[d.Path.District] = (int) hs[d.Path.District] + 1;
                }
            }

            foreach (DictionaryEntry h in hs)
            {
                var c = newList.Cast<DictionaryEntry>().Aggregate(0, (current, hh) => current + (int) hh.Value);

                if (c < n*0.45 && (c + (int) h.Value < n*0.55))
                {
                    newList.Add(h.Key, h.Value);
                }
                else
                {
                    oldList.Add(h.Key, h.Value);
                }
            }
            return new List<Hashtable> {oldList, newList};
        }
        public void Cast_OnlySetsWritableProperties()
        {
            var parameters = new Hashtable { { "Port", 80 } };
            var sut = parameters.Cast<ReadonlyParameter>();

            Assert.Equal(90, sut.Port);
        }
 private static Dictionary<string, string> ToDictionary(Hashtable hashTable)
 {
     return hashTable.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString());
 }
        public void Cast_GivesParametersWhenSuppliedUsingCorrectCasing()
        {
            var parameters = new Hashtable {{"SiteName", "MySite"}};

            var sut = parameters.Cast<InstallerContextTests.SingleStringParameter>();

            Assert.Equal("MySite", sut.SiteName);
        }
 private static Dictionary<string, string> HashtableToDictionary(Hashtable table)
 {
     return table
       .Cast<DictionaryEntry>()
       .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
 }
Ejemplo n.º 29
0
 public static Dictionary <K, V> ToDictionary <K, V>(this Hashtable table)
 {
     return(table
            .Cast <DictionaryEntry>()
            .ToDictionary(kvp => (K)kvp.Key, kvp => (V)kvp.Value));
 }