Example #1
0
        public void test_serialization()
        {
            string s1 = "Some current item", s2 = "Some former item";
            BaseDomain <string> foo = new BaseDomain <string>(), bar;

            foo.add_item(s1);
            Guid rem_guid = foo.add_item(s2);

            foo.remove_item(rem_guid);

            DataContractSerializer fmt = new DataContractSerializer(typeof(BaseDomain <string>));

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
                fmt.WriteObject(ms, foo);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                System.Xml.XmlDictionaryReader xr = System.Xml.XmlDictionaryReader.CreateTextReader(ms, new System.Xml.XmlDictionaryReaderQuotas());
                bar = (BaseDomain <string>)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.items.Count, bar.items.Count);
            foreach (Guid item in foo.items.Keys)
            {
                Assert.IsTrue(bar.items.ContainsKey(item));
                Assert.AreEqual(foo.items[item], bar.items[item]);
            }
            Assert.AreEqual(foo.active_items.Count, bar.active_items.Count);
            foreach (Guid item in foo.active_items)
            {
                Assert.IsTrue(bar.active_items.Contains(item));
            }
        }
        public BaseStrategy Request(string domainName)
        {
            string protocol = @"service://";
            Regex  regex    = new Regex(protocol);

            if (false == regex.IsMatch(domainName))
            {
                return(null);
            }
            domainName = domainName.Replace(protocol, "");
            char[]   delimiter = new char[] { '/' };
            string[] schema    = domainName.Split(delimiter);
            if (0 == schema.Length)
            {
                return(null);
            }
            string serviceName = schema[0];

            if (false == this.serviceDictionary.ContainsKey(serviceName))
            {
                return(null);
            }
            BaseDomain service      = this.serviceDictionary[serviceName];
            string     strategyName = "";

            for (int i = 1; i < schema.Length; i++)
            {
                strategyName += schema[i];
                if (i < schema.Length - 1)
                {
                    strategyName += "/";
                }
            }
            return(service.Create(strategyName));
        }
Example #3
0
        public void test_add_item_duplicate()
        {
            BaseDomain <string> domain = new BaseDomain <string>();
            string s = "Some item";

            domain.add_item(s);
            domain.add_item(s);
        }
Example #4
0
        public void test_restore_item_active()
        {
            BaseDomain <string> domain = new BaseDomain <string>();
            string s         = "Some item";
            Guid   item_guid = domain.add_item(s);

            domain.restore_item(item_guid);
        }
Example #5
0
        public void test_add_item_duplicate_guid()
        {
            BaseDomain <string> domain = new BaseDomain <string>();
            string s1 = "Some item", s2 = "Some other item";

            Guid item_guid = domain.add_item(s1);

            domain.add_item(s2, item_guid);
        }
 private void DoSaveRollbackSQLLog(string fileName, BaseDomain obj)
 {
     using (StreamWriter sw = new StreamWriter(fileName, File.Exists(fileName), _options.GetEncoding()))
     {
         foreach (var item in obj.GetProcessedItems().OrderByDescending(x => x.ExecOrder))
         {
             sw.WriteLine(item.RevertSQL);
         }
         sw.Close();
     }
 }
Example #7
0
        public void test_remove_item()
        {
            BaseDomain <string> domain = new BaseDomain <string>();
            string s         = "Some item";
            Guid   item_guid = domain.add_item(s);

            domain.remove_item(item_guid);
            Assert.AreEqual(domain.items.Count, 1);
            Assert.IsTrue(domain.items.ContainsKey(item_guid));
            Assert.AreEqual(domain.items[item_guid], s);
            Assert.AreEqual(domain.active_items.Count, 0);
        }
Example #8
0
        public virtual bool Equals(BaseDomain other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(false);
        }
