Esempio n. 1
0
        void ProcessCurrentWord()
        {
            TextRange range = WordBreaker.GetWordRange(Editor.CaretPosition);

            string text = range.Text.Trim();

            // Validate if the email address is valid
            if (!SourceAddress.IsValidEmail(text))
            {
                if (ValidationEnabled)
                {
                    range.ApplyPropertyValue(TextBlock.ForegroundProperty, FindResource("TabAndLightButtonText"));

                    SuppressListForCurrentWord = false;
                }

                return;
            }

            SuppressListForCurrentWord = false;

            SourceAddress address = new SourceAddress(text);

            AddRecipient(address);

            // Notify listeners of new entry
            RebuildRecipientsList();
        }
        public override byte[] GetProtocolPacketBytes(byte[] payLoad)
        {
            var offset = 0;

            var ipv6Packet = new byte[Ipv6HeaderLength + payLoad.Length];

            ipv6Packet[offset++] = (byte)((Version << 4) | ((TrafficClass >> 4) & 0xF));

            ipv6Packet[offset++] = (byte)((uint)((TrafficClass << 4) & 0xF0) | (Flow >> 16) & 0xF);
            ipv6Packet[offset++] = (byte)((Flow >> 8) & 0xFF);
            ipv6Packet[offset++] = (byte)(Flow & 0xFF);

            Console.WriteLine("Next header = {0}", NextHeader);

            byte[] byteValue = BitConverter.GetBytes(ipPayloadLength);
            Array.Copy(byteValue, 0, ipv6Packet, offset, byteValue.Length);
            offset += byteValue.Length;

            ipv6Packet[offset++] = NextHeader;
            ipv6Packet[offset++] = HopLimit;

            byteValue = SourceAddress.GetAddressBytes();
            Array.Copy(byteValue, 0, ipv6Packet, offset, byteValue.Length);
            offset += byteValue.Length;

            byteValue = DestinationAddress.GetAddressBytes();
            Array.Copy(byteValue, 0, ipv6Packet, offset, byteValue.Length);
            offset += byteValue.Length;

            Array.Copy(payLoad, 0, ipv6Packet, offset, payLoad.Length);

            return(ipv6Packet);
        }
Esempio n. 3
0
        public async Task GeocodeAsync(SourceAddress source)
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(
                    new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                var response = await client.GetAsync(BuildUrlRequest(source));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    AzureMapsGeocodeResult geocodeResult = JsonConvert.DeserializeObject <AzureMapsGeocodeResult>(content);
                    GeocodeResult <Result> bestResult    = GetBestGeocodeResult(geocodeResult, source);

                    string freeformAddress = bestResult.Result == null ? "NULL" : bestResult.Result.Address.FreeformAddress;
                    string resultType      = bestResult.Result == null ? "NULL" : bestResult.Result.Type;

                    ReportComparer.SaveAndDisplay(path, $"Azure Maps;{source.Id};{source.Address};{source.Locality};{source.PostalCode};{source.Country};{resultType};{freeformAddress};{bestResult.Status};{geocodeResult.Summary.NumResults}");
                }
                else
                {
                    //var error = await response.Content.ReadAsAsync<ErrorResponse>();
                    Console.WriteLine("Azure HTTP Error");
                    ReportComparer.SaveAndDisplay(path, $"Azure Maps;{source.Id};{source.Address};{source.Locality};{source.PostalCode};{source.Country};NULL;NULL;ZERO_RESULT;0");
                }
            }
        }
Esempio n. 4
0
        public byte[] ToBytes()
        {
            byte[] byteValue;
            byte[] payload    = Payload.ToBytes();
            byte[] ipv6Packet = new byte[Ipv6HeaderLength + payload.Length];
            int    offset     = 0;

            ipv6Packet[offset++] = (byte)((Version << 4) | ((TrafficClass >> 4) & 0xF));
            ipv6Packet[offset++] = (byte)((uint)((TrafficClass << 4) & 0xF0) | (uint)((Flow >> 16) & 0xF));
            ipv6Packet[offset++] = (byte)((Flow >> 8) & 0xFF);
            ipv6Packet[offset++] = (byte)(Flow & 0xFF);


            byteValue = NetUtilities.FromLittleEndian(PayloadLength);
            Array.Copy(byteValue, 0, ipv6Packet, offset, byteValue.Length);
            offset += byteValue.Length;

            ipv6Packet[offset++] = (byte)NextHeader;
            ipv6Packet[offset++] = (byte)HopLimit;

            byteValue = SourceAddress.GetAddressBytes();
            Array.Copy(byteValue, 0, ipv6Packet, offset, byteValue.Length);
            offset += byteValue.Length;

            byteValue = DestinationAddress.GetAddressBytes();
            Array.Copy(byteValue, 0, ipv6Packet, offset, byteValue.Length);
            offset += byteValue.Length;

            Array.Copy(payload, 0, ipv6Packet, offset, payload.Length);

            return(ipv6Packet);
        }
        IEnumerable <SourceAddress> FilterByTargetChannel(IEnumerable <SourceAddress> source, ChannelInstance channel)
        {
            foreach (var address in source)
            {
                if (channel.Configuration.Charasteristics.SupportsEmail)
                {
                    // Mail channels allow everything that is a valid email address
                    if (SourceAddress.IsValidEmail(address.Address))
                    {
                        yield return(address);
                    }
                }
                else
                {
                    // Social channels only allow entries that are available in the addressbook
                    SourceAddress address1 = address;

                    using (mailbox.Profiles.ReaderLock)
                        if (mailbox.Profiles.Where(p => p.Address == address1.Address).Count() > 0)
                        {
                            yield return(address);
                        }
                }
            }
        }
