Example #1
0
        public static void Run()
        {
            string dataRoot = @"C:\Temp\SLXData\ActiveForms_bin";
            SortedDictionary<string, long> plugins = new SortedDictionary<string, long>();

            foreach (DirectoryInfo directory in new DirectoryInfo(dataRoot).GetDirectories())
            {
                foreach (DirectoryInfo subDirectory in directory.GetDirectories())
                {
                    foreach (FileInfo file in subDirectory.GetFiles())
                    {
                        plugins.Add(file.FullName, file.Length);
                    }
                }
            }

            string[] fileNames = new string[plugins.Count];
            plugins.Keys.CopyTo(fileNames, 0);
            long[] fileSizes = new long[plugins.Count];
            plugins.Values.CopyTo(fileSizes, 0);
            Array.Sort(fileSizes, fileNames);

            IFormFlatteningService flattener = new FormFlatteningService();

            foreach (string fileName in fileNames)
            {
                Console.WriteLine(fileName);
                byte[] data = File.ReadAllBytes(fileName);
                DelphiComponent component;

                using (DelphiBinaryReader binaryReader = new DelphiBinaryReader(data))
                {
                    component = binaryReader.ReadComponent(true);
                }

                IList<string> beforeNames = new List<string>();
                GatherControlNames(component, beforeNames);
                flattener.Flatten(component, false);
                IList<string> afterNames = new List<string>();
                GatherControlNames(component, afterNames);
                Debug.Assert(beforeNames.Count == afterNames.Count);

                for (int i = 0; i < beforeNames.Count; i++)
                {
                    Debug.Assert(beforeNames[i] == afterNames[i]);
                }

                foreach (DelphiComponent childComponent in component.Components)
                {
                    foreach (DelphiComponent grandComponent in childComponent.Components)
                    {
                        Debug.Assert(grandComponent != null);
                        Debug.Assert(!grandComponent.Properties.ContainsKey("CLSID"));
                    }
                }
            }
        }
        private DelphiComponent ParseItems(DelphiBinaryReader binaryReader, bool isPrefixed)
        {
            DelphiComponent component = binaryReader.ReadComponent(isPrefixed);
            _componentSimplifier.Simplify(component);
            byte b = binaryReader.ReadByte();
            Debug.Assert(b == 1);

            while (binaryReader.PeekChar() != 0)
            {
                component.Components.Add(ParseItems(binaryReader, false));
            }

            binaryReader.ReadByte();
            return component;
        }
        private void Parse(Plugin plugin)
        {
            DelphiComponent component;

            using (MemoryStream stream = new MemoryStream(plugin.Blob.Data))
            {
                stream.Position = 0xE;

                using (DelphiBinaryReader binaryReader = new DelphiBinaryReader(stream))
                {
                    component = binaryReader.ReadComponent(true);
                }
            }

            _componentSimplifier.Simplify(component);
            byte[] data;

            if (component.TryGetPropertyValue("Toolbars.WhenItems", out data))
            {
                using (DelphiBinaryReader binaryReader = new DelphiBinaryReader(data))
                {
                    component = ParseItems(binaryReader, true);
                }

                foreach (DelphiComponent groupComponent in component.Components)
                {
                    string group;
                    string defaultDock;

                    if (groupComponent.TryGetPropertyValue("DefaultDock", out defaultDock) && defaultDock == "wtdLeft")
                    {
                        groupComponent.TryGetPropertyValue("Caption", out group);
                    }
                    else
                    {
                        group = null;
                    }

                    foreach (DelphiComponent itemComponent in groupComponent.Components)
                    {
                        string caption;

                        if (itemComponent.TryGetPropertyValue("Caption", out caption) && !string.IsNullOrEmpty(caption))
                        {
                            string action;
                            string argument;
                            itemComponent.TryGetPropertyValue("Caption", out caption);
                            itemComponent.TryGetPropertyValue("WhenClick.Action", out action);
                            itemComponent.TryGetPropertyValue("WhenClick.Argument", out argument);
                            Image glyph = (itemComponent.TryGetPropertyValue("Glyph.Data", out data)
                                               ? BorlandUtils.ParseGlyphData(data)
                                               : null);
                            _context.Navigation.Add(new NavigationInfo(plugin, caption, group, action, argument, glyph));
                        }
                    }
                }
            }
        }
