コード例 #1
0
ファイル: VaultManagement.cs プロジェクト: weijx-xa/test
 public void ServerAppDisconnect()
 {
     if (ServerAppConnected())
     {
         _serverApp.Disconnect();
     }
 }
コード例 #2
0
        public bool ConnectToServer(string userName, string password, VaultServer server, bool windowsUser)
        {
            var app = new MFilesServerApplication();

            try
            {
                var authType = MFAuthType.MFAuthTypeSpecificMFilesUser;
                if (windowsUser)
                {
                    authType = MFAuthType.MFAuthTypeSpecificWindowsUser;
                }
                var status = app.Connect(authType, userName, password, "", "ncacn_ip_tcp",
                                         server.LocalIp, server.ServerPort);
                var ok = status == MFServerConnection.MFServerConnectionAuthenticated;
                try
                {
                    app.Disconnect();
                }
                catch
                {
                }
                return(ok);
            }
            catch (Exception ex)
            {
                Log.Error("登录服务器失败:" + ex.Message, ex);
            }
            return(false);
        }
コード例 #3
0
 private void btn_ResetForm_Click(object sender, EventArgs e)
 {
     txt_VaultUsers.Clear();
     this.Controls.Clear();
     this.InitializeComponent();
     app.Disconnect();
     EnableLoginButtons(false);
     EnableTopButtons(false);
     EnableButtons(false);
 }
コード例 #4
0
 /// <summary>
 /// Clears the components data and logs out of the M-Files server.
 /// </summary>
 public void UnloadComponent()
 {
     //TODO!!
     if (sessionID != null)
     {
         var msg = vault.DetachSession();
         Console.WriteLine("Detaching session from vault: " + msg);
         mfserver.Disconnect();
         vault    = null;
         mfserver = null;
     }
     else
     {
         sessionID = Encoding.Unicode.GetBytes(vault.LoginSessionID);
         vault.LogOutSilent();
         mfserver.Disconnect();
         vault    = null;
         mfserver = null;
     }
     currentFolderContent = null;
 }
コード例 #5
0
ファイル: MFWorkHourService.cs プロジェクト: weijx-xa/test
 private void LogOut()
 {
     if (_serverApp != null)
     {
         try
         {
             _serverApp.Disconnect();
         }
         catch
         {
         }
     }
 }
コード例 #6
0
 private void buttonenableusers_Click(object sender, EventArgs e)
 {
     try
     {
         var app = new MFilesServerApplication();
         app.Connect(MFAuthType.MFAuthTypeSpecificMFilesUser, textBoxuser.Text, textBoxpass.Text, "",
                     "ncacn_ip_tcp",
                     textBoxmfserver.Text);
         var accs = app.LoginAccountOperations.GetLoginAccounts();
         foreach (LoginAccount acc in accs)
         {
             acc.Enabled = true;
             app.LoginAccountOperations.ModifyLoginAccount(acc);
             richTextBox1.AppendText(Environment.NewLine + string.Format("{0},{1},{2} enabled", acc.FullName, acc.UserName, acc.AccountName));
         }
         app.Disconnect();
     }
     catch (Exception ex)
     {
         richTextBox1.AppendText(Environment.NewLine + ex.Message);
     }
 }
コード例 #7
0
        /// <summary>
        /// Executes a search by display/external id using the API directly.
        /// </summary>
        static void UseApiDirectly()
        {
            // Connect to the server (localhost, tcp, current Windows user).
            var application = new MFilesServerApplication();

            application.ConnectAdministrative();

            // Get a connection to the vault.
            var vault = application.LogInToVault(Program.sampleVaultGuid.ToString("B"));

            // Create the basic search conditions collection.
            var searchConditions = new SearchConditions();

            // Create the search condition.
            SearchCondition condition = new SearchCondition
            {
                ConditionType = MFConditionType.MFConditionTypeEqual,
            };

            condition.Expression.DataStatusValueType = MFStatusType.MFStatusTypeExtID;
            condition.TypedValue.SetValue(MFDataType.MFDatatypeText, Program.customerDisplayId);

            // Add the condition to the collection.
            searchConditions.Add(-1, condition);

            // Search.
            var results = vault.ObjectSearchOperations.SearchForObjectsByConditions(searchConditions,
                                                                                    MFSearchFlags.MFSearchFlagNone, SortResults: false);

            // Output the number of items matching (should be one in each object type, at a maximum).
            Console.WriteLine($"There were {results.Count} objects with the display Id of {Program.customerDisplayId}:");

            Console.WriteLine($"Complete.");

            // Disconnect.
            vault.LogOutSilent();
            application.Disconnect();
        }
コード例 #8
0
        /// <summary>
        /// Executes a segmented search using the API directly.
        /// </summary>
        static void UseApiDirectly()
        {
            // Connect to the server (localhost, tcp, current Windows user).
            var application = new MFilesServerApplication();

            application.ConnectAdministrative();

            // Get a connection to the vault.
            var vault = application.LogInToVault(Program.sampleVaultGuid.ToString("B"));

            // Load the object types from the vault.
            Console.WriteLine("Loading object types...");
            var objectTypes = vault
                              .ObjectTypeOperations
                              .GetObjectTypes()
                              .Cast <ObjType>()
                              .ToList();

            Console.WriteLine($"Iterating over {objectTypes.Count} object types...");

            // Iterate over the object types to count the objects.
            foreach (var objectType in objectTypes)
            {
                // Create the basic search conditions collection.
                var searchConditions = new SearchConditions();

                // Add a condition for the object type we're interested in.
                {
                    // Create the search condition (for object type id).
                    SearchCondition condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeEqual
                    };
                    condition.Expression.SetStatusValueExpression(MFStatusType.MFStatusTypeObjectTypeID, null);
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeLookup, objectType.ID);

                    // Add the condition at the index provided.
                    searchConditions.Add(-1, condition);
                }

                // Create variables for the segment information.
                const int itemsPerSegment       = 1000; // Maximum number of items in each segment.
                var       segment               = 0;    // Start; this will increment as we go.
                var       moreItems             = true; // Whether there are more items to load.
                var       countIncludingDeleted = 0;    // The count of matching items.

                // Whilst there are items in the results, we need to loop.
                while (moreItems)
                {
                    // Execute a search within the object id segment.
                    {
                        // Clone the search conditions (so we can add current-segment condition).
                        var internalSearchConditions = searchConditions.Clone();

                        // Add search condition:
                        //   Id within the range: (segment - itemsPerSegment) to ((segment + 1) * itemsPerSegment)
                        {
                            // Create the search condition.
                            SearchCondition condition = new SearchCondition
                            {
                                ConditionType = MFConditionType.MFConditionTypeEqual
                            };
                            condition.Expression.SetObjectIDSegmentExpression(itemsPerSegment);
                            condition.TypedValue.SetValue(MFDataType.MFDatatypeInteger, segment);

                            // Add the condition at the index provided.
                            internalSearchConditions.Add(-1, condition);
                        }

                        // Execute the search and increment the count.
                        countIncludingDeleted += vault.ObjectSearchOperations
                                                 .SearchForObjectsByConditionsEx(internalSearchConditions, MFSearchFlags.MFSearchFlagDisableRelevancyRanking,
                                                                                 SortResults: false, MaxResultCount: 0,
                                                                                 SearchTimeoutInSeconds: 0).Count;

                        // Move to the next segment.
                        segment++;
                    }

                    // Are there any more items?
                    {
                        // Clone the search conditions (so we can add object id condition).
                        var internalSearchConditions = searchConditions.Clone();

                        // Add search condition:
                        //   Id at least (segment * itemsPerSegment)
                        {
                            // Create the search condition.
                            SearchCondition condition = new SearchCondition
                            {
                                ConditionType = MFConditionType.MFConditionTypeGreaterThanOrEqual
                            };
                            condition.Expression.SetStatusValueExpression(MFStatusType.MFStatusTypeObjectID, null);
                            condition.TypedValue.SetValue(MFDataType.MFDatatypeInteger, segment * itemsPerSegment);

                            // Add the condition at the index provided.
                            internalSearchConditions.Add(-1, condition);
                        }

                        // If we get one item then there's more results.
                        moreItems = 1 == vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(
                            internalSearchConditions,                      // Our search conditions.
                            MFSearchFlags.MFSearchFlagDisableRelevancyRanking,
                            SortResults: false,                            // Don't bother attempting to sort them.
                            MaxResultCount: 1,                             // We only need to know if there is at least one, nothing more.
                            SearchTimeoutInSeconds: 0).Count;
                    }
                }

                // Output the stats.
                Console.WriteLine($"\t{objectType.NamePlural}:");
                Console.WriteLine($"\t\tTotal: {countIncludingDeleted} (included deleted)");
            }

            Console.WriteLine($"Complete.");

            // Disconnect.
            vault.LogOutSilent();
            application.Disconnect();
        }