示例#1
0
        public static void RunAlias(ComboBoxItem cbi)
        {
            //comboBox1.SelectedItem 取出 后
            //根据 type 选择处理的方式执行就好
            AliasType AT = (new Cmd.Func()).GetAliasType(cbi.Type);
            string    s  = cbi.Value.ToString();

            string[] arr = s.Split(';');
            switch (AT)
            {
            case AliasType.http:
                Array.ForEach(arr, item => ProcessStar(item));
                break;

            case AliasType.exe:
                ProcessStar(s);      // ExeExe(s);
                break;

            case AliasType.dos:
                ExeProcessCmd(s.Replace("dos:", ""));     //因为历史数据问题,所有要替换dos:成空
                break;

            case AliasType.txt:
                Alias al = new Alias {
                    ID = cbi.ID, Name = cbi.Text, Path = cbi.Value.ToString(), Type = cbi.Type
                };

                (new Func()).Open_Form("RichForm", s, al);  //显示富文本aaa
                break;

            default:
                break;
            }
        }
        public MovieResponse MovieAlias(string id, AliasType type = AliasType.IMDB)
        {
            var urlParams = new { id, type = type.ToString().ToLower() };
            var request   = CreateRequest("movie_alias.json", urlParams: urlParams);

            return(Execute <MovieResponse>(request));
        }
示例#3
0
        private void CreateNewType(Type type, string typeName)
        {
            BaseType t = null;

            if (type == typeof(AliasType))
            {
                t = new AliasType(typeName, null);
                AllTypes.Add(t);
                AddNodeToTree(t);
            }

            if (type == typeof(UserType))
            {
                t = new UserType(typeName);
                AllTypes.Add(t);
                AddNodeToTree(t);
            }

            RefershTypeTreeView();

            foreach (TreeNode item in m_rootNode.Nodes)
            {
                if (item.Text == typeName)
                {
                    m_typeTreeView.SelectedNode = item;
                    break;
                }
            }
        }
示例#4
0
        public override bool CheckSemantic(List <Error> errors, SymbolTable symbolTable)
        {
            if (_isValid)
            {
                int initErr = errors.Count;

                //obtengo el tipo para modificarle su original type
                TypeSymbol typeSymbol;
                if (MappingDeclaration(Identifier, symbolTable, errors, Line, CharPositionInLine, out typeSymbol))
                {
                    AliasType  aliasType = typeSymbol.TypeExpression as AliasType;
                    TypeSymbol origTypeSymbol;
                    //check BaseType
                    if (MappingDeclaration(OriginalTypeId, symbolTable, errors, GetChild(1).Line, GetChild(1).CharPositionInLine,
                                           out origTypeSymbol))
                    {
                        aliasType.RenamedType = origTypeSymbol.TypeExpression;
                        TypeExpression        = aliasType;
                    }
                }

                if (initErr == errors.Count)
                {
                    Scope = symbolTable.TopScope.Clone();
                    return(true);
                }
                symbolTable.InvalidateDeclaration <TypeSymbol>(Identifier);
            }
            return(false);
        }
示例#5
0
        public AliasTypeWidget(AliasType aliasType)
        {
            InitializeComponent();
            m_type = aliasType;

            Initialize();
        }
示例#6
0
        private void CheckConflicts()
        {
            bool foundConflicts = false;

            if (this.Alias)
            {
                AliasType atype = this.checkBoxUseRegex.IsChecked == true ? AliasType.Regex : AliasType.None;
                Alias     a     = new Alias()
                {
                    Pattern = this.Pattern, AliasType = atype
                };
                IEnumerable <Alias> conflicts = this.money.FindSubsumedAliases(a);
                if (conflicts.Count() > 0)
                {
                    foundConflicts              = true;
                    ClashPromp.Visibility       = Visibility.Visible;
                    ClashingAliases.ItemsSource = (from i in conflicts select i.Pattern).ToList();
                    ClashingAliases.Visibility  = Visibility.Visible;
                }
            }

            if (!foundConflicts)
            {
                ClashPromp.Visibility       = Visibility.Collapsed;
                ClashingAliases.ItemsSource = null;
                ClashingAliases.Visibility  = Visibility.Collapsed;
            }
        }
        public ByteArrayResponse GetSystemUsersCompressedList(AliasType type)
        {
            ByteArrayResponse r = new ByteArrayResponse();

            r.IsSucceded = true;
            r.Value      = System.IO.File.ReadAllBytes(".\\Uyumsoft\\MockData\\UserPkList.zip");
            return(r);
        }