Example #4
0
        public string SaveAsPDF(string OutputFileName = null, string OutputFilePath = null)
        {
            if (OutputFileName == null)
            {
                OutputFileName = string.Format("{0}-{1}.pdf", this.ReportName, Environment.TickCount);
            }
            if (OutputFilePath == null || !Directory.Exists(OutputFilePath))
            {
                OutputFilePath = Path.GetTempPath();
            }
            var fileName = Path.Combine(OutputFilePath, SanitizeFileName(OutputFileName));

            Log.Debug("File name to output report to: " + fileName);

            try
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
            catch { }

            var plugin = Plugin.LoadByName(this.ReportName, this.ReportFamily, PluginType.CrystalReport);

            if (plugin != null)
            {
                var tempRpt = Path.GetTempFileName() + ".rpt";
                using (var stream = new MemoryStream(plugin.Blob.Data))
                {
                    using (var reader = new DelphiBinaryReader(stream))
                    {
                        reader.ReadComponent(true);
                        using (var file = File.OpenWrite(tempRpt))
                        {
                            stream.CopyTo(file);
                        }
                    }
                }

                using (var report = new SlxReport())
                {
                    report.Load(tempRpt);
                    report.UpdateDbConnectionInfo(this.ConnectionString);
                    if (!string.IsNullOrEmpty(report.RecordSelectionFormula))
                    {
                        report.RecordSelectionFormula = string.Format("{0}({0}{1}{0}) and {0}{2}", System.Environment.NewLine, report.RecordSelectionFormula, this.RecordSelectionFormula);
                    }
                    else
                    {
                        report.RecordSelectionFormula = this.RecordSelectionFormula;
                    }
                    if (this.Parameters.Count > 0)
                    {
                        this.Parameters.ForEach(param => report.SetParameterValue(param.Key, param.Value));
                    }
                    report.ExportAsPdfEx(fileName, plugin.Name, true);
                    report.Close();
                }
            }
            else
            {
                throw new ArgumentException("The report plugin for " + this.ReportPlugin + "can not be found.");
            }

            return(fileName);
        }
    protected void _changePassword_Click(object sender, EventArgs e)
    {
        DelphiComponent dc = new DelphiComponent();
        Sage.SalesLogix.SystemInformation si = Sage.SalesLogix.SystemInformationRules.GetSystemInfo();

        DelphiBinaryReader delphi = new DelphiBinaryReader(si.Data);
        dc = delphi.ReadComponent(true);

        string minPasswordLength = dc.Properties["MinPasswordLength"].ToString();
        bool noBlankPassword  = (bool)dc.Properties["NoBlankPassword"];
        bool alphaNumPassword = (bool)dc.Properties["AlphaNumPassword"];
        bool noNameInPassword = (bool)dc.Properties["NoNameInPassword"];

        Regex objAlphaNumericPattern = new Regex("[a-zA-Z][0-9]");
        string changingUser = string.Empty;

        // Get the user name of the person who's getting their password changed
         Sage.Entity.Interfaces.IUser us = User.LookupResultValue as IUser;

         if (us != null)
         {
             changingUser = us.UserName;
         }
         else
         {
             changingUser = slxUserService.UserName;
         }

        string newPassword = _newPassword.Text;
        if (Convert.ToInt32(minPasswordLength) != 0)
        {
            if (newPassword.Length < Convert.ToInt32(minPasswordLength))
            {
                lblMessage.Text = string.Format(GetLocalResourceObject("minPasswordLength").ToString(), minPasswordLength); //   "Password length must be {0} chars or greater!"
                return;
            }
            if (alphaNumPassword && !objAlphaNumericPattern.IsMatch(newPassword))
            {
                lblMessage.Text = GetLocalResourceObject("alphaNumPassword").ToString();// "Passwords must be alphanumeric!";
                return;
            }

        }
        else if (noBlankPassword && newPassword.Length == 0)
        {
            lblMessage.Text = GetLocalResourceObject("noBlankPassword").ToString();//Passwords can not be blank!";
            return;
        }

        if (noNameInPassword && newPassword.ToUpper().Contains(changingUser.ToUpper()))
        {
            if (curUser.ToUpper().Contains("ADMIN") && !changingUser.ToUpper().Contains("ADMIN"))
                lblMessage.Text = GetLocalResourceObject("noNameInPasswordAdmin").ToString(); // "Passwords cannot contain the user name!";
            else
                lblMessage.Text = GetLocalResourceObject("noNameInPasswordUser").ToString(); //"Passwords cannot contain your user name!";
            return;
        }

        // save values
        if (newPassword == _confirmPassword.Text)
        {
            ChangePasswordOptions options = new ChangePasswordOptions();
            options.NewPassword = newPassword;

            string curUser = slxUserService.GetUser().Id;
            if (curUser.ToString().Trim() != "ADMIN")
            {
                options.UserId = curUser;
            }
            else
            {
                options.UserId = ((IUser)this.User.LookupResultValue).Id.ToString();
            }
            options.Save();
            if (_newPassword.Text.Length == 0)
            {
                lblMessage.Text = GetLocalResourceObject("PasswordBlank").ToString();
            }
            else
            {
                lblMessage.Text = string.Empty;
            }
        }
        else
        {
            lblMessage.Text = GetLocalResourceObject("PasswordNotMatch").ToString();
        }
    }
