Пример #1
0
        // Deep clone, recursive
        public override ConnectionInfo Clone()
        {
            var newContainer = new ContainerInfo();

            newContainer.CopyFrom(this);
            newContainer.ConstantID = MiscTools.CreateConstantID();
            newContainer.SetParent(Parent);
            newContainer.OpenConnections = new ProtocolList();
            newContainer.Inheritance     = Inheritance.Clone();
            foreach (var child in Children.ToArray())
            {
                var newChild = child.Clone();
                newChild.RemoveParent();
                newContainer.AddChild(newChild);
            }
            return(newContainer);
        }
Пример #2
0
        private async void SetOnlineStatus()
        {
            SetNetworkControlsEnabledState(false);
            LabelStatus.Content = "Checking internet connection, please wait …";
            if (!await Task.Run(() => MiscTools.IsComputerOnline()))
            {
                LabelStatus.Content = "Computer is not online. All online functionality will be disabled.";
                await Task.Delay(5000);

                _online = false;
            }
            else
            {
                _online = true;
            }
            LabelStatus.Content = "Ready.";
            SetNetworkControlsEnabledState(true);
        }
Пример #3
0
        private async void CheckIfSongIsPlaying()
        {
            if (!shouldCheck || !MiscTools.IsInForeground())
            {
                return;
            }
            if (notificationSong.Normal.Id == previousNtfSong.Normal.Id)
            {
                return;
            }

            Log(Type.Event, "Song playing is different, updating...");

            nowPlayingMode  = true;
            songInfo        = notificationSong;
            previousNtfSong = notificationSong;

            bool autoUpdate = Prefs.GetBoolean("auto_update_page", false);

            if (autoUpdate && nowPlayingMode)
            {
                shouldCheck = false;
                LoadSong();
            }
            else if (nowPlayingMode)
            {
                shouldCheck = false;

                Android.Views.Animations.Animation anim = Animations.BlinkingAnimation(700, 3);
                npTxt.StartAnimation(anim);
                Log(Type.Event, "Playing animation on npTxt");
            }
            else if (!nowPlayingMode)
            {
                shouldCheck = false;

                Android.Views.Animations.Animation anim = Animations.BlinkingImageAnimation(500, 4);
                shineView.Visibility = ViewStates.Visible;
                shineView.StartAnimation(anim);
                Log(Type.Event, "Playing animation on shineView");
            }
        }
Пример #4
0
        public void AddMessage(ChatMessage message)
        {
            lock (LockObj)
            {
                LockObj.LockMessage = MiscTools.GetCurrentMethod();
                var line = new ChatLog
                {
                    SentAt      = message.SentAt,
                    MessageType = MessageTypes.ChatMessage,
                    ChannelId   = message.Channel.Identifier,
                    Channel     = message.Channel.Name,
                    SenderId    = message.Sender.DbUser.Id,
                    Nick        = message.Sender.Nickname,
                    Message     = message.Body
                };

                SqlConnector.Insert(line);
            }
            LockObj.LockMessage = "None";
        }
Пример #5
0
        public void IncrementWords(Dictionary <string, int> usages)
        {
            lock (LockObj)
            {
                LockObj.LockMessage = MiscTools.GetCurrentMethod();

                SqlConnector.Words.Delete(w => true);

                //var currentUsages = SqlConnector.Words.Select( w => w);
                var rows = usages.Select(pair => new UsedWord
                {
                    Word = pair.Key,
                    Uses = pair.Value
                }).OrderByDescending(w => w.Uses);

                SqlConnector.InsertMultiple(rows);

                LockObj.LockMessage = "None";
            }
        }
Пример #6
0
        private async Task <string> GetUsers(LoadOptions options, int[] users)
        {
            if (options.Execute)
            {
                var req = new Request <User[]> {
                    MethodName = "execute.mfetch25a",
                    Token      = _api.CurrentToken,
                    Parameters = new Dictionary <string, string>()
                };
                req.Parameters.Add("fields", string.Join(",", MiscTools.GetUserFields(options.Fields)));
                var uids = users.Select((value, index) => new { value, index }).GroupBy(a => a.index / 1000).Select(a => a.Select(b => b.value).ToArray()).ToArray();
                for (int i = 0; i < uids.Length; i++)
                {
                    req.Parameters.Add("u" + i, uids[i].ToNCStringA());
                }

                return(await _api.Executor.ExecRawAsync(req).ConfigureAwait(false));
            }
            return(await _api.Users.Get(options.Fields, NameCase.Nom, users).ConfigureAwait(false));
        }
Пример #7
0
        public async Task <User[]> UsersSearchAsync(UsersSearchParams usersSearchParams)
        {
            var req = new VKRequest <User> {
                MethodName = "users.search",
                Parameters =
                    new Dictionary <string, string> {
                    { "q", usersSearchParams.Query },
                    { "sort", ((int)usersSearchParams.Sort).ToNCString() },
                    { "offset", MiscTools.NullableString(usersSearchParams.Offset) },
                    { "count", MiscTools.NullableString(usersSearchParams.Count) },
                    { "fields", String.Join(",", MiscTools.GetUserFields(usersSearchParams.Fields)) },
                    { "city", MiscTools.NullableString(usersSearchParams.CityId) },
                    { "country", MiscTools.NullableString(usersSearchParams.CountryId) },
                    { "hometown", usersSearchParams.Hometown },
                    { "university_country", MiscTools.NullableString(usersSearchParams.UniversityCountryId) },
                    { "university", MiscTools.NullableString(usersSearchParams.UniversityId) },
                    { "university_year", MiscTools.NullableString(usersSearchParams.UniversityYear) },
                    { "sex", usersSearchParams.Sex != null ? ((int)usersSearchParams.Sex).ToNCString() : "" },
                    { "status", MiscTools.NullableString(usersSearchParams.Relation) },
                    { "age_from", MiscTools.NullableString(usersSearchParams.AgeFrom) },
                    { "age_to", MiscTools.NullableString(usersSearchParams.AgeTo) },
                    { "birth_day", MiscTools.NullableString(usersSearchParams.BirthDay) },
                    { "birth_month", MiscTools.NullableString(usersSearchParams.BirthMonth) },
                    { "birth_year", MiscTools.NullableString(usersSearchParams.BirthYear) },
                    { "online", MiscTools.NullableString(usersSearchParams.Online.HasValue ? (uint?)(usersSearchParams.Online.Value ? 1 : 0) : null) },
                    { "has_photo", MiscTools.NullableString(usersSearchParams.HasPhoto.HasValue ? (uint?)(usersSearchParams.HasPhoto.Value ? 1 : 0) : null) },
                    { "school_country", MiscTools.NullableString(usersSearchParams.SchoolCountryId) },
                    { "school_city", MiscTools.NullableString(usersSearchParams.SchoolCityId) },
                    { "school", MiscTools.NullableString(usersSearchParams.SchoolId) },
                    { "school_year", MiscTools.NullableString(usersSearchParams.SchoolYear) },
                    { "religion", usersSearchParams.Religion },
                    { "interests", usersSearchParams.Interests },
                    { "company", usersSearchParams.Company },
                    { "position", usersSearchParams.Position },
                    { "group_id", MiscTools.NullableString(usersSearchParams.GroupId) }
                },
                Token = IsLogged ? CurrentToken : null
            };

            return((await _executor.ExecAsync(req)).Data);
        }
        public void WriteDatabaseMetaData(RootNodeInfo rootTreeNode, SqlDatabaseConnector sqlDatabaseConnector)
        {
            var    cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            string strProtected;

            if (rootTreeNode != null)
            {
                if (rootTreeNode.Password)
                {
                    var password = rootTreeNode.PasswordString.ConvertToSecureString();
                    strProtected = cryptographyProvider.Encrypt("ThisIsProtected", password);
                }
                else
                {
                    strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", Runtime.EncryptionKey);
                }
            }
            else
            {
                strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", Runtime.EncryptionKey);
            }

            var sqlQuery = new SqlCommand("DELETE FROM tblRoot", sqlDatabaseConnector.SqlConnection);

            sqlQuery.ExecuteNonQuery();

            if (rootTreeNode != null)
            {
                sqlQuery =
                    new SqlCommand(
                        "INSERT INTO tblRoot (Name, Export, Protected, ConfVersion) VALUES(\'" +
                        MiscTools.PrepareValueForDB(rootTreeNode.Name) + "\', 0, \'" + strProtected + "\'," +
                        ConnectionsFileInfo.ConnectionFileVersion.ToString(CultureInfo.InvariantCulture) + ")",
                        sqlDatabaseConnector.SqlConnection);
                sqlQuery.ExecuteNonQuery();
            }
            else
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, $"UpdateRootNodeTable: rootTreeNode was null. Could not insert!");
            }
        }