Esempio n. 6
0
        private string BuildUrlRequest(SourceAddress source, bool withExtendedPostalCodesFor = true)
        {
            const string extendedPostalCodesFor = "PAD,POI";
            var          result = default(string);

            switch (MethodType)
            {
            case AzureMapsGeocodeMethodType.GeocodeSearchAddress:

                if (withExtendedPostalCodesFor)
                {
                    result = $"https://atlas.microsoft.com/search/address/json?api-version=1.0&countrySet=ES&subscription-key={SubscriptionKey}&typeahead=true&extendedPostalCodesFor={extendedPostalCodesFor}&query={source.FormattedAddress}";
                }
                else
                {
                    result = $"https://atlas.microsoft.com/search/address/json?api-version=1.0&countrySet=ES&subscription-key={SubscriptionKey}&typeahead=true&query={source.FormattedAddress}";
                }

                break;

            case AzureMapsGeocodeMethodType.GeocodeSearchAddressStructured:
                result = $"https://atlas.microsoft.com/search/address/structured/json?subscription-key={SubscriptionKey}&api-version=1.0&countryCode={source.Country}&streetName={source.Address}&municipality={source.Locality}&postalCode={source.PostalCode}";
                break;

            case AzureMapsGeocodeMethodType.GeocodeSearchFuzzy:
                result = $"https://atlas.microsoft.com/search/fuzzy/json?subscription-key={SubscriptionKey}&api-version=1.0&query={source.FormattedAddress}&openingHours=nextSevenDays";
                break;

            default:
                break;
            }

            return(result);
        }
Esempio n. 7
0
        long SavePerson(SourceAddress address)
        {
            // Create new person
            Person person = DispatcherActivator <Person> .Create();

            person.Name = address.DisplayName;
            // See comment in SaveProfile method
            person.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId;;
            person.DateCreated = DateTime.Now;

            mailbox.Persons.Add(person);

            Thread.CurrentThread.ExecuteOnUIThread(() => person.Messages.Add(message));

            person.RebuildScore();

            ClientState.Current.DataService.Save(person);

            Logger.Debug("Person saved successfully in ProfileMatcher. Person = {0}", LogSource.Sync, person.PersonId);

            SaveProfile(person, address);

            return(person.PersonId.Value);
        }
Esempio n. 8
0
        public UserStatus(IDataReader reader)
            : this()
        {
            StatusId = reader.GetInt64(0);
            StatusKey = reader.GetString(1);
            ParentKey = reader.GetString(2);

            ProfileId = reader.GetInt64(3);

            SourceChannelId = reader.GetInt64(4);
            TargetChannelId = reader.GetString(5);

            ChannelStatusKey = reader.GetString(6);

            From = new SourceAddress(reader.GetString(7));
            To = new SourceAddress(reader.GetString(8));

            Status = reader.GetString(9);

            InReplyTo = reader.GetString(10);
            StatusType = reader.GetInt32(11);

            SearchKeyword = reader.GetString(12);
            IsRead = reader.ReadBoolean(13);

            SortDate = reader.ReadDateTime(14);
            DateRead = reader.ReadDateTimeOrNull(15);
            DateCreated = reader.ReadDateTime(16);
        }
Esempio n. 9
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            LocalizeView();

            AddHighlightColors(lstHighlights);
            PopulateLists();
            LoadZones();
            LoadData();

            var sourceAddress = HccApp.ContactServices.Addresses.FindStoreContactAddress();

            SourceAddress.LoadFromAddress(sourceAddress);

            var destinationAdress = new Address();

            destinationAdress.CountryBvin = Country.UnitedStatesCountryBvin;
            destinationAdress.Line1       = "319 N. Clematis St.";
            destinationAdress.Line2       = "Suite 500";
            destinationAdress.RegionBvin  = "FL";
            destinationAdress.City        = "West Palm Beach";
            destinationAdress.PostalCode  = "33401";
            DestinationAddress.LoadFromAddress(destinationAdress);
        }
        private SourceAddress BuildSourceAddress(XElement response)
        {
            if (response.Element("update-content").Element("person").Element("picture-url") != null)
            {
                // User has avatar
                return(new SourceAddress(
                           response.Element("update-content").Element("person").Element("id").Value,
                           string.Format("{0} {1}",
                                         response.Element("update-content").Element("person").Element("first-name").Value,
                                         response.Element("update-content").Element("person").Element("last-name").Value),
                           response.Element("update-content").Element("person").Element("picture-url").Value,
                           response.Element("update-content").Element("person").Element("site-standard-profile-request").Element("url").Value));
            }
            else
            {
                // No Avatar
                var address = new SourceAddress(
                    response.Element("update-content").Element("person").Element("id").Value,
                    string.Format("{0} {1}",
                                  response.Element("update-content").Element("person").Element("first-name").Value,
                                  response.Element("update-content").Element("person").Element("last-name").Value));

                address.ProfileUrl =
                    response.Element("update-content").Element("person").Element("site-standard-profile-request").Element("url").Value;

                return(address);
            }
        }
Esempio n. 11
0
        Profile LoadPerson(Message message, SourceAddress address)
        {
            if (!keyedProfiles.ContainsKey(address.Address))
            {
                return(null);
            }

            var profile = keyedProfiles[address.Address];

            if (profile.Person == null)
            {
                Logger.Warn("Profile found, but person was null. MessageId = {0}", LogSource.Actions, message.MessageId);

                return(null);
            }

            if (!profile.Messages.Contains(message))
            {
                profile.Messages.Add(message);
                profile.Documents.AddRange(message.Documents);
            }

            if (!profile.Person.Messages.Contains(message))
            {
                profile.Person.Messages.Add(message);
                profile.Person.Documents.AddRange(message.Documents);
            }

            return(profile);
        }