Example #6
0
        private static void Output_Series(byte[] data, string indentation)
        {
            using (MemoryStream stream = new MemoryStream(data))
            {
                DelphiBinaryReader reader = new DelphiBinaryReader(stream);
                int count = reader.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    int len = reader.ReadInt32();
                    string type = reader.ReadString(len);
                    WriteLine("{0}{1}", indentation, type);
                    OutputComponent(reader.ReadComponent(true), indentation + "  ");
                    OutputProperty("SQL", reader.ReadString(reader.ReadInt32()), indentation + "  ");
                    //TODO: figure out what these numbers mean
                    Debug.Assert(reader.ReadInt32() == 0);
                    Debug.Assert(reader.ReadInt32() == 0);
                }

                Debug.Assert(stream.Position == stream.Length);
            }
        }
Example #7
0
        private static void OutputProperty(DelphiBinaryReader reader, string indentation)
        {
            string key = reader.ReadString();

            switch (key)
            {
                case "PopupMenu":
                case "PopupMenuX":
                case "ImageList":
                case "ImagesList":
                case "LargeImagesList":
                case "SmallImagesList":
                case "StateImagesList":
                case "_ImageList":
                    WriteLine("{0}{1}", indentation, key);
                    OutputComponent(reader.ReadComponent(false), indentation + "  ");
                    break;
                default:
                    object value = reader.ReadValue();
                    OutputProperty(key, value, indentation);
                    break;
            }
        }
        private void Parse(Plugin plugin)
        {
            DelphiComponent component;

            using (DelphiBinaryReader binaryReader = new DelphiBinaryReader(new MemoryStream(BorlandUtils.ObjectTextToBinary(plugin.Blob.Data))))
            {
                component = binaryReader.ReadComponent(true);
            }

            _componentSimplifier.Simplify(component);

            string baseTable;
            string detailsViewName;
            component.TryGetPropertyValue("BaseTable", out baseTable);
            component.TryGetPropertyValue("DetailsViewName", out detailsViewName);
            MainViewInfo mainView = new MainViewInfo(plugin, baseTable, detailsViewName);
            _context.MainViews.Add(mainView.FullName, mainView);

            //TODO: might need EntityNameSingular, EntityNamePlural, EntityFieldName

            string script;

            if (component.TryGetPropertyValue("ScriptText", out script) && !string.IsNullOrEmpty(script))
            {
                //TODO: need to add proper script support for main views
                ScriptInfo scriptInfo = new ScriptInfo(plugin, script);
                _context.Scripts.Add(scriptInfo.PrefixedFullName, scriptInfo);
            }
        }
        private void ParseProperty(DelphiBinaryReader reader, IDictionary<string, object> properties)
        {
            string key = reader.ReadString();
            object value;

            switch (key)
            {
                case "PopupMenu":
                case "PopupMenuX":
                case "ImageList":
                case "ImagesList":
                case "LargeImagesList":
                case "SmallImagesList":
                case "StateImagesList":
                case "_ImageList":
                    DelphiComponent component = reader.ReadComponent(false);
                    _componentSimplifier.Simplify(component);
                    value = component;
                    break;
                default:
                    value = reader.ReadValue();
                    break;
            }

            properties.Add(key, value);
        }