Пример #9
0
        private async void HandleChosenSong(Song chosen)
        {
            if (chosen.Likeness >= MaxLikeness)
            {
                Log(Type.Info, $"Selected song {chosen.Title} by {chosen.Artist} with likeness {chosen.Likeness} is too unlikely.\n Song not found.");
                ntfManager.Cancel(NotificationId);
            }
            else if (string.IsNullOrEmpty(chosen.Title))
            {
                Log(Type.Info, "Song not found!");
                ntfManager.Cancel(NotificationId);
            }
            else if (chosen.Likeness <= MaxLikeness)
            {
                Log(Type.Event, $"Selected song is {chosen.Title} by {chosen.Artist} with likeness {chosen.Likeness}.");

                if (!MiscTools.IsInForeground())
                {
                    CreateNotification(new SongBundle(chosen, new RomanizedSong()));
                }
            }
        }
Пример #10
0
 private void CreateScreenshot()
 {
     cmenTab.Close();
     Application.DoEvents();
     Windows.ScreenshotForm.AddScreenshot(MiscTools.TakeScreenshot(this));
 }
Пример #11
0
        private void UpdateUpdatesTable(SqlDatabaseConnector sqlDatabaseConnector)
        {
            var sqlQuery = new SqlCommand("DELETE FROM tblUpdate", sqlDatabaseConnector.SqlConnection);

            sqlQuery.ExecuteNonQuery();
            sqlQuery = new SqlCommand("INSERT INTO tblUpdate (LastUpdate) VALUES(\'" + MiscTools.DBDate(DateTime.Now) + "\')", sqlDatabaseConnector.SqlConnection);
            sqlQuery.ExecuteNonQuery();
        }