Esempio n. 12
0
        protected bool PrintSource(Interpreter interpreter, StackFrame frame)
        {
            SourceAddress location = frame.SourceAddress;

            if (location == null)
            {
                return(false);
            }

            SourceBuffer buffer;

            if (location.SourceFile != null)
            {
                string filename = location.SourceFile.FileName;
                buffer = interpreter.SourceFileFactory.FindFile(filename);
            }
            else
            {
                buffer = location.SourceBuffer;
            }

            if ((buffer == null) || (buffer.Contents == null) || (location.Row == 0))
            {
                return(false);
            }

            string line = buffer.Contents [location.Row - 1];

            interpreter.Print(String.Format("{0,4} {1}", location.Row, line));
            return(true);
        }
Esempio n. 13
0
        private byte[] GetHeaderBytes()
        {
            //TODO - the following things don't work (because of endianism)
            // Identification + Flags + Fragment Offset
            // Header Checksum

            List <byte>   bytes  = new List <byte>();
            List <UInt32> fields = new List <UInt32>();

            //Add the packetsections together into 32-bit words
            //UInt32 field1 = 0;
            UInt32 xVersion       = (UInt32)(this.Version << 28);
            UInt32 xHeaderLength  = (UInt32)(this.HeaderLength << 24);
            UInt32 xTypeOfService = (UInt32)(this.TypeOfService << 16);
            UInt32 xTotalLength   = (UInt32)(this.TotalLength << 0);

            //field1 = ;
            fields.Add(HostToNetwork(xVersion + xHeaderLength + xTypeOfService + xTotalLength));

            //UInt32 field2 = (UInt32)((this.Identification << 16) | ((byte)(this.FragmentFlags)) << 12 | (this.FragmentOffset << 1));
            UInt32 field2   = 0;
            UInt32 Identity = (UInt32)(this.Identification << 16);
            UInt32 Flags    = (UInt32)((byte)(this.FragmentFlags)) << 14;
            UInt32 Offset   = (UInt32)((this.FragmentOffset) & (UInt16)0xFF);

            field2 = Identity + Flags + Offset;
            fields.Add(HostToNetwork(field2));

            //UInt32 field3 = (UInt32)((this.TimeToLive << 0) | (((byte)(this.Protocol)) << 8) | (UInt16)(this.HeaderChecksum << 16));
            UInt32 xTimeToLive     = (UInt32)(this.TimeToLive << 24);
            UInt32 xProtocol       = (UInt32)((byte)this.Protocol << 16);
            UInt32 xHeaderChecksum = (UInt32)(this.HeaderChecksum << 0);

            //Console.WriteLine("Field3: " + field3.ToBinary(32));
            fields.Add(HostToNetwork(xTimeToLive + xProtocol + xHeaderChecksum));

            //Split the 32-bit words into bytes
            for (int i = 0; i < fields.Count; i++)
            {
                bytes.Add((byte)(fields[i] >> 0));
                bytes.Add((byte)(fields[i] >> 8));
                bytes.Add((byte)(fields[i] >> 16));
                bytes.Add((byte)(fields[i] >> 24));
            }

            //Source and Destination
            foreach (byte b in SourceAddress.ToByteArray())
            {
                bytes.Add(b);
            }

            foreach (byte b in DestinationAddress.ToByteArray())
            {
                bytes.Add(b);
            }

            //TODO - Options field

            return(bytes.ToArray());
        }
Esempio n. 14
0
        public DocumentVersion(IDataReader reader)
            : this()
        {
            VersionId = reader.GetInt64(0);
            DocumentId = reader.GetInt64(1);
            MessageId = reader.ReadInt64OrNull(2);

            Filename = reader.GetString(3);

            SourceChannelId = reader.GetInt64(4);
            TargetChannelId = reader.GetInt64(5);

            From = new SourceAddress(reader.GetString(6));
            To = new SourceAddressCollection(reader.GetString(7));

            StreamName = reader.GetString(8);
            Crc32 = reader.GetString(9);
            Size = reader.GetInt32(10);

            DateReceived = reader.ReadDateTimeOrNull(11);
            DateSent = reader.ReadDateTimeOrNull(12);

            DateCreated = reader.ReadDateTimeOrNull(13);
            DateModified = reader.ReadDateTimeOrNull(14);
        }
Esempio n. 15
0
        public UserStatus(IDataReader reader) : this()
        {
            StatusId  = reader.GetInt64(0);
            StatusKey = reader.GetString(1);
            ParentKey = reader.GetString(2);

            ProfileId = reader.GetInt64(3);

            SourceChannelId = reader.GetInt64(4);
            TargetChannelId = reader.GetString(5);

            ChannelStatusKey = reader.GetString(6);

            From = new SourceAddress(reader.GetString(7));
            To   = new SourceAddress(reader.GetString(8));

            Status = reader.GetString(9);

            InReplyTo  = reader.GetString(10);
            StatusType = reader.GetInt32(11);

            SearchKeyword = reader.GetString(12);
            IsRead        = reader.ReadBoolean(13);

            SortDate    = reader.ReadDateTime(14);
            DateRead    = reader.ReadDateTimeOrNull(15);
            DateCreated = reader.ReadDateTime(16);
        }
Esempio n. 16
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SourceAddress address = (SourceAddress)value;

            IContactsResolver resolver = ObjectComposer.GetObject <IContactsResolver>();

            return(resolver.Find(address));
        }
