Exemple #1
0
 public double Add(double a, double b)
 {
     _actions.Add("AlternativeCalculator Add");
     _log.Log("3");
     _log.Log("4");
     return(a + b);
 }
Exemple #2
0
 public double Add(double a, double b)
 {
     _actions.Add("Calculator Add");
     _log.Log("1");
     _log.Log("2");
     return(a + b);
 }
Exemple #3
0
            internal void Run(string environment)
            {
                ILoggable log = LoggerFactory.GetLogger(environment);

                _actions.Add("ClientX");
                log.Log("1");
                log.Log("2");
            }
Exemple #4
0
        /// <summary>Validates given ShuffleDefinition with XSD.</summary>
        /// <param name="def"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public static string ValidateDefinitionXml(XmlDocument def, ILoggable log)
        {
            var result = "";

            try
            {
                Assembly assembly     = System.Reflection.Assembly.GetExecutingAssembly();
                string   assemblyname = assembly.ManifestModule.ToString();
                if (log != null)
                {
                    log.Log("Original assembly name: {0}", assemblyname);
                }

                if (assemblyname.ToUpperInvariant().EndsWith(".DLL"))
                {
                    assemblyname = assemblyname.Substring(0, assemblyname.Length - 4);
                }
                assemblyname = assemblyname.Replace("Merged", "");
                assemblyname = assemblyname.Replace("..", ".");
                if (log != null)
                {
                    log.Log("Fixed assemblyname: {0}", assemblyname);
                }

                Stream stream = assembly.GetManifestResourceStream(assemblyname + ".Resources.ShuffleDefinition.xsd");
                if (stream == null)
                {
                    result = "Cannot find resource " + assemblyname + ".Resources.ShuffleDefinition.xsd";
                }
                else
                {
                    def.Schemas = new XmlSchemaSet();
                    def.Schemas.Add(null, XmlReader.Create(stream));
                    stream = assembly.GetManifestResourceStream(assemblyname + ".Resources.QueryExpression.xsd");
                    if (stream == null)
                    {
                        result = "Cannot find resource " + assemblyname + ".Resources.QueryExpression.xsd";
                    }
                    else
                    {
                        def.Schemas.Add(null, XmlReader.Create(stream));
                        def.Validate(null);
                    }
                }
            }
            catch (XmlSchemaValidationException ex)
            {
                if (log != null)
                {
                    log.Log(ex);
                }

                throw;
            }
            return(result);
        }
        public void MakeNoise()
        {
            //code to make some noise.


            logger.Log("Honked car horn at " + DateTime.Now);
        }
Exemple #6
0
 /// <summary>Validates given ShuffleDefinition with XSD.</summary>
 /// <param name="def"></param>
 /// <param name="log"></param>
 /// <returns></returns>
 public static void ValidateDefinitionXml(XmlDocument def, ILoggable log)
 {
     try
     {
         def.Schemas = Schemas;
         if (def.Schemas.Count >= 2)
         {
             def.Validate(null);
             log?.Log("ShuffleDefinition validated");
         }
     }
     catch (XmlSchemaValidationException ex)
     {
         log?.Log(ex);
         throw;
     }
 }
Exemple #7
0
        public void DisplayProducts(List <Product> products)
        {
            ViewTable.Rows.Clear();
            foreach (var prod in products)
            {
                AddRow(MakeRow(prod));
            }

            Log.Log($"Показани са {products.Count} продукти");
        }