Example #9
0
        public static BaseDomain ReadData(string path,
                                          string columnLetter,
                                          string sheetName = null)
        {
            var xlsFile = ReadExcelFile(path, sheetName);

            if (xlsFile == null)
            {
                return(new BaseDomain
                {
                    QuantidadePendencias = "-",
                    DataPrimeiraPendencia = "-"
                });
            }

            var maxRows    = xlsFile.RowsUsed().Count();
            var maxColumns = xlsFile.ColumnsUsed().Count();

            if (maxRows == 0)
            {
                return(new BaseDomain
                {
                    QuantidadePendencias = "-",
                    DataPrimeiraPendencia = "-"
                });
            }

            var listDate = new List <DateTime>();

            for (var row = 2; row <= maxRows; row++)
            {
                for (var column = 1; column <= maxColumns; column++)
                {
                    var value = xlsFile.Cell(row, column);
                    if (value.Address?.ColumnLetter == columnLetter)
                    {
                        listDate.Add(FormatDateCell(value));
                    }
                }
            }

            var baseDomain = new BaseDomain
            {
                QuantidadePendencias  = (maxRows - 1).ToString(),
                DataPrimeiraPendencia = listDate.Min().Date.ToString(Execute.CulturaPtBr)
            };

            return(baseDomain);
        }
        public IPiosResult AskPios(string domain, bool fresh = false)
        {
            // Log stuff.
            _logger.LogInformation($"Got request for {domain}");

            // Extract the base domain.
            var baseDomain = new BaseDomain(domain);

            // Check if a valid domain could be found, otherwise return an empty result.
            if (!baseDomain.IsValid)
            {
                _logger.LogInformation($"\"{domain}\" is an invalid .gr/.ελ domain.");
                return(new PiosResult());
            }

            // Check for cached results, unless otherwise requested.
            if (!fresh)
            {
                var cached = RecallResult(baseDomain.Value);
                if (cached != null)
                {
                    return(cached);
                }
            }

            // At this point it's clear we need to query The Registry.
            _logger.LogInformation($"No cached results found or fresh results were requested for {baseDomain}. Fetching some fresh information.");

            // Fill in the domain query.
            _builder.Query = $"domainName={baseDomain}";

            // Fetch what needs to be fetched.
            HtmlWeb web     = new HtmlWeb();
            var     htmlDoc = web.Load(_builder.Uri);

            // Isolate the response body.
            var node = htmlDoc.DocumentNode.SelectSingleNode("//body");

            // Parse the result.
            var result = ParsePios(baseDomain.Value, node.InnerText);

            // Cache the result.
            CacheResult(result);

            // We are done here.
            return(result);
        }
Example #11
0
 public EntityController(BaseDomain <TEntity, TDto> domain, bool validateEntityBelongsToUser = true)
 {
     this.domain = domain;
     this.validateEntityBelongsToUser = validateEntityBelongsToUser;
 }
Example #12
0
        public void test_add_item_null()
        {
            BaseDomain <string> domain = new BaseDomain <string>();

            domain.add_item(null);
        }
Example #13
0
        public void test_restore_item_no_such_guid()
        {
            BaseDomain <string> domain = new BaseDomain <string>();

            domain.restore_item(Guid.NewGuid());
        }
Example #14
0
 public void ChangeEntityStatusToDelete(BaseDomain entity)
 {
     adapter.ChangeEntityStatusToDelete(entity);
 }
Example #15
0
 public void ChangeEntityStatus(BaseDomain entity, EntityState newStatus)
 {
     adapter.ChangeEntityStatus(entity, newStatus);
 }
 public static BaseDto ToDto(this IMapper mapper, BaseDomain baseDomain)
 {
     return(mapper.Map <BaseDto>(baseDomain));
 }
Example #17
0
 public void ChangeEntityStatus(BaseDomain domain, EntityState novoStatus)
 {
     context.Entry(domain).State = novoStatus;
 }
Example #18
0
 public void ChangeEntityStatusToDelete(BaseDomain domain)
 {
     ChangeEntityStatus(domain, EntityState.Deleted);
 }