Esempio n. 17
0
 /// <summary>
 /// Converts the packet to a string.
 /// </summary>
 /// <returns></returns>
 public override String ToString()
 {
     return(base.ToString() + "\r\nIPv6 Packet [\r\n"
            + "\tIPv6 Source Address: " + SourceAddress.ToString() + ", \r\n"
            + "\tIPv6 Destination Address: " + DestinationAddress.ToString() + "\r\n"
            + "]");
     // TODO Implement Better ToString
 }
Esempio n. 18
0
        public override int GetHashCode()
        {
            const int prime  = 31;
            var       result = 1;

            result = prime * result + ((SlaveId == null) ? 0 : SlaveId.GetHashCode());
            result = prime * result + ((SourceAddress == null) ? 0 : SourceAddress.GetHashCode());
            return(result);
        }
Esempio n. 19
0
        public IEnumerable <Address> Convert(SourceAddress source, IEnumerable <Address> destination, ResolutionContext context)
        {
            IList <Address> address    = new List <Address>();
            Address         newAddress = context.Mapper.Map <SourceAddress, Address>(source);

            newAddress.zipcode = context.Mapper.Map <SourceAddress, Zipcode>(source);
            address.Add(newAddress);
            return(address);
        }
Esempio n. 20
0
 public static void New(SourceAddress to)
 {
     ClientState.Current.ViewController.MoveTo(
         PluginsManager.Current.GetPlugin<ConversationsPlugin>().NewItemView,
         new NewMessageDataHelper
             {
                 To = to.ToList(),
                 Body = MessageBodyGenerator.CreateBodyText()
             });
 }
Esempio n. 21
0
 public static void New(SourceAddress to)
 {
     ClientState.Current.ViewController.MoveTo(
         PluginsManager.Current.GetPlugin <ConversationsPlugin>().NewItemView,
         new NewMessageDataHelper
     {
         To   = to.ToList(),
         Body = MessageBodyGenerator.CreateBodyText()
     });
 }
Esempio n. 22
0
        long ProcessSourceAddress(SourceAddress address)
        {
            var profiles = dataService.SelectAllBy <Profile>(new { Address = address.Address }).ToList();

            if (profiles.Count == 0)
            {
                Logger.Debug("Profile for address {0} not found", LogSource.Sync, address);

                if (String.IsNullOrEmpty(address.DisplayName))
                {
                    Logger.Warn("Address {0} had no displayname, ignoring", LogSource.Sync, address);

                    return(-1);
                }
                else
                {
                    // No profile found, try to match on person
                    string name = PersonName.Parse(address.DisplayName).ToString();

                    // The non spaced match helps with contacts that are for instance called waseemsadiq on twitter and Waseem Sadiq elsewhere
                    var person = dataService.SelectBy <Person>(
                        String.Format("select * from Persons where (Firstname || ' ' || Lastname) = '{0}' or Firstname || ' ' || Lastname = '{1}'",
                                      name.AddSQLiteSlashes(), name.Replace(" ", "").AddSQLiteSlashes()));

                    if (person != null)
                    {
                        Logger.Debug("Profile for address {0} had contact, creating new profile", LogSource.Sync, address);

                        // Person has been redirected
                        if (person.RedirectPersonId.HasValue)
                        {
                            person = dataService.SelectBy <Person>(new { PersonId = person.RedirectPersonId });
                        }

                        if (person != null)
                        {
                            SaveProfile(person, address);

                            return(person.PersonId.Value);
                        }
                    }

                    Logger.Debug("Person for address {0} not found, creating new person and profile", LogSource.Sync, address);

                    // Create new soft contact and soft profile
                    return(SavePerson(address));
                }
            }
            else
            {
                var profile = profiles.First();

                return(profile.PersonId);
            }
        }
Esempio n. 23
0
        public override int GetHashCode()
        {
            var hash = Type.GetHashCode();

            hash ^= SourceAddress?.GetHashCode() ?? 0;
            hash ^= DestinationAddress?.GetHashCode() ?? 0;
            hash ^= SourcePort;
            hash ^= DestinationPort << 16;

            return(hash);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SourceAddress address = (SourceAddress)value;

            if (String.IsNullOrEmpty(address.DisplayName))
            {
                return(address.Address);
            }

            return(String.Format("{0} <{1}>", address.DisplayName, address.Address));
        }
Esempio n. 25
0
        public Person FindPerson(SourceAddress address)
        {
            var profile = Find(address);

            if (profile != null && profile.Person != null)
            {
                return(profile.Person);
            }

            return(null);
        }
Esempio n. 26
0
        public static void View(SourceAddress address)
        {
            Profile profile;

            using (VirtualMailBox.Current.Profiles.ReaderLock)
                profile = VirtualMailBox.Current.Profiles.FirstOrDefault(p => p.SourceAddress != null && p.SourceAddress.Equals(address));

            if (profile != null)
            {
                EventBroker.Publish(AppEvents.View, profile.Person);
            }
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
                return null;

            if (String.IsNullOrEmpty(value.ToString()))
                return null;

            SourceAddress address = new SourceAddress(value.ToString());

            return address;
        }
