Пример #1
0
 private static string ReplaceSuffix(string newString)
 {
     if (newString.Contains("FoodCategoryInfo"))
     {
     }
     return(GenericInfo.GenerateGeneric(newString).ToString());
 }
Пример #2
0
        public string GetFileNameFromClassName(string name)
        {
            GenericInfo generic = GenericInfo.GenerateGeneric(name);

            generic.ClearNameSpaces(ClearString);
            return(generic.Name.ToString() + ".ts");
        }
        private static GenericInfo ToMultiLine(GenericInfo info)
        {
            SyntaxNode declaration = info.Node;
            SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = info.ConstraintClauses;

            TypeParameterConstraintClauseSyntax first = constraintClauses.First();

            SyntaxToken previousToken = declaration.FindToken(first.FullSpan.Start - 1);

            declaration = declaration.ReplaceToken(previousToken, previousToken.WithTrailingTrivia(TriviaList(NewLine())));

            SyntaxTriviaList leadingTrivia = declaration
                                             .FindToken(declaration.SpanStart)
                                             .LeadingTrivia;

            SyntaxTriviaList trivia = IncreaseIndentation(leadingTrivia.LastOrDefault());

            int count = constraintClauses.Count;

            for (int i = 0; i < count; i++)
            {
                TypeParameterConstraintClauseSyntax newNode = constraintClauses[i].WithLeadingTrivia(trivia);

                if (i < count - 1)
                {
                    newNode = newNode.WithTrailingTrivia(NewLine());
                }

                constraintClauses = constraintClauses.ReplaceAt(i, newNode);
            }

            return(SyntaxInfo.GenericInfo(declaration).WithConstraintClauses(constraintClauses));
        }
        private static Task <Document> WrapBaseListAsync(
            Document document,
            BaseListSyntax baseList,
            CancellationToken cancellationToken = default)
        {
            List <TextChange> textChanges = GetFixListChanges(
                baseList,
                baseList.ColonToken,
                baseList.Types,
                ListFixMode.Wrap,
                cancellationToken);

            if (baseList.Types.Count > 1)
            {
                GenericInfo genericInfo = SyntaxInfo.GenericInfo(baseList.Parent);

                SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = genericInfo.ConstraintClauses;

                if (constraintClauses.Any())
                {
                    List <TextChange> textChanges2 = GetFixListChanges(
                        genericInfo.Node,
                        constraintClauses.First().WhereKeyword.GetPreviousToken(),
                        constraintClauses,
                        ListFixMode.Wrap,
                        cancellationToken);

                    textChanges.AddRange(textChanges2);
                }
            }

            return(document.WithTextChangesAsync(textChanges, cancellationToken));
        }
        private static GenericInfo ToSingleLine(GenericInfo info)
        {
            SyntaxNode declaration = info.Node;

            SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = info.ConstraintClauses;

            SyntaxToken previousToken = declaration.FindToken(constraintClauses.First().FullSpan.Start - 1);

            declaration = declaration.ReplaceToken(previousToken, previousToken.WithTrailingTrivia(TriviaList(ElasticSpace)));

            int count = constraintClauses.Count;

            for (int i = 0; i < count; i++)
            {
                TypeParameterConstraintClauseSyntax constraintClause = constraintClauses[i];

                TextSpan?span = null;

                if (i == count - 1)
                {
                    span = TextSpan.FromBounds(constraintClause.FullSpan.Start, constraintClause.Span.End);
                }

                TypeParameterConstraintClauseSyntax newNode = constraintClause
                                                              .RemoveWhitespace(span)
                                                              .WithFormatterAnnotation();

                constraintClauses = constraintClauses.ReplaceAt(i, newNode);
            }

            return(SyntaxInfo.GenericInfo(declaration).WithConstraintClauses(constraintClauses));
        }
        public MainWindow()
        {
            InitializeComponent();
            Ginfo       = new GenericInfo();
            Pinfo       = new ProductInfo();
            _UISettings = new TemplateUISettings()
            {
                Color      = Properties.Settings.Default.Color,
                IsDarkMode = Properties.Settings.Default.IsDarkMode,
                FontFamily = Properties.Settings.Default.FontFamily,
                FontSize   = Properties.Settings.Default.FontSize
            };
            LogWriter.CreateTodaysLog();

            KeyBinding OpenCmdKeyBinding = new KeyBinding(
                ApplicationCommands.New,
                Key.R,
                ModifierKeys.Control);

            this.InputBindings.Add(OpenCmdKeyBinding);


            //Initial setup process.
            FillComboBoxes();

            SetTheme(new TemplateUISettings()
            {
                Color      = Properties.Settings.Default.Color,
                IsDarkMode = Properties.Settings.Default.IsDarkMode,
                FontFamily = Properties.Settings.Default.FontFamily,
                FontSize   = Properties.Settings.Default.FontSize
            });
            DataContext = UISettings;
            ContactNameBox.Focus();
        }
