public static WindowsInformation Enumerate(ManagementScope Scope)
        {
            var result = new WindowsInformation();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    result.WindowsDirectory = m["WindowsDirectory"] != null?StringFormatting.CleanInvalidXmlChars(m["WindowsDirectory"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.Name = m["Caption"] != null?StringFormatting.CleanInvalidXmlChars(m["Caption"].ToString().Replace(" (Registered Trademark)", "")).TrimStart().TrimEnd() : string.Empty;

                    result.Version = m["Version"] != null?StringFormatting.CleanInvalidXmlChars(m["Version"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.OSArchitecture = m["OSArchitecture"] != null?StringFormatting.CleanInvalidXmlChars(m["OSArchitecture"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.Manufacturer = m["Manufacturer"] != null?StringFormatting.CleanInvalidXmlChars(m["Manufacturer"].ToString()).TrimStart().TrimEnd() : string.Empty;

                    result.InstallDate = m["InstallDate"] != null?ManagementDateTimeConverter.ToDateTime(StringFormatting.CleanInvalidXmlChars(m["InstallDate"].ToString()).TrimStart().TrimEnd()).ToString() : string.Empty;

                    result.AviailableMemory = m["FreePhysicalMemory"] != null ? ((double)((UInt64)m["FreePhysicalMemory"]) / 1024 / 1024).ToString("0.00 Gb").TrimStart().TrimEnd() : string.Empty;
                }
            }
            catch (Exception) { }
            return(result);
        }
        public static List <PhysicalDrive> Enumerate(ManagementScope Scope)
        {
            var result = new List <PhysicalDrive>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_DiskDrive");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    result.Add(new PhysicalDrive
                    {
                        Model        = m["Model"] != null ? StringFormatting.CleanInvalidXmlChars(m["Model"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        SerialNumber = m["SerialNumber"] != null ? StringFormatting.CleanInvalidXmlChars(m["SerialNumber"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        Size         = m["Size"] != null ? StringFormatting.CleanInvalidXmlChars((((UInt64)m["Size"]) / 1024 / 1024 / 1024).ToString("0 Gb")).TrimStart().TrimEnd() : string.Empty
                    });
                }
            }
            catch (Exception) { }
            if (result.Count > 0)
            {
                return(result);
            }
            else
            {
                return(new List <PhysicalDrive>());
            }
        }
        public virtual string Format(string format)
        {
            if (Taxon == Taxon.Empty)
            {
                return(string.Empty);
            }

            return(StringFormatting.Tokenize(format, token =>
            {
                if (Taxon.IsMyToken(token))
                {
                    return Taxon.FormatByToken(token);
                }
                else if (IsCodeToken(token))
                {
                    return Code;
                }
                else if (IsRefToken(token))
                {
                    return Reference();
                }
                else if (IsFieldToken(token))
                {
                    return Field();
                }
                else if (IsLocalityToken(token))
                {
                    return Locality;
                }
                throw new Exception("Invalid token");
            }));
        }
Exemple #4
0
        public static List <VideoController> Enumerate(ManagementScope Scope)
        {
            var result = new List <VideoController>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_VideoController");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    result.Add(new VideoController
                    {
                        Name                 = m["Name"] != null ? StringFormatting.CleanInvalidXmlChars(m["Name"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        VideoProcessor       = m["VideoProcessor"] != null ? StringFormatting.CleanInvalidXmlChars(m["VideoProcessor"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        VideoModeDescription = m["VideoModeDescription"] != null ? StringFormatting.CleanInvalidXmlChars(m["VideoModeDescription"].ToString()).TrimStart().TrimEnd() : string.Empty
                    });
                }
            }
            catch (Exception) { }
            if (result.Count > 0)
            {
                return(result);
            }
            else
            {
                return(new List <VideoController>());
            }
        }
        public static List <LogicalDrive> Enumerate(ManagementScope Scope)
        {
            var result = new List <LogicalDrive>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_LogicalDisk");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    if (m["Description"] != null)
                    {
                        if (m["Description"].ToString() == "Local Fixed Disk" || m["Description"].ToString() == "Локальный несъемный диск")
                        {
                            result.Add(new LogicalDrive
                            {
                                Letter         = m["Name"] != null ? StringFormatting.CleanInvalidXmlChars(m["Name"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                AviailableSize = m["FreeSpace"] != null ? StringFormatting.CleanInvalidXmlChars((((UInt64)m["FreeSpace"]) / 1024 / 1024 / 1024).ToString("0 Gb")).TrimStart().TrimEnd() : string.Empty,
                                TotalSize      = m["Size"] != null ? StringFormatting.CleanInvalidXmlChars((((UInt64)m["Size"]) / 1024 / 1024 / 1024).ToString("0 Gb")).TrimStart().TrimEnd() : string.Empty
                            });
                        }
                    }
                }
            }
            catch (Exception) { }
            return(result.OrderBy(x => x.Letter).ToList());
        }
        public static List <Monitor> Enumerate(ManagementScope Scope)
        {
            var result = new List <Monitor>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM WmiMonitorID");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                var queryList = queryCollection.Cast <ManagementObject>().ToList();
                foreach (ManagementObject m in queryList)
                {
                    var mm = string.Empty;
                    var sn = string.Empty;
                    var mn = string.Empty;
                    try { mm = StringFormatting.ConvertUInt16ArrayToString((UInt16[])m["UserFriendlyName"]).Replace("\0", "").Replace("SERIES", "").Replace("Series", "").Replace("ACER", "").Replace("HWP ", "").Replace("DELL ", "").TrimStart().TrimEnd(); } catch (Exception) { }
                    try { sn = StringFormatting.ConvertUInt16ArrayToString((UInt16[])m["SerialNumberID"]).Replace("\0", "").TrimStart().TrimEnd(); } catch (Exception) { }
                    try { mn = StringFormatting.ConvertUInt16ArrayToString((UInt16[])m["ManufacturerName"]).Replace("\0", "").Replace("VSC", "ViewSonic").Replace("ACR", "Acer").Replace("DEL", "Dell").Replace("PHL", "Philips").TrimStart().TrimEnd(); } catch (Exception) { }
                    result.Add(new Monitor()
                    {
                        MonitorModel = StringFormatting.CleanInvalidXmlChars(mm), MonitorSerialNumber = StringFormatting.CleanInvalidXmlChars(sn), Manufacturer = StringFormatting.CleanInvalidXmlChars(mn)
                    });
                }
            }
            catch (Exception) { }
            return(result);
        }
Exemple #7
0
        public void ResultsAreEqual()
        {
            var bench = new StringFormatting();
            var a     = bench.Default();
            var b     = bench.StringBuilder();
            var c     = bench.StringBuilderWithInitializedSize();
            var d     = bench.StringBuilderWithInitializedSizeAndFormat();
            var e     = bench.CachedStringBuilderWithFormat();

            b.Length.Should().Be(a.Length);
            c.Length.Should().Be(a.Length);
            d.Length.Should().Be(a.Length);
            e.Length.Should().Be(a.Length);
        }
        public static bool IsUnitTestProject(Project project)
        {
            string projectTypeGuids = GetProjectTypeGuids(project);

            if (string.IsNullOrEmpty(projectTypeGuids))
            {
                return(false);
            }

            projectTypeGuids = StringFormatting.RemoveBracesToUpper(projectTypeGuids);
            string[] guids = projectTypeGuids.Split(';');

            return(guids.Contains(ExtensionConstants.UnitTestProjectType.ToString(), StringComparer.InvariantCultureIgnoreCase));
        }
Exemple #9
0
            static void Main(string[] args)
            {
                StringFormatting myFormatter = new StringFormatting();

                // now you can call the methods


                Console.WriteLine("Enter your string to test");

                String userTest = Console.ReadLine();

                Console.WriteLine("Testing stringSeparator");
                Console.WriteLine("The result was : {0}", myFormatter.stringSeparator(userTest));

                Console.WriteLine("Testing stringReverse");
                Console.WriteLine("The result was : {0}", myFormatter.stringReverse(userTest));

                Console.WriteLine("Enter your second string");
                String userTest2 = Console.ReadLine();

                int result = myFormatter.stringCompare(userTest, userTest2);

                switch (result)
                {
                case -1:
                    Console.WriteLine("The strings are unequal");
                    break;

                case 0:
                    Console.WriteLine("The length of both strings are equal");
                    break;

                case 1:
                    Console.WriteLine("The length of both strings are equal");
                    Console.WriteLine("And also, both strings are equal.");
                    break;

                default:
                    Console.WriteLine("Something weird happened");
                    break;
                }

                Console.WriteLine("The number of vowels in first string are {0}", myFormatter.sumVowels(userTest));
                Console.WriteLine("The number of consonants in first string are {0}", myFormatter.sumConsonants(userTest));

                // delay disposal of window
                Console.ReadLine();
            }
        private void AssertFormat(string expected, string format)
        {
            var result = StringFormatting.Tokenize(format, token =>
            {
                if (token == "a")
                {
                    return("1");
                }
                else if (token == "b")
                {
                    return("2");
                }
                return(string.Empty);
            });

            Assert.AreEqual(expected, result);
        }
        /// <summary>
        /// Gets total cost of shopping cart, returns currency formatted string
        /// </summary>
        /// <returns></returns>
        public string GetCartTotal()
        {
            decimal?totalPrice = 0;
            var     carts      = db.ShoppingCarts.Include("Product").Where(x => x.CartID == ShoppingCartID);

            foreach (var item in carts)
            {
                if (item.Product.WildmanPrice != null)
                {
                    totalPrice += item.Product.WildmanPrice * item.Quantity;
                }
                else
                {
                    totalPrice += item.Product.Price * item.Quantity;
                }
            }

            return(StringFormatting.FormattedPrice(totalPrice ?? 0));
        }
Exemple #12
0
        public static List <SoftwareLicensingProduct> Enumerate(ManagementScope Scope)
        {
            var result = new List <SoftwareLicensingProduct>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM SoftwareLicensingProduct");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    if (m["Name"] != null && m["PartialProductKey"] != null)
                    {
                        if (m["Name"].ToString() != string.Empty && m["PartialProductKey"].ToString() != string.Empty)
                        {
                            var LicenseStatus = m["LicenseStatus"] != null?int.Parse(m["LicenseStatus"].ToString()) : -1;

                            var ProductKeyID = string.Empty;
                            try { ProductKeyID = m["ProductKeyID2"] != null?StringFormatting.CleanInvalidXmlChars(m["ProductKeyID2"].ToString()).TrimStart().TrimEnd() : string.Empty; } catch (Exception) { }
                            result.Add(new SoftwareLicensingProduct
                            {
                                Name              = m["Name"] != null ? StringFormatting.CleanInvalidXmlChars(m["Name"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                Description       = m["Description"] != null ? StringFormatting.CleanInvalidXmlChars(m["Description"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                LicenseFamily     = m["LicenseFamily"] != null ? StringFormatting.CleanInvalidXmlChars(m["LicenseFamily"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                PatrialProductKey = m["PartialProductKey"] != null ? StringFormatting.CleanInvalidXmlChars(m["PartialProductKey"].ToString()).TrimStart().TrimEnd() : string.Empty,
                                ProductKeyID      = ProductKeyID,
                                LicenseStatus     = LicenseStatus switch
                                {
                                    -1 => "Unknown",
                                    0 => "Unlicensed",
                                    1 => "Licensed",
                                    2 => "OOBGrace",
                                    3 => "OOTGrace",
                                    4 => "NonGenuineGrace",
                                    5 => "Notification",
                                    _ => ""
                                }
                            });
                        }
        public static List <NetworkAdapter> Enumerate(ManagementScope Scope)
        {
            var result = new List <NetworkAdapter>();

            try
            {
                Scope.Options.Timeout = new TimeSpan(0, 1, 0);
                Scope.Connect();
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(Scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                foreach (ManagementObject m in queryCollection)
                {
                    if (m["IPEnabled"] != null && StringFormatting.CleanInvalidXmlChars(m["IPEnabled"].ToString()).ToLower() != "false")
                    {
                        result.Add(new NetworkAdapter
                        {
                            Adapter        = m["Description"] != null ? StringFormatting.CleanInvalidXmlChars(m["Description"].ToString()).TrimStart().TrimEnd() : string.Empty,
                            MAC            = m["MACAddress"] != null ? StringFormatting.CleanInvalidXmlChars(m["MACAddress"].ToString()).TrimStart().TrimEnd() : string.Empty,
                            DHCP_Enabled   = m["DHCPEnabled"] != null ? StringFormatting.CleanInvalidXmlChars(m["DHCPEnabled"].ToString()).TrimStart().TrimEnd() : string.Empty,
                            IPAddress      = m["IPAddress"] != null ? StringFormatting.CleanInvalidXmlChars(((Array)m["IPAddress"]).GetValue(0).ToString()).TrimStart().TrimEnd() : string.Empty,
                            SubnetMasks    = m["IPSubnet"] != null ? StringFormatting.CleanInvalidXmlChars(((Array)m["IPSubnet"]).GetValue(0).ToString()).TrimStart().TrimEnd() : string.Empty,
                            DefaultGeteway = m["DefaultIPGateway"] != null ? StringFormatting.CleanInvalidXmlChars(((Array)m["DefaultIPGateway"]).GetValue(0).ToString()).TrimStart().TrimEnd() : string.Empty,
                            DHCP_ServerIP  = m["DHCPServer"] != null ? StringFormatting.CleanInvalidXmlChars(m["DHCPServer"].ToString()).TrimStart().TrimEnd() : string.Empty,
                        });
                    }
                }
            }
            catch (Exception) { }
            if (result.Count > 0)
            {
                return(result);
            }
            else
            {
                return(new List <NetworkAdapter>());
            }
        }
        //Draws Track inspector
        public override void OnInspectorGUI()
        {
            //Updates the Track object
            serializedObject.Update();
            CreateStyles();

            //Banner display
            Rect BannerRect = GUILayoutUtility.GetRect(0.0f, 0.0f);

            BannerRect.height = Screen.width * 250 / 1600;
            GUILayout.Space(BannerRect.height);
            GUI.Label(BannerRect, Banner);

            //Displays Track name
            GUILayout.BeginVertical(BackgroundStyles[0], GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.PropertyField(TrackName, new GUIContent("Track Name", "(Optional) The name of the Track."));
            GUILayout.EndVertical();

            //Draws Intro field
            GUILayout.BeginVertical(BackgroundStyles[1], GUILayout.Height((TrackInstance.Intro != null ? 3 : 1) * EditorGUIUtility.singleLineHeight));
            Rect IntroRect = EditorGUILayout.GetControlRect();

            EditorGUI.LabelField(new Rect(IntroRect.x, IntroRect.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight), new GUIContent("Intro Audio", "(Optional) The intro audio to be played before looping the main Edition."));
            EditorGUI.PropertyField(new Rect(IntroRect.x + EditorGUIUtility.labelWidth, IntroRect.y, IntroRect.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight), Intro, GUIContent.none);

            //Full intro details
            if (TrackInstance.Intro != null)
            {
                //Draws intro duration
                EditorGUI.LabelField(new Rect(IntroRect.x + 82, IntroRect.y, EditorGUIUtility.labelWidth - 20 - 82, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(TrackInstance.Intro.length), CenteredMiniLabel);

                //Draws Volume slider
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(new GUIContent("Intro Volume", "The volume of the intro audio."), GUILayout.Width(EditorGUIUtility.labelWidth - 4));
                IntroVolume.floatValue = EditorGUILayout.Slider(IntroVolume.floatValue, 0, 1);
                EditorGUILayout.EndHorizontal();

                //Draws overlap slider
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(new GUIContent("Intro Overlap Duration", "Duration of the overlap between the end of the intro and the start of the first Edition."), GUILayout.Width(EditorGUIUtility.labelWidth - 4));
                IntroOverlap.floatValue = EditorGUILayout.Slider(IntroOverlap.floatValue, 0, TrackInstance.Intro.length);
                EditorGUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();

            //Preview
            GUILayout.BeginVertical(BackgroundStyles[0], GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.BeginHorizontal();
            GUI.enabled = MusicManager.Main;
            EditorGUILayout.LabelField(new GUIContent("Preview", "Preview options for the Track. Only available at runtime."));
            if (GUILayout.Button(new GUIContent("Play", "Plays the Track.")))
            {
                MusicManager.Main.Play(TrackInstance);
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            //Adds new Edition if the list is empty
            if (TrackInstance.Editions.Length == 0)
            {
                TrackInstance.Editions = new Edition[1];
                TrackInstance.Editions[0].SoundtrackVolume = 1f;
                TrackInstance.Editions[0].TransitionVolume = 1f;
            }

            //Enables Edition removal button if more than one is present
            EditionListDisplay.displayRemove = TrackInstance.Editions.Length > 1;

            //Draws list and updates Track
            EditionListDisplay.DoLayoutList();
            serializedObject.ApplyModifiedProperties();
        }
        /// <summary>Draws the sub-inspector for an SFXLayer.</summary>
        /// <param name="DrawRect">The rect in the list display that this SFXLayer has to be drawn in.</param>
        /// <param name="Index">The index of this SFXLayer in the Track.</param>
        /// <param name="IsActive">If the SFXLayer is actively selected.</param>
        /// <param name="IsFocused">If the SFXLayer is in focus.</param>
        private void DrawSFXLayerInspector(Rect DrawRect, int Index, bool IsActive, bool IsFocused)
        {
            //Shifts rect to create border
            DrawRect.y += 2;

            //Calculates commonly used spacings
            float Spacing      = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            float LabelWidth   = EditorGUIUtility.labelWidth - 20;
            float FieldPadding = 20f;

            //Starts counter for current displayed property
            int PropertyIndex = 0;

            //Caches serialised properties
            SerializedProperty CurrentSFXLayer         = SFXLayerListDisplay.serializedProperty.GetArrayElementAtIndex(Index);
            SerializedProperty NameProperty            = CurrentSFXLayer.FindPropertyRelative("LayerName");
            SerializedProperty SFXProperty             = CurrentSFXLayer.FindPropertyRelative("SFX");
            SerializedProperty RandomizeVolumeProperty = CurrentSFXLayer.FindPropertyRelative("RandomizeVolume");
            SerializedProperty FixedVolumeProperty     = CurrentSFXLayer.FindPropertyRelative("FixedVolume");
            SerializedProperty MinVolumeProperty       = CurrentSFXLayer.FindPropertyRelative("MinVolume");
            SerializedProperty MaxVolumeProperty       = CurrentSFXLayer.FindPropertyRelative("MaxVolume");
            SerializedProperty RandomizePitchProperty  = CurrentSFXLayer.FindPropertyRelative("RandomizePitch");
            SerializedProperty FixedPitchProperty      = CurrentSFXLayer.FindPropertyRelative("FixedPitch");
            SerializedProperty MinPitchProperty        = CurrentSFXLayer.FindPropertyRelative("MinPitch");
            SerializedProperty MaxPitchProperty        = CurrentSFXLayer.FindPropertyRelative("MaxPitch");
            SerializedProperty DelayProperty           = CurrentSFXLayer.FindPropertyRelative("DelaySFX");
            SerializedProperty RandomizeDelayProperty  = CurrentSFXLayer.FindPropertyRelative("RandomizeDelay");
            SerializedProperty FixedDelayProperty      = CurrentSFXLayer.FindPropertyRelative("FixedDelayTime");
            SerializedProperty MinDelayProperty        = CurrentSFXLayer.FindPropertyRelative("MinDelayTime");
            SerializedProperty MaxDelayProperty        = CurrentSFXLayer.FindPropertyRelative("MaxDelayTime");
            SerializedProperty PriorityProperty        = CurrentSFXLayer.FindPropertyRelative("Priority");
            SerializedProperty StereoProperty          = CurrentSFXLayer.FindPropertyRelative("StereoPan");
            SerializedProperty SpatialProperty         = CurrentSFXLayer.FindPropertyRelative("SpatialBlend");
            SerializedProperty ReverbProperty          = CurrentSFXLayer.FindPropertyRelative("ReverbZoneMix");
            SerializedProperty BypassEffectsProperty   = CurrentSFXLayer.FindPropertyRelative("BypassEffects");
            SerializedProperty BypassReverbProperty    = CurrentSFXLayer.FindPropertyRelative("BypassReverbZones");
            SerializedProperty MuteProperty            = CurrentSFXLayer.FindPropertyRelative("Mute");

            //Draws a property with a custom style
            Action <SerializedProperty, string, string, GUIStyle> DrawPropertyStyled = (SerializedProperty Property, string PropertyName, string Tooltip, GUIStyle TextStyle) =>
            {
                //Draws label
                EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip), TextStyle);

                //Draws property field
                EditorGUI.PropertyField(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property, GUIContent.none);

                //Increments property counter
                PropertyIndex++;
            };

            //Draws a slider for a property
            Action <SerializedProperty, string, string, float, float> DrawSlider = (SerializedProperty Property, string PropertyName, string Tooltip, float MinLim, float MaxLim) =>
            {
                //Draws label
                EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip));

                //Draws the slider
                Property.floatValue = EditorGUI.Slider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property.floatValue, MinLim, MaxLim);

                //Increments property counter
                PropertyIndex++;
            };

            //Draws an int slider for a property
            Action <SerializedProperty, string, string, int, int> DrawIntSlider = (SerializedProperty Property, string PropertyName, string Tooltip, int MinLim, int MaxLim) =>
            {
                //Draws label
                EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip));

                //Draws the slider
                Property.intValue = (int)EditorGUI.Slider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property.intValue, MinLim, MaxLim);

                //Increments property counter
                PropertyIndex++;
            };

            //Draws a min max slider for a property
            Action <SerializedProperty, SerializedProperty, string, string, float, float> DrawMinMaxSlider = (SerializedProperty PropertyLeft, SerializedProperty PropertyRight, string PropertyName, string Tooltip, float MinLim, float MaxLim) =>
            {
                //Draws label
                EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip));

                //Draws the slider
                AMPEditorFields.MinMaxSlider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), GUIContent.none, PropertyLeft, PropertyRight, MinLim, MaxLim);

                //Increments property counter
                PropertyIndex++;
            };

            //Draws a property
            Action <SerializedProperty, string, string> DrawProperty = (SerializedProperty Property, string PropertyName, string Tooltip) =>
            {
                DrawPropertyStyled(Property, PropertyName, Tooltip, EditorStyles.label);
            };

            //Gets and draws SFXLayer name
            string Name = NameProperty.stringValue;

            if (string.IsNullOrEmpty(Name.Trim()))
            {
                Name = "Untitled";
            }
            EditorGUI.LabelField(new Rect(DrawRect.x, DrawRect.y, DrawRect.width - 90, EditorGUIUtility.singleLineHeight), Name, (SFXObjectInstance.SFXLayers[Index].SFX == null && SFXObjectInstance.CollapseEditions ? InvalidBoldStyle : EditorStyles.boldLabel));

            //Draws SFX length
            if (SFXObjectInstance.SFXLayers[Index].SFX != null)
            {
                EditorGUI.LabelField(new Rect((DrawRect.x + DrawRect.width) / 2 - 40, DrawRect.y, 80, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(SFXObjectInstance.SFXLayers[Index].SFX.length), CenteredMiniLabel);
            }

            //Displays basic properties if uncollapsed
            if (!SFXObjectInstance.CollapseEditions)
            {
                DrawProperty(NameProperty, "Layer Name", "(Optional) The name of the Edition.");
                DrawPropertyStyled(SFXProperty, "SFX", "The audio to be played in this SFXLayer.", (SFXObjectInstance.SFXLayers[Index].SFX == null ? InvalidStyle : EditorStyles.label));

                //Shows full properties if the SFX is not null
                if (SFXObjectInstance.SFXLayers[Index].SFX != null)
                {
                    //Volume properties
                    DrawProperty(RandomizeVolumeProperty, "Randomize Volume", "If the volume of the sound should be randomised.");
                    if (SFXObjectInstance.SFXLayers[Index].RandomizeVolume)
                    {
                        DrawMinMaxSlider(MinVolumeProperty, MaxVolumeProperty, "Volume", "The range of values that the volume of the SFXLayer can be.", 0, 1);
                        EditorGUI.LabelField(new Rect(DrawRect.x + 82, PropertyIndex * Spacing + DrawRect.y, LabelWidth - 82, EditorGUIUtility.singleLineHeight), NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MinVolume, 2).ToString() + " - " + NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MaxVolume, 2).ToString(), CenteredMiniLabel);
                    }
                    else
                    {
                        DrawSlider(FixedVolumeProperty, "Volume", "The volume of the SFXLayer.", 0, 1);
                    }

                    //Pitch properties
                    DrawProperty(RandomizePitchProperty, "Randomize Pitch", "If the pitch of the sound should be randomised.");
                    if (SFXObjectInstance.SFXLayers[Index].RandomizePitch)
                    {
                        DrawMinMaxSlider(MinPitchProperty, MaxPitchProperty, "Pitch", "The range of values that the pitch of the SFXLayer can be.", 0, 3);
                        EditorGUI.LabelField(new Rect(DrawRect.x + 82, PropertyIndex * Spacing + DrawRect.y, LabelWidth - 82, EditorGUIUtility.singleLineHeight), NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MinPitch, 2).ToString() + " - " + NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MaxPitch, 2).ToString(), CenteredMiniLabel);
                    }
                    else
                    {
                        DrawSlider(FixedPitchProperty, "Pitch", "The pitch of the SFXLayer.", 0, 3);
                    }

                    //Delay properties
                    DrawProperty(DelayProperty, "Delay", "If there should be a delay before playing this SFXLayer.");
                    if (SFXObjectInstance.SFXLayers[Index].DelaySFX)
                    {
                        DrawProperty(RandomizeDelayProperty, "Randomize Delay", "If the delay time should be randomized.");
                        if (SFXObjectInstance.SFXLayers[Index].RandomizeDelay)
                        {
                            DrawProperty(MinDelayProperty, "Minimum Delay", "Minimum duration of the delay.");
                            DrawProperty(MaxDelayProperty, "Maximum Delay", "Maximum duration of the delay.");
                            MinDelayProperty.floatValue = Mathf.Max(0, MinDelayProperty.floatValue);
                            MaxDelayProperty.floatValue = Mathf.Max(SFXObjectInstance.SFXLayers[Index].MinDelayTime, MaxDelayProperty.floatValue);
                        }
                        else
                        {
                            DrawProperty(FixedDelayProperty, "Delay Duration", "Duration of the delay.");
                            FixedDelayProperty.floatValue = Mathf.Max(0, FixedDelayProperty.floatValue);
                        }
                    }

                    //Other properties
                    DrawProperty(MuteProperty, "Mute", "Mutes the sound.");
                    DrawProperty(BypassEffectsProperty, "Bypass Effects", "Bypass any applied effects on the SFXLayer.");
                    DrawProperty(BypassReverbProperty, "Bypass Reverb Zones", "Bypasses any reverb zones");

                    DrawIntSlider(PriorityProperty, "Priority", "The priority of the SFXLayer.", 0, 256);
                    EditorGUI.LabelField(new Rect(DrawRect.x + LabelWidth, PropertyIndex * Spacing + DrawRect.y + 8, 30, EditorGUIUtility.singleLineHeight), "High", LeftMiniLabel);
                    EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - FieldPadding - 95, PropertyIndex * Spacing + DrawRect.y + 8, 40, EditorGUIUtility.singleLineHeight), "Low", RightMiniLabel);

                    DrawSlider(StereoProperty, "Stero Pan", "Pans a playing sound in a stereo way (left or right). This only applies to sounds that are Mono or Stereo.", -1, 1);
                    EditorGUI.LabelField(new Rect(DrawRect.x + LabelWidth, PropertyIndex * Spacing + DrawRect.y + 8, 25, EditorGUIUtility.singleLineHeight), "Left", LeftMiniLabel);
                    EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - FieldPadding - 95, PropertyIndex * Spacing + DrawRect.y + 8, 40, EditorGUIUtility.singleLineHeight), "Right", RightMiniLabel);

                    DrawSlider(SpatialProperty, "Spatial Blend", "Sets how much this SFXLayer is affected by 3D spatialisation calculations. 0.0 makes the sound full 2D, 1.0 makes it full 3D.", 0, 1);
                    EditorGUI.LabelField(new Rect(DrawRect.x + LabelWidth, PropertyIndex * Spacing + DrawRect.y + 8, 25, EditorGUIUtility.singleLineHeight), "2D", LeftMiniLabel);
                    EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - FieldPadding - 95, PropertyIndex * Spacing + DrawRect.y + 8, 40, EditorGUIUtility.singleLineHeight), "3D", RightMiniLabel);

                    DrawSlider(ReverbProperty, "Reverb Zone Mix", "The amount by which the signal from the AudioSource will be mixed into the global reverb associated with the Reverb Zones.", 0, 1.1f);
                }
                else
                {
                    //Displays error if no SFX is selected
                    EditorGUI.HelpBox(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y + 2f, DrawRect.width - FieldPadding, 30), "SFX required. Please assign an AudioClip to this SFXLayer.", MessageType.Error);
                }
            }
        }
 public void TestCapitalizeAll_SentenceWithPunctuation()
 {
     //Assert
     Assert.AreEqual("1st Sunday Of Advent.", StringFormatting.CapitalizeAllWords("1st sunday of advent."));
 }
 public void TestCapitalize_NullArgument_ReturnsEmptyString()
 {
     //Assert
     Assert.AreEqual(String.Empty, StringFormatting.Capitalize(null));
 }
 public void TestCapitalizeAll_SentenceWithNumbers()
 {
     //Assert
     Assert.AreEqual("1st Sunday Of Advent", StringFormatting.CapitalizeAllWords("1st sunday of advent"));
 }
 public void TestCapitalizeAll_FullName()
 {
     //Assert
     Assert.AreEqual("Dr Bob M Johnson Sr", StringFormatting.CapitalizeAllWords("dr bob m johnson sr"));
 }
 public void TestCapitalizeAll_SingleWord()
 {
     //Assert
     Assert.AreEqual("Bob", StringFormatting.Capitalize("bob"));
 }
 public void TestCapitalizeAll_WhiteSpaceArgument_ReturnsEmptyString()
 {
     //Assert
     Assert.AreEqual(String.Empty, StringFormatting.Capitalize("   "));
 }
 public void TestCapitalize_WordWithWhiteSpace_WhiteSpaceIsTrimmed()
 {
     //Assert
     Assert.AreEqual("Good", StringFormatting.Capitalize("   good  "));
 }
 public void TestCapitalize_Word()
 {
     //Assert
     Assert.AreEqual("Good", StringFormatting.Capitalize("good"));
 }
 public void TestCapitalize_SingleCharacter()
 {
     //Assert
     Assert.AreEqual("G", StringFormatting.Capitalize("g"));
 }
        /// <summary>Draws the sub-inspector for an Edition.</summary>
        /// <param name="DrawRect">The rect in the list display that this Edition has to be drawn in.</param>
        /// <param name="Index">The index of this Edition in the Track.</param>
        /// <param name="IsActive">If the Edition is actively selected.</param>
        /// <param name="IsFocused">If the Edition is in focus.</param>
        private void DrawEditionInspector(Rect DrawRect, int Index, bool IsActive, bool IsFocused)
        {
            //Shifts rect to create border
            DrawRect.y += 2;

            //Calculates commonly used spacings
            float Spacing      = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            float LabelWidth   = EditorGUIUtility.labelWidth - 20;
            float FieldPadding = 20f;

            //Starts counter for current displayed property
            int PropertyIndex = 0;

            //Caches serialised properties
            SerializedProperty CurrentEdition           = EditionListDisplay.serializedProperty.GetArrayElementAtIndex(Index);
            SerializedProperty NameProperty             = CurrentEdition.FindPropertyRelative("Name");
            SerializedProperty SoundtrackProperty       = CurrentEdition.FindPropertyRelative("Soundtrack");
            SerializedProperty SoundtrackVolumeProperty = CurrentEdition.FindPropertyRelative("SoundtrackVolume");
            SerializedProperty TransitionSoundProperty  = CurrentEdition.FindPropertyRelative("TransitionSound");
            SerializedProperty TransitionVolumeProperty = CurrentEdition.FindPropertyRelative("TransitionVolume");
            SerializedProperty PlaybackProperty         = CurrentEdition.FindPropertyRelative("KeepPlaybackTime");
            SerializedProperty FadeProperty             = CurrentEdition.FindPropertyRelative("FadeLength");

            //Draws a property with a custom style
            Action <SerializedProperty, string, string, GUIStyle> DrawPropertyStyled = (SerializedProperty Property, string PropertyName, string Tooltip, GUIStyle TextStyle) =>
            {
                //Draws label
                EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip), TextStyle);

                //Draws property field
                EditorGUI.PropertyField(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property, GUIContent.none);

                //Increments property counter
                PropertyIndex++;
            };

            //Draws a slider for a volume property
            Action <SerializedProperty, string, string> DrawVolumeSlider = (SerializedProperty Property, string PropertyName, string Tooltip) =>
            {
                //Draws label
                EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip));

                //Draws the slider
                Property.floatValue = EditorGUI.Slider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property.floatValue, 0, 1f);

                //Increments property counter
                PropertyIndex++;
            };

            //Draws a property
            Action <SerializedProperty, string, string> DrawProperty = (SerializedProperty Property, string PropertyName, string Tooltip) =>
            {
                DrawPropertyStyled(Property, PropertyName, Tooltip, EditorStyles.label);
            };

            //Gets and draws edition name
            string Name = NameProperty.stringValue;

            if (string.IsNullOrEmpty(Name.Trim()))
            {
                Name = "Untitled";
            }
            EditorGUI.LabelField(new Rect(DrawRect.x, DrawRect.y, DrawRect.width - 90, EditorGUIUtility.singleLineHeight), Name, (TrackInstance.Editions[Index].Soundtrack == null && TrackInstance.CollapseEditions ? InvalidBoldStyle : EditorStyles.boldLabel));

            //Draws main edition if it is the first edition
            if (Index == 0)
            {
                EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - 90, DrawRect.y, 70, EditorGUIUtility.singleLineHeight), "Main Edition", EditorStyles.miniLabel);
            }

            //Draws sountrack length
            if (TrackInstance.Editions[Index].Soundtrack != null)
            {
                EditorGUI.LabelField(new Rect((DrawRect.x + DrawRect.width) / 2 - 40, DrawRect.y, 80, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(TrackInstance.Editions[Index].Soundtrack.length), CenteredMiniLabel);
            }

            //Displays basic properties if uncollapsed
            if (!TrackInstance.CollapseEditions)
            {
                DrawProperty(NameProperty, "Edition Name", "(Optional) The name of the Edition.");
                DrawPropertyStyled(SoundtrackProperty, "Soundtrack", "The AudioClip containing the soundtrack for this Edition.", (TrackInstance.Editions[Index].Soundtrack == null ? InvalidStyle : EditorStyles.label));

                //Shows full properties if the sountrack is not null
                if (TrackInstance.Editions[Index].Soundtrack != null)
                {
                    DrawVolumeSlider(SoundtrackVolumeProperty, "Soundtrack Volume", "The volume of the soundtrack in this Edition.");
                    DrawProperty(TransitionSoundProperty, "Transition Sound", "(Optional) The AudioClip for the transition sound to be played when switching to this Edition of the Track.");

                    //Displays transiton sound properties
                    if (TrackInstance.Editions[Index].TransitionSound != null)
                    {
                        EditorGUI.LabelField(new Rect(DrawRect.x + 96, PropertyIndex * Spacing + DrawRect.y, LabelWidth - 96, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(TrackInstance.Editions[Index].TransitionSound.length), CenteredMiniLabel);
                        DrawVolumeSlider(TransitionVolumeProperty, "Transition Volume", "The volume of the transition sound to this Edition.");
                    }

                    DrawProperty(PlaybackProperty, "Keep Playback Time", "Whether to play the soundtrack from the beginning when switching to this Edition or whether to retain the playback time from the previous Edition.");
                    DrawProperty(FadeProperty, "Fade Duration", "The duration of the cross-fade when switching to this Edition.");
                    FadeProperty.floatValue = Mathf.Max(0, FadeProperty.floatValue);
                }
                else
                {
                    //Displays error if no soundtrack is selected
                    EditorGUI.HelpBox(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y + 2f, DrawRect.width - FieldPadding, 30), "Soundtrack required. Please assign an AudioClip to this Edition.", MessageType.Error);
                }
            }
        }
Exemple #26
0
        private static bool RemoveDeletedItems(string extractedFolder, ProjectItems projectItems, string projectFolder)
        {
            var itemChanged = false;

            //Handle file & folder deletes
            foreach (ProjectItem projectItem in projectItems)
            {
                var name = projectItem.FileNames[0];
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                if (StringFormatting.RemoveBracesToUpper(projectItem.Kind) == VSConstants.GUID_ItemType_PhysicalFile.ToString())
                {
                    name = Path.GetFileName(name);
                    // Do not delete the mapping file
                    if (name == ExtensionConstants.SolutionPackagerMapFile)
                    {
                        continue;
                    }
                    // Do not delete the config file
                    if (name == ExtensionConstants.SpklConfigFile)
                    {
                        continue;
                    }
                    if (File.Exists(Path.Combine(extractedFolder, name)))
                    {
                        continue;
                    }

                    projectItem.Delete();
                    itemChanged = true;
                }

                if (StringFormatting.RemoveBracesToUpper(projectItem.Kind) == VSConstants.GUID_ItemType_PhysicalFolder.ToString())
                {
                    name = new DirectoryInfo(name).Name;
                    if (name == projectFolder || name.Equals(D365DeveloperExtensions.Core.Resources.Resource.Constant_PropertiesFolder,
                                                             StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    if (!Directory.Exists(Path.Combine(extractedFolder, name)))
                    {
                        projectItem.Delete();
                        itemChanged = true;
                    }
                    else
                    {
                        if (projectItem.ProjectItems.Count <= 0)
                        {
                            continue;
                        }

                        var subItemChanged = RemoveDeletedItems(Path.Combine(extractedFolder, name),
                                                                projectItem.ProjectItems, projectFolder);
                        if (subItemChanged)
                        {
                            itemChanged = true;
                        }
                    }
                }
            }

            return(itemChanged);
        }
Exemple #27
0
 public virtual string Format(string format)
 {
     return(StringFormatting.Tokenize(format, token => FormatByToken(token)));
 }