Exemple #8
0
        private void WaitForSQLToInitialize()
        {
            var cmdText         = "USE octestdb;";
            var waitInterval    = 5000;
            var waitIntervalMax = 180000;
            var backoutFactor   = 2;
            var retriesMax      = 5;
            int retry           = 0;

            while (retry < retriesMax)
            {
                try
                {
                    using (var con = _conn_init())
                    {
                        con.Open();
                        using (var command = new SqlCommand(cmdText, con))
                        {
                            command.ExecuteNonQuery();
                        }
                        con.Close();
                    }
                    break;
                }
                catch (SqlException)
                {
                    if (retry < retriesMax)
                    {
                        int retryTime = Math.Min((int)(waitInterval * Math.Pow(backoutFactor, retry)), waitIntervalMax);
                        Thread.Sleep(retryTime);
                        _logger?.Log($"SQL Server is not ready yet, retry in {retryTime/1000} seconds ...");
                        retry++;
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Exemple #9
0
        public void Log_ReturnsCustomerInformation()
        {
            var customer = new Customer(1)
            {
                EmailAddress = "*****@*****.**",
                FirstName    = "Hari",
                LastName     = "Nike",
                CustomerType = 1
            };
            var       expected    = "ID: 1 Name: Nike, Hari Email: [email protected] Type: 1";
            ILoggable customerLog = customer;

            var actual = customerLog.Log();

            Assert.AreEqual(expected, actual);
        }
 private static void AddRelationFilter(ShuffleBlocks blocks, DataBlockRelation relation, XmlNode xEntity, ILoggable log)
 {
     if (blocks != null && blocks.Count > 0)
     {
         var block       = relation.Block;
         var attribute   = relation.Attribute;
         var pkattribute = relation.PKAttribute;
         var includenull = relation.IncludeNull;
         var ids         = new List <string>();
         var parentcoll  = blocks.ContainsKey(block) ? blocks[block] : null;
         if (parentcoll != null && parentcoll.Count > 0)
         {
             foreach (var parent in parentcoll)
             {
                 if (string.IsNullOrEmpty(pkattribute))
                 {
                     ids.Add(parent.Id.ToString());
                 }
                 else
                 {
                     ids.Add(parent.Property <EntityReference>(pkattribute, new EntityReference()).Id.ToString());
                 }
             }
         }
         else
         {
             // Adding temp guid to indicate "no matches", as ConditionOperator.In will fail if no values are given
             ids.Add(new Guid().ToString());
         }
         if (!includenull)
         {
             CintFetchXML.AppendFilter(xEntity, "and", attribute, "in", ids.ToArray());
         }
         else
         {
             var xFilter = CintFetchXML.AppendFilter(xEntity, "or");
             CintFetchXML.AppendCondition(xFilter, attribute, "null");
             CintFetchXML.AppendCondition(xFilter, attribute, "in", ids.ToArray());
         }
         log.Log("Adding relation condition for {0} in {1} values in {2}.{3}", attribute, ids.Count, block, pkattribute);
     }
 }
        private void AddRelationFilter(ShuffleBlocks blocks, string entityName, DataBlockRelation relation, FilterExpression filter, ILoggable log)
        {
            log.StartSection(MethodBase.GetCurrentMethod().Name);
            if (blocks != null && blocks.Count > 0)
            {
                var block       = relation.Block;
                var attribute   = relation.Attribute;
                var pkattribute = relation.PKAttribute;
                var includenull = relation.IncludeNull;

                var type = GetAttributeType(attribute, entityName);

                var cond = new ConditionExpression
                {
                    AttributeName = attribute,
                    Operator      = Microsoft.Xrm.Sdk.Query.ConditionOperator.In
                };

                var ids        = new List <object>();
                var parentcoll = blocks.ContainsKey(block) ? blocks[block] : null;
                if (parentcoll != null && parentcoll.Count > 0)
                {
                    foreach (var parent in parentcoll)
                    {
                        if (string.IsNullOrEmpty(pkattribute))
                        {
                            if (type == AttributeTypeCode.String)
                            {
                                ids.Add(parent.Id.ToString());
                            }
                            else
                            {
                                ids.Add(parent.Id);
                            }
                        }
                        else if (type == AttributeTypeCode.String)
                        {
                            ids.Add(parent.Property <EntityReference>(pkattribute, new EntityReference()).Id.ToString());
                        }
                        else
                        {
                            ids.Add(parent.Property <EntityReference>(pkattribute, new EntityReference()).Id);
                        }
                    }
                }
                else
                {
                    // Adding temp guid to indicate "no matches", as ConditionOperator.In will fail if no values are given
                    ids.Add(new Guid());
                }
                cond.Values.AddRange(ids);
                if (!includenull)
                {
                    filter.AddCondition(cond);
                }
                else
                {
                    var orfilter = new FilterExpression(LogicalOperator.Or);
                    orfilter.AddCondition(attribute, Microsoft.Xrm.Sdk.Query.ConditionOperator.Null);
                    orfilter.AddCondition(cond);
                    filter.AddFilter(orfilter);
                }
                log.Log("Adding relation condition for {0} in {1} values in {2}.{3}", attribute, ids.Count, block, pkattribute);
            }
            log.EndSection();
        }
        public void PerformComplicatedTask()
        {
            //some more code here...

            logger.Log("Cured the Common Cold at " + DateTime.Now);
        }
Exemple #13
0
 public void MakeNoise()
 {
     logger.Log("SOCIABLE!!!!!");
 }
Exemple #14
0
        ///<summary>Logs a single object to a file</summary>
        ///<exception cref="Exception">Thrown when failed to log data to file.</exception>
        public static void Log(ILoggable item, string path)
        {
            try
            {
                if (item != null)
                {
                    string logLine;

                    using (StreamWriter sw = new StreamWriter(path, true))
                    {
                        logLine = DateTime.Now.ToString() + ", " + item.GetType().ToString() + ", " + item.Log();
                        sw.WriteLine(logLine);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
 internal void Run(ILoggable log)
 {
     _actions.Add("ClientX");
     log.Log("1");
     log.Log("2");
 }
Exemple #16
0
 public void MakeLog(string fileText)
 {
     logger.Log(DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt") + fileText);
 }
Exemple #17
0
 public void DoSomethingGood()
 {
     //more code here...
     logger.Log("Donated time to good cause at " + DateTime.Now);
 }
Exemple #18
0
 public void WriteToFile(ILoggable obj)
 {
     Console.WriteLine(obj.Log());
 }
Exemple #19
0
 public void DoSomethingGood()
 {
     logger.Log("Bill Gates donated $1000000 to fight crime");
 }
        public void TakeDrink()
        {
            //some more code here

            logger.Log("Took a drink of water at " + DateTime.Now);
        }
 internal void Run(ILoggable log)
 {
     _actions.Add("ClientY");
     log.Log("3");
     log.Log("4");
 }
 public void MakeNoise()
 {
     logger.Log("TNT!!!! DYNOMITE!!!");
 }
Exemple #23
0
 public void PerformComplicatedTask()
 {
     logger.Log("Performed Quadruple Bypass surgery...");
 }
Exemple #24
0
        /// <summary>
        /// Deserialize xml/string to blocks with entities
        /// </summary>
        /// <param name="serialized"></param>
        /// <returns>Optional, only required for SerializationType: Text</returns>
        public ShuffleBlocks Deserialize(XmlDocument serialized)
        {
            log.StartSection("Deserialize");
            ShuffleBlocks result = new ShuffleBlocks();

            if (serialized != null)
            {
                XmlNode root    = CintXML.FindChild(serialized, "ShuffleData");
                string  sertype = CintXML.GetAttribute(root, "Type");
                SendLine("Deserialize from {0}", sertype);
                if (sertype == SerializationType.Full.ToString() ||
                    sertype == SerializationType.Simple.ToString() ||
                    sertype == SerializationType.SimpleNoId.ToString() ||
                    sertype == SerializationType.SimpleWithValue.ToString() ||
                    sertype == SerializationType.Explicit.ToString())
                {
                    foreach (XmlNode xBlock in root.ChildNodes)
                    {
                        if (xBlock.NodeType == XmlNodeType.Element && xBlock.Name == "Block" && xBlock.ChildNodes.Count == 1)
                        {
                            string      name = CintXML.GetAttribute(xBlock, "Name");
                            XmlDocument xml  = new XmlDocument();
                            xml.AppendChild(xml.ImportNode(xBlock.ChildNodes[0], true));
                            CintDynEntityCollection cEntities = new CintDynEntityCollection(xml, crmsvc, log);
                            SendLine("Block {0}: {1} records", name, cEntities.Count);
                            result.Add(name, cEntities);
                        }
                    }
                }
                else if (sertype == SerializationType.Text.ToString())
                {
                    string        strdelimeter    = CintXML.GetAttribute(root, "Delimeter");
                    char          delimeter       = strdelimeter.Length == 1 ? strdelimeter[0] : '\t';
                    XmlNode       xText           = CintXML.FindChild(root, "Text");
                    StringReader  reader          = new StringReader(xText.InnerText);
                    int           line            = 0;
                    string        name            = "";
                    StringBuilder serializedblock = null;
                    string        current         = reader.ReadLine();
                    while (current != null)
                    {
                        log.Log("Line {0:000}: {1}", line, current);
                        if (current.StartsWith("<<<") && current.Contains(">>>"))
                        {
                            log.Log("Block start");
                            if (!string.IsNullOrWhiteSpace(name) && serializedblock != null)
                            {
                                CintDynEntityCollection cEntities = new CintDynEntityCollection(serializedblock.ToString(), delimeter, crmsvc, log);
                                result.Add(name, cEntities);
                                SendLine("Block {0}: {1} records", name, cEntities.Count);
                            }
                            name            = current.Substring(3);
                            name            = name.Substring(0, name.IndexOf(">>>", StringComparison.Ordinal));
                            serializedblock = new StringBuilder();
                        }
                        else
                        {
                            serializedblock.AppendLine(current);
                        }
                        current = reader.ReadLine();
                        line++;
                    }
                    if (!string.IsNullOrWhiteSpace(serializedblock.ToString()))
                    {
                        CintDynEntityCollection cEntities = new CintDynEntityCollection(serializedblock.ToString(), delimeter, crmsvc, log);
                        result.Add(name, cEntities);
                        SendLine("Block {0}: {1} records", name, cEntities.Count);
                    }
                }
            }
            log.EndSection();
            return(result);
        }
 public string ToLower(string value)
 {
     _logger.Log($"Converting {value} to upper");
     return(value.ToLower());
 }
    void MyMethod()
    {
        ILoggable loggable = this;

        loggable.Log("Using injected logging");
    }
 public void MakeNoise()
 {
     logger.Log("BOOOOM!!!!");
 }