Esempio n. 28
0
        long ProcessSourceAddress(SourceAddress address)
        {
            var profiles = dataService.SelectAllBy<Profile>(new { Address = address.Address }).ToList();

            if (profiles.Count == 0)
            {
                Logger.Debug("Profile for address {0} not found", LogSource.Sync, address);

                if (String.IsNullOrEmpty(address.DisplayName))
                {
                    Logger.Warn("Address {0} had no displayname, ignoring", LogSource.Sync, address);

                    return -1;
                }
                else
                {
                    // No profile found, try to match on person
                    string name = PersonName.Parse(address.DisplayName).ToString();

                    // The non spaced match helps with contacts that are for instance called waseemsadiq on twitter and Waseem Sadiq elsewhere
                    var person = dataService.SelectBy<Person>(
                        String.Format("select * from Persons where (Firstname || ' ' || Lastname) = '{0}' or Firstname || ' ' || Lastname = '{1}'",
                            name.AddSQLiteSlashes(), name.Replace(" ", "").AddSQLiteSlashes()));

                    if (person != null)
                    {
                        Logger.Debug("Profile for address {0} had contact, creating new profile", LogSource.Sync, address);

                        // Person has been redirected
                        if (person.RedirectPersonId.HasValue)
                            person = dataService.SelectBy<Person>(new { PersonId = person.RedirectPersonId });

                        if (person != null)
                        {
                            SaveProfile(person, address);

                            return person.PersonId.Value;
                        }
                    }

                    Logger.Debug("Person for address {0} not found, creating new person and profile", LogSource.Sync, address);

                    // Create new soft contact and soft profile
                    return SavePerson(address);
                }
            }
            else
            {
                var profile = profiles.First();

                return profile.PersonId;
            }
        }
Esempio n. 29
0
        public Person(SourceAddress address)
            : this()
        {
            if (String.IsNullOrEmpty(address.Address))
                throw new ApplicationException("Invalid address");

            if (!String.IsNullOrEmpty(address.DisplayName))
            {
                Name = address.DisplayName;
            }
            else
            {
                Name = address.Address.SmartSplit("@")[0];
            }
        }
 string GetAppendAddress(SourceAddress address)
 {
     if (String.IsNullOrEmpty(address.DisplayName))
     {
         return(SourceAddress.IsValidEmail(address.Address) ?
                address.Address.Split('@')[0] :
                address.ToString());
     }
     else
     {
         return(SourceAddress.IsValidEmail(address.DisplayName) ?
                address.DisplayName.Split('@')[0] :
                PersonName.Parse(address.DisplayName).Firstname);
     }
 }
Esempio n. 31
0
 /// <summary>
 /// Compare with other SerialPackage use with priority
 /// </summary>
 /// <param name="other">Second comparable operand</param>
 /// <returns>Compare result. If it is less than zero => this instance is less than value. If zero => this instance is equal to value. Greater than zero => this instance is greater than value</returns>
 public int CompareTo(SerialPackage other)
 {
     if (IsToken && other.IsToken)
     {
         return(0);
     }
     if (IsToken)
     {
         return(-1);
     }
     if (other.IsToken)
     {
         return(1);
     }
     return(SourceAddress.CompareTo(other.SourceAddress));
 }
Esempio n. 32
0
        public Person(SourceAddress address) : this()
        {
            if (String.IsNullOrEmpty(address.Address))
            {
                throw new ApplicationException("Invalid address");
            }

            if (!String.IsNullOrEmpty(address.DisplayName))
            {
                Name = address.DisplayName;
            }
            else
            {
                Name = address.Address.SmartSplit("@")[0];
            }
        }
Esempio n. 33
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(value.ToString()))
            {
                return(null);
            }

            SourceAddress address = new SourceAddress(value.ToString());

            return(address);
        }
Esempio n. 34
0
        public Profile Find(SourceAddress address)
        {
            Profile found;

            using (Profiles.ReaderLock)
                found = Profiles.FirstOrDefault(p => p.Address.Equals(address.Address, StringComparison.InvariantCultureIgnoreCase));

            if (found == null)
            {
                found = new Profile {
                    SourceAddress = address
                };
            }

            return(found);
        }
        public Stream ToStream()
        {
            MemoryStream mem = null;

            if (null != Packet)
            {
                if (0 <= Packet.Length)
                {
                    mem          = new MemoryStream(Packet);
                    mem.Position = 0;
                    return(mem);
                } /* Packet has data. */
            }     /* Packet is not null. */

            mem = new MemoryStream();
            using (var writer = new BinaryWriter(mem))
            {
                // Combine Versiona and IHL nibbles and write complete byte.
                writer.Write(Version.AddLowNibble(IHL));
                // Write TOS byte.
                writer.Write(TOS);
                // Write total length bytes.
                writer.Write(TotalLength);
                // Write identification bytes.
                writer.Write(Identification);

                // Create 2 byte long data type and assign flags to it.
                ushort s = (ushort)Flags.ToByte();
                // Combine and write the flags and the fragment offset.
                writer.Write((ushort)(s + FragmentOffset));
                // Write ttl byte.
                writer.Write(TTL);
                // Write protocl byte.
                writer.Write((byte)Protocol);
                // Write checksum bytes.
                writer.Write(HeaderChecksum);
                // Write source address bytes.
                writer.Write(SourceAddress.GetAddressBytes());
                // Write destination address bytes.
                writer.Write(DestinationAddress.GetAddressBytes());
                // Write options and padding bytes.
                writer.Write(OptionsAndPadding);
                // Write data payload bytes.
                writer.Write(Data);
            }
            return(mem);
        }