示例#8
0
 public string GetAliasTypeFormat(AliasType aliasType)
 {
     if (aliasType == AliasType.undefined)
     {
         return("");
     }
     return(string.Join(" ", aliasType.ToString().ToCharArray().Select(n => $"${n}")).Replace(" $m", "*"));
 }
示例#9
0
 /// <summary>
 /// Deserializes the data present in the packet contents into data fields in the class.
 /// </summary>
 public override void Deserialize()
 {
     sender    = ReadNullString();
     alias     = ReadNullString();
     aliasType = (AliasType)_contentReader.ReadByte();
     aliasTo   = ReadNullString();
     level     = _contentReader.ReadInt16();
 }
示例#10
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Username.Length != 0)
            {
                hash ^= Username.GetHashCode();
            }
            if (Title.Length != 0)
            {
                hash ^= Title.GetHashCode();
            }
            if (Content.Length != 0)
            {
                hash ^= Content.GetHashCode();
            }
            if (Status != 0)
            {
                hash ^= Status.GetHashCode();
            }
            if (Level != 0)
            {
                hash ^= Level.GetHashCode();
            }
            if (Creator.Length != 0)
            {
                hash ^= Creator.GetHashCode();
            }
            if (ExtJson.Length != 0)
            {
                hash ^= ExtJson.GetHashCode();
            }
            if (IsStock != false)
            {
                hash ^= IsStock.GetHashCode();
            }
            if (IsNotify != false)
            {
                hash ^= IsNotify.GetHashCode();
            }
            if (AliasType.Length != 0)
            {
                hash ^= AliasType.GetHashCode();
            }
            if (Type.Length != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (NotificationTypeId != 0)
            {
                hash ^= NotificationTypeId.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
 public AliasAttribute(AliasType type, string space = null, string name = null)
 {
     if (type == AliasType.Custom)
     {
         Space = space;
         Name  = name;
     }
     AliasType = type;
 }
示例#12
0
        public string MakeAlias(Phoneme[] phonemes, AliasType aliasType)
        {
            var alias           = Formats[aliasType];
            var multiconsonants = new List <string>();

            for (var i = 0; i < phonemes.Count(); i++)
            {
                var    phoneme = phonemes[i];
                string mask    = ExtractFirstPhonemeMask(alias);
                if (mask == null)
                {
                    return(null); // too many phonemes
                }
                if (mask == MULTICONSONANT_MASK)
                {
                    var isCorrect = IsPhonemeTypeCorrect(CONSONANT_MASK, phoneme.Type);
                    if (IsPhonemeTypeCorrect(CONSONANT_MASK, phoneme.Type))
                    {
                        multiconsonants.Add(phoneme.Alias);
                    }
                    if (!isCorrect || i == phonemes.Count() - 1)
                    {
                        alias = new Regex(EcraneMask(mask)).Replace(alias, string.Join(Formats[AliasType.CmC], multiconsonants), 1);
                        multiconsonants.Clear();
                        if (!isCorrect)
                        {
                            i--;
                        }
                    }
                }
                else
                {
                    if (multiconsonants.Count > 0)
                    {
                        throw new Exception();
                    }
                    else
                    {
                        if (!IsPhonemeTypeCorrect(mask, phoneme.Type))
                        {
                            return(null); // wrong phoneme type
                        }
                        alias = new Regex(EcraneMask(mask)).Replace(alias, phoneme.Alias, 1);
                    }
                }
            }
            if (ExtractFirstPhonemeMask(alias) != null)
            {
                return(null); // not enough phonemes
            }
            return(Replace(alias));
        }
示例#13
0
            //获取枚举类型
            public AliasType GetAliasType(string s)
            {
                AliasType AT = new AliasType();

                foreach (AliasType hs1 in Enum.GetValues(typeof(AliasType)))
                {
                    if (hs1.ToString() == s)
                    {
                        AT = hs1; break;
                    }
                }
                return(AT);
            }
示例#14
0
 public bool CanGenerateOnPosition(string filename, AliasType aliasType, int position)
 {
     if (Default == null && (wavGroupsByFilename == null || wavGroupsByFilename.Count == 0))
     {
         return(true); // without mask file we generate all possible
     }
     if (wavGroupsByFilename.ContainsKey(filename))
     {
         foreach (var wavGroup in wavGroupsByFilename[filename])
         {
             if (wavGroup.CanGenerateOnPosition(aliasType, position))
             {
                 return(true);
             }
         }
     }
     return(Default.CanGenerateOnPosition(aliasType, position));
 }
        /// <summary>
        /// Initializes a new instance of the ListViewGroup class.
        /// </summary>
        /// <param name="aliasType">item type.</param>
        public ListViewGroup(AliasType aliasType)
        {
            switch (aliasType)
            {
            case AliasType.Certificate:
                this.Title     = "Certificate";
                this.ShortName = "C";
                break;

            case AliasType.Key:
                this.Title     = "Key";
                this.ShortName = "K";
                break;

            case AliasType.Data:
                this.Title     = "Data";
                this.ShortName = "D";
                break;
            }
        }
示例#16
0
        public bool IsFormatValid(AliasType aliasType, string format)
        {
            var aliasTypeParts = aliasType.ToString().ToCharArray().Select(n => n.ToString()).ToList();

            for (var i = 0; i + 1 < format.Count() && aliasTypeParts.Count > 0; i++)
            {
                if (format[i] == '$')
                {
                    var formatString = format[i + 1].ToString();
                    if (format[i + 1].ToString() == aliasTypeParts[0])
                    {
                        if (i + 2 < format.Count() && format[i + 2] == '*')
                        {
                            if (formatString == "C" && aliasTypeParts.Count > 1 && aliasTypeParts[1] == "m")
                            {
                                aliasTypeParts.RemoveAt(0);
                                aliasTypeParts.RemoveAt(0);
                                i++;
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            aliasTypeParts.RemoveAt(0);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#17
0
        private bool LoadFile(string path)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AutoVisualizer));
                if (!File.Exists(path))
                {
                    _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.FileNotFound, path));
                    return(false);
                }
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = true;
                settings.IgnoreProcessingInstructions = true;
                settings.IgnoreWhitespace             = true;
                settings.XmlResolver = null;

                using (var stream = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(stream, settings))
                    {
                        AutoVisualizer autoVis = null;
                        autoVis = serializer.Deserialize(reader) as AutoVisualizer;
                        if (autoVis != null)
                        {
                            FileInfo f = new FileInfo(autoVis);
                            if (autoVis.Items == null)
                            {
                                return(false);
                            }
                            foreach (var o in autoVis.Items)
                            {
                                if (o is VisualizerType)
                                {
                                    VisualizerType v = (VisualizerType)o;
                                    TypeName       t = TypeName.Parse(v.Name);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Visualizers.Add(new TypeInfo(t, v));
                                        }
                                    }
                                    // add an entry for each alternative name too
                                    if (v.AlternativeType != null)
                                    {
                                        foreach (var a in v.AlternativeType)
                                        {
                                            t = TypeName.Parse(a.Name);
                                            if (t != null)
                                            {
                                                lock (_typeVisualizers)
                                                {
                                                    f.Visualizers.Add(new TypeInfo(t, v));
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (o is AliasType)
                                {
                                    AliasType a = (AliasType)o;
                                    TypeName  t = TypeName.Parse(a.Name);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Aliases.Add(new AliasInfo(t, a));
                                        }
                                    }
                                }
                            }
                            _typeVisualizers.Add(f);
                        }
                        return(autoVis != null);
                    }
            }
            catch (Exception exception)
            {
                // don't allow natvis failures to stop debugging
                _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.ErrorReadingFile, exception.Message, path));
                return(false);
            }
        }
示例#18
0
 public AliasInfo(TypeName name, AliasType alias)
 {
     ParsedName = name;
     Alias      = alias;
 }
示例#19
0
        public User SQLiteUserFind(string VergiNo)
        {
            User r = null;

            using (SQLiteConnection con = NewSQLiteConnection())
            {
                con.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(con))
                {
                    cmd.CommandText = "Select * from GIB_UserList where identifier=@identifier";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add(new SQLiteParameter("@identifier", VergiNo));
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            r                      = new User();
                            r.Identifier           = reader["identifier"].ToString();
                            r.Title                = reader["title"].ToString();
                            r.Type                 = (UsrType)reader["type"].AsIntNull();
                            r.FirstCreationTime    = reader["firstCreationTime"].AsDateTime().ToString("yyy-MM-ddThh.mm.ss");
                            r.AccountType          = (AccType)reader["AccountType"].AsIntNull();
                            r.AccountTypeSpecified = true;
                        }
                        reader.Close();
                    }

                    if (r != null)
                    {
                        cmd.CommandText = "Select * from GIB_Alias where identifier=@identifier and type=@type ";
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.Add(new SQLiteParameter("@identifier", VergiNo));
                        cmd.Parameters.Add(new SQLiteParameter("@type", DocType.Invoice));
                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            DocumentType doc1 = new DocumentType();
                            doc1.type          = DocType.Invoice;
                            doc1.typeSpecified = true;
                            List <AliasType> aliasList = new List <AliasType>();

                            while (reader.Read())
                            {
                                var alias = new AliasType();
                                alias.Name         = new string[1];
                                alias.Name[0]      = reader["name"].ToString();
                                alias.CreationTime = reader["creationTime"].AsDateTime().ToString("yyy-MM-ddThh.mm.ss");
                                alias.DeletionTime = reader["deletionTime"].AsDateTime().ToString("yyy-MM-ddThh.mm.ss");
                                aliasList.Add(alias);
                            }
                            doc1.Alias     = aliasList.ToArray();
                            r.Documents    = new DocumentType[1];
                            r.Documents[0] = doc1;
                            reader.Close();
                        }
                    }
                }
                con.Close();
            }

            return(r);
        }