Пример #7
0
 public CompInfo(VisualEffect comp, string prop, Type type)
 {
     infoType    = InfoType.VFX;
     genericInfo = new GenericInfo(type, prop);
     this.type   = type;
     this.comp   = comp;
 }
Пример #8
0
        private static void AnalyzeTypeParameterList(SyntaxNodeAnalysisContext context)
        {
            var typeParameterList = (TypeParameterListSyntax)context.Node;

            GenericInfo genericInfo = SyntaxInfo.GenericInfo(typeParameterList);

            if (!genericInfo.Success)
            {
                return;
            }

            if (!genericInfo.TypeParameters.Any())
            {
                return;
            }

            if (!genericInfo.ConstraintClauses.Any())
            {
                return;
            }

            if (genericInfo.ConstraintClauses.SpanContainsDirectives())
            {
                return;
            }

            if (!IsFixable(genericInfo.TypeParameters, genericInfo.ConstraintClauses))
            {
                return;
            }

            DiagnosticHelpers.ReportDiagnostic(context,
                                               DiagnosticDescriptors.OrderTypeParameterConstraints,
                                               genericInfo.ConstraintClauses[0]);
        }
Пример #9
0
        public string GetFileNameFromClassName(string name)
        {
            GenericInfo generic = GenericInfo.GenerateGeneric(name);

            generic.ClearNameSpaces(ClearString);
            string filename = generic.Name + ".java";
            string dir      = Path.GetDirectoryName(filename);

            return(filename);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            if (!Settings.IsCodeFixEnabled(CodeFixIdentifiers.RemoveTypeParameter))
            {
                return;
            }

            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeParameterSyntax typeParameter))
            {
                return;
            }

            foreach (Diagnostic diagnostic in context.Diagnostics)
            {
                switch (diagnostic.Id)
                {
                case CompilerDiagnosticIdentifiers.TypeParameterHasSameNameAsTypeParameterFromOuterType:
                {
                    TypeParameterInfo typeParameterInfo = SyntaxInfo.TypeParameterInfo(typeParameter);

                    if (!typeParameterInfo.Success)
                    {
                        break;
                    }

                    CodeAction codeAction = CodeAction.Create(
                        $"Remove type parameter '{typeParameterInfo.Name}'",
                        cancellationToken =>
                        {
                            GenericInfo genericInfo = SyntaxInfo.GenericInfo(typeParameterInfo.Declaration);

                            GenericInfo newGenericInfo = genericInfo.RemoveTypeParameter(typeParameter);

                            TypeParameterConstraintClauseSyntax constraintClause = typeParameterInfo.ConstraintClause;

                            if (constraintClause != null)
                            {
                                newGenericInfo = newGenericInfo.RemoveConstraintClause(constraintClause);
                            }

                            return(context.Document.ReplaceNodeAsync(genericInfo.Declaration, newGenericInfo.Declaration, cancellationToken));
                        },
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }
                }
            }
        }
        private static Task <Document> RefactorAsync(
            Document document,
            SyntaxNode node,
            CancellationToken cancellationToken)
        {
            GenericInfo genericInfo = SyntaxInfo.GenericInfo(node);

            SyntaxList <TypeParameterConstraintClauseSyntax> newConstraintClauses = SortConstraints(genericInfo.TypeParameters, genericInfo.ConstraintClauses);

            GenericInfo newInfo = genericInfo.WithConstraintClauses(newConstraintClauses);

            return(document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken));
        }
