Example #1
0
        public void FixSlashes()
        {
            string       temp         = null;
            const string alreadyFixed = @"C:\usr\local\cell";

            var fix1 = SledUtil.FixSlashes(temp);

            Assert.AreEqual(0, string.Compare(string.Empty, fix1));

            temp = @"C:/usr/local/cell/";
            fix1 = SledUtil.FixSlashes(temp);
            Assert.AreEqual(0, string.Compare(fix1, alreadyFixed));

            temp = @"C:/usr/local/cell";
            fix1 = SledUtil.FixSlashes(temp);
            Assert.AreEqual(0, string.Compare(fix1, alreadyFixed));

            temp = @"C:\usr/local\cell/";
            fix1 = SledUtil.FixSlashes(temp);
            Assert.AreEqual(0, string.Compare(fix1, alreadyFixed));

            temp = @"C:/usr\local/cell";
            fix1 = SledUtil.FixSlashes(temp);
            Assert.AreEqual(0, string.Compare(fix1, alreadyFixed));
        }
Example #2
0
        /// <summary>
        /// Finishes initializing component by registering with settings service
        /// </summary>
        public virtual void Initialize()
        {
            {
                var owner =
                    string.Format(
                        "{0}-{1}-TreeListView-Settings",
                        this,
                        TreeListView.Name);

                SettingsService.RegisterSettings(
                    SledUtil.GuidFromString(owner),
                    new BoundPropertyDescriptor(
                        TreeListView,
                        () => TreeListView.PersistedSettings,
                        owner,
                        null,
                        owner));
            }

            ControlHostService.RegisterControl(TreeListView, m_controlInfo, this);

            StandardEditCommands.Copying += StandardEditCommandsCopying;
            StandardEditCommands.Copied  += StandardEditCommandsCopied;

            if (!AllowDebugFreeze)
            {
                return;
            }

            DebugFreezeService.Freezing += DebugFreezeServiceFreezing;
            DebugFreezeService.Thawing  += DebugFreezeServiceThawing;
        }
        void IInitializable.Initialize()
        {
            if (IsInitialized)
            {
                return;
            }

            var networkPlugins = SledServiceInstance.GetAll <ISledNetworkPlugin>();

            m_lstPlugins.Clear();

            using (new SledOutDevice.BreakBlock())
            {
                foreach (var netPlugin in networkPlugins)
                {
                    // Add plugin to list
                    m_lstPlugins.Add(netPlugin);

                    // Report the plugin was found
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        SledUtil.TransSub(Localization.SledNetworkPluginLoaded, netPlugin.Protocol, netPlugin.Name));
                }
            }

            try
            {
                Initialized.Raise(this, EventArgs.Empty);
            }
            finally
            {
                IsInitialized = true;
            }
        }
Example #4
0
        public void Read()
        {
            try
            {
                m_bLoading = true;

                var filePath = m_uri.LocalPath;
                if (File.Exists(filePath))
                {
                    // Store whether file has byte order mark
                    m_bHasBom = SledUtil.FileHasBom(filePath);

                    using (Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        using (var reader = new StreamReader(stream, true))
                        {
                            // Store encoding
                            m_encoding = reader.CurrentEncoding;

                            // Read file and update editor
                            m_editor.Text  = reader.ReadToEnd();
                            m_editor.Dirty = false;
                        }
                    }
                }
            }
            finally
            {
                m_bLoading = false;
            }
        }
        private void DebugServiceBreakpointHit(object sender, SledDebugServiceBreakpointEventArgs e)
        {
            if (string.IsNullOrEmpty(e.Breakpoint.File))
            {
                // TODO: open a faux document saying something about unknown file?
                return;
            }

            // Get absolute path to file
            var szAbsPath = SledUtil.GetAbsolutePath(e.Breakpoint.File, m_projectService.AssetDirectory);

            if (!string.IsNullOrEmpty(szAbsPath) && File.Exists(szAbsPath))
            {
                ISledDocument sd;
                var           uri = new Uri(szAbsPath);

                // If already open jump to line otherwise open the file
                if (m_documentService.IsOpen(uri, out sd))
                {
                    m_gotoService.Get.GotoLine(sd, m_curBreakpoint.Line, true);
                }
                else
                {
                    m_documentService.Open(uri, out sd);
                }
            }

            MarkProjectDocsReadOnly(false);
        }
        private void DebugServiceBreakpointHitting(object sender, SledDebugServiceBreakpointEventArgs e)
        {
            m_curBreakpoint = e.Breakpoint.Clone() as SledNetworkBreakpoint;

            if (m_curBreakpoint.IsUnknownFile())
            {
                return;
            }

            // Get absolute path to file
            var szAbsPath = SledUtil.GetAbsolutePath(e.Breakpoint.File, m_projectService.AssetDirectory);

            if (string.IsNullOrEmpty(szAbsPath) || !File.Exists(szAbsPath))
            {
                return;
            }

            // Check if file is in the project
            var projFile = m_projectFileFinderService.Get.Find(szAbsPath);

            // Try and add file to project
            if (projFile == null)
            {
                m_projectService.AddFile(szAbsPath, out projFile);
            }
        }
