コード例 #1
0
        public static void TruncateAll(this DbContext entities)
        {
            SqlCommand cmd;
            var        builder          = new StringBuilder();
            var        entityType       = entities.GetType();
            var        properties       = entityType.GetProperties().Where(p => p.PropertyType.Name.StartsWith("ObjectSet"));
            var        database         = entities.GetDatabaseName();
            var        entityConnection = entities.Database.GetDbConnection();
            var        connection       = new SqlConnection(entityConnection.ConnectionString);

            connection.Open();

            cmd = connection.CreateCommand();

            foreach (var property in properties)
            {
                DebugUtils.Break();

                //builder.AppendLineFormat("delete {0}.dbo.{1}", database, property.Name.Singularize());
            }

            cmd.CommandText = builder.ToString();

            cmd.ExecuteNonQuery();

            connection.Close();
        }
コード例 #2
0
        public static double Compare(this Color color, Color colorCompare, ColorCompareOption option)
        {
            var rgbColor   = new Rgb(color.R, color.G, color.B);
            var rgbCompare = new Rgb(colorCompare.R, colorCompare.G, colorCompare.B);

            switch (option)
            {
            case ColorCompareOption.CIE2000:
                return(rgbColor.Compare(rgbCompare, new CieDe2000Comparison()));

            default:
                DebugUtils.Break();
                return(-1);
            }
        }
コード例 #3
0
ファイル: ObjectTreeItem.cs プロジェクト: CloudIDEaaS/hydra
        public ObjectTreeItem(T obj)
        {
            if (obj != null)
            {
                this.InternalObject = obj;
            }

            this.Children           = new BaseList <ObjectTreeItem <T> >();
            this.ChildrenLinkedList = new LinkedList <ObjectTreeItem <T> >();

            ((INotifyCollectionChanged)this.Children).CollectionChanged += (sender, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:

                    foreach (var item in e.NewItems.Cast <ObjectTreeItem <T> >())
                    {
                        item.Parent = this;

                        item.LinkedListNode = this.ChildrenLinkedList.AddLast(item);
                    }

                    this.Root.ItemsAdded(e.NewItems);

                    break;

                case NotifyCollectionChangedAction.Remove:

                    foreach (var item in e.OldItems.Cast <ObjectTreeItem <T> >())
                    {
                        item.Parent = this;

                        this.ChildrenLinkedList.Remove(item);
                    }

                    this.Root.ItemsRemoved(e.OldItems);

                    break;

                default:
                    DebugUtils.Break();
                    break;
                }
            };
        }
コード例 #4
0
ファイル: TfsAgent.cs プロジェクト: CloudIDEaaS/hydra
        public void CheckoutFiles(string rootPath)
        {
            try
            {
                Workspace workspace;

                versionControlServer = (VersionControlServer)teamFoundationServices.GetService(typeof(VersionControlServer));

                workspace = versionControlServer.GetWorkspace(rootPath);
                workspace.Refresh();

                workspace.PendEdit(rootPath, RecursionType.Full);
            }
            catch (Exception ex)
            {
                DebugUtils.Break();
            }
        }
コード例 #5
0
ファイル: TfsAgent.cs プロジェクト: CloudIDEaaS/hydra
        public void CheckoutFiles(string rootPath, string pattern, SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            try
            {
                var workspace = versionControlServer.GetWorkspace(rootPath);

                workspace.Refresh();

                foreach (var file in Directory.GetFiles(rootPath, pattern, searchOption))
                {
                    workspace.PendEdit(file);
                }
            }
            catch (Exception ex)
            {
                DebugUtils.Break();
            }
        }
コード例 #6
0
        public static void ShowConsole()
        {
            if (isHidden)
            {
                var hwndConsole = ControlExtensions.GetConsoleWindow();

                ControlExtensions.ShowWindowAsync(hwndConsole, ControlExtensions.ShowWindowCommands.Show);

                isHidden = true;
            }
            else
            {
                if (!AllocConsole())
                {
                    DebugUtils.Break();
                }
            }
        }