Пример #12
0
        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            Diagnostic diagnostic = context.Diagnostics[0];

            if (!Settings.IsEnabled(diagnostic.Id, CodeFixIdentifiers.RemoveTypeParameter))
            {
                return;
            }

            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeParameterSyntax typeParameter))
            {
                return;
            }

            string name = typeParameter.Identifier.ValueText;

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                $"Remove type parameter '{name}'",
                cancellationToken =>
            {
                GenericInfo genericInfo = SyntaxInfo.GenericInfo(typeParameter);

                GenericInfo newGenericInfo = genericInfo.RemoveTypeParameter(typeParameter);

                TypeParameterConstraintClauseSyntax constraintClause = genericInfo.FindConstraintClause(name);

                if (constraintClause != null)
                {
                    newGenericInfo = newGenericInfo.RemoveConstraintClause(constraintClause);
                }

                return(context.Document.ReplaceNodeAsync(genericInfo.Node, newGenericInfo.Node, cancellationToken));
            },
                GetEquivalenceKey(diagnostic));

            context.RegisterCodeFix(codeAction, diagnostic);
        }
            public GenericInfo()
            {
                m_info = GetInfo(typeof(TRole));
                var roleEnums = m_info.RoleValues as TRole[];

                m_nameTable = new IndexedTable <string, TRole>(roleEnums.Length);
                m_roles     = new TRole[ValidRoleLength];

                for (int i = 0; i < m_roles.Length; ++i)
                {
                    m_roles[i] = InvalidRole;
                }

                for (int i = 0; i < roleEnums.Length; ++i)
                {
                    var roleValue = ToRoleValue(roleEnums[i]);

                    m_nameTable.Add(GetNameByElementIndex(i), roleEnums[i]);

                    if (roleValue == InvalidRoleValue)
                    {
                        m_invalidRole = roleEnums[i];
                    }
                    else
                    {
                        var offset = RoleValueToRoleOffset(roleValue);
                        m_roles[offset] = roleEnums[i];
                    }
                }

                m_minValidRole = ToRole(m_info.MinValidRoleValue);
                m_maxValidRole = ToRole(m_info.MaxValidRoleValue);

                if (s_instance == null)
                {
                    s_instance = this;
                }
                else
                {
                    UnityEngine.Debug.Log("redundant instance for RoleInfo<" + typeof(TRole).Name + ">");
                }
            }
Пример #14
0
        private string AddToDictionary(Dictionary <string, Dictionary <string, string> > keyValuePairs, string fullName)
        {
            if (string.IsNullOrEmpty(fullName) || fullName == "SignalGo.Shared.Http.ActionResult")
            {
                return(fullName);
            }
            GenericInfo generic = GenericInfo.GenerateGeneric(fullName);

            Dictionary <string, List <string> > data = new Dictionary <string, List <string> >();

            generic.GetNameSpaces(data, ClearString);
            foreach (KeyValuePair <string, List <string> > item in data)
            {
                foreach (string value in item.Value)
                {
                    string full = FixIllegalChars(item.Key + "." + value);
                    if (fixedReturnTypes.ContainsKey(full.ToLower()))
                    {
                        continue;
                    }
                    if (keyValuePairs.TryGetValue(full, out Dictionary <string, string> dic))
                    {
                        if (!dic.ContainsKey(FixIllegalChars(item.Key)))
                        {
                            dic[FixIllegalChars(item.Key)] = FixIllegalChars(value);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        keyValuePairs[full] = new Dictionary <string, string>()
                        {
                            { FixIllegalChars(item.Key), FixIllegalChars(value) }
                        };
                    }
                }
            }
            generic.ClearNameSpaces(ClearString);
            return(generic.ToString());
        }
Пример #15
0
        public static void ComputeRefactoring(RefactoringContext context, TypeParameterConstraintClauseSyntax constraintClause)
        {
            GenericInfo genericInfo = SyntaxInfo.GenericInfo(constraintClause);

            if (!genericInfo.Success)
            {
                return;
            }

            SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = genericInfo.ConstraintClauses;

            if (constraintClauses.IsSingleLine())
            {
                if (constraintClauses.Count > 1)
                {
                    context.RegisterRefactoring(
                        "Wrap constraints",
                        ct =>
                    {
                        GenericInfo newInfo = WrapConstraints(genericInfo);

                        return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, ct));
                    },
                        RefactoringDescriptors.WrapConstraintClauses);
                }
            }
            else if (constraintClause.DescendantTrivia(constraintClause.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia()) &&
                     constraintClauses[0].GetFirstToken().GetPreviousToken().TrailingTrivia.IsEmptyOrWhitespace())
            {
                context.RegisterRefactoring(
                    "Unwrap constraints",
                    ct =>
                {
                    GenericInfo newInfo = UnwrapConstraints(genericInfo);

                    return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, ct));
                },
                    RefactoringDescriptors.WrapConstraintClauses);
            }
        }