Example #7
0
        public void FileEndsWithExtension()
        {
            var extensions = new[] { ".txt", ".exe" };
            var filenames  = new[] { @"C:\text.txt", @"C:\executable.exe", @"C:\image.bmp" };

            Assert.That(!SledUtil.StringEndsWithExtension(null, null));
            Assert.That(!SledUtil.StringEndsWithExtension(null, extensions));
            Assert.That(!SledUtil.StringEndsWithExtension(filenames[0], null));

            string out1, out2;

            Assert.That(!SledUtil.StringEndsWithExtension(null, null, out out1));
            Assert.AreEqual(0, string.Compare(string.Empty, out1));

            Assert.That(!SledUtil.StringEndsWithExtension(null, extensions, out out1));
            Assert.AreEqual(0, string.Compare(string.Empty, out1));

            Assert.That(!SledUtil.StringEndsWithExtension(filenames[1], null, out out1));
            Assert.AreEqual(0, string.Compare(string.Empty, out1));

            Assert.That(SledUtil.StringEndsWithExtension(filenames[0], extensions));
            Assert.That(!SledUtil.StringEndsWithExtension(filenames[2], extensions));
            Assert.That(SledUtil.StringEndsWithExtension(filenames[1], extensions, out out1));
            Assert.That(!SledUtil.StringEndsWithExtension(filenames[2], extensions, out out2));

            Assert.AreEqual(0, string.Compare(extensions[1], out1, true));
            Assert.AreEqual(0, string.Compare(string.Empty, out2, true));
        }
Example #8
0
        private void UpdateRemoteTargetComboBox()
        {
            try
            {
                // Add all targets to combo box
                m_remoteTargetComboBox.Items.Clear();
                foreach (var target in m_lstTargets)
                {
                    m_remoteTargetComboBox.Items.Add(target);
                }

                // Select the proper target
                var selTarget = SelectedTarget;
                if (selTarget != null)
                {
                    m_remoteTargetComboBox.SelectedItem = selTarget;
                }
                else if (m_remoteTargetComboBox.Items.Count > 0)
                {
                    m_remoteTargetComboBox.SelectedItem = m_remoteTargetComboBox.Items[0];
                }
                else
                {
                    m_remoteTargetComboBox.Text = string.Empty;
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledRemoteTargetErrorUpdatingComboBox, ex.Message));
            }
        }
        private void FuncCallsEditorMouseDoubleClick(object sender, MouseEventArgs e)
        {
            var editor = sender.As <SledLuaProfileFuncCallsEditor>();

            if (editor == null)
            {
                return;
            }

            if (editor.LastHit == null)
            {
                return;
            }

            var pi = editor.LastHit.As <SledProfileInfoType>();

            if (pi == null)
            {
                return;
            }

            var szAbsPath =
                SledUtil.GetAbsolutePath(
                    pi.File,
                    m_projectService.Get.AssetDirectory);

            if (!File.Exists(szAbsPath))
            {
                return;
            }

            m_gotoService.Get.GotoLine(szAbsPath, pi.Line, false);
        }
