Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using LFSO100Lib;
using System.Configuration;
using System.Collections.Generic;

namespace LaserficheDataProvider.Lib
{

    public struct LaserficheCredentials
    {
        public string ServerAddress { get; set; }
        public string Repository { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }

        public LaserficheCredentials(string serverAddress, string repository, string username, string password)
        {
            ServerAddress = serverAddress;
            Repository = repository;
            Username = username;
            Password = password;
        }

    };

    public struct LaserficheConnection
    {
        public LFApplication Application { get; set; }
        public LFServer Server { get; set; }
        public LFDatabase Database { get; set; }
        public LFConnection Connection { get; set; }

        public LaserficheConnection(LFApplication application, LFServer server, LFDatabase database, LFConnection connection)
        {
            Application = application;
            Server = server;
            Database = database;
            Connection = connection;
        }
    }

    public sealed class LaserficheDataProvider
    {

        private string _ReferenceNumber { get; set; }
        private LaserficheCredentials _LaserficheCredentials { get; set; }
        private LaserficheConnection _LaserficheConnection { get; set; }
        private List<string> _Errors { get; set; }

        public string ReferenceNumber { get { return _ReferenceNumber; } }
        public LaserficheCredentials LaserficheCredentials { get { return _LaserficheCredentials; } }
        public LaserficheConnection LaserficheConnection { get { return _LaserficheConnection; } }
        public List<string> Errors { get { return _Errors; } }
        public bool HasErrors { get; set; } 

        public LaserficheDataProvider(string referenceNumber)
        {
            HasErrors = false;
            _Errors = new List<string>();
            _ReferenceNumber = referenceNumber;
            Initialize();
        }

        public int GetEntryId()
        {
            int result = -1;
            try
            {
                string[] results = ReferenceNumber.Split(
                    new char[]
                    {
                            '-'
                    }

                );
                string path = ConfigurationManager.AppSettings["LF_ROOT"] + results[0] + "\\" + results[1];
                ILFEntry entry = LaserficheConnection.Database.GetEntryByPath(path);
                result = entry.ID;

            } catch(Exception ex)
            {
                HasErrors = true;
                Errors.Add(ex.Message);
                return -1;
            }
            HasErrors = false;
            return result;            
        }

        public void CloseConnection()
        {
            LaserficheConnection.Connection.Terminate();
        }


        private void Initialize()
        {
            _LaserficheCredentials = new LaserficheCredentials()
            {
                ServerAddress = ConfigurationManager.AppSettings["LF_SERVER"].ToString(),
                Repository = ConfigurationManager.AppSettings["LF_REPO"].ToString(),
                Username = ConfigurationManager.AppSettings["LF_USER"].ToString(),
                Password = ConfigurationManager.AppSettings["LF_PASS"].ToString()
            };

            LFApplication application = null;
            LFServer server = null;
            LFDatabase database = null;
            LFConnection connection = null;


            try
            {
                application = new LFApplication();
                server = application.GetServerByName(LaserficheCredentials.ServerAddress);
                database = server.GetDatabaseByName(LaserficheCredentials.Repository);
                connection = new LFConnection();
                connection.UserName = LaserficheCredentials.Username;
                connection.Password = LaserficheCredentials.Password;
                connection.Create(database);
            }
            catch (Exception ex)
            {
                HasErrors = true;
                _Errors.Add(ex.Message);
                return;
            }

            _LaserficheConnection = new LaserficheConnection()
            {
                Application = application,
                Server = server,
                Database = database,
                Connection = connection
            };
            HasErrors = false;
        }

    }
}

Commits for ChrisCompleteCodeTrunk/LaserficheDataProvider/LaserficheDataProvider.Lib/LaserficheDataProvider.cs

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000