コード例 #7
0
        public static void SetAutocomplete(this TextBox textBox, IEnumerable <string> strings)
        {
            if (autoCompletedTextboxes.ContainsKey(textBox))
            {
                var pair                 = autoCompletedTextboxes[textBox];
                var autoComplete         = pair.Key;
                var enumStrings          = pair.Value;
                var autoCompleteDropdown = (IAutoCompleteDropDown)autoComplete;

                enumStrings.ResetStrings(strings);

                autoCompleteDropdown.ResetEnumerator();
            }
            else
            {
                var enumStrings  = new EnumString(strings);
                var autoComplete = GetAutoComplete();
                int hr;

                hr = autoComplete.Init(textBox.Handle, enumStrings, 0, 0);

                if (hr != 0)
                {
                    DebugUtils.Break();
                }

                textBox.HandleDestroyed += (sender, e) =>
                {
                    var pair          = autoCompletedTextboxes[textBox];
                    var autoComplete2 = pair.Key;

                    Marshal.ReleaseComObject(autoComplete2);

                    autoCompletedTextboxes.Remove((TextBox)sender);
                };

                autoComplete.SetOptions(AUTOCOMPLETEOPTIONS.ACO_AUTOSUGGEST | AUTOCOMPLETEOPTIONS.ACO_UPDOWNKEYDROPSLIST);

                autoCompletedTextboxes.Add(textBox, new KeyValuePair <IAutoComplete2, EnumString>(autoComplete, enumStrings));
            }
        }
コード例 #8
0
ファイル: TfsAgent.cs プロジェクト: CloudIDEaaS/hydra
        public void CheckinFile(string rootPath, string file)
        {
            try
            {
                Workspace            workspace;
                PendingChange        pendingChange;
                List <PendingChange> pendingChanges;

                workspace = versionControlServer.GetWorkspace(rootPath);
                workspace.Refresh();

                pendingChanges = workspace.GetPendingChangesEnumerable().ToList();
                pendingChange  = pendingChanges.Single(p => p.LocalItem == file);

                workspace.CheckIn(new PendingChange[] { pendingChange }, string.Format("Auto check in of {0} by {1} on {2}", file, Environment.UserName, DateTime.Now.ToDateTimeText()));
            }
            catch (Exception ex)
            {
                DebugUtils.Break();
            }
        }
コード例 #9
0
ファイル: TfsAgent.cs プロジェクト: CloudIDEaaS/hydra
        public bool HasPendingChanges(string rootPath, List <string> files)
        {
            try
            {
                Workspace workspace;
                IEnumerable <PendingChange> pendingChanges;

                workspace = versionControlServer.GetWorkspace(rootPath);
                workspace.Refresh();

                pendingChanges = workspace.GetPendingChangesEnumerable().Where(p => files.Any(f => f == p.LocalItem));

                return(pendingChanges.Count() > 0);
            }
            catch (Exception ex)
            {
                DebugUtils.Break();
            }

            return(false);
        }
コード例 #10
0
ファイル: TfsAgent.cs プロジェクト: CloudIDEaaS/hydra
        public void CheckinFiles(string rootPath)
        {
            try
            {
                Workspace workspace;
                IEnumerable <PendingChange> pendingChanges;

                workspace = versionControlServer.GetWorkspace(rootPath);
                workspace.Refresh();

                pendingChanges = workspace.GetPendingChangesEnumerable().ToList();

                if (pendingChanges.Count() > 0)
                {
                    workspace.CheckIn(pendingChanges.ToArray(), string.Format("Auto check in by {0} on {1}", Environment.UserName, DateTime.Now.ToDateTimeText()));
                }
            }
            catch (Exception ex)
            {
                DebugUtils.Break();
            }
        }
コード例 #11
0
ファイル: TfsAgent.cs プロジェクト: CloudIDEaaS/hydra
        public void CheckoutFiles(string rootPath, List <string> files)
        {
            try
            {
                Workspace workspace;

                versionControlServer = (VersionControlServer)teamFoundationServices.GetService(typeof(VersionControlServer));

                workspace = versionControlServer.GetWorkspace(rootPath);
                workspace.Refresh();

                foreach (var file in files)
                {
                    workspace.PendEdit(file);
                }

                workspace.Refresh();
            }
            catch (Exception ex)
            {
                DebugUtils.Break();
            }
        }
コード例 #12
0
ファイル: TfsAgent.cs プロジェクト: CloudIDEaaS/hydra
        public void CheckinFiles(string rootPath, string pattern = "*.*", SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            try
            {
                var pendingChanges = new List <PendingChange>();
                var workspace      = versionControlServer.GetWorkspace(rootPath);

                workspace.Refresh();

                foreach (var file in Directory.GetFiles(rootPath, pattern, searchOption))
                {
                    var pendingChange = workspace.GetPendingChangesEnumerable().Single(p => p.FileName == file);

                    pendingChanges.Add(pendingChange);
                }

                workspace.CheckIn(pendingChanges.ToArray(), string.Format("Auto check in by {0} on {1}", Environment.UserName, DateTime.Now.ToDateTimeText()));
            }
            catch (Exception ex)
            {
                DebugUtils.Break();
            }
        }