Example #10
0
        /// <summary>
        /// Reads a DomObject from the given stream
        /// </summary>
        /// <param name="stream">Stream to read</param>
        /// <returns>Dom tree that was read</returns>
        public override DomObject Read(Stream stream)
        {
            // Read project settings
            DomObject rootProjDomObject = ReadInternal(stream);

            // Try and read temporary settings file
            DomObject rootTempDomObject = null;

            try
            {
                // Path to project file
                string szAbsProjPath = ((FileStream)stream).Name;
                // Path to hidden project temporary settings file
                string szAbsTempPath = Path.ChangeExtension(szAbsProjPath, m_extTmp);

                // Read from disk if file exists
                if (File.Exists(szAbsTempPath))
                {
                    using (FileStream file = new FileStream(szAbsTempPath, FileMode.Open, FileAccess.Read))
                    {
                        rootTempDomObject = ReadInternal(file);
                    }
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(SledMessageType.Error, SledUtil.TransSub(Localization.SledSharedLoadTempSettingsFileError, new string[] { ex.Message }));
            }

            // Combine project file with temporary settings file
            Combine(rootProjDomObject, rootTempDomObject);

            return(rootProjDomObject);
        }
Example #11
0
        private void AuthenticateVersion()
        {
            var ver       = GetScmpBlob <Shared.Scmp.Version>();
            var verNumber = Shared.Scmp.ScmpExtension.ToInt32(ver);

            var appVer       = new Version(Application.ProductVersion);
            var appVerNumber = appVer.ToInt32();

            var minVerNumber = m_minVersion.ToInt32();

            // Allow a range of versions
            if ((verNumber >= minVerNumber) && (verNumber <= appVerNumber))
            {
                // Send success message
                SendScmp(new Shared.Scmp.Success(SledPluginId));
            }
            else
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(
                        Localization.SledRemoteTargetErrorVersionMismatch,
                        appVer.Major, appVer.Minor,
                        m_minVersion.Major, m_minVersion.Minor,
                        ver.Major, ver.Minor));

                // Send failure message
                SendScmp(new Shared.Scmp.Failure(SledPluginId));
            }
        }
Example #12
0
        private string GetUriRelPath(IResource resource)
        {
            if (resource == null)
            {
                return(string.Empty);
            }

            try
            {
                return
                    (SledUtil.GetRelativePath(
                         resource.Uri.LocalPath,
                         m_projectService.AssetDirectory));
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    "Exception getting relative " +
                    "path for Uri \"{0}\": {1}",
                    resource.Uri, ex.Message);

                return(resource.Uri.LocalPath);
            }
        }
Example #13
0
        public void GetAbsolutePath()
        {
            var basePaths = new[] { @"C:\usr\local\cell", @"C:\usr\local\cell\" };

            const string relPath1 = @"..\..\some\folder\file.txt";
            const string relPath2 = @"some\folder\file.txt";

            var absPath1 = SledUtil.GetAbsolutePath(relPath1, basePaths[0]);
            var absPath2 = SledUtil.GetAbsolutePath(relPath1, basePaths[1]);
            var absPath3 = SledUtil.GetAbsolutePath(relPath1, basePaths[0]);
            var absPath4 = SledUtil.GetAbsolutePath(relPath1, basePaths[1]);

            const string absPath5 = @"C:\usr\some\folder\file.txt";
            const string absPath6 = @"C:\usr\local\cell\some\folder\file.txt";

            Assert.That(
                (string.Compare(absPath1, absPath5) == 0) &&
                (string.Compare(absPath2, absPath5) == 0) &&
                (string.Compare(absPath3, absPath5) == 0) &&
                (string.Compare(absPath4, absPath5) == 0));

            absPath1 = SledUtil.GetAbsolutePath(relPath2, basePaths[0]);
            absPath2 = SledUtil.GetAbsolutePath(relPath2, basePaths[1]);
            absPath3 = SledUtil.GetAbsolutePath(relPath2, basePaths[0]);
            absPath4 = SledUtil.GetAbsolutePath(relPath2, basePaths[1]);

            Assert.That(
                (string.Compare(absPath1, absPath6) == 0) &&
                (string.Compare(absPath2, absPath6) == 0) &&
                (string.Compare(absPath3, absPath6) == 0) &&
                (string.Compare(absPath4, absPath6) == 0));
        }
Example #14
0
        private void EditorKeyPress(object sender, KeyPressEventArgs e)
        {
            if (!m_editor.ReadOnly)
            {
                return;
            }

            if ((s_debugService.Get != null) && s_debugService.Get.IsDebugging)
            {
                MessageBox.Show(
                    s_mainForm.Get,
                    Localization.SledCannotMakeChanges,
                    Localization.SledEditorLocked,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            else
            {
                // Quick hack for a feature Zindagi requested
                if (CanGetSourceControlToCheckOut(this))
                {
                    return;
                }

                // Otherwise show normal GUI
                var res =
                    MessageBox.Show(
                        s_mainForm.Get,
                        string.Format(
                            "{0}{1}{1}{2}",
                            Localization.SledFileReadOnly,
                            Environment.NewLine,
                            Localization.SledAttemptChangeFilePermissions),
                        Localization.SledFileReadOnly,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Error);

                if (res == DialogResult.Yes)
                {
                    try
                    {
                        File.SetAttributes(Uri.LocalPath, FileAttributes.Normal);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            s_mainForm.Get,
                            string.Format(
                                "{0}{1}{1}{2}",
                                Localization.SledFailChangePermissions,
                                Environment.NewLine,
                                SledUtil.TransSub(Localization.SledErrorWas, ex.Message)),
                            Localization.SledFileReadOnlyError,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
        }
        /// <summary>
        /// OnNodeSet
        /// </summary>
        protected override void OnNodeSet()
        {
            if (DomNode.IsAttributeDefault(SledLuaSchema.SledLuaProjectFilesWatchType.guidAttribute))
            {
                Guid = SledUtil.MakeXmlSafeGuid();
            }

            base.OnNodeSet();
        }
Example #16
0
        public void IsWhiteSpace()
        {
            var test = "\t\r\n ";

            Assert.That(SledUtil.IsWhiteSpace(test));

            test = "\t\r\n a";
            Assert.That(!SledUtil.IsWhiteSpace(test));
        }
Example #17
0
 /// <summary>
 /// Fill in contents for displaying on a GUI
 /// </summary>
 /// <param name="item"></param>
 /// <param name="info">structure to hold display information</param>
 public void GetInfo(object item, ItemInfo info)
 {
     info.Label       = Address;
     info.Checked     = Checked;
     info.Properties  = new[] { Name };
     info.IsLeaf      = false;
     info.Description = SledUtil.TransSub(Localization.SledLuaLuaState, Address);
     info.ImageIndex  = info.GetImageIndex(Atf.Resources.DataImage);
 }
Example #18
0
        /// <summary>
        /// Go to a specific word on a line in a file
        /// </summary>
        /// <param name="sd">document</param>
        /// <param name="szWord">word to find</param>
        /// <param name="iLine">line in document</param>
        /// <param name="iOccurence">if the word occurs multiple times on a line then this represents which occurence</param>
        /// <param name="bUseCsi">whether to use a "current statement indicator" or not</param>
        public void GotoLineWord(ISledDocument sd, string szWord, int iLine, int iOccurence, bool bUseCsi)
        {
            if (sd == null)
            {
                return;
            }

            // Bring this files tab to the front
            m_controlHostService.Show(sd.Control);

            try
            {
                if (iOccurence < 0)
                {
                    // Selecting whole line
                    sd.Editor.SelectLine(iLine);
                }
                else
                {
                    // Selecting part of line

                    // Try and select the word "name" on the line
                    var szLine = sd.Editor.GetLineText(iLine);

                    var iBeg = -1;
                    for (var i = 0; i < iOccurence; i++)
                    {
                        iBeg = szLine.IndexOf(szWord, iBeg + 1);
                    }

                    var iEnd = iBeg + szWord.Length - 1;

                    // Select
                    sd.Editor.SelectLine(iLine, iBeg, iEnd);
                }

                // Scroll to line
                sd.Editor.CurrentLineNumber = iLine;

                if (bUseCsi)
                {
                    sd.Editor.CurrentStatement(iLine, true);
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(
                        Localization.SledGotoLineError1,
                        iLine, Path.GetFileName(sd.Uri.LocalPath), ex.Message));
            }

            // Now force focus to actually see the cursor on the newly selected line
            sd.Control.Focus();
        }
Example #19
0
        /// <summary>
        /// Generate a unique name for this item
        /// </summary>
        public void GenerateUniqueName()
        {
            NodeUniqueName = "PI:" + Function + ":" + File + ":" + Line;
            NodeSortName   = NodeUniqueName;

            if (m_md5Hash == 0)
            {
                m_md5Hash = SledUtil.GetMd5HashForText(NodeUniqueName);
            }
        }
        public void AddDirectory(string absDirPath)
        {
            var di = SledUtil.CreateDirectoryInfo(absDirPath, true);

            if (di == null)
            {
                return;
            }

            AddDirectory(di);
        }
Example #21
0
        /// <summary>
        /// Load a TTY filter file
        /// </summary>
        /// <param name="szAbsPath"></param>
        private void TryLoadTtyFilterFile(string szAbsPath)
        {
            try
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(szAbsPath);

                if (xmlDoc.DocumentElement == null)
                {
                    return;
                }

                var nodes = xmlDoc.DocumentElement.SelectNodes("TTYFilter");
                if ((nodes == null) || (nodes.Count == 0))
                {
                    MessageBox.Show(
                        this,
                        SledUtil.TransSub(Localization.SledTTYFilterNoNodesFoundInFile, szAbsPath),
                        Localization.SledTTYFilterFileError,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);

                    return;
                }

                foreach (XmlElement elem in nodes)
                {
                    var filter = new SledTtyFilter(
                        elem.GetAttribute("filter"),
                        ((int.Parse(elem.GetAttribute("result")) == 1) ? SledTtyFilterResult.Show : SledTtyFilterResult.Ignore),
                        Color.FromArgb(
                            int.Parse(elem.GetAttribute("txtColorR")),
                            int.Parse(elem.GetAttribute("txtColorG")),
                            int.Parse(elem.GetAttribute("txtColorB"))
                            ),
                        Color.FromArgb(
                            int.Parse(elem.GetAttribute("bgColorR")),
                            int.Parse(elem.GetAttribute("bgColorG")),
                            int.Parse(elem.GetAttribute("bgColorB"))
                            ));

                    TryAddTtyFilter(filter);
                }
            }
            catch
            {
                MessageBox.Show(
                    this,
                    SledUtil.TransSub(Localization.SledTTYFilterErrorLoadingFile, szAbsPath),
                    Localization.SledTTYFilterFileError,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
Example #22
0
        private void NetPluginReadyEvent(ISledTarget target)
        {
            // Fake event

            SledOutDevice.OutLine(
                SledMessageType.Info,
                SledUtil.TransSub(Localization.SledTargetReady, target));

            // Fire event
            Ready.Raise(this, new SledDebugServiceEventArgs(target));
        }
Example #23
0
        public void RemoveWhiteSpace()
        {
            var test    = "\t\r\n ";
            var remove1 = SledUtil.RemoveWhiteSpace(test);

            Assert.That(string.Compare(remove1, string.Empty) == 0);

            test    = "\t\r\n a";
            remove1 = SledUtil.RemoveWhiteSpace(test);
            Assert.That(string.Compare(remove1, "a") == 0);
        }
Example #24
0
        /// <summary>
        /// Validate the condition string has some text in it
        /// </summary>
        /// <param name="sender">object that fired the event</param>
        /// <param name="e">event arguments</param>
        private void BtnOkClick(object sender, EventArgs e)
        {
            // Need to make sure if a condition is being saved then it must be valid
            var bSyntaxCheckCondition = (ConditionEnabled || !string.IsNullOrEmpty(Condition));

            if (!bSyntaxCheckCondition)
            {
                return;
            }

            if (string.IsNullOrEmpty(Condition))
            {
                MessageBox.Show(
                    this,
                    Localization.SledBreakpointConditionErrorNoCondition,
                    Localization.SledBreakpointConditionError,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                // Make user enter valid stuff
                DialogResult = DialogResult.None;
            }
            else
            {
                // Check syntax
                if (m_plugin != null)
                {
                    // Wrap the condition in a function like how it would be when running in libluaplugin
                    var szCondFunc = string.Format("function libluaplugin_condfunc(){0}    return ({1}){0}end", Environment.NewLine, Condition);

                    // Format actual syntax checker to use
                    var szSyntaxCheckFunc =
                        string.Format("function libluaplugin_condfunc()\nreturn ({0})\nend", Condition);

                    var syntaxCheckerService = SledServiceInstance.Get <ISledSyntaxCheckerService>();

                    // Force a syntax check of the string
                    var errors = syntaxCheckerService.CheckString(m_plugin, szSyntaxCheckFunc);
                    if (errors.Any())
                    {
                        // Show error
                        MessageBox.Show(
                            this,
                            SledUtil.TransSub(
                                Localization.SledBreakpointConditionErrorVarArg,
                                Environment.NewLine, szCondFunc, errors.ElementAt(0).Error),
                            Localization.SledBreakpointConditionSyntaxError);

                        // Make user fix error
                        DialogResult = DialogResult.None;
                    }
                }
            }
        }
Example #25
0
        private void SetupFile(SledProjectFilesFileType file)
        {
            // Assign language plugin (if any)
            file.LanguagePlugin = m_languagePluginService.Get.GetPluginForExtension(Path.GetExtension(file.Path));

            var project = file.Project ?? m_projectService.Get.ActiveProject;

            // Set Uri
            var absPath = SledUtil.GetAbsolutePath(file.Path, project.AssetDirectory);

            file.Uri = new Uri(absPath);
        }
Example #26
0
        /// <summary>
        /// Create SledProjectFilesFileType
        /// </summary>
        /// <param name="szAbsPath">Absolute path of file</param>
        /// <param name="project">Project details used to aid in creating the project file representation</param>
        /// <returns>SledProjectFilesFileType</returns>
        public static SledProjectFilesFileType Create(string szAbsPath, SledProjectFilesType project)
        {
            var node = new DomNode(SledSchema.SledProjectFilesFileType.Type);

            var file = node.As <SledProjectFilesFileType>();

            file.Uri  = new Uri(szAbsPath);
            file.Name = System.IO.Path.GetFileName(szAbsPath);
            file.Path = SledUtil.GetRelativePath(szAbsPath, project.AssetDirectory);

            return(file);
        }
Example #27
0
        /// <summary>
        /// Open the project file and make sure the namespace is correct
        /// </summary>
        /// <param name="szAbsPath"></param>
        public static void CleanupProjectFileNamespace(string szAbsPath)
        {
            if (!File.Exists(szAbsPath))
            {
                return;
            }

            if (SledUtil.IsFileReadOnly(szAbsPath))
            {
                return;
            }

            try
            {
                Encoding encoding;
                string   szFileContents;

                using (Stream stream = new FileStream(szAbsPath, FileMode.Open, FileAccess.Read))
                {
                    using (var reader = new StreamReader(stream, true))
                    {
                        // Store encoding & read contents
                        encoding       = reader.CurrentEncoding;
                        szFileContents = reader.ReadToEnd();
                    }
                }

                if (!string.IsNullOrEmpty(szFileContents))
                {
                    const string szOldXmlNs = "xmlns=\"lua\"";
                    const string szNewXmlNs = "xmlns=\"sled\"";

                    if (szFileContents.Contains(szOldXmlNs))
                    {
                        szFileContents = szFileContents.Replace(szOldXmlNs, szNewXmlNs);

                        using (Stream stream = new FileStream(szAbsPath, FileMode.Create, FileAccess.Write))
                        {
                            using (var writer = new StreamWriter(stream, encoding))
                            {
                                writer.Write(szFileContents);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledProjectFilesErrorVerifyingNamespace, ex.Message, szAbsPath));
            }
        }
Example #28
0
        protected override void ShowHelpAbout()
        {
            try
            {
                var assem   = Assembly.GetAssembly(typeof(SledAboutService));
                var version = assem.GetName().Version.ToString();

                var title =
                    SledUtil.TransSub(Resources.Resource.HelpAboutTitleWithVersion, version);

                using (Image image = m_mainForm.Icon.ToBitmap())
                {
                    {
                        //
                        // WWS version
                        //

                        using (var richTextBox = new RichTextBox())
                        {
                            richTextBox.BorderStyle = BorderStyle.None;
                            richTextBox.ReadOnly    = true;

                            using (var strm = assem.GetManifestResourceStream(Resources.Resource.HelpAboutAssemblyPath))
                            {
                                if (strm != null)
                                {
                                    richTextBox.LoadFile(strm, RichTextBoxStreamType.RichText);
                                }

                                using (var dialog =
                                           new AboutDialog(
                                               title,
                                               ApplicationUrl,
                                               richTextBox,
                                               image,
                                               null,
                                               true))
                                {
                                    dialog.ShowDialog(m_mainForm);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledHelpAboutErrorException, ex.Message));
            }
        }
Example #29
0
        private void NetPluginConnectingEvent(ISledTarget target)
        {
            // Fake event

            m_curTarget = target;

            SledOutDevice.OutLine(
                SledMessageType.Info,
                SledUtil.TransSub(Localization.SledTargetConnectionNegotiating, target));

            // Fire event
            Connecting.Raise(this, new SledDebugServiceEventArgs(target));
        }
Example #30
0
        public void Clamp()
        {
            const int minValue            = 0;
            const int maxValue            = 10;
            const int lessThanMinValue    = -5;
            const int greaterThanMaxValue = 20;

            const int value1 = 5;

            Assert.AreEqual(value1, SledUtil.Clamp(value1, minValue, maxValue));
            Assert.AreEqual(value1, SledUtil.Clamp(value1, lessThanMinValue, greaterThanMaxValue));
            Assert.AreEqual(minValue, SledUtil.Clamp(lessThanMinValue, minValue, maxValue));
            Assert.AreEqual(maxValue, SledUtil.Clamp(greaterThanMaxValue, minValue, maxValue));
        }
        private static IEnumerable<SledSyntaxCheckerEntry> CheckFiles(IEnumerable<SledProjectFilesFileType> files, SledSyntaxCheckerVerbosity verbosity, object userData, SledUtil.BoolWrapper shouldCancel)
        {
            SledHiPerfTimer timer = null;

            var enumeratedFiles = new List<SledProjectFilesFileType>(files);
            
            var errors = new List<SledSyntaxCheckerEntry>();
            var fileCount = enumeratedFiles.Count;

            try
            {
                if (verbosity > SledSyntaxCheckerVerbosity.None)
                {
                    timer = new SledHiPerfTimer();
                    timer.Start();
                }
                
                var allWorkItems = new SyntaxCheckerWorkItem[fileCount];

                for (var i = 0; i < fileCount; ++i)
                    allWorkItems[i] = new SyntaxCheckerWorkItem(enumeratedFiles[i], verbosity, userData, shouldCancel);

                var workerCount = Math.Min(ProducerConsumerQueue.WorkerCount, fileCount);
                using (var pcQueue = new ProducerConsumerQueue(workerCount, shouldCancel))
                {
                    pcQueue.EnqueueWorkItems(allWorkItems);
                }

                if (shouldCancel.Value)
                    return EmptyEnumerable<SledSyntaxCheckerEntry>.Instance;

                // gather all results from all work items
                foreach (var workItem in allWorkItems)
                    errors.AddRange(workItem.Errors);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    "{0}: Exception syntax checking files: {1}",
                    typeof(SledLuaSyntaxCheckerService), ex.Message);
            }
            finally
            {
                if ((timer != null) && (!shouldCancel.Value))
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        "[Lua] Syntax checked {0} files in {1} seconds",
                        fileCount, timer.Elapsed);
                }
            }

            return errors;
        }
 public SyntaxCheckerWorkItem(SledProjectFilesFileType file, SledSyntaxCheckerVerbosity verbosity, object userData, SledUtil.BoolWrapper shouldCancel)
 {
     m_file = file;
     m_verbosity = verbosity;
     m_userData = userData;
     m_shouldCancel = shouldCancel;
     Errors = new List<SledSyntaxCheckerEntry>();
 }
 public ParserWorkItem(SledProjectFilesFileType file, SledLanguageParserVerbosity verbosity, object userData, SledUtil.BoolWrapper shouldCancel)
 {
     m_file = file;
     m_verbosity = verbosity;
     m_userData = userData;
     m_shouldCancel = shouldCancel;
     Results = new List<SledLanguageParserResult>();
 }
Example #34
0
        public ProducerConsumerQueue(int workerCount, SledUtil.BoolWrapper shouldCancel)
        {
            m_workers = new Thread[workerCount];
            m_cancel = shouldCancel;

            for (var i = 0; i < workerCount; i++)
            {
                m_workers[i] =
                    new Thread(ThreadRun)
                    {
                        Name = string.Format("SLED - PCQueue Thread:{0}", i),
                        IsBackground = true,
                        CurrentCulture = Thread.CurrentThread.CurrentCulture,
                        CurrentUICulture = Thread.CurrentThread.CurrentUICulture
                    };

                m_workers[i].SetApartmentState(ApartmentState.STA);
                m_workers[i].Start();
            }
        }