Esempio n. 36
0
        /// <summary>
        /// Converts <c>MPLSPackage</c> to bytes
        /// </summary>
        /// <returns>Converted package</returns>
        public byte[] ToBytes()
        {
            List <byte> result = new List <byte>();

            PacketLength = HeaderLength + Payload.Length;

            result.AddRange(LabelStack.GetBytes());
            result.AddRange(BitConverter.GetBytes(ID));
            result.AddRange(BitConverter.GetBytes(PacketLength));
            result.AddRange(BitConverter.GetBytes(TTL));
            result.AddRange(SourceAddress.GetAddressBytes());
            result.AddRange(DestAddress.GetAddressBytes());
            result.AddRange(BitConverter.GetBytes(Port));
            result.AddRange(Encoding.ASCII.GetBytes(Payload ?? ""));

            return(result.ToArray());
        }
Esempio n. 37
0
        public Profile(IDataReader reader)
            : this()
        {
            ProfileId = reader.GetInt64(0);

            if (!reader.IsDBNull(1))
                ProfileKey = reader.GetString(1);

            if (!reader.IsDBNull(2))
                PersonId = reader.GetInt64(2);

            if (!reader.IsDBNull(3))
                IsSoft = reader.ReadBoolean(3);

            if (!reader.IsDBNull(4))
                ChannelProfileKey = reader.GetString(4);

            if (!reader.IsDBNull(5))
                SourceChannelId = reader.GetInt64(5);

            try
            {
                if (!reader.IsDBNull(6))
                    ProfileType = (ProfileType)Enum.Parse(typeof(ProfileType), reader.GetString(6));
            }
            catch (Exception)
            {
                // Due to an update in the ProfileType enumeration, revert back to default in case of an exception
                ProfileType = ProfileType.Default;
            }

            if (!reader.IsDBNull(7))
                AvatarStreamName = reader.GetString(7);

            if (!reader.IsDBNull(8))
                ScreenName = reader.GetString(8);

            if (!reader.IsDBNull(9))
                Address = reader.GetString(9);

            if (!reader.IsDBNull(10))
                Url = reader.GetString(10);

            if (!reader.IsDBNull(11))
                SourceAddress = new SourceAddress(reader.GetString(11));

            if (!reader.IsDBNull(12))
                Location = reader.GetString(12);

            if (!reader.IsDBNull(13))
                GeoLocation = reader.GetString(13);

            if (!reader.IsDBNull(14))
                CompanyName = reader.GetString(14);

            if (!reader.IsDBNull(15))
                Title = reader.GetString(15);

            if (!reader.IsDBNull(16))
                Street = reader.GetString(16);

            if (!reader.IsDBNull(17))
                HouseNumber = reader.GetString(17);

            if (!reader.IsDBNull(18))
                ZipCode = reader.GetString(18);

            if (!reader.IsDBNull(19))
                City = reader.GetString(19);

            if (!reader.IsDBNull(20))
                State = reader.GetString(20);

            if (!reader.IsDBNull(21))
                Country = reader.GetString(21);

            if (!reader.IsDBNull(22))
                CountryCode = reader.GetString(22);

            if (!reader.IsDBNull(23))
                PhoneNr = reader.GetString(23);

            if (!reader.IsDBNull(24))
                MobileNr = reader.GetString(24);

            if (!reader.IsDBNull(25))
                FaxNr = reader.GetString(25);

            if (!reader.IsDBNull(26))
                DateCreated = reader.ReadDateTime(26);
        }
 public void AddToRecipient(SourceAddress recipient)
 {
     ToRecipients.AddRecipient(mailbox.Find(recipient));
 }
        public void AddCCRecipient(SourceAddress recipient)
        {
            CcRecipients.AddRecipient(mailbox.Find(recipient));

            IsCCBCCFieldOpen = true;
        }
Esempio n. 40
0
        public Person FindPerson(SourceAddress address)
        {
            var profile = Find(address);

            if (profile != null && profile.Person != null)
                return profile.Person;

            return null;
        }
        public static NewMessageDataHelper Parse(string mailtoString)
        {
            var uri = new Uri(mailtoString);

            var to = new SourceAddress(String.Format("{0}@{1}", uri.UserInfo, uri.DnsSafeHost));
            var cc = new SourceAddressCollection();
            var bcc = new SourceAddressCollection();
            var subject = String.Empty;
            var body = String.Empty;

            // See if there is a subject embedded in the url
            if (uri.Query.Length > 0)
            {
                var parts = NameValueParser.GetCollection(uri.Query, "?", "&");

                if (parts["subject"] != null)
                    subject = parts["subject"];

                if (parts["body"] != null)
                    body = parts["body"];

                if (parts["cc"] != null)
                    cc = new SourceAddressCollection(parts["cc"]);

                if (parts["bcc"] != null)
                    bcc = new SourceAddressCollection(parts["bcc"]);
            }

            return new NewMessageDataHelper { Context = subject, To = to.ToList(), Cc = cc, Bcc = bcc, Body = body };
        }
Esempio n. 42
0
        long SavePerson(SourceAddress address)
        {
            // Create new person
            Person person = DispatcherActivator<Person>.Create();

            person.Name = address.DisplayName;
            // See comment in SaveProfile method
            person.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId; ;
            person.DateCreated = DateTime.Now;

            mailbox.Persons.Add(person);

            Thread.CurrentThread.ExecuteOnUIThread(() => person.Messages.Add(message));

            person.RebuildScore();

            ClientState.Current.DataService.Save(person);

            Logger.Debug("Person saved successfully in ProfileMatcher. Person = {0}", LogSource.Sync, person.PersonId);

            SaveProfile(person, address);

            return person.PersonId.Value;
        }
