Exemplo n.º 1
1
        public static pt intersect(line m, line n) 
        {
            pt res = new pt();
	        float zn = det (m.a, m.b, n.a, n.b);
	        if (Math.Abs(zn) < EPS)
		        return null;
	        res.x = - det (m.c, m.b, n.c, n.b) / zn;
	        res.y = - det (m.a, m.c, n.a, n.c) / zn;
            return res;
        }
        public void LatLonEqualsTest()
        {
            var p1 = new pt(2.0, 80.0);
            var p2 = new pt(2.05, 80.0);

            Assert.IsFalse(p1.LatLonEquals(p2));
            Assert.IsFalse(p1.LatLonEquals(p2, 0.03));
            Assert.IsTrue(p1.LatLonEquals(p2, 0.06));
        }
Exemplo n.º 3
0
    public static pt Parse(SqlString s)
    {
        if (s.IsNull || s.Value.ToLower() == "null")
        {
            return(Null);
        }
        pt u = new pt();

        u.value = float.Parse(s.Value);
        // Put your code here
        return(u);
    }
Exemplo n.º 4
0
        private Occurrence ToSDBTrace(pt.sapo.gis.trace.Trace t)
        {
            var occurrence = new Occurrence
            {
                //Id = t.Id,
                Start = t.Start,
                End = t.End,
                Service = new Service(),
                Summary = new OccurrenceSummary()
            };
            if (t.Properties.ContainsKey(SDBTraceProperties.SERVICE_NAME_PROPERTY))
            {
                occurrence.Service.Name = (String)t.Properties[SDBTraceProperties.SERVICE_NAME_PROPERTY];
            }
            if (t.Properties.ContainsKey(SDBTraceProperties.SERVICE_OPERATION_NAME_PROPERTY))
            {
                occurrence.Service.Operation = (String)t.Properties[SDBTraceProperties.SERVICE_OPERATION_NAME_PROPERTY];
            }
            if (t.Properties.ContainsKey(SDBTraceProperties.TRACE_RESULT_PROPERTY) && t.Properties.ContainsKey(SDBTraceProperties.TRACE_SUCCESS_PROPERTY))
            {
                occurrence.Summary.Success = (bool)t.Properties[SDBTraceProperties.TRACE_SUCCESS_PROPERTY];
            }
            // TODO: Change to valid response according to SDB Trace infrastructure
            occurrence.Summary.Result = occurrence.Summary.Success ? "OK" : "Failed";

            if (t.ServerInfo != null)
            {
                var host = Dns.GetHostEntry(t.ServerInfo);
                occurrence.Server = new Server
                {
                    Name = host.HostName,
                    Address = t.ServerInfo.ToString(),
                };
            }

            if (t.ClientInfo != null)
            {
                occurrence.Client = new Client
                {
                    Address = t.ClientInfo.ToString()
                };
            }

            Entry entry;
            occurrence.Entries = new List<Entry>();
            foreach (pt.sapo.gis.trace.Entry e in t.Entries)
            {
                entry = ToSDBEntry(e, occurrence.Messages);
                occurrence.Entries.Add(entry);
            }
            return occurrence;
        }
Exemplo n.º 5
0
        public static pt intersect(line m, line n)
        {
            pt    res = new pt();
            float zn  = det(m.a, m.b, n.a, n.b);

            if (Math.Abs(zn) < EPS)
            {
                return(null);
            }
            res.x = -det(m.c, m.b, n.c, n.b) / zn;
            res.y = -det(m.a, m.c, n.a, n.c) / zn;
            return(res);
        }
 public BrokerSMILoggerAppender(pt.sapo.gis.trace.configuration.appender config)
     : base(config)
 {
     Properties = new BrokerSMILoggerAppenderConfigProperties(base.Properties);
     base.Properties = Properties;
     try
     {
         this.brokerClient = new BrokerClient(new HostInfo(Properties.Host, Properties.Port));
     }
     catch (Exception ex)
     {
         throw new IntializationException("Error initialize sapo broker client", ex);
     }
     this.topic = Properties.Topic;
 }
Exemplo n.º 7
0
 private void FillFailure(pt.sapo.gis.trace.Entry entry, List<Failure> failures, EntryFilterHandler filter)
 {
     // only add entry if there is no filter or it pass the filter test
     if (filter(entry))
     {
         Failure failure = new Failure
         {
             FailureID = GetFailureCodeFromEntry(entry),
             SourceID = entry.Properties.ContainsKey(FAILURE_SOURCE_ID_PROPERTY) ? entry.Properties[FAILURE_SOURCE_ID_PROPERTY] as String : (TraceManager.Trace.Properties.ContainsKey(REPORT_SOURCE_ID_PROPERTY) ? TraceManager.Trace.Properties[REPORT_SOURCE_ID_PROPERTY] as String : Properties.DefaultSourceId),
             //Details = entry.Properties.Where(e => e.Key != FAILURE_SOURCE_ID_PROPERTY).ToDictionary(x => x.Key, x => x.Value) //correction for exceptionEntries
         };
         FillFailureDetails(entry.Properties.Where(e => e.Key != FAILURE_SOURCE_ID_PROPERTY).ToDictionary(x => x.Key, x => x.Value), failure);
         failures.Add(failure);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Register the appender on trace events indicated on configuration object
 /// </summary>
 /// <param name="config">the appender configuration object</param>
 /// <exception cref="IntializatonException">When fail to initialize.</exception>
 public Appender(pt.sapo.gis.trace.configuration.appender config)
 {
     Properties = new AppenderConfigProperties(config.property);
     severities = config.events.Where(e => e.filters != null).ToDictionary(e => e.type, e => e.filters);
     foreach(@event evt in config.events){                
         switch(evt.type) {
             case eventType.entry:
                 if (evt.filters == null || evt.filters.Length == 0)
                     onEntry = e => OnEntry(e);                            
                 else 
                     onEntry = e => { if(evt.filters.Contains(e.Severity)) OnEntry(e); };
                 TraceManager.OnEntry += onEntry;
                 break;
             case eventType.trace:
                 if (evt.filters == null || evt.filters.Length == 0)
                     onTrace = t => OnTrace(t);
                 else 
                     onTrace = t => { if(t.GetSeverityTypes().Any(s => evt.filters.Contains(s))) OnTrace(t); };
                 TraceManager.OnTrace += onTrace;
                 break;
         }
     }
     
 }
Exemplo n.º 9
0
 [TearDown] // Sửa lại cho phù hợp với NUnit hiện tại
 public void TearDown()
 {
     operation = null;
 }
Exemplo n.º 10
0
 [SetUp] // Sửa lại cho phù hợp với NUnit hiện tại
 public void SetUp()
 {
     operation = new pt();
 }
Exemplo n.º 11
0
 public FileAppender(pt.sapo.gis.trace.configuration.appender config)
     : base(config) {                
         properties = new FileAppenderConfigProperties(base.Properties);                
 }        
Exemplo n.º 12
0
 public override void OnTrace(pt.sapo.gis.trace.Trace t)
 {
     if (t.ContextId != null)
     {
         var request = (HttpWebRequest)WebRequest.Create(String.Format("{0}://{1}{2}/{3}?traceContext={4}", Properties.Protocol, Properties.Host, Properties.Port.HasValue ? ":" + Properties.Port.Value : String.Empty, Properties.Path.TrimStart('/'), t.ContextId));
         request.Method = "POST";
         request.Headers.Add("Authorization", String.Format("ESB Token=\"{0}\"", Properties.Token));
         request.ContentType = "application/json";
         using (var str = new StreamWriter(request.GetRequestStream()))
         {
             new Newtonsoft.Json.JsonSerializer()
                 .Serialize(str, ToSDBTrace(t));
         }
         try
         {
             using (var resposnse = request.GetResponse())
             {
                 Console.WriteLine(" ============= SDBTraceAppender ==============");
                 Console.WriteLine("https://backoffice.services.bk.sapo.pt/Trace/{0}",t.Id);
             }
         }
         catch (WebException e)
         {
             var response = (HttpWebResponse)e.Response;
             using (var reader = new StreamReader(response.GetResponseStream()))
             {
                 log.ErrorFormat("SDB trace publish fail: [{0}-{1}] {2}", (int)response.StatusCode, response.StatusDescription, reader.ReadToEnd());
             }
         }
     }
 }
 public TimeoutFileLogAppender(pt.sapo.gis.trace.configuration.appender config)
     : base(config) {
     this.Properties = new TimeoutFileLogAppenderConfigProperties(base.Properties);
     base.Properties = this.Properties;        
 }
Exemplo n.º 14
0
 get => new Product(pt, products.ContainsKey(pt) ? products[pt] : 0);
Exemplo n.º 15
0
 public ConsoleAppender(pt.sapo.gis.trace.configuration.appender config)
     : base(config, Console.Out)
 {
 }        
Exemplo n.º 16
0
 public override void OnEntry(pt.sapo.gis.trace.Entry e) { }
        public void GetClosestEmptyCollectionShouldThrow()
        {
            var items = new pt[0];

            Assert.Throws <InvalidOperationException>(() => items.GetClosest(0.0, 0.0));
        }
Exemplo n.º 18
0
 /// <summary>
 /// 
 /// </summary>    
 /// <param name="config"></param>    
 /// <exception cref="IntializationException">When failing to initialize.</exception>
 public SDBTraceAppender(pt.sapo.gis.trace.configuration.appender config)
     : base(config)
 {
     this.Properties = new SDBTraceAppenderConfigProperties(base.Properties);
     base.Properties = Properties;
 }
        public void TotalDistance0Pt()
        {
            var pts = new pt[] { };

            Assert.AreEqual(0.0, pts.TotalDistance(), delta);
        }
Exemplo n.º 20
0
        private Entry ToSDBEntry(pt.sapo.gis.trace.Entry e, IList<Message> messages)
        {
            var entry = new Entry();
            entry.Description = e.Description;
            entry.Severity = (Severity)Enum.Parse(typeof(Severity), e.Severity.ToString(), true);
            entry.Offset = e.Offset;
            entry.Duration = e.Duration;
            entry.Properties = e.Properties.Where(p => KNOWNED_PROPERTIES.Contains(p.Key) == false).ToNameValueCollection();

            if (e.Properties.ContainsKey(MessageEntry.MESSAGE_PROPERTY_NAME))
            {
                MessageEntryProperty m = (MessageEntryProperty)e.Properties[MessageEntry.MESSAGE_PROPERTY_NAME];
                Message message = ToSDBMessage(m);
                messages.Add(message);
                entry.MessageNumber = messages.IndexOf(message);
            }

            if (e.Properties.ContainsKey(ExceptionEntry.EXCEPTION_PROPERTY))
            {
                System.Exception ex = ((ExceptionEntry)e).Exception;
                entry.Exception = new sapo.sdb.trace.Exception { Type = ex.GetType().FullName, StackTrace = ex.StackTrace };
            }

            if (e.Properties.ContainsKey(LinkedEntry.LINKED_TRACE_ID_PROPERTY))
            {
                String link = (String)e.Properties[LinkedEntry.LINKED_TRACE_ID_PROPERTY];
                entry.LinkedTraceId = link;
            }

            if (entry.Properties.Count == 0)
                entry.Properties = null;

            Entry innerEntry;
            entry.Entries = new List<Entry>();
            foreach (pt.sapo.gis.trace.Entry ie in e.Entries)
            {
                innerEntry = ToSDBEntry(ie, messages);
                entry.Entries.Add(innerEntry);
            }
            return entry;
        }
Exemplo n.º 21
0
        private String GetFailureCodeFromEntry(pt.sapo.gis.trace.Entry e)
        {

            return (e.Type != null) ? e.Type.ToString() : null;            
        }
Exemplo n.º 22
0
        public static pt segments_intersection(segment s1, segment s2)
        {
            line l1 = segment_to_line(s1);
            line l2 = segment_to_line(s2);

            pt result = intersect(l1, l2);

            if (result == null)
            {
                return(null);
            }

            int x = (int)Math.Round(result.x);
            int y = (int)Math.Round(result.y);

            int x1 = 0;
            int x2 = 0;
            int x3 = 0;
            int x4 = 0;
            int y1 = 0;
            int y2 = 0;
            int y3 = 0;
            int y4 = 0;

            if ((int)s1.x1 < (int)s1.x2)
            {
                x1 = (int)s1.x1;
                x2 = (int)s1.x2;
            }
            else
            {
                x1 = (int)s1.x2;
                x2 = (int)s1.x1;
            }

            if ((int)s1.y1 < (int)s1.y2)
            {
                y1 = (int)s1.y1;
                y2 = (int)s1.y2;
            }
            else
            {
                y1 = (int)s1.y2;
                y2 = (int)s1.y1;
            }

            if ((int)s2.x1 < (int)s2.x2)
            {
                x3 = (int)s2.x1;
                x4 = (int)s2.x2;
            }
            else
            {
                x3 = (int)s2.x2;
                x4 = (int)s2.x1;
            }

            if ((int)s2.y1 < (int)s2.y2)
            {
                y3 = (int)s2.y1;
                y4 = (int)s2.y2;
            }
            else
            {
                y3 = (int)s2.y2;
                y4 = (int)s2.y1;
            }

            if (((x >= x1) && (x <= x2) && (x >= x3) && (x <= x4)) && ((y >= y1) && (y <= y2) && (y >= y3) && (y <= y4)))
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 23
0
        private void fill(int x, int y)
        {
            Queue <pt> points = new Queue <pt>();

            pt centerPoint;

            centerPoint.x = x;
            centerPoint.y = y;

            unsafe
            {
                BitmapData bitmapData     = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadWrite, img.PixelFormat);
                int        bytesPerPixel  = System.Drawing.Bitmap.GetPixelFormatSize(img.PixelFormat) / 8;
                int        heightInPixels = bitmapData.Height;
                int        widthInBytes   = bitmapData.Width * bytesPerPixel;
                byte *     ptrFirstPixel  = (byte *)bitmapData.Scan0;
                byte *     currentLine    = ptrFirstPixel + (y * bitmapData.Stride);

                if (Color.FromArgb(currentLine[x * bytesPerPixel + 2], currentLine[x * bytesPerPixel + 1], currentLine[x * bytesPerPixel]) != colorDraw)
                {
                    int[,] visited = new int[img.Width, img.Height];

                    for (int g = 0; g < img.Width; g++)
                    {
                        for (int h = 0; h < img.Height; h++)
                        {
                            visited[g, h] = 0;
                        }
                    }

                    points.Enqueue(centerPoint);

                    Color fillingColor = Color.FromArgb(currentLine[x * bytesPerPixel + 2], currentLine[x * bytesPerPixel + 1], currentLine[x * bytesPerPixel]);
                    int   fillR        = (currentLine[x * bytesPerPixel + 2]);
                    int   fillG        = (currentLine[x * bytesPerPixel + 1]);
                    int   fillB        = (currentLine[x * bytesPerPixel]);

                    Console.WriteLine(fillR + " " + fillG + " " + fillB);

                    while (points.Count > 0)
                    {
                        pt currentPoint = points.Dequeue();

                        currentLine = ptrFirstPixel + (currentPoint.y * bitmapData.Stride);

                        currentLine[currentPoint.x * bytesPerPixel]     = (byte)colorDraw.B;
                        currentLine[currentPoint.x * bytesPerPixel + 1] = (byte)colorDraw.G;
                        currentLine[currentPoint.x * bytesPerPixel + 2] = (byte)colorDraw.R;

                        if (withinBounds(currentPoint.x + 1, currentPoint.y) && currentLine[(currentPoint.x + 1) * bytesPerPixel + 2] == fillR && currentLine[(currentPoint.x + 1) * bytesPerPixel + 1] == fillG && currentLine[(currentPoint.x + 1) * bytesPerPixel] == fillB && visited[currentPoint.x + 1, currentPoint.y] == 0)
                        {
                            points.Enqueue(new pt(currentPoint.x + 1, currentPoint.y));
                            visited[currentPoint.x + 1, currentPoint.y] = 1;
                        }

                        if (withinBounds(currentPoint.x - 1, currentPoint.y) && currentLine[(currentPoint.x - 1) * bytesPerPixel + 2] == fillR && currentLine[(currentPoint.x - 1) * bytesPerPixel + 1] == fillG && currentLine[(currentPoint.x - 1) * bytesPerPixel] == fillB && visited[currentPoint.x - 1, currentPoint.y] == 0)
                        {
                            points.Enqueue(new pt(currentPoint.x - 1, currentPoint.y));
                            visited[currentPoint.x - 1, currentPoint.y] = 1;
                        }

                        currentLine = ptrFirstPixel + ((currentPoint.y + 1) * bitmapData.Stride);
                        if (withinBounds(currentPoint.x, currentPoint.y + 1) && currentLine[(currentPoint.x) * bytesPerPixel + 2] == fillR && currentLine[(currentPoint.x) * bytesPerPixel + 1] == fillG && currentLine[(currentPoint.x) * bytesPerPixel] == fillB && visited[currentPoint.x, currentPoint.y + 1] == 0)
                        {
                            points.Enqueue(new pt(currentPoint.x, currentPoint.y + 1));
                            visited[currentPoint.x, currentPoint.y + 1] = 1;
                        }

                        currentLine = ptrFirstPixel + ((currentPoint.y - 1) * bitmapData.Stride);
                        if (withinBounds(currentPoint.x, currentPoint.y - 1) && currentLine[(currentPoint.x) * bytesPerPixel + 2] == fillR && currentLine[(currentPoint.x) * bytesPerPixel + 1] == fillG && currentLine[(currentPoint.x) * bytesPerPixel] == fillB && visited[currentPoint.x, currentPoint.y - 1] == 0)
                        {
                            points.Enqueue(new pt(currentPoint.x, currentPoint.y - 1));
                            visited[currentPoint.x, currentPoint.y - 1] = 1;
                        }
                    }
                }


                img.UnlockBits(bitmapData);

                pictureBox1.Image = img;
            }
        }