Пример #16
0
        public static void ComputeRefactoring(RefactoringContext context, TypeParameterConstraintClauseSyntax constraintClause)
        {
            GenericInfo genericInfo = SyntaxInfo.GenericInfo(constraintClause);

            if (!genericInfo.Success)
            {
                return;
            }

            SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = genericInfo.ConstraintClauses;

            if (constraintClauses.IsSingleLine())
            {
                if (constraintClauses.Count > 1)
                {
                    context.RegisterRefactoring(
                        "Format constraints on separate lines",
                        cancellationToken =>
                    {
                        GenericInfo newInfo = ToMultiLine(genericInfo);

                        return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken));
                    },
                        RefactoringIdentifiers.FormatConstraintClauses);
                }
            }
            else if (constraintClause.DescendantTrivia(constraintClause.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia()) &&
                     constraintClauses[0].GetFirstToken().GetPreviousToken().TrailingTrivia.IsEmptyOrWhitespace())
            {
                context.RegisterRefactoring(
                    "Format constraints on a single line",
                    cancellationToken =>
                {
                    GenericInfo newInfo = ToSingleLine(genericInfo);

                    return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken));
                },
                    RefactoringIdentifiers.FormatConstraintClauses);
            }
        }
Пример #17
0
        public static void CheckThresholds(Link_Param_Abs_Type type, int value)
        {
            foreach (ActiveThreshold a in OneShotThresholds)
            {
                if (a.Param_Type == type)
                {
                    if (a.CheckIfCrossed(value))
                    {
                        Program.toMihf.Send(MessageBuilders.Link_Parameters_Report_Indication_MsgBuilder(
                                                new ID(new OctetString(GenericInfo.myID)),
                                                new ID(new OctetString(GenericInfo.mihfID)),
                                                GenericInfo.WlanInterfaceInstance.CurrentConnection.wlanAssociationAttributes.Dot11Bssid,
                                                GenericInfo.WlanInterfaceInstance.CurrentConnection.wlanAssociationAttributes.dot11Ssid.SSID,
                                                type,
                                                GenericInfo.GetValueForParam(type)).ByteValue);
                        OneShotThresholds.Remove(a);
                    }
                }
            }

            foreach (ActiveThreshold a in ActiveThresholds)
            {
                if (a.Param_Type == type)
                {
                    if (a.CheckIfCrossed(value))
                    {
                        Program.toMihf.Send(MessageBuilders.Link_Parameters_Report_Indication_MsgBuilder(
                                                new ID(new OctetString(GenericInfo.myID)),
                                                new ID(new OctetString(GenericInfo.mihfID)),
                                                GenericInfo.WlanInterfaceInstance.CurrentConnection.wlanAssociationAttributes.Dot11Bssid,
                                                GenericInfo.WlanInterfaceInstance.CurrentConnection.wlanAssociationAttributes.dot11Ssid.SSID,
                                                type,
                                                GenericInfo.GetValueForParam(type)).ByteValue);
                    }
                }
            }
        }
Пример #18
0
        public static void ComputeRefactoring(RefactoringContext context, TypeParameterConstraintClauseSyntax constraintClause)
        {
            GenericInfo genericInfo = SyntaxInfo.GenericInfo(constraintClause);

            if (!genericInfo.Success)
            {
                return;
            }

            SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = genericInfo.ConstraintClauses;

            if (constraintClauses.IsSingleLine())
            {
                if (constraintClauses.Count > 1)
                {
                    context.RegisterRefactoring(
                        "Format constraints on separate lines",
                        cancellationToken =>
                    {
                        GenericInfo newInfo = ToMultiLine(genericInfo);

                        return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken));
                    });
                }
            }
            else
            {
                context.RegisterRefactoring(
                    "Format constraints on a single line",
                    cancellationToken =>
                {
                    GenericInfo newInfo = ToSingleLine(genericInfo);

                    return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken));
                });
            }
        }