Пример #12
0
 public Taskbar()
 {
     InitializeComponent();
     Width             = SystemParameters.PrimaryScreenWidth;
     Top               = SystemParameters.PrimaryScreenHeight - Height;
     Left              = 0;
     IsVisibleChanged += Taskbar_IsVisibleChanged;
     //Visibility = Visibility.Hidden;
     InitialPopulateTaskbar();
     ClockTimer.Elapsed += delegate
     {
         Dispatcher.Invoke(new Action(() =>
         {
             ClockTime.Content = DateTime.Now.ToShortTimeString();
             ClockDate.Content = DateTime.Now.ToShortDateString();
         }));
     };
     ClockTimer.Start();
     ProgramWindow.WindowOpened += InsertCreatedWindow;
     ProgramWindow.WindowClosed += RemoveClosedWindow;
     _activeWindowTimer.Elapsed += delegate
     {
         Dispatcher.Invoke(new Action(() =>
         {
             var active = MiscTools.GetForegroundWindow();
             foreach (TaskbarGroupStackPanel t in Taskband.Children)
             {
                 try
                 {
                     if (t.ForceCombine | (Config.GroupingMode == TaskbarGroupingMode.Combine))
                     {
                         var isAnythingActive = false;
                         foreach (var b in t.ProgramWindowsList)
                         {
                             if (b.Hwnd == active)
                             {
                                 isAnythingActive = true;
                             }
                         }
                         if (isAnythingActive)
                         {
                             t.RunningBackgroundButton.IsActiveWindow = true;
                         }
                         else
                         {
                             t.RunningBackgroundButton.IsActiveWindow = false;
                         }
                     }
                     else
                     {
                         foreach (TaskItemButton b in t.Buttons.Children)
                         {
                             if ((b.Tag as ProgramWindow).Hwnd == active)
                             {
                                 b.IsActiveWindow = true;
                             }
                             else
                             {
                                 b.IsActiveWindow = false;
                             }
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Debug.WriteLine(ex);
                 }
             }
         }));
     };
     _activeWindowTimer.Start();
     Debug.WriteLine(MainTools.GetFixedModule("Test Module").ModuleName + " FOUND!");
 }
Пример #13
0
    private void HorizontalMovement()
    {
        //Horizontal Input
        h = Input.GetAxisRaw("Horizontal");

        //If there is horizontal input, change the velocity
        if (h != 0)
        {
            //If Run input is detected, run
            if (Input.GetAxisRaw("Run") == 1)
            {
                //animator.SetFloat("Speed", Mathf.Abs(h)+1);
                //Set the velocity. Multiply by h to set direction
                rigidbody2D.velocity = new Vector2(MiscTools.IncrementTowards(rigidbody2D.velocity.x, h * maxRunSpeed, runForce), rigidbody2D.velocity.y);
            }
            //If no run input is detected, walk
            else
            {
                //animator.SetFloat("Speed", Mathf.Abs(h));
                //Set the velocity. Multiply by h to set direction
                rigidbody2D.velocity = new Vector2(MiscTools.IncrementTowards(rigidbody2D.velocity.x, h * maxWalkSpeed, walkForce), rigidbody2D.velocity.y);
            }
            //Emit particles
            if (grounded)
            {
                dustParticles.enableEmission = true;
            }
            else
            {
                dustParticles.enableEmission = false;
            }
        }
        else
        {
            dustParticles.enableEmission = false;
        }


        // If the input is moving the player right and the player is facing left...
        if (h > 0 && !facingRight)
        {
            Flip();
        }
        // Otherwise if the input is moving the player left and the player is facing right...
        else if (h < 0 && facingRight)
        {
            Flip();
        }


        //If the player is grounded and there is no more horizontal input, decelerate the player
        if (!Input.GetButton("Horizontal") && grounded)
        {
            rigidbody2D.velocity = new Vector2(MiscTools.IncrementTowards(rigidbody2D.velocity.x, 0, deceleration), rigidbody2D.velocity.y);
            //animator.SetFloat("Speed", 0);
        }

        //If the player's y position gets lower than a certain point, respawn and subtract 1 hp
        if (transform.position.y < -30)
        {
            transform.position = currentCheckpoint;
            SubtractHP(1);
        }
    }
Пример #14
0
        // Writes a song to the saved lyrics database.
        // Returns true if successful.
        //TODO: Add ability to return an error, song already saved or saved successfully messages
        public static async Task <bool> WriteInfoAndLyrics(SongBundle song)
        {
            await MiscTools.CheckAndCreateAppFolders();

            InitializeTables();
            db = await ReadDatabaseFile(DbPath);

            rdb = await ReadRomanizedDatabaseFile(RomanizedDbPath);

            try
            {
                if (await GetSongFromTable(song.Normal.Id) == null)
                {
                    // Write lyrics to file
                    string filepath = Path.Combine(LyricsPath, song.Normal.Id + Globals.LyricsExtension);
                    File.WriteAllText(filepath, song.Normal.Lyrics);

                    if (song.Romanized != null)
                    {
                        string romanizedFilepath = Path.Combine(LyricsPath, song.Normal.Id + Globals.RomanizedExtension);
                        File.WriteAllText(romanizedFilepath, song.Romanized.Lyrics);

                        song.Normal.Romanized = true;

                        rdb.Rows.Add(
                            song.Romanized.Id,
                            song.Romanized.Title,
                            song.Romanized.Artist,
                            song.Romanized.Album,
                            song.Romanized.FeaturedArtist);
                        rdb.WriteXml(RomanizedDbPath);
                    }

                    await WriteImages(song.Normal);

                    db.Rows.Add(
                        song.Normal.Id,
                        song.Normal.Title,
                        song.Normal.Artist,
                        song.Normal.Album,
                        song.Normal.FeaturedArtist,
                        song.Normal.Cover,
                        song.Normal.Header,
                        song.Normal.Romanized,
                        song.Normal.ApiPath,
                        song.Normal.Path);
                    db.WriteXml(DbPath);

                    Logging.Log(Logging.Type.Event, $"Wrote song {song.Normal.Id} to file");
                    Analytics.TrackEvent("Wrote song to file", new Dictionary <string, string> {
                        { "SongID", song.Normal.Id.ToString() },
                        { "DBSize", db.Rows.Count.ToString() },
                        { "RomanizedDBSize", rdb.Rows.Count.ToString() }
                    });
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (IOException ex)
            {
                Crashes.TrackError(ex, new Dictionary <string, string> {
                    { "SongID", song.Normal.Id.ToString() },
                    { "Exception", ex.ToString() }
                });
                Logging.Log(Logging.Type.Error, "Exception while writing lyrics to disk!\n" + ex);

                return(false);
            }
            catch (NullReferenceException ex)
            {
                Crashes.TrackError(ex, new Dictionary <string, string> {
                    { "SongID", song.Normal.Id.ToString() },
                    { "Exception", ex.ToString() }
                });
                Logging.Log(Logging.Type.Error, "NullReferenceException while writing lyrics to disk! Reload song and try again.\n" + ex);

                return(false);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex, new Dictionary <string, string> {
                    { "SongID", song.Normal.Id.ToString() },
                    { "Exception", ex.ToString() }
                });
                Logging.Log(Logging.Type.Error, "Unkown error while writing song to disk!\n" + ex);

                return(false);
            }
        }
Пример #15
0
        public static void LoadConnections(bool withDialog = false, bool update = false)
        {
            var connectionsLoader = new ConnectionsLoader();

            try
            {
                // disable sql update checking while we are loading updates
                SQLConnProvider?.Disable();

                if (ConnectionList != null && ContainerList != null)
                {
                    PreviousConnectionList = ConnectionList.Copy();
                    PreviousContainerList  = ContainerList.Copy();
                }

                ConnectionList = new ConnectionList();
                ContainerList  = new ContainerList();

                if (!Settings.Default.UseSQLServer)
                {
                    if (withDialog)
                    {
                        var loadDialog = Tools.Controls.ConnectionsLoadDialog();
                        if (loadDialog.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        connectionsLoader.ConnectionFileName = loadDialog.FileName;
                    }
                    else
                    {
                        connectionsLoader.ConnectionFileName = GetStartupConnectionFileName();
                    }

                    CreateBackupFile(Convert.ToString(connectionsLoader.ConnectionFileName));
                }

                connectionsLoader.ConnectionList = ConnectionList;
                connectionsLoader.ContainerList  = ContainerList;

                if (PreviousConnectionList != null && PreviousContainerList != null)
                {
                    connectionsLoader.PreviousConnectionList = PreviousConnectionList;
                    connectionsLoader.PreviousContainerList  = PreviousContainerList;
                }

                if (update)
                {
                    connectionsLoader.PreviousSelected = LastSelected;
                }

                ConnectionTree.ResetTree();

                connectionsLoader.RootTreeNode     = Windows.treeForm.tvConnections.Nodes[0];
                connectionsLoader.UseDatabase      = Settings.Default.UseSQLServer;
                connectionsLoader.DatabaseHost     = Settings.Default.SQLHost;
                connectionsLoader.DatabaseName     = Settings.Default.SQLDatabaseName;
                connectionsLoader.DatabaseUsername = Settings.Default.SQLUser;
                var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                connectionsLoader.DatabasePassword = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.SQLPass), GeneralAppInfo.EncryptionKey);
                connectionsLoader.DatabaseUpdate   = update;
                connectionsLoader.LoadConnections(false);

                if (Settings.Default.UseSQLServer)
                {
                    LastSqlUpdate = DateTime.Now;
                }
                else
                {
                    if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName())
                    {
                        Settings.Default.LoadConsFromCustomLocation = false;
                    }
                    else
                    {
                        Settings.Default.LoadConsFromCustomLocation = true;
                        Settings.Default.CustomConsPath             = connectionsLoader.ConnectionFileName;
                    }
                }

                // re-enable sql update checking after updates are loaded
                SQLConnProvider?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:
                        LoadConnections(withDialog, update);
                        return;

                    case 1:
                        Settings.Default.UseSQLServer = false;
                        LoadConnections(true, update);
                        return;

                    default:
                        Application.Exit();
                        return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg);
                    NewConnections(Convert.ToString(connectionsLoader.ConnectionFileName));
                    return;
                }

                MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex);
                if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog, update);
                }
                else
                {
                    MessageBox.Show(frmMain.Default,
                                    string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                                    "Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }
        public string buildTransDirectory(string pathPrefix, string yyyyMMDDHHMM, string wsProjectID, string projName, string[] targetLocales, string XMLFilename)
        {
            string rootDir    = ConfigurationSettings.AppSettings["MTD_PATH"];
            string transRoot  = rootDir + pathPrefix + "4-MyMedialocate\\" + yyyyMMDDHHMM + "-" + wsProjectID + "-" + projName;
            string sourceRoot = rootDir + pathPrefix + "1-Preparation\\A-Source_Files\\" + yyyyMMDDHHMM + "-" + wsProjectID + "-" + projName;

            string[] pathArray = XMLFilename.Split('\\');
            string   filename  = pathArray[pathArray.Length - 1];

            WindowsImpersonationContext impersonationContext = null;

            if (MiscTools.impersonateValidUser(ref impersonationContext))
            {
                //Insert your code that runs under the security context of a specific user here.
                if (Directory.Exists(rootDir) == true)
                {
                    if (Directory.Exists(sourceRoot) == false)
                    {
                        Directory.CreateDirectory(sourceRoot);

                        //write file to this folder
                        File.Copy(XMLFilename, sourceRoot + "\\" + filename);
                    }
                }
                if (Directory.Exists(rootDir) == true)
                {
                    if (Directory.Exists(transRoot) == false)
                    {
                        Directory.CreateDirectory(transRoot);

                        //write file to this folder
                    }
                    int count = targetLocales.Length;
                    for (int i = 0; i < count; i++)
                    {
                        if (targetLocales[i] != null)
                        {
                            string locale = targetLocales[i];
                            if (locale == "es_EC")
                            {
                                locale = "es_LA";
                            }

                            string transRootLang = transRoot + "\\" + locale;
                            if (Directory.Exists(transRootLang) == false)
                            {
                                Directory.CreateDirectory(transRootLang);
                                /* According to Marcelo, no docs need to be ITAR compliant  9/6/12 */
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Warning: the directory <b>" + rootDir + "</b> does not exists or is inaccessible.");
                }
                MiscTools.undoImpersonation(impersonationContext);
            }
            else
            {
                string error = "Your impersonation failed ";
                throw new Exception(error);
            }

            return(transRoot);
        }
Пример #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="withDialog">
        /// Should we show the file selection dialog to allow the user to select
        /// a connection file
        /// </param>
        public static void LoadConnections(bool withDialog = false)
        {
            var connectionFileName = "";

            try
            {
                // disable sql update checking while we are loading updates
                ConnectionsService.RemoteConnectionsSyncronizer?.Disable();

                if (withDialog)
                {
                    var loadDialog = DialogFactory.BuildLoadConnectionsDialog();
                    if (loadDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    connectionFileName            = loadDialog.FileName;
                    Settings.Default.UseSQLServer = false;
                    Settings.Default.Save();
                }
                else if (!Settings.Default.UseSQLServer)
                {
                    connectionFileName = ConnectionsService.GetStartupConnectionFileName();
                }

                ConnectionsService.LoadConnections(Settings.Default.UseSQLServer, false, connectionFileName);

                if (Settings.Default.UseSQLServer)
                {
                    ConnectionsService.LastSqlUpdate = DateTime.Now;
                }

                // re-enable sql update checking after updates are loaded
                ConnectionsService.RemoteConnectionsSyncronizer?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:
                        LoadConnections(withDialog);
                        return;

                    case 1:
                        Settings.Default.UseSQLServer = false;
                        LoadConnections(true);
                        return;

                    default:
                        Application.Exit();
                        return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), ex, MessageClass.InformationMsg);

                    string[] commandButtons =
                    {
                        Language.ConfigurationCreateNew,
                        Language.ConfigurationCustomPath,
                        Language.ConfigurationImportFile,
                        Language.strMenuExit
                    };

                    var answered = false;
                    while (!answered)
                    {
                        try
                        {
                            CTaskDialog.ShowTaskDialogBox(
                                GeneralAppInfo.ProductName,
                                Language.ConnectionFileNotFound,
                                "", "", "", "", "",
                                string.Join(" | ", commandButtons),
                                ETaskDialogButtons.None,
                                ESysIcons.Question,
                                ESysIcons.Question);

                            switch (CTaskDialog.CommandButtonResult)
                            {
                            case 0:
                                ConnectionsService.NewConnectionsFile(connectionFileName);
                                answered = true;
                                break;

                            case 1:
                                LoadConnections(true);
                                answered = true;
                                break;

                            case 2:
                                ConnectionsService.NewConnectionsFile(connectionFileName);
                                Import.ImportFromFile(ConnectionsService.ConnectionTreeModel.RootNodes[0]);
                                answered = true;
                                break;

                            case 3:
                                Application.Exit();
                                answered = true;
                                break;
                            }
                        }
                        catch (Exception exc)
                        {
                            MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), exc, MessageClass.InformationMsg);
                        }
                    }
                    return;
                }

                MessageCollector.AddExceptionStackTrace(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionFileName), ex);
                if (connectionFileName != ConnectionsService.GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog);
                }
                else
                {
                    MessageBox.Show(FrmMain.Default,
                                    string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, ConnectionsService.GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                                    @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }
Пример #18
0
 private void MasterConnection_OnRouterReceiveMessage(RouterMessage msg)
 {
     if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_STATUS)
     {
         OnCmdGetStatus(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_ADDPACKAGE)
     {
         OnCmdAddPackage(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_ADDVERSION)
     {
         OnCmdAddVersion(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_ADDINSTANCE)
     {
         OnCmdAddInstance(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_LISTPACKAGES)
     {
         msg.RespondJson(MiscTools.DictToList(session.packages), true);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_LISTVERSIONS)
     {
         msg.RespondJson(MiscTools.DictToList(session.versions), true);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_LISTINSTANCES)
     {
         msg.RespondJson(session.instances, true);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_UPDATEINSTANCE)
     {
         OnCmdUpdateInstance(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_DESTROYINSTANCE)
     {
         OnCmdRemoveInstance(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_DELETEVERSION)
     {
         OnCmdDeleteVersion(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_ADDSITE)
     {
         OnCmdAddSite(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_LISTSITES)
     {
         msg.RespondJson(MiscTools.DictToList(session.sites), true);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_M_ASSIGNSITE)
     {
         OnCmdAssignSite(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_REBOOT_INSTANCE)
     {
         OnCmdRebootInstance(msg);
     }
     else if (msg.opcode == MasterConnectionOpcodes.OPCODE_MASTER_PING_INSTANCE)
     {
         OnCmdGetInstanceStatus(msg).GetAwaiter().GetResult();
     }
     else
     {
         Log("MasterConnection_OnRouterReceiveMessage", $"Got message with unknown opcode {msg.opcode}.", DeltaLogLevel.Medium);
     }
 }
Пример #19
0
        private void UpdateRootNodeTable(RootNodeInfo rootTreeNode, SqlDatabaseConnector sqlDatabaseConnector)
        {
            var    cryptographyProvider = new LegacyRijndaelCryptographyProvider();
            string strProtected;

            if (rootTreeNode != null)
            {
                if (rootTreeNode.Password)
                {
                    _password    = Convert.ToString(rootTreeNode.PasswordString).ConvertToSecureString();
                    strProtected = cryptographyProvider.Encrypt("ThisIsProtected", _password);
                }
                else
                {
                    strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _password);
                }
            }
            else
            {
                strProtected = cryptographyProvider.Encrypt("ThisIsNotProtected", _password);
            }

            var sqlQuery = new SqlCommand("DELETE FROM tblRoot", sqlDatabaseConnector.SqlConnection);

            sqlQuery.ExecuteNonQuery();

            sqlQuery = new SqlCommand("INSERT INTO tblRoot (Name, Export, Protected, ConfVersion) VALUES(\'" + MiscTools.PrepareValueForDB(rootTreeNode.Name) + "\', 0, \'" + strProtected + "\'," + ConnectionsFileInfo.ConnectionFileVersion.ToString(CultureInfo.InvariantCulture) + ")", sqlDatabaseConnector.SqlConnection);
            sqlQuery.ExecuteNonQuery();
        }
        private Optional <SecureString> PromptForPassword()
        {
            var password = MiscTools.PasswordDialog("", false);

            return(password);
        }
Пример #21
0
 public NotAdminDialog()
 {
     InitializeComponent();
     ShieldIcon.Source = MiscTools.GetUACShieldIcon();
 }
        public void buildProjDirStructure(string monthYear, string projectNum, bool ITARFlag)
        {
            string debugLine = "";
            string rootDir   = ConfigurationSettings.AppSettings["MTD_PATH"];
            string projRoot  = rootDir + "Projects\\" + monthYear;

            string itarGroup = "ITAR";

            if (ConfigurationSettings.AppSettings["ITAR_GROUP"] != null)
            {
                itarGroup = ConfigurationSettings.AppSettings["ITAR_GROUP"];
            }

            //FileSystemAccessRule itarRule = new FileSystemAccessRule(itarGroup, FileSystemRights.FullControl, AccessControlType.Deny);
            FileSystemAccessRule itarRule = new FileSystemAccessRule(itarGroup, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Deny);

            WindowsImpersonationContext impersonationContext = null;

            if (MiscTools.impersonateValidUser(ref impersonationContext))
            {
                //Insert your code that runs under the security context of a specific user here.
                if (Directory.Exists(rootDir) == true)
                {
                    if (Directory.Exists(projRoot) == false)
                    {
                        Directory.CreateDirectory(projRoot);
                    }

                    projRoot = projRoot + "\\" + projectNum;
                    if (Directory.Exists(projRoot) == false)
                    {
                        DirectoryInfo itar = Directory.CreateDirectory(projRoot);
                        if (ITARFlag == true)
                        {
                            try
                            {
                                DirectorySecurity dirSec = itar.GetAccessControl();
                                dirSec.AddAccessRule(itarRule);
                                itar.SetAccessControl(dirSec);
                            }
                            catch (Exception ex)
                            {
                                debugLine = DateTime.Now + " Error setting project directory ITAR permissions"; WriteDebugfile(debugLine);
                            }
                        }
                    }

                    /////////////////////////////

                    // Admin
                    buildDirectory(projRoot + "\\0-Admin", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\0-Admin\\A-Schedules", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\0-Admin\\B-Misc", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\0-Admin\\C-Invoices", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\0-Admin\\D-Emails", ITARFlag, itarRule);

                    // Preparation
                    buildDirectory(projRoot + "\\1-Preparation", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\1-Preparation\\A-Source_Files", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\1-Preparation\\B-Engineering", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\1-Preparation\\B-Engineering\\1-File_Prep", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\1-Preparation\\B-Engineering\\2-Eng_Testing", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\1-Preparation\\B-Engineering\\3-To_Trans_Logs", ITARFlag, itarRule);

                    // Production

                    buildDirectory(projRoot + "\\2-Production", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\A-Translation", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\A-Translation\\1-From_Translation", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\A-Translation\\2-From_Editing", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\B-Formatting", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\B-Formatting\\1-To_Format", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\B-Formatting\\2-From_Format", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\C-Engineering", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\C-Engineering\\1-To_Engineering", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\C-Engineering\\2-Build", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\C-Engineering\\3-From_Engineering", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\D-Mech_QA", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\D-Mech_QA\\1-To_Mech_QA", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\D-Mech_QA\\2-From_Mech_QA", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\E-Ling_QA", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\E-Ling_QA\\1-To_Ling_QA", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\E-Ling_QA\\2-From_Ling_QA", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\F-Incorps", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\F-Incorps\\1-To_Incorps", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\F-Incorps\\2-From_Incorps", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\G-Client_Review", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\G-Client_Review\\1-To_Client", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\G-Client_Review\\2-From_Client", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\G-Client_Review\\3-From_Client_Review_Validation", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\H-Regression", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\H-Regression\\1-From_Regression", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\2-Production\\I-Final", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\2-Production\\I-Final\\1-Obsolete", ITARFlag, itarRule);

                    buildDirectory(projRoot + "\\3-Deliveries", ITARFlag, itarRule);
                    buildDirectory(projRoot + "\\4-MyMedialocate", ITARFlag, itarRule);
                }
                else
                {
                    debugLine = DateTime.Now + " Warning: the directory " + rootDir + " does not exists or is inaccessible."; WriteDebugfile(debugLine);
                }
                MiscTools.undoImpersonation(impersonationContext);
            }
            else
            {
                //Your impersonation failed. Therefore, include a fail-safe mechanism here.
            }
        }
Пример #23
0
        private void SerializeConnectionInfo(ConnectionInfo connectionInfo)
        {
            _currentNodeIndex++;
            var dataRow = _dataTable.NewRow();

            dataRow["ID"]         = DBNull.Value;
            dataRow["Name"]       = connectionInfo.Name;
            dataRow["Type"]       = connectionInfo.GetTreeNodeType().ToString();
            dataRow["ConstantID"] = connectionInfo.ConstantID;
            dataRow["ParentID"]   = connectionInfo.Parent?.ConstantID ?? "";
            dataRow["PositionID"] = _currentNodeIndex;
            dataRow["LastChange"] = MiscTools.DBTimeStampNow();
            dataRow["Expanded"]   =
                false; // TODO: this column can eventually be removed. we now save this property locally
            dataRow["Description"] = connectionInfo.Description;
            dataRow["Icon"]        = connectionInfo.Icon;
            dataRow["Panel"]       = connectionInfo.Panel;
            dataRow["Username"]    = _saveFilter.SaveUsername ? connectionInfo.Username : "";
            dataRow["DomainName"]  = _saveFilter.SaveDomain ? connectionInfo.Domain : "";
            dataRow["Password"]    = _saveFilter.SavePassword
                ? _cryptographyProvider.Encrypt(connectionInfo.Password, _encryptionKey)
                : "";
            dataRow["Hostname"]                 = connectionInfo.Hostname;
            dataRow["Protocol"]                 = connectionInfo.Protocol;
            dataRow["PuttySession"]             = connectionInfo.PuttySession;
            dataRow["Port"]                     = connectionInfo.Port;
            dataRow["ConnectToConsole"]         = connectionInfo.UseConsoleSession;
            dataRow["UseCredSsp"]               = connectionInfo.UseCredSsp;
            dataRow["RenderingEngine"]          = connectionInfo.RenderingEngine;
            dataRow["ICAEncryptionStrength"]    = connectionInfo.ICAEncryptionStrength;
            dataRow["RDPAuthenticationLevel"]   = connectionInfo.RDPAuthenticationLevel;
            dataRow["RDPMinutesToIdleTimeout"]  = connectionInfo.RDPMinutesToIdleTimeout;
            dataRow["RDPAlertIdleTimeout"]      = connectionInfo.RDPAlertIdleTimeout;
            dataRow["LoadBalanceInfo"]          = connectionInfo.LoadBalanceInfo;
            dataRow["Colors"]                   = connectionInfo.Colors;
            dataRow["Resolution"]               = connectionInfo.Resolution;
            dataRow["AutomaticResize"]          = connectionInfo.AutomaticResize;
            dataRow["DisplayWallpaper"]         = connectionInfo.DisplayWallpaper;
            dataRow["DisplayThemes"]            = connectionInfo.DisplayThemes;
            dataRow["EnableFontSmoothing"]      = connectionInfo.EnableFontSmoothing;
            dataRow["EnableDesktopComposition"] = connectionInfo.EnableDesktopComposition;
            dataRow["CacheBitmaps"]             = connectionInfo.CacheBitmaps;
            dataRow["RedirectDiskDrives"]       = connectionInfo.RedirectDiskDrives;
            dataRow["RedirectPorts"]            = connectionInfo.RedirectPorts;
            dataRow["RedirectPrinters"]         = connectionInfo.RedirectPrinters;
            dataRow["RedirectClipboard"]        = connectionInfo.RedirectClipboard;
            dataRow["RedirectSmartCards"]       = connectionInfo.RedirectSmartCards;
            dataRow["RedirectSound"]            = connectionInfo.RedirectSound;
            dataRow["SoundQuality"]             = connectionInfo.SoundQuality;
            dataRow["RedirectAudioCapture"]     = connectionInfo.RedirectAudioCapture;
            dataRow["RedirectKeys"]             = connectionInfo.RedirectKeys;
            dataRow["Connected"]                =
                false; // TODO: this column can eventually be removed. we now save this property locally
            dataRow["PreExtApp"]        = connectionInfo.PreExtApp;
            dataRow["PostExtApp"]       = connectionInfo.PostExtApp;
            dataRow["MacAddress"]       = connectionInfo.MacAddress;
            dataRow["UserField"]        = connectionInfo.UserField;
            dataRow["ExtApp"]           = connectionInfo.ExtApp;
            dataRow["VNCCompression"]   = connectionInfo.VNCCompression;
            dataRow["VNCEncoding"]      = connectionInfo.VNCEncoding;
            dataRow["VNCAuthMode"]      = connectionInfo.VNCAuthMode;
            dataRow["VNCProxyType"]     = connectionInfo.VNCProxyType;
            dataRow["VNCProxyIP"]       = connectionInfo.VNCProxyIP;
            dataRow["VNCProxyPort"]     = connectionInfo.VNCProxyPort;
            dataRow["VNCProxyUsername"] = connectionInfo.VNCProxyUsername;
            dataRow["VNCProxyPassword"] =
                _cryptographyProvider.Encrypt(connectionInfo.VNCProxyPassword, _encryptionKey);
            dataRow["VNCColors"]            = connectionInfo.VNCColors;
            dataRow["VNCSmartSizeMode"]     = connectionInfo.VNCSmartSizeMode;
            dataRow["VNCViewOnly"]          = connectionInfo.VNCViewOnly;
            dataRow["RDGatewayUsageMethod"] = connectionInfo.RDGatewayUsageMethod;
            dataRow["RDGatewayHostname"]    = connectionInfo.RDGatewayHostname;
            dataRow["RDGatewayUseConnectionCredentials"] = connectionInfo.RDGatewayUseConnectionCredentials;
            dataRow["RDGatewayUsername"] = connectionInfo.RDGatewayUsername;
            dataRow["RDGatewayPassword"] = _cryptographyProvider.Encrypt(connectionInfo.RDGatewayPassword, _encryptionKey);
            dataRow["RDGatewayDomain"]   = connectionInfo.RDGatewayDomain;
            if (_saveFilter.SaveInheritance)
            {
                dataRow["InheritCacheBitmaps"]             = connectionInfo.Inheritance.CacheBitmaps;
                dataRow["InheritColors"]                   = connectionInfo.Inheritance.Colors;
                dataRow["InheritDescription"]              = connectionInfo.Inheritance.Description;
                dataRow["InheritDisplayThemes"]            = connectionInfo.Inheritance.DisplayThemes;
                dataRow["InheritDisplayWallpaper"]         = connectionInfo.Inheritance.DisplayWallpaper;
                dataRow["InheritEnableFontSmoothing"]      = connectionInfo.Inheritance.EnableFontSmoothing;
                dataRow["InheritEnableDesktopComposition"] = connectionInfo.Inheritance.EnableDesktopComposition;
                dataRow["InheritDomain"]                   = connectionInfo.Inheritance.Domain;
                dataRow["InheritIcon"]                              = connectionInfo.Inheritance.Icon;
                dataRow["InheritPanel"]                             = connectionInfo.Inheritance.Panel;
                dataRow["InheritPassword"]                          = connectionInfo.Inheritance.Password;
                dataRow["InheritPort"]                              = connectionInfo.Inheritance.Port;
                dataRow["InheritProtocol"]                          = connectionInfo.Inheritance.Protocol;
                dataRow["InheritPuttySession"]                      = connectionInfo.Inheritance.PuttySession;
                dataRow["InheritRedirectDiskDrives"]                = connectionInfo.Inheritance.RedirectDiskDrives;
                dataRow["InheritRedirectKeys"]                      = connectionInfo.Inheritance.RedirectKeys;
                dataRow["InheritRedirectPorts"]                     = connectionInfo.Inheritance.RedirectPorts;
                dataRow["InheritRedirectPrinters"]                  = connectionInfo.Inheritance.RedirectPrinters;
                dataRow["InheritRedirectClipboard"]                 = connectionInfo.Inheritance.RedirectClipboard;
                dataRow["InheritRedirectSmartCards"]                = connectionInfo.Inheritance.RedirectSmartCards;
                dataRow["InheritRedirectSound"]                     = connectionInfo.Inheritance.RedirectSound;
                dataRow["InheritSoundQuality"]                      = connectionInfo.Inheritance.SoundQuality;
                dataRow["InheritRedirectAudioCapture"]              = connectionInfo.Inheritance.RedirectAudioCapture;
                dataRow["InheritResolution"]                        = connectionInfo.Inheritance.Resolution;
                dataRow["InheritAutomaticResize"]                   = connectionInfo.Inheritance.AutomaticResize;
                dataRow["InheritUseConsoleSession"]                 = connectionInfo.Inheritance.UseConsoleSession;
                dataRow["InheritUseCredSsp"]                        = connectionInfo.Inheritance.UseCredSsp;
                dataRow["InheritRenderingEngine"]                   = connectionInfo.Inheritance.RenderingEngine;
                dataRow["InheritUsername"]                          = connectionInfo.Inheritance.Username;
                dataRow["InheritICAEncryptionStrength"]             = connectionInfo.Inheritance.ICAEncryptionStrength;
                dataRow["InheritRDPAuthenticationLevel"]            = connectionInfo.Inheritance.RDPAuthenticationLevel;
                dataRow["InheritRDPMinutesToIdleTimeout"]           = connectionInfo.Inheritance.RDPMinutesToIdleTimeout;
                dataRow["InheritRDPAlertIdleTimeout"]               = connectionInfo.Inheritance.RDPAlertIdleTimeout;
                dataRow["InheritLoadBalanceInfo"]                   = connectionInfo.Inheritance.LoadBalanceInfo;
                dataRow["InheritPreExtApp"]                         = connectionInfo.Inheritance.PreExtApp;
                dataRow["InheritPostExtApp"]                        = connectionInfo.Inheritance.PostExtApp;
                dataRow["InheritMacAddress"]                        = connectionInfo.Inheritance.MacAddress;
                dataRow["InheritUserField"]                         = connectionInfo.Inheritance.UserField;
                dataRow["InheritExtApp"]                            = connectionInfo.Inheritance.ExtApp;
                dataRow["InheritVNCCompression"]                    = connectionInfo.Inheritance.VNCCompression;
                dataRow["InheritVNCEncoding"]                       = connectionInfo.Inheritance.VNCEncoding;
                dataRow["InheritVNCAuthMode"]                       = connectionInfo.Inheritance.VNCAuthMode;
                dataRow["InheritVNCProxyType"]                      = connectionInfo.Inheritance.VNCProxyType;
                dataRow["InheritVNCProxyIP"]                        = connectionInfo.Inheritance.VNCProxyIP;
                dataRow["InheritVNCProxyPort"]                      = connectionInfo.Inheritance.VNCProxyPort;
                dataRow["InheritVNCProxyUsername"]                  = connectionInfo.Inheritance.VNCProxyUsername;
                dataRow["InheritVNCProxyPassword"]                  = connectionInfo.Inheritance.VNCProxyPassword;
                dataRow["InheritVNCColors"]                         = connectionInfo.Inheritance.VNCColors;
                dataRow["InheritVNCSmartSizeMode"]                  = connectionInfo.Inheritance.VNCSmartSizeMode;
                dataRow["InheritVNCViewOnly"]                       = connectionInfo.Inheritance.VNCViewOnly;
                dataRow["InheritRDGatewayUsageMethod"]              = connectionInfo.Inheritance.RDGatewayUsageMethod;
                dataRow["InheritRDGatewayHostname"]                 = connectionInfo.Inheritance.RDGatewayHostname;
                dataRow["InheritRDGatewayUseConnectionCredentials"] =
                    connectionInfo.Inheritance.RDGatewayUseConnectionCredentials;
                dataRow["InheritRDGatewayUsername"] = connectionInfo.Inheritance.RDGatewayUsername;
                dataRow["InheritRDGatewayPassword"] = connectionInfo.Inheritance.RDGatewayPassword;
                dataRow["InheritRDGatewayDomain"]   = connectionInfo.Inheritance.RDGatewayDomain;
            }
            else
            {
                dataRow["InheritCacheBitmaps"]             = false;
                dataRow["InheritColors"]                   = false;
                dataRow["InheritDescription"]              = false;
                dataRow["InheritDisplayThemes"]            = false;
                dataRow["InheritDisplayWallpaper"]         = false;
                dataRow["InheritEnableFontSmoothing"]      = false;
                dataRow["InheritEnableDesktopComposition"] = false;
                dataRow["InheritDomain"]                   = false;
                dataRow["InheritIcon"]                              = false;
                dataRow["InheritPanel"]                             = false;
                dataRow["InheritPassword"]                          = false;
                dataRow["InheritPort"]                              = false;
                dataRow["InheritProtocol"]                          = false;
                dataRow["InheritPuttySession"]                      = false;
                dataRow["InheritRedirectDiskDrives"]                = false;
                dataRow["InheritRedirectKeys"]                      = false;
                dataRow["InheritRedirectPorts"]                     = false;
                dataRow["InheritRedirectPrinters"]                  = false;
                dataRow["InheritRedirectClipboard"]                 = false;
                dataRow["InheritRedirectSmartCards"]                = false;
                dataRow["InheritRedirectSound"]                     = false;
                dataRow["InheritSoundQuality"]                      = false;
                dataRow["InheritRedirectAudioCapture"]              = false;
                dataRow["InheritResolution"]                        = false;
                dataRow["InheritAutomaticResize"]                   = false;
                dataRow["InheritUseConsoleSession"]                 = false;
                dataRow["InheritUseCredSsp"]                        = false;
                dataRow["InheritRenderingEngine"]                   = false;
                dataRow["InheritUsername"]                          = false;
                dataRow["InheritICAEncryptionStrength"]             = false;
                dataRow["InheritRDPAuthenticationLevel"]            = false;
                dataRow["InheritRDPMinutesToIdleTimeout"]           = false;
                dataRow["InheritRDPAlertIdleTimeout"]               = false;
                dataRow["InheritLoadBalanceInfo"]                   = false;
                dataRow["InheritPreExtApp"]                         = false;
                dataRow["InheritPostExtApp"]                        = false;
                dataRow["InheritMacAddress"]                        = false;
                dataRow["InheritUserField"]                         = false;
                dataRow["InheritExtApp"]                            = false;
                dataRow["InheritVNCCompression"]                    = false;
                dataRow["InheritVNCEncoding"]                       = false;
                dataRow["InheritVNCAuthMode"]                       = false;
                dataRow["InheritVNCProxyType"]                      = false;
                dataRow["InheritVNCProxyIP"]                        = false;
                dataRow["InheritVNCProxyPort"]                      = false;
                dataRow["InheritVNCProxyUsername"]                  = false;
                dataRow["InheritVNCProxyPassword"]                  = false;
                dataRow["InheritVNCColors"]                         = false;
                dataRow["InheritVNCSmartSizeMode"]                  = false;
                dataRow["InheritVNCViewOnly"]                       = false;
                dataRow["InheritRDGatewayUsageMethod"]              = false;
                dataRow["InheritRDGatewayHostname"]                 = false;
                dataRow["InheritRDGatewayUseConnectionCredentials"] = false;
                dataRow["InheritRDGatewayUsername"]                 = false;
                dataRow["InheritRDGatewayPassword"]                 = false;
                dataRow["InheritRDGatewayDomain"]                   = false;
            }

            _dataTable.Rows.Add(dataRow);
        }
Пример #24
0
        public static void LoadConnections(bool withDialog = false, bool update = false)
        {
            var connectionsLoader = new ConnectionsLoader();

            try
            {
                // disable sql update checking while we are loading updates
                RemoteConnectionsSyncronizer?.Disable();

                if (!Settings.Default.UseSQLServer)
                {
                    if (withDialog)
                    {
                        var loadDialog = Controls.ConnectionsLoadDialog();
                        if (loadDialog.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        connectionsLoader.ConnectionFileName = loadDialog.FileName;
                    }
                    else
                    {
                        connectionsLoader.ConnectionFileName = GetStartupConnectionFileName();
                    }

                    CreateBackupFile(Convert.ToString(connectionsLoader.ConnectionFileName));
                }

                connectionsLoader.UseDatabase        = Settings.Default.UseSQLServer;
                ConnectionTreeModel                  = connectionsLoader.LoadConnections(false);
                Windows.TreeForm.ConnectionTreeModel = ConnectionTreeModel;

                if (Settings.Default.UseSQLServer)
                {
                    LastSqlUpdate = DateTime.Now;
                }
                else
                {
                    if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName())
                    {
                        Settings.Default.LoadConsFromCustomLocation = false;
                    }
                    else
                    {
                        Settings.Default.LoadConsFromCustomLocation = true;
                        Settings.Default.CustomConsPath             = connectionsLoader.ConnectionFileName;
                    }
                }

                // re-enable sql update checking after updates are loaded
                RemoteConnectionsSyncronizer?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:
                        LoadConnections(withDialog, update);
                        return;

                    case 1:
                        Settings.Default.UseSQLServer = false;
                        LoadConnections(true, update);
                        return;

                    default:
                        Application.Exit();
                        return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg);
                    NewConnections(Convert.ToString(connectionsLoader.ConnectionFileName));
                    return;
                }

                MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex);
                if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog, update);
                }
                else
                {
                    MessageBox.Show(frmMain.Default,
                                    string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                                    @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }
Пример #25
0
 private void CreateSchema(DataTable dataTable)
 {
     // Note: these columns must be defined in the same order that they exist in the DB
     dataTable.Columns.Add("ID", typeof(int));
     dataTable.Columns[0].AutoIncrement = true;
     dataTable.Columns.Add("ConstantID", typeof(string));
     dataTable.Columns.Add("PositionID", typeof(int));
     dataTable.Columns.Add("ParentID", typeof(string));
     dataTable.Columns.Add("LastChange", MiscTools.DBTimeStampType());
     dataTable.Columns.Add("Name", typeof(string));
     dataTable.Columns.Add("Type", typeof(string));
     dataTable.Columns.Add("Expanded", typeof(bool));
     dataTable.Columns.Add("Description", typeof(string));
     dataTable.Columns.Add("Icon", typeof(string));
     dataTable.Columns.Add("Panel", typeof(string));
     dataTable.Columns.Add("Username", typeof(string));
     dataTable.Columns.Add("DomainName", typeof(string));
     dataTable.Columns.Add("Password", typeof(string));
     dataTable.Columns.Add("Hostname", typeof(string));
     dataTable.Columns.Add("Protocol", typeof(string));
     dataTable.Columns.Add("PuttySession", typeof(string));
     dataTable.Columns.Add("Port", typeof(int));
     dataTable.Columns.Add("ConnectToConsole", typeof(bool));
     dataTable.Columns.Add("UseCredSsp", typeof(bool));
     dataTable.Columns.Add("RenderingEngine", typeof(string));
     dataTable.Columns.Add("ICAEncryptionStrength", typeof(string));
     dataTable.Columns.Add("RDPAuthenticationLevel", typeof(string));
     dataTable.Columns.Add("Colors", typeof(string));
     dataTable.Columns.Add("Resolution", typeof(string));
     dataTable.Columns.Add("DisplayWallpaper", typeof(bool));
     dataTable.Columns.Add("DisplayThemes", typeof(bool));
     dataTable.Columns.Add("EnableFontSmoothing", typeof(bool));
     dataTable.Columns.Add("EnableDesktopComposition", typeof(bool));
     dataTable.Columns.Add("CacheBitmaps", typeof(bool));
     dataTable.Columns.Add("RedirectDiskDrives", typeof(bool));
     dataTable.Columns.Add("RedirectPorts", typeof(bool));
     dataTable.Columns.Add("RedirectPrinters", typeof(bool));
     dataTable.Columns.Add("RedirectClipboard", typeof(bool));
     dataTable.Columns.Add("RedirectSmartCards", typeof(bool));
     dataTable.Columns.Add("RedirectSound", typeof(string));
     dataTable.Columns.Add("RedirectAudioCapture", typeof(bool));
     dataTable.Columns.Add("RedirectKeys", typeof(bool));
     dataTable.Columns.Add("Connected", typeof(bool));
     dataTable.Columns.Add("PreExtApp", typeof(string));
     dataTable.Columns.Add("PostExtApp", typeof(string));
     dataTable.Columns.Add("MacAddress", typeof(string));
     dataTable.Columns.Add("UserField", typeof(string));
     dataTable.Columns.Add("ExtApp", typeof(string));
     dataTable.Columns.Add("VNCCompression", typeof(string));
     dataTable.Columns.Add("VNCEncoding", typeof(string));
     dataTable.Columns.Add("VNCAuthMode", typeof(string));
     dataTable.Columns.Add("VNCProxyType", typeof(string));
     dataTable.Columns.Add("VNCProxyIP", typeof(string));
     dataTable.Columns.Add("VNCProxyPort", typeof(int));
     dataTable.Columns.Add("VNCProxyUsername", typeof(string));
     dataTable.Columns.Add("VNCProxyPassword", typeof(string));
     dataTable.Columns.Add("VNCColors", typeof(string));
     dataTable.Columns.Add("VNCSmartSizeMode", typeof(string));
     dataTable.Columns.Add("VNCViewOnly", typeof(bool));
     dataTable.Columns.Add("RDGatewayUsageMethod", typeof(string));
     dataTable.Columns.Add("RDGatewayHostname", typeof(string));
     dataTable.Columns.Add("RDGatewayUseConnectionCredentials", typeof(string));
     dataTable.Columns.Add("RDGatewayUsername", typeof(string));
     dataTable.Columns.Add("RDGatewayPassword", typeof(string));
     dataTable.Columns.Add("RDGatewayDomain", typeof(string));
     dataTable.Columns.Add("InheritCacheBitmaps", typeof(bool));
     dataTable.Columns.Add("InheritColors", typeof(bool));
     dataTable.Columns.Add("InheritDescription", typeof(bool));
     dataTable.Columns.Add("InheritDisplayThemes", typeof(bool));
     dataTable.Columns.Add("InheritDisplayWallpaper", typeof(bool));
     dataTable.Columns.Add("InheritEnableFontSmoothing", typeof(bool));
     dataTable.Columns.Add("InheritEnableDesktopComposition", typeof(bool));
     dataTable.Columns.Add("InheritDomain", typeof(bool));
     dataTable.Columns.Add("InheritIcon", typeof(bool));
     dataTable.Columns.Add("InheritPanel", typeof(bool));
     dataTable.Columns.Add("InheritPassword", typeof(bool));
     dataTable.Columns.Add("InheritPort", typeof(bool));
     dataTable.Columns.Add("InheritProtocol", typeof(bool));
     dataTable.Columns.Add("InheritPuttySession", typeof(bool));
     dataTable.Columns.Add("InheritRedirectDiskDrives", typeof(bool));
     dataTable.Columns.Add("InheritRedirectKeys", typeof(bool));
     dataTable.Columns.Add("InheritRedirectPorts", typeof(bool));
     dataTable.Columns.Add("InheritRedirectPrinters", typeof(bool));
     dataTable.Columns.Add("InheritRedirectClipboard", typeof(bool));
     dataTable.Columns.Add("InheritRedirectSmartCards", typeof(bool));
     dataTable.Columns.Add("InheritRedirectSound", typeof(bool));
     dataTable.Columns.Add("InheritRedirectAudioCapture", typeof(bool));
     dataTable.Columns.Add("InheritResolution", typeof(bool));
     dataTable.Columns.Add("InheritUseConsoleSession", typeof(bool));
     dataTable.Columns.Add("InheritUseCredSsp", typeof(bool));
     dataTable.Columns.Add("InheritRenderingEngine", typeof(bool));
     dataTable.Columns.Add("InheritICAEncryptionStrength", typeof(bool));
     dataTable.Columns.Add("InheritRDPAuthenticationLevel", typeof(bool));
     dataTable.Columns.Add("InheritUsername", typeof(bool));
     dataTable.Columns.Add("InheritPreExtApp", typeof(bool));
     dataTable.Columns.Add("InheritPostExtApp", typeof(bool));
     dataTable.Columns.Add("InheritMacAddress", typeof(bool));
     dataTable.Columns.Add("InheritUserField", typeof(bool));
     dataTable.Columns.Add("InheritExtApp", typeof(bool));
     dataTable.Columns.Add("InheritVNCCompression", typeof(bool));
     dataTable.Columns.Add("InheritVNCEncoding", typeof(bool));
     dataTable.Columns.Add("InheritVNCAuthMode", typeof(bool));
     dataTable.Columns.Add("InheritVNCProxyType", typeof(bool));
     dataTable.Columns.Add("InheritVNCProxyIP", typeof(bool));
     dataTable.Columns.Add("InheritVNCProxyPort", typeof(bool));
     dataTable.Columns.Add("InheritVNCProxyUsername", typeof(bool));
     dataTable.Columns.Add("InheritVNCProxyPassword", typeof(bool));
     dataTable.Columns.Add("InheritVNCColors", typeof(bool));
     dataTable.Columns.Add("InheritVNCSmartSizeMode", typeof(bool));
     dataTable.Columns.Add("InheritVNCViewOnly", typeof(bool));
     dataTable.Columns.Add("InheritRDGatewayUsageMethod", typeof(bool));
     dataTable.Columns.Add("InheritRDGatewayHostname", typeof(bool));
     dataTable.Columns.Add("InheritRDGatewayUseConnectionCredentials", typeof(bool));
     dataTable.Columns.Add("InheritRDGatewayUsername", typeof(bool));
     dataTable.Columns.Add("InheritRDGatewayPassword", typeof(bool));
     dataTable.Columns.Add("InheritRDGatewayDomain", typeof(bool));
     dataTable.Columns.Add("LoadBalanceInfo", typeof(string));
     dataTable.Columns.Add("AutomaticResize", typeof(bool));
     dataTable.Columns.Add("InheritLoadBalanceInfo", typeof(bool));
     dataTable.Columns.Add("InheritAutomaticResize", typeof(bool));
     dataTable.Columns.Add("RDPMinutesToIdleTimeout", typeof(int));
     dataTable.Columns.Add("RDPAlertIdleTimeout", typeof(bool));
     dataTable.Columns.Add("SoundQuality", typeof(string));
     dataTable.Columns.Add("InheritRDPMinutesToIdleTimeout", typeof(bool));
     dataTable.Columns.Add("InheritRDPAlertIdleTimeout", typeof(bool));
     dataTable.Columns.Add("InheritSoundQuality", typeof(bool));
 }