示例#20
0
        private bool LoadFile(string path)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AutoVisualizer));
                if (!File.Exists(path))
                {
                    _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.FileNotFound, path));
                    return(false);
                }
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments = true;
                settings.IgnoreProcessingInstructions = true;
                settings.IgnoreWhitespace             = true;

                // set XmlResolver via reflection, if it exists. This is required for desktop CLR, as otherwise the XML reader may
                // attempt to hit untrusted external resources.
                var xmlResolverProperty = settings.GetType().GetProperty("XmlResolver", BindingFlags.Public | BindingFlags.Instance);
                xmlResolverProperty?.SetValue(settings, null);

                using (var stream = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(stream, settings))
                    {
                        AutoVisualizer autoVis = null;
                        autoVis = serializer.Deserialize(reader) as AutoVisualizer;
                        if (autoVis != null)
                        {
                            FileInfo f = new FileInfo(autoVis);
                            if (autoVis.Items == null)
                            {
                                return(false);
                            }
                            foreach (var o in autoVis.Items)
                            {
                                if (o is VisualizerType)
                                {
                                    VisualizerType v = (VisualizerType)o;
                                    TypeName       t = TypeName.Parse(v.Name, _process.Logger);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Visualizers.Add(new TypeInfo(t, v));
                                        }
                                    }
                                    // add an entry for each alternative name too
                                    if (v.AlternativeType != null)
                                    {
                                        foreach (var a in v.AlternativeType)
                                        {
                                            t = TypeName.Parse(a.Name, _process.Logger);
                                            if (t != null)
                                            {
                                                lock (_typeVisualizers)
                                                {
                                                    f.Visualizers.Add(new TypeInfo(t, v));
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (o is AliasType)
                                {
                                    AliasType a = (AliasType)o;
                                    TypeName  t = TypeName.Parse(a.Name, _process.Logger);
                                    if (t != null)
                                    {
                                        lock (_typeVisualizers)
                                        {
                                            f.Aliases.Add(new AliasInfo(t, a));
                                        }
                                    }
                                }
                            }
                            _typeVisualizers.Add(f);
                        }
                        return(autoVis != null);
                    }
            }
            catch (Exception exception)
            {
                // don't allow natvis failures to stop debugging
                _process.WriteOutput(String.Format(CultureInfo.CurrentCulture, ResourceStrings.ErrorReadingFile, exception.Message, path));
                return(false);
            }
        }
示例#21
0
        protected override void ProcessDeclaration(SymbolTable symbolTable)
        {
            TypeExpression type = new AliasType(null, Identifier, symbolTable.TopScope.Id);

            symbolTable.InsertDeclaration(new TypeSymbol(type));
        }
示例#22
0
 public Alias(AliasType type, string value)
 {
     Type  = type;
     Value = value;
 }
示例#23
0
 internal static extern void IAlias_SetAliasType(IntPtr ptr, AliasType aliasType);
示例#24
0
 public void SetFormat(AliasType key, string value)
 {
     Formats[key] = value;
 }
示例#25
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Alias" /> class.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="address"></param>
 /// <param name="mosaicId"></param>
 public Alias(AliasType type, Address address, MosaicId mosaicId)
 {
     Type     = type;
     Address  = address;
     MosaicId = mosaicId;
 }
示例#26
0
 /// <summary>
 /// Initializes a new instance of the Item class.
 /// </summary>
 /// <param name="alias">The name of an item.</param>
 /// <param name="type">The type of an item.</param>
 public Item(string alias, AliasType type)
 {
     this.Alias = alias;
     this.Type  = type;
 }
示例#27
0
        private Oto GenerateSingleOto(ProjectLine projectLine, int position, Phoneme[] phonemes, Dictionary <PhonemeType, List <Phoneme> > phonemesOfType, Phoneme next)
        {
            var recline = projectLine.Recline;

            Phoneme   p1 = phonemes.First();
            Phoneme   p2 = phonemes.Last();
            double    offset = 0, consonant = 0, cutoff = 0, preutterance = 0, overlap = 0;
            bool      hasZones  = p1.HasZone && p2.HasZone;
            AliasType aliasType = AliasTypeResolver.Current.GetAliasType(GetAliasType(phonemes));
            bool      masked    = aliasType != AliasType.undefined && Project.Reclist.WavMask.CanGenerateOnPosition(projectLine.Recline.Name, aliasType, position);
            var       p1Attack  = Project.AttackOfType(p1.Type);
            var       p2Attack  = Project.AttackOfType(p2.Type);

            if (!masked)
            {
                return(null);
            }

            string alias = Project.Replacer.MakeAlias(phonemes, aliasType);

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

            bool hasAliasType = true;

            switch (aliasType)
            {
            // Absolute values, relative ones are made in Oto on write (!)
            case AliasType.V:
                offset       = p1.Zone.In + Project.DecayV;
                overlap      = p1.Zone.In + Project.DecayV + Project.DecayV;
                preutterance = overlap - 5;
                consonant    = overlap;
                cutoff       = p1.Zone.Out - p1Attack;
                break;

            // Ends with vowel
            case AliasType.VV:
            case AliasType.CV:
            case AliasType.CmV:
            case AliasType.VCV:
            case AliasType.VCmV:
                offset       = p1.Zone.Out - p1Attack < p1.Zone.In ? p1.Zone.In : p1.Zone.Out - p1Attack;
                overlap      = p1.Zone.Out;
                preutterance = p2.Zone.In;
                consonant    = p2.Zone.In + Project.DecayV;
                cutoff       = p2.Zone.Out - p2Attack;
                break;

            case AliasType.RV:
                offset       = p1.Zone.Out;
                overlap      = p1.Zone.Out + p1Attack;
                preutterance = p2.Zone.In;
                consonant    = p2.Zone.In + Project.DecayV;
                cutoff       = p2.Zone.Out - p2Attack;
                break;

            case AliasType.RCV:
            case AliasType.RCmV:
                offset       = p1.Zone.Out;
                overlap      = p1.Zone.Out + p1Attack;
                preutterance = p2.Zone.In;
                consonant    = p2.Zone.In + Project.DecayV;
                cutoff       = p2.Zone.Out - p2Attack;
                break;

            case AliasType.RC:
            case AliasType.RCm:
                var nextP  = next != null ? next.Zone.In : p2.Zone.Out;
                var firstC = phonemes[1];
                offset       = firstC.Zone.In - p1Attack;
                overlap      = firstC.Zone.In;
                preutterance = p2.Zone.In;
                consonant    = nextP + Project.DecayC;
                cutoff       = nextP + Project.DecayC + Project.AttackC;
                break;

            // Ends with Rest

            case AliasType.VR:
            case AliasType.VCR:
            case AliasType.VCmR:
                offset       = p1.Zone.Out - p1Attack;
                overlap      = p1.Zone.Out;
                preutterance = p2.Zone.In;
                consonant    = p2.Zone.Out + Project.DecayR;
                cutoff       = next == null || IsNextLast(next) ? 0 : next.Zone.In - Project.AttackR;
                break;

            case AliasType.CR:
            case AliasType.CmR:
                offset       = p1.Zone.In;
                overlap      = p1.Zone.Out;
                preutterance = p2.Zone.In;
                consonant    = p2.Zone.Out + Project.DecayR;
                cutoff       = next == null || IsNextLast(next) ? 0 : next.Zone.In - Project.AttackR;
                break;

            // Ends with Consonant
            case AliasType.VC:
            case AliasType.VCm:
            case AliasType.Cm:
                offset       = p1.Zone.Out - p1Attack;
                overlap      = p1.Zone.Out;
                preutterance = p2.Zone.In;
                consonant    = p2.Zone.Out - p2Attack;
                cutoff       = p2.Zone.Out;
                break;

            default:
                hasAliasType = false;
                break;
            }
            if (hasAliasType)
            {
                if (hasZones)
                {
                    var oto = new Oto(recline.Name, alias, offset, consonant, cutoff, preutterance, overlap);
                    oto.Smarty();
                    return(oto);
                }
                else if (MustGeneratePreoto)
                {
                    return(new Oto(recline.Name, alias, 10, 100, 150, 60, 40));
                }
            }
            return(null);
        }
 public ByteArrayResponse GetSystemUsersCompressedList(AliasType type)
 {
     return(service.GetSystemUsersCompressedList(type));
 }
示例#29
0
        void OnOkButton_Click(object sender, RoutedEventArgs e)
        {
            Payee  q         = this.money.Payees.FindPayee(this.Value, true);
            string pattern   = this.Pattern;
            bool   cancelled = true;
            bool   added     = false;

            cancelled = false;
            if (pattern != q.Name)
            {
                AliasType atype = this.checkBoxUseRegex.IsChecked == true ? AliasType.Regex : AliasType.None;
                Alias     a     = null;
                if (this.Alias)
                {
                    a = this.money.Aliases.FindAlias(pattern);
                    if (a == null)
                    {
                        // map this alias to the payee just chosen by the user.
                        a         = new Alias();
                        a.Pattern = pattern;
                        a.Payee   = q;
                        added     = true;
                    }
                    else
                    {
                        a.Payee = q;
                    }
                    a.AliasType = atype;
                }
                else
                {
                    // create temporary alias object for GetTransactionsByAlias.
                    a           = new Alias();
                    a.Pattern   = pattern;
                    a.AliasType = atype;
                    a.Payee     = q;
                }

                Debug.Assert(a.Payee != null);

                if (a.Matches(q.Name))
                {
                    // return the new payee
                    this.selectedPayee = a.Payee;
                }

                IEnumerable <Transaction> transactions = this.money.Transactions.GetAllTransactions();
                if (ServiceProvider != null)
                {
                    // make sure we search visible transactions being edited as well.
                    TransactionCollection viewModel = ServiceProvider.GetService(typeof(TransactionCollection)) as TransactionCollection;
                    if (viewModel != null)
                    {
                        transactions = transactions.Concat(viewModel);
                    }
                }

                // Now see if we have any matches
                IEnumerable <PersistentObject> result = this.money.FindAliasMatches(a, transactions);
                if (!result.Any())
                {
                    if (MessageBoxResult.Cancel == MessageBoxEx.Show("No matching transactions found (that don't already have the target Payee), do you want to save it anyway?", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning))
                    {
                        this.textBox1.Focus();
                        this.textBox1.SelectAll();
                        cancelled = true;
                    }
                }
                if (!cancelled)
                {
                    List <Alias> subsumed = new List <Alias>(this.money.FindSubsumedAliases(a));

                    HashSet <string> conflicts = new HashSet <string>();
                    foreach (var b in subsumed)
                    {
                        if (b.Payee != a.Payee)
                        {
                            conflicts.Add(b.Payee.Name);
                        }
                    }
                    if (conflicts.Count > 0)
                    {
                        List <string> sorted    = new List <string>(conflicts);
                        bool          truncated = false;
                        if (sorted.Count > 10)
                        {
                            sorted.RemoveRange(10, sorted.Count - 10);
                            truncated = true;
                        }
                        sorted.Sort();
                        if (truncated)
                        {
                            sorted.Add("...");
                        }

                        if (MessageBoxResult.Cancel == MessageBoxEx.Show("There are subsumed Aliases that map to " + conflicts.Count + " different Payees: [" +
                                                                         string.Join(", ", sorted) + "].  Are you sure you want to continue with this rename?",
                                                                         "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning))
                        {
                            this.textBox1.Focus();
                            this.textBox1.SelectAll();
                            cancelled = true;
                        }
                    }

                    if (!cancelled)
                    {
                        foreach (var b in subsumed)
                        {
                            this.money.Aliases.RemoveAlias(b);
                        }

                        if (added)
                        {
                            this.money.Aliases.AddAlias(a);
                        }
                        // Now the user really wants to switch all transactions
                        // referencing p over to q, then remove p.
                        int count = this.money.ApplyAlias(a, transactions);
                    }
                }
            }
            else
            {
                // warn the user that they changed nothing?
            }

            if (!cancelled)
            {
                this.DialogResult = true;
                this.Close();
            }
        }
示例#30
0
        void OnOkButton_Click(object sender, RoutedEventArgs e)
        {
            Payee  q       = this.money.Payees.FindPayee(this.Value, true);
            string pattern = this.Pattern;
            bool   close   = true;

            if (pattern != q.Name)
            {
                AliasType atype = this.checkBoxUseRegex.IsChecked == true ? AliasType.Regex : AliasType.None;
                Alias     a     = null;
                if (this.Alias)
                {
                    a = this.money.Aliases.FindAlias(pattern);
                    if (a == null)
                    {
                        // map this alias to the payee just chosen by the user.
                        a = new Alias();
                        this.money.Aliases.AddAlias(a);
                        a.Pattern = pattern;
                        a.Payee   = q;
                    }
                    else
                    {
                        a.Payee = q;
                    }
                    a.AliasType = atype;
                }
                else
                {
                    // create temporary alias object for GetTransactionsByAlias.
                    a           = new Alias();
                    a.Pattern   = pattern;
                    a.AliasType = atype;
                    a.Payee     = q;
                }

                Debug.Assert(a.Payee != null);

                if (a.Matches(q.Name))
                {
                    // return the new payee
                    this.selectedPayee = a.Payee;
                }

                IEnumerable <Transaction> transactions = this.money.Transactions.GetAllTransactions();
                if (ServiceProvider != null)
                {
                    // make sure we search visible transactions being edited as well.
                    TransactionCollection viewModel = ServiceProvider.GetService(typeof(TransactionCollection)) as TransactionCollection;
                    if (viewModel != null)
                    {
                        transactions = transactions.Concat(viewModel);
                    }
                }

                // Now see if we have any matches
                IEnumerable <PersistentObject> result = this.money.FindAliasMatches(a, transactions);
                if (!result.Any())
                {
                    if (MessageBoxResult.Cancel == MessageBoxEx.Show("No matching transactions found (that don't already have the target Payee), do you want to save it anyway?", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning))
                    {
                        this.textBox1.Focus();
                        this.textBox1.SelectAll();
                        close = false;
                    }
                }

                // Now the user really wants to switch all transactions
                // referencing p over to q, then remove p.
                int count = this.money.ApplyAlias(a, transactions);
            }
            else
            {
                // warn the user that they changed nothing?
            }

            if (close)
            {
                this.DialogResult = true;
                this.Close();
            }
        }