Пример #19
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            if (!Settings.IsAnyEnabled(
                    CodeFixIdentifiers.RemoveConstraintClauses,
                    CodeFixIdentifiers.CombineConstraintClauses))
            {
                return;
            }

            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeParameterConstraintClauseSyntax constraintClause))
            {
                return;
            }

            foreach (Diagnostic diagnostic in context.Diagnostics)
            {
                switch (diagnostic.Id)
                {
                case CompilerDiagnosticIdentifiers.ConstraintsAreNotAllowedOnNonGenericDeclarations:
                {
                    if (!Settings.IsEnabled(CodeFixIdentifiers.RemoveConstraintClauses))
                    {
                        break;
                    }

                    GenericInfo genericInfo = SyntaxInfo.GenericInfo(constraintClause);

                    if (!genericInfo.Success)
                    {
                        break;
                    }

                    CodeAction codeAction = CodeAction.Create(
                        "Remove constraints",
                        cancellationToken =>
                        {
                            GenericInfo newGenericInfo = genericInfo.RemoveAllConstraintClauses();

                            return(context.Document.ReplaceNodeAsync(genericInfo.Node, newGenericInfo.Node, cancellationToken));
                        },
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }

                case CompilerDiagnosticIdentifiers.ConstraintClauseHasAlreadyBeenSpecified:
                {
                    if (!Settings.IsEnabled(CodeFixIdentifiers.CombineConstraintClauses))
                    {
                        break;
                    }

                    GenericInfo genericInfo = SyntaxInfo.GenericInfo(constraintClause);

                    int index = genericInfo.ConstraintClauses.IndexOf(constraintClause);

                    string name = constraintClause.Name.Identifier.ValueText;

                    TypeParameterConstraintClauseSyntax constraintClause2 = genericInfo.FindConstraintClause(name);

                    if (constraintClause2 == null)
                    {
                        break;
                    }

                    CodeAction codeAction = CodeAction.Create(
                        $"Combine constraints for '{name}'",
                        cancellationToken =>
                        {
                            TypeParameterConstraintClauseSyntax newConstraintClause = constraintClause2.WithConstraints(constraintClause2.Constraints.AddRange(constraintClause.Constraints));

                            SyntaxList <TypeParameterConstraintClauseSyntax> newConstraintClauses = genericInfo.ConstraintClauses
                                                                                                    .Replace(constraintClause2, newConstraintClause)
                                                                                                    .RemoveAt(index);

                            GenericInfo newGenericInfo = genericInfo.WithConstraintClauses(newConstraintClauses);

                            return(context.Document.ReplaceNodeAsync(genericInfo.Node, newGenericInfo.Node, cancellationToken));
                        },
                        GetEquivalenceKey(diagnostic));

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }
                }
            }
        }