コード例 #13
0
ファイル: DynamicObject.cs プロジェクト: CloudIDEaaS/hydra
 public static void SetDynamicMember(this object obj, string name, object value)
 {
     DebugUtils.Break();
 }
コード例 #14
0
        public static void DisplayHelp(this ParseResultBase parseResult)
        {
            var parseResultType        = parseResult.GetType();
            var parserAttribute        = parseResultType.GetCustomAttribute <CommandLineParserAttribute>();
            var switchType             = parserAttribute.SwitchType;
            var commandLineDescription = parserAttribute.Description;
            var programAssembly        = parserAttribute.ProgramAssemblyType.Assembly;
            var assemblyNameParts      = programAssembly.GetNameParts();
            var assemblyAttributes     = programAssembly.GetAttributes();
            var assemblyName           = assemblyNameParts.AssemblyName;
            var syntaxBuilder          = new StringBuilder();
            var switchListingBuilder   = new StringBuilder();
            var switches    = new List <CommandLineSwitchAttribute>();
            var switchNames = new List <string>();
            int maxSwitchName;
            int x;

            foreach (var match in commandLineDescription.GetAttributeStringExpressionMatches())
            {
                var expression = match.GetGroupValue("expression");

                switch (expression)
                {
                case "AssemblyProduct":
                    commandLineDescription = match.Replace(commandLineDescription, assemblyAttributes.Product ?? assemblyName);
                    break;

                case "AssemblyName":
                    commandLineDescription = match.Replace(commandLineDescription, assemblyName);
                    break;

                default:
                    DebugUtils.Break();
                    break;
                }
            }

            Console.WriteLine(commandLineDescription);
            Console.WriteLine();
            Console.WriteLine("Syntax:");

            syntaxBuilder.Append(assemblyName);

            foreach (var switchProperty in parserAttribute.SwitchType.GetConstants())
            {
                if (switchProperty.HasCustomAttribute <CommandLineSwitchAttribute>())
                {
                    var switchAttribute = switchProperty.GetCustomAttribute <CommandLineSwitchAttribute>();
                    var switchName      = (string)switchProperty.GetValue(null);

                    syntaxBuilder.AppendFormat(" [/{0}]", switchName);

                    switchNames.Add(switchName);
                    switches.Add(switchAttribute);
                }
            }

            maxSwitchName = switchNames.Max(n => n.Length);
            x             = 0;

            foreach (var switchAttribute in switches)
            {
                var switchName           = switchNames.ElementAt(x);
                var padding              = maxSwitchName + (switchAttribute.DescriptionLeftPaddingTabCount * 8);
                var attributeDescription = switchAttribute.Description;
                var switchNamePadded     = switchName.PadRight(padding, ' ');

                foreach (var match in attributeDescription.GetAttributeStringExpressionMatches())
                {
                    var expression = match.GetGroupValue("expression");
                    var property   = switchType.GetProperty(expression);
                    var value      = (string)property.GetValue(null);
                    var lines      = value.GetLines().Select(l => ' '.Repeat(12 + switchNamePadded.Length) + l);
                    var ending     = attributeDescription.RegexGet(match.Value + @"(?<ending>[^\{]*)", "ending");

                    value = lines.Join();

                    attributeDescription = match.Replace(attributeDescription, value);

                    if (ending.Length > 0)
                    {
                        attributeDescription = attributeDescription.Replace(ending, "\r\n" + ' '.Repeat(4 + switchNamePadded.Length) + ending);
                    }
                }

                switchListingBuilder.AppendLineFormat(@"{0}/{1}{2}", ' '.Repeat(4), switchNamePadded, attributeDescription);

                x++;
            }

            Console.WriteLine(syntaxBuilder);

            Console.WriteLine();
            Console.WriteLine(switchListingBuilder);

            Console.Write("Press any key to continue . . .");
            Console.ReadKey();

            parseResult.HelpDisplayed = true;
        }