Esempio n. 43
0
        public static void View(SourceAddress address)
        {
            Profile profile;

            using (VirtualMailBox.Current.Profiles.ReaderLock)
                profile = VirtualMailBox.Current.Profiles.FirstOrDefault(p => p.SourceAddress != null && p.SourceAddress.Equals(address));

            if (profile != null)
                EventBroker.Publish(AppEvents.View, profile.Person);
        }
 public override string BuildServiceProfileUrl(SourceAddress address)
 {
     return address.ProfileUrl;
 }
Esempio n. 45
0
        public IEnumerable<SourceAddress> GetAddresses(string uids)
        {
            Authenticate();

            string call_id = GetNextCallNr();
            string query = String.Format("SELECT uid, name FROM user WHERE uid IN ({0})", uids);

            Dictionary<string, string> requestParams = new Dictionary<string, string>();
            requestParams.Add("method", "fql.query");
            requestParams.Add("api_key", apiKey);
            requestParams.Add("session_key", sessionKey);
            requestParams.Add("call_id", call_id);
            requestParams.Add("v", "1.0");
            requestParams.Add("query", query);

            var result = channel.ExecuteQuery(apiKey, sessionKey, call_id, GenerateSignature(requestParams, sessionSecret), query);

            XNamespace ns = result.GetDefaultNamespace();

            foreach (XElement element in result.Descendants(ns + "user"))
            {
                SourceAddress address;

                try
                {
                    address = new SourceAddress(element.Element(ns + "uid").Value, element.Element(ns + "name").Value);
                }
                catch (Exception ex)
                {
                    Logger.Error("Unable to retreive user source address. Result = {0}. Exception = {1}", LogSource.Channel, element.Value, ex);

                    continue;
                }

                yield return address;
            }
        }
Esempio n. 46
0
        void SaveProfile(Person person, SourceAddress address)
        {
            // Create new profile
            var profile = new Profile();

            profile.PersonId = person.PersonId.Value;

            // SourceChannelId is 0 if its a valid email (because soft email addresses are not
            // nescessarily tied to any channel), otherwise its the SourceChannelId of the message
            // (usually Facebook/Twitter/etc)
            profile.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId;

            profile.ScreenName = address.DisplayName;
            profile.Address = address.Address;
            profile.SourceAddress = address;
            profile.ProfileType = ProfileType.Default;
            profile.IsSoft = true;
            profile.DateCreated = DateTime.Now;

            ClientState.Current.DataService.Save(profile);

            Logger.Debug("Profile saved successfully in ProfileMatcher. Person = {0}, Profile.SourceAddress = {1}", LogSource.Sync, person.PersonId, profile.SourceAddress);
        }
Esempio n. 47
0
        long SavePerson(SourceAddress address)
        {
            // Create new person
            var person = new Person();

            // See comment in SaveProfile method
            person.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId; ;

            person.Name = address.DisplayName;
            person.DateCreated = DateTime.Now;

            ClientState.Current.DataService.Save(person);

            Logger.Debug("Person saved successfully in ProfileMatcher. Person = {0}", LogSource.Sync, person.PersonId);

            SaveProfile(person, address);

            return person.PersonId.Value;
        }
        private SourceAddress BuildSourceAddress(XElement response)
        {
            if (response.Element("update-content").Element("person").Element("picture-url") != null)
            {
                // User has avatar
                return new SourceAddress(
                    response.Element("update-content").Element("person").Element("id").Value,
                    string.Format("{0} {1}",
                        response.Element("update-content").Element("person").Element("first-name").Value,
                        response.Element("update-content").Element("person").Element("last-name").Value),
                    response.Element("update-content").Element("person").Element("picture-url").Value,
                    response.Element("update-content").Element("person").Element("site-standard-profile-request").Element("url").Value);
            }
            else
            {
                // No Avatar
                var address = new SourceAddress(
                    response.Element("update-content").Element("person").Element("id").Value,
                    string.Format("{0} {1}",
                        response.Element("update-content").Element("person").Element("first-name").Value,
                        response.Element("update-content").Element("person").Element("last-name").Value));

                address.ProfileUrl =
                    response.Element("update-content").Element("person").Element("site-standard-profile-request").Element("url").Value;

                return address;
            }
        }
Esempio n. 49
0
 public AssertionMethod(SourceAddress sourceAddress, string methodName)
     : base(sourceAddress, methodName)
 {
 }
Esempio n. 50
0
        Profile LoadPerson(Message message, SourceAddress address)
        {
            if (!keyedProfiles.ContainsKey(address.Address))
                return null;

            var profile = keyedProfiles[address.Address];

            if (profile.Person == null)
            {
                Logger.Warn("Profile found, but person was null. MessageId = {0}", LogSource.Actions, message.MessageId);

                return null;
            }

            if (!profile.Messages.Contains(message))
            {
                profile.Messages.Add(message);
                profile.Documents.AddRange(message.Documents);
            }

            if (!profile.Person.Messages.Contains(message))
            {
                profile.Person.Messages.Add(message);
                profile.Person.Documents.AddRange(message.Documents);
            }

            return profile;
        }