Пример #20
0
        private void GenerateModelClass(ClassReferenceInfo classReferenceInfo, string prefix, StringBuilder builder, MapDataClassInfo mapDataClassInfo, string baseServiceName, Dictionary <string, Dictionary <string, string> > nameSpaces)
        {
            string mainName = classReferenceInfo.NormalizedName;

            if (mainName.Contains("<"))
            {
                mainName = mainName.Substring(0, mainName.IndexOf('<'));
            }

            string name = mainName;

            //while (RenamedModels.ContainsKey(classReferenceInfo.NameSpace + "." + name))
            //{
            //    index++;
            //    name = mainName + index;
            //}
            if (classReferenceInfo.NormalizedName.Contains("<"))
            {
                int indexName = classReferenceInfo.NormalizedName.Count(x => x == '>' || x == '<' || x == ',');
                mainName = name + indexName + classReferenceInfo.NormalizedName.Substring(classReferenceInfo.NormalizedName.IndexOf('<'));
                if (GeneratedModels.Contains(classReferenceInfo.NameSpace + "." + mainName))
                {
                    return;
                }
                GeneratedModels.Add(classReferenceInfo.NameSpace + "." + mainName);
                classReferenceInfo.Name = mainName;
                //RenamedModels.Add(classReferenceInfo.NameSpace + "." + name, classReferenceInfo.NameSpace + "." + oldName);
            }
            else
            {
                if (GeneratedModels.Contains(classReferenceInfo.NameSpace + "." + name))
                {
                    return;
                }
                GeneratedModels.Add(classReferenceInfo.NameSpace + "." + name);
                classReferenceInfo.Name = name;
                //RenamedModels.Add(classReferenceInfo.NameSpace + "." + name, classReferenceInfo.NameSpace + "." + oldName);
            }
            string baseName = "";

            if (!string.IsNullOrEmpty(classReferenceInfo.BaseClassName) && !classReferenceInfo.BaseClassName.StartsWith("SignalGo."))
            {
                GenericInfo generic = GenericInfo.GenerateGeneric(classReferenceInfo.BaseClassName);
                generic.ClearNameSpaces(ClearString);
                string typeName = generic.ToString();
                AddToDictionary(nameSpaces, classReferenceInfo.BaseClassName);

                baseName = " extends " + typeName;
            }
            GenericInfo genericInfo = GenericInfo.GenerateGeneric(classReferenceInfo.NormalizedName, GenericNumbericTemeplateType.Skip);

            builder.AppendLine("import com.fasterxml.jackson.annotation.JsonProperty;");
            builder.AppendLine();
            builder.AppendLine("public class " + classReferenceInfo.NormalizedName + baseName + "{");
            builder.AppendLine($@"
        public {genericInfo.Name}() {{
        ");
            if (!string.IsNullOrEmpty(baseName))
            {
                builder.AppendLine("super();");
            }
            foreach (PropertyReferenceInfo propertyInfo in classReferenceInfo.Properties)
            {
                if (mapDataClassInfo != null && mapDataClassInfo.IgnoreProperties.Contains(propertyInfo.Name))
                {
                    continue;
                }
                if (propertyInfo.ReturnTypeName == "T")
                {
                    continue;
                }
                SetPropertyValue(propertyInfo, prefix + prefix, false, builder, baseServiceName, nameSpaces);
            }
            //end of constructor
            builder.AppendLine(prefix + "}");
            foreach (PropertyReferenceInfo propertyInfo in classReferenceInfo.Properties)
            {
                if (mapDataClassInfo != null && mapDataClassInfo.IgnoreProperties.Contains(propertyInfo.Name))
                {
                    continue;
                }
                GenerateProperty(propertyInfo, prefix + prefix, false, builder, baseServiceName, nameSpaces);
            }

            foreach (PropertyReferenceInfo propertyInfo in classReferenceInfo.Properties)
            {
                if (mapDataClassInfo != null && mapDataClassInfo.IgnoreProperties.Contains(propertyInfo.Name))
                {
                    continue;
                }
                GeneratePropertyGetterSetter(propertyInfo, prefix + prefix, false, builder, baseServiceName, nameSpaces);
            }

            if (mapDataClassInfo != null && !string.IsNullOrEmpty(mapDataClassInfo.Body))
            {
                builder.AppendLine(mapDataClassInfo.Body);
            }
            builder.AppendLine();

            builder.AppendLine(prefix + "}");

            builder.AppendLine();
        }
        private GenericInfo ConstructGenericInfo(UploadAppSampleDataDictionary d)
        {
            var geninfo = new GenericInfo
            {
                ApplicationType = (ApplicationTypes)Enum.Parse(typeof(ApplicationTypes), GetNextValue(d.ApplicationType)),

                Gender = GetNextValue(d.Gender),

                IsSecondNameNOTChanged   = Convert.ToBoolean(GetNextValue(d.IsSecondNameNOTChanged)),
                IsAgreeAuthorityTransfer = Convert.ToBoolean(GetNextValue(d.IsSecondNameNOTChanged)),
                SMScode      = GetNextDigitSequence(6),
                BirthDate    = GetNextRangeValue(d.BirthDate),
                PlaceOfBirth = GetNextValue(d.PlaceOfBirth),
                RegistrationDateOnAddress = GetNextRangeValue(d.IssuedOn),
                IsRegEqualFactAddress     = Convert.ToBoolean(GetNextRangeValue(new [] { 0, 1 })),
                Citizenship          = "643",
                ContactPhone         = "+7" + GetNextDigitSequence(10),
                ContactName          = GetNextValue(d.ContactName),
                RelationDegree       = GetNextValue(d.RelationDegree),
                IsNotPublicPerson    = true,
                MaidenName           = GetNextValue(d.MaidenName),
                SecretQuestion       = GetNextValue(d.SecretQuestion),
                SecretQuestionAnswer = GetNextValue(d.SecretQuestion),
                SecretWord           = GetNextValue(d.SecretWord),
                TPin            = GetNextDigitSequence(4),
                IsDataAuthentic = Convert.ToBoolean(GetNextValue(d.IsDataAuthentic)),
                CardCategory    = GetNextValue(d.CardCategory),
                UserIP          = String.Format("{0}.{1}.{2}.{3}", GetNextRangeValue(new [] { 1, 255 }), GetNextRangeValue(new [] { 1, 255 }), GetNextRangeValue(new [] { 1, 255 }), GetNextRangeValue(new [] { 1, 255 })),
                //TrafficSource = GetNextRangeValue(d.TrafficSource),
                //TrafficType = GetNextRangeValue(d.TrafficType),
                //AdvertContent = GetNextRangeValue(d.AdvertContent),
                //ContentAdvertKeyWord = GetNextRangeValue(d.ContentAdvertKeyWord),
                //AdvertCompanyProduct = GetNextRangeValue(d.AdvertCompanyProduct),
                //PageAddress = GetNextRangeValue(d.PageAddress),
                //PartnerMark = GetNextRangeValue(d.PartnerMark),
                ClientType = GetNextValue(d.ClientType),
                //FillingStartDate = GetNextRangeValue(d.FillingStartDate),
                SendingDateTime = DateTime.Now,
            };

            // Split card types to debit/credit
            geninfo.BankingService = geninfo.ApplicationType == ApplicationTypes.credit ? GetNextValue(d.BankingServiceCredit) : GetNextValue(d.BankingServiceDebit);

            if (geninfo.Gender == "M")
            {
                geninfo.Name         = GetNextValue(d.NameM);
                geninfo.PaternalName = GetNextValue(d.PaternalNameM);
                geninfo.LastName     = GetNextValue(d.LastNameM);
            }
            else
            {
                geninfo.Name         = GetNextValue(d.NameG);
                geninfo.PaternalName = GetNextValue(d.PaternalNameG);
                geninfo.LastName     = GetNextValue(d.LastNameG);
            }

            geninfo.FirstNameRomanType  = UberTranslit.GetTranslit(geninfo.Name);
            geninfo.SecondNameRomanType = UberTranslit.GetTranslit(geninfo.LastName);

            geninfo.CurrencyAsked = geninfo.ApplicationType == ApplicationTypes.credit ?
                                    "RUB" : GetNextValue(d.CurrencyAsked);

            return(geninfo);
        }
Пример #22
0
        private void GenerateModelClass(ClassReferenceInfo classReferenceInfo, string prefix, StringBuilder builder, MapDataClassInfo mapDataClassInfo, string baseServiceName, Dictionary <string, Dictionary <string, string> > nameSpaces)
        {
            string mainName = classReferenceInfo.Name;

            if (mainName.Contains("<"))
            {
                mainName = mainName.Substring(0, mainName.IndexOf('<'));
            }

            string name = mainName;

            //while (RenamedModels.ContainsKey(classReferenceInfo.NameSpace + "." + name))
            //{
            //    index++;
            //    name = mainName + index;
            //}
            if (classReferenceInfo.Name.Contains("<"))
            {
                int indexName = classReferenceInfo.Name.Count(x => x == '>' || x == '<' || x == ',');
                mainName = name + indexName + classReferenceInfo.Name.Substring(classReferenceInfo.Name.IndexOf('<'));
                if (GeneratedModels.Contains(classReferenceInfo.NameSpace + "." + mainName))
                {
                    return;
                }
                GeneratedModels.Add(classReferenceInfo.NameSpace + "." + mainName);
                classReferenceInfo.Name = mainName;
                //RenamedModels.Add(classReferenceInfo.NameSpace + "." + name, classReferenceInfo.NameSpace + "." + oldName);
            }
            else
            {
                if (GeneratedModels.Contains(classReferenceInfo.NameSpace + "." + name))
                {
                    return;
                }
                GeneratedModels.Add(classReferenceInfo.NameSpace + "." + name);
                classReferenceInfo.Name = name;
                //RenamedModels.Add(classReferenceInfo.NameSpace + "." + name, classReferenceInfo.NameSpace + "." + oldName);
            }
            string baseName = "";

            if (!string.IsNullOrEmpty(classReferenceInfo.BaseClassName) && !classReferenceInfo.BaseClassName.StartsWith("SignalGo."))
            {
                GenericInfo generic = GenericInfo.GenerateGeneric(classReferenceInfo.BaseClassName);
                generic.ClearNameSpaces(ClearString);
                string typeName = generic.ToString();
                AddToDictionary(nameSpaces, classReferenceInfo.BaseClassName);

                baseName = " extends " + typeName;
            }
            builder.AppendLine(prefix + "export class " + classReferenceInfo.Name + baseName + "{");
            foreach (PropertyReferenceInfo propertyInfo in classReferenceInfo.Properties)
            {
                if (mapDataClassInfo != null && mapDataClassInfo.IgnoreProperties.Contains(propertyInfo.Name))
                {
                    continue;
                }
                GenerateProperty(propertyInfo, prefix + prefix, false, builder, baseServiceName, nameSpaces);
            }
            if (mapDataClassInfo != null && !string.IsNullOrEmpty(mapDataClassInfo.Body))
            {
                builder.AppendLine(mapDataClassInfo.Body);
            }
            builder.AppendLine();

            builder.AppendLine(prefix + "}");

            builder.AppendLine();
        }
Пример #23
0
        private void button_Decompress_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "LoGH Containers|*.mvx;*.arc";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string      outputFolderPath = openFileDialog.FileName + "_";
                GenericInfo tmpGeneric       = new GenericInfo
                {
                    ContainerName = openFileDialog.FileName,
                    ContainerType = Path.GetExtension(openFileDialog.FileName)
                };

                ARCHeader     tmpHeader = new ARCHeader();
                List <ARCToc> tmpToc    = new List <ARCToc>();

                using (BinaryReader reader = new BinaryReader(new FileStream(openFileDialog.FileName, FileMode.Open)))
                {
                    //Parse Header
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    tmpHeader.HeaderIdentifier     = reader.ReadBytes(4);
                    tmpHeader.FileReaderBufferSize = reader.ReadByte();
                    tmpHeader.UnknownType          = reader.ReadByte();

                    reader.BaseStream.Seek(3, SeekOrigin.Current); //0x00 three times

                    tmpHeader.UnknownValue1   = reader.ReadByte();
                    tmpHeader.TocPointer2     = reader.ReadByte();
                    tmpHeader.UnknownValue2   = reader.ReadByte();
                    tmpHeader.UnknownType2    = reader.ReadByte();
                    tmpHeader.FileCount       = reader.ReadByte();
                    tmpHeader.UnknownValue3   = reader.ReadByte();
                    tmpHeader.CompressionType = reader.ReadByte();

                    tmpHeader.HeaderLeftover = reader.ReadBytes(112);

                    //Begin of TOC
                    reader.BaseStream.Seek(2, SeekOrigin.Current); //skip two 0x00
                    for (int i = 1; i <= tmpHeader.FileCount; i++)
                    {
                        long   entryOffset = reader.BaseStream.Position;
                        ARCToc localToc    = new ARCToc();

                        for (int j = 1; j <= 5; j++)
                        {
                            var VAL1 = reader.ReadByte();
                            reader.BaseStream.Seek(6, SeekOrigin.Current);
                            var VAL2 = reader.ReadByte();
                            reader.BaseStream.Seek(6, SeekOrigin.Current);
                            var VAL3 = reader.ReadByte();
                            reader.BaseStream.Seek(6, SeekOrigin.Current);
                            var VAL4 = reader.ReadByte();
                            reader.BaseStream.Seek(6, SeekOrigin.Current);

                            var tmpVal = (VAL1 | (VAL2 << 8) | (VAL3 << 16) | (VAL4 << 24));

                            switch (j)
                            {
                            case 1:
                                localToc.NameOffset = tmpVal;
                                break;

                            case 2:
                                localToc.NameLength = tmpVal;
                                break;

                            case 3:
                                localToc.Offset = tmpVal;
                                break;

                            case 4:
                                localToc.Zsize = tmpVal;
                                break;

                            case 5:
                                localToc.Size = tmpVal;
                                break;

                            default:
                                throw new Exception("NOPE!");
                            }

                            entryOffset += 1;
                            reader.BaseStream.Seek(entryOffset, SeekOrigin.Begin);
                        }

                        //Readout name string
                        long preOffset = reader.BaseStream.Position;
                        reader.BaseStream.Seek(localToc.NameOffset, SeekOrigin.Begin);
                        localToc.NameBytes = reader.ReadBytes(localToc.NameLength);
                        localToc.Name      = new ASCIIEncoding().GetString(localToc.NameBytes, 0, localToc.NameLength - 1); //-1 because we dont want the null terminator

                        //Read DATA (offset since file begin)
                        reader.BaseStream.Seek(localToc.Offset, SeekOrigin.Begin);
                        localToc.Data      = reader.ReadBytes(localToc.Zsize);
                        localToc.OffsetEnd = (int)reader.BaseStream.Position;

                        //Reset Seek for next header file
                        reader.BaseStream.Seek(preOffset, SeekOrigin.Begin);

                        //Add toc to list
                        tmpToc.Add(localToc);

                        //Everything is ready to readout compressed data
                        if (localToc.Zsize == localToc.Size)
                        {
                            //Content is unencrypted... passtrough directly to filewriter
                            localToc.DataDecompressed = localToc.Data;
                        }
                        else
                        {
                            //decompress with lzss
                            localToc.DataDecompressed = LZSS.Decompress(localToc.Data);
                        }

                        reader.BaseStream.Seek(27, SeekOrigin.Current);
                    }
                }

                //PHASE 2: Export data from memory to Filesystem
                DirectoryInfo di = Directory.CreateDirectory(outputFolderPath);
                foreach (var toc in tmpToc)
                {
                    //Check name for sub-folders - when there are some - create
                    Directory.CreateDirectory(Path.GetDirectoryName(outputFolderPath + "//" + toc.Name));

                    //Decompressed file
                    using (FileStream fs = File.Create(outputFolderPath + "//" + toc.Name))
                    {
                        fs.Write(toc.DataDecompressed, 0, toc.DataDecompressed.Length);
                    }

                    //Compressed file
                    using (FileStream fs = File.Create(outputFolderPath + "//" + toc.Name + "_COMP"))
                    {
                        fs.Write(toc.Data, 0, toc.Data.Length);
                    }
                }

                SerializeCollection tmpSer = new SerializeCollection
                {
                    generic   = tmpGeneric,
                    arcHeader = tmpHeader,
                    arcToc    = tmpToc
                };

                //Serialize header & toc
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(outputFolderPath + "//_header.bin", FileMode.Create, FileAccess.Write, FileShare.None);
                //GZipStream gzip = new GZipStream(stream, CompressionLevel.Fastest);
                formatter.Serialize(stream, tmpSer);
                stream.Close();
            }
        }