コード例 #15
0
        private void TryGetSet(RegistryKey key, object obj, string keyName, RegistryValueKind valueKind)
        {
            object value = null;

            try
            {
                value = key.GetValue(keyName);
            }
            catch
            {
            }

            if (value != null)
            {
                try
                {
                    var property = obj.GetType().GetProperty(keyName);

                    if (property.PropertyType.IsEnum)
                    {
                        var enumValue = Enum.Parse(property.PropertyType, value.ToString());
                        obj.SetPropertyValue(keyName, enumValue);
                    }
                    else
                    {
                        switch (property.PropertyType.Name)
                        {
                        case "DateTime":

                            switch (valueKind)
                            {
                            case RegistryValueKind.String:

                                var date = DateTime.Parse(value.ToString());
                                obj.SetPropertyValue(keyName, date);
                                break;

                            default:
                                DebugUtils.Break();
                                break;
                            }

                            break;

                        case "String":

                            switch (valueKind)
                            {
                            case RegistryValueKind.String:
                                obj.SetPropertyValue(keyName, value.ToString());
                                break;

                            default:
                                DebugUtils.Break();
                                break;
                            }

                            break;

                        case "Int32":
                        {
                            obj.SetPropertyValue(keyName, (int)value);
                            break;
                        }


                        case "Boolean":
                        {
                            obj.SetPropertyValue(keyName, (int)value == 0 ? true : false);
                            break;
                        }

                        default:
                            DebugUtils.Break();
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    DebugUtils.Break();
                }
            }
        }
コード例 #16
0
        private void DoSave(RegistryKey key, object obj)
        {
            // public strings

            foreach (var propertyValue in obj.GetPublicPropertyValuesOfType <string>())
            {
                if (!propertyValue.Value.IsNullWhiteSpaceOrEmpty())
                {
                    if (obj is IRegistryKey)
                    {
                        if (propertyValue.Key != "KeyName")
                        {
                            key.SetValue(propertyValue.Key, propertyValue.Value);
                        }
                    }
                    else
                    {
                        key.SetValue(propertyValue.Key, propertyValue.Value);
                    }
                }
            }

            // non strings

            foreach (var attributeProperty in obj.GetPublicPropertiesWithAttributeType <RegistryNonStringValueAttribute>())
            {
                var attribute = attributeProperty.Key;
                var property  = attributeProperty.Value;
                var value     = property.GetValue(obj, null);
                var valueKind = attribute.ValueKind;

                switch (valueKind)
                {
                case RegistryValueKind.String:

                    if (value != null)
                    {
                        key.SetValue(property.Name, value.ToString(), valueKind);
                    }

                    break;

                case RegistryValueKind.DWord:

                    if (value != null)
                    {
                        switch (property.PropertyType.Name)
                        {
                        case "Boolean":
                            key.SetValue(property.Name, (bool)value ? 1 : 0, valueKind);
                            break;

                        default:
                            key.SetValue(property.Name, (int)value, valueKind);
                            break;
                        }
                    }

                    break;

                default:
                    DebugUtils.Break();
                    break;
                }
            }

            // enumerables

            foreach (var attributeProperty in obj.GetPublicPropertiesWithAttributeType <RegistryKeyEnumerableAttribute>())
            {
                var attribute = attributeProperty.Key;
                var property  = attributeProperty.Value;
                var value     = property.GetValue(obj, null);
                var subKey    = key.CreateSubKey(attribute.KeyName);

                if (value is IRegistryKeyWithSubKeys)
                {
                    DebugUtils.Break();
                }
                else
                {
                    var enumerable = (IEnumerable)value;
                    var x          = 1;

                    foreach (var subValue in enumerable)
                    {
                        if (subValue is IRegistryKey)
                        {
                            var registryKeyObject = (IRegistryKey)subValue;

                            if (registryKeyObject is IRegistryKeyWithSubKeys)
                            {
                                DebugUtils.Break();
                            }
                            else
                            {
                                subKey = subKey.CreateSubKey(string.Format(registryKeyObject.KeyName, x));
                            }
                        }

                        DoSave(subKey, subValue);

                        x++;
                    }
                }
            }

            // public properties of type IRegistryKey

            foreach (var propertyValue in obj.GetPublicPropertyValuesOfType <IRegistryKey>())
            {
                var value = propertyValue.Value;

                if (value is IRegistryKey)
                {
                    var registryKeyObject = (IRegistryKey)value;

                    if (registryKeyObject is IRegistryKeyWithSubKeys)
                    {
                        DebugUtils.Break();
                    }
                    else
                    {
                        var subKey = key.CreateSubKey(registryKeyObject.KeyName);

                        DoSave(subKey, registryKeyObject);
                    }
                }
            }
        }