Esempio n. 51
0
        long ProcessSourceAddress(SourceAddress address)
        {
            List<Profile> profiles;

            using (mailbox.Profiles.ReaderLock)
                profiles = mailbox.Profiles.Where(p => p.Address == address.Address).ToList();

            if (profiles.Count == 0)
            {
                Logger.Debug("Profile for address {0} not found", LogSource.Sync, address);

                if (String.IsNullOrEmpty(address.DisplayName))
                {
                    Logger.Warn("Address {0} had no displayname, ignoring", LogSource.Sync, address);

                    return -1;
                }
                else
                {
                    // No profile found, try to match on person
                    string name = PersonName.Parse(address.DisplayName).ToString();
                    List<Person> persons;

                    // The non spaced matche helps with contacts that are for instance called waseemsadiq on twitter and Waseem Sadiq elsewhere
                    using (mailbox.Persons.ReaderLock)
                        persons = mailbox.Persons.Where(c => c.Name == name || c.Name == name.Replace(" ", String.Empty).Trim()).ToList();

                    if (persons.Count > 0)
                    {
                        Logger.Debug("Profile for address {0} had contact, creating new profile", LogSource.Sync, address);

                        // Add profile to existing person
                        var person = persons.First();

                        // Person has been redirected
                        if (person.RedirectPersonId.HasValue)
                        {
                            using (mailbox.Persons.ReaderLock)
                            {
                                // Find redirected person
                                Person person1 = person;

                                person = mailbox.Persons.FirstOrDefault(p => p.PersonId == person1.RedirectPersonId);
                            }
                        }

                        if (person != null)
                        {
                            // If personid does not have a value yet, spin until the object is written to the database
                            while (!person.PersonId.HasValue)
                                Thread.SpinWait(1000);

                            SaveProfile(person, address);

                            return person.PersonId.Value;
                        }
                    }

                    Logger.Debug("Person for address {0} not found, creating new person and profile", LogSource.Sync, address);

                    // Create new soft contact and soft profile
                    return SavePerson(address);
                }
            }
            else
            {
                var profile = profiles.First();

                Thread.CurrentThread.ExecuteOnUIThread(delegate
                    {
                        // Set profile
                        message.Profile = profile;

                        profile.Messages.Add(message);

                        if (profile.Person != null)
                        {
                            profile.Person.Messages.Add(message);

                            profile.Person.RebuildScore();
                        }
                    });

                return profile.PersonId;
            }
        }
 public IndexedAssertionGroup(SourceAddress callAddress, string expressionAlias, int index)
     : base(callAddress, expressionAlias)
 {
     this.index = index;
 }
        void ProcessCurrentWord()
        {
            TextRange range = WordBreaker.GetWordRange(Editor.CaretPosition);

            string text = range.Text.Trim();

            // Validate if the email address is valid
            if (!SourceAddress.IsValidEmail(text))
            {
                if (ValidationEnabled)
                {
                    range.ApplyPropertyValue(TextBlock.ForegroundProperty, FindResource("TabAndLightButtonText"));

                    SuppressListForCurrentWord = false;
                }

                return;
            }

            SuppressListForCurrentWord = false;

            SourceAddress address = new SourceAddress(text);
            AddRecipient(address);

            // Notify listeners of new entry
            RebuildRecipientsList();
        }
Esempio n. 54
0
        // <summary>
        //   Checks whether to do a "method operation".
        //
        //   This is only used while doing a source stepping operation and ensures
        //   that we don't stop somewhere inside a method's prologue code or
        //   between two source lines.
        // </summary>
        Operation check_method_operation(TargetAddress address, Method method,
						  SourceAddress source, Operation operation)
        {
            // Do nothing if this is not a source stepping operation.
            if ((operation == null) || !operation.IsSourceOperation)
                return null;

            if (method.WrapperType != WrapperType.None)
                return new OperationWrapper (this, method, operation.Result);
            if (method.IsIterator)
                return new OperationStepIterator (this, method, operation.Result);

            Language language = method.Module.Language;
            if (source == null)
                return null;

            if ((source.LineOffset > 0) && (source.LineRange > 0)) {
                // We stopped between two source lines.  This normally
                // happens when returning from a method call; in this
                // case, we need to continue stepping until we reach the
                // next source line.
                StepFrame sframe = new StepFrame (
                    language, StepMode.SourceLine, null,
                    address - source.LineOffset, address + source.LineRange);
                return new OperationStep (this, sframe, operation.Result);
            }

            LineNumberTable lnt = method.LineNumberTable;
            if (lnt.HasMethodBounds && (address < lnt.MethodStartAddress)) {
                StepFrame sframe = new StepFrame (
                    null, StepMode.Finish, null,
                    method.StartAddress, lnt.MethodStartAddress);
                return new OperationStep (this, sframe, operation.Result);
            } else if (method.HasMethodBounds && (address < method.MethodStartAddress)) {
                // Do not stop inside a method's prologue code, but stop
                // immediately behind it (on the first instruction of the
                // method's actual code).
                StepFrame sframe = new StepFrame (
                    null, StepMode.Finish, null,
                    method.StartAddress, method.MethodStartAddress);
                return new OperationStep (this, sframe, operation.Result);
            }

            return null;
        }
 public override string BuildServiceProfileUrl(SourceAddress address)
 {
     return String.Format("http://www.twitter.com/{0}", address.Address);
 }
Esempio n. 56
0
        public Profile Find(SourceAddress address)
        {
            Profile found;

            using (Profiles.ReaderLock)
                found = Profiles.FirstOrDefault(p => p.Address.Equals(address.Address, StringComparison.InvariantCultureIgnoreCase));

            if (found == null)
            {
                found = new Profile {SourceAddress = address};
            }

            return found;
        }
Esempio n. 57
0
 protected AssertionComponent(SourceAddress sourceAddress, string methodName)
 {
     SourceAddress = sourceAddress;
     MethodName = methodName;
 }
Esempio n. 58
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SourceAddress address = new SourceAddress(value.ToString());

            return address;
        }
 public override string BuildServiceProfileUrl(SourceAddress address)
 {
     return String.Format("https://www.yammer.com/users/{0}", address.Address);
 }
Esempio n. 60
0
 public Continuation(SourceAddress sourceAddress, string methodName)
     : base(sourceAddress, methodName)
 {
 }