コード例 #1
0
ファイル: FBClient.cs プロジェクト: nibbler13/Inventory
        public bool ExecuteUpdateQuery(string query, Dictionary <string, object> parameters)
        {
            bool updated = false;

            if (!IsConnectionOpened())
            {
                return(updated);
            }

            try {
                FbCommand update = new FbCommand(query, connection);

                if (parameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parameter in parameters)
                    {
                        update.Parameters.AddWithValue(parameter.Key, parameter.Value);
                    }
                }

                updated = update.ExecuteNonQuery() > 0 ? true : false;
            } catch (Exception e) {
                LoggingSystem.LogMessageToFile("ExecuteUpdateQuery exception: " + query +
                                               Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace);
                connection.Close();
            }

            return(updated);
        }
コード例 #2
0
ファイル: FBClient.cs プロジェクト: nibbler13/Inventory
        public DataTable GetDataTable(string query, Dictionary <string, object> parameters)
        {
            DataTable dataTable = new DataTable();

            if (!IsConnectionOpened())
            {
                return(dataTable);
            }

            try {
                FbCommand command = new FbCommand(query, connection);

                if (parameters.Count > 0)
                {
                    foreach (KeyValuePair <string, object> parameter in parameters)
                    {
                        command.Parameters.AddWithValue(parameter.Key, parameter.Value);
                    }
                }

                FbDataAdapter fbDataAdapter = new FbDataAdapter(command);
                fbDataAdapter.Fill(dataTable);
            } catch (Exception e) {
                LoggingSystem.LogMessageToFile("GetDataTable exception: " + query +
                                               Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace);
                connection.Close();
            }

            return(dataTable);
        }
コード例 #3
0
ファイル: EventChecker.cs プロジェクト: nibbler13/Inventory
        public EventChecker()
        {
            string misDbAddress  = ConfigurationManager.AppSettings["MisDbAddress"];
            string misDbName     = ConfigurationManager.AppSettings["MisDbName"];
            string misDbUser     = ConfigurationManager.AppSettings["MisDbUser"];
            string misDbPassword = ConfigurationManager.AppSettings["MisDbPassword"];

            misSqlQueryLastId     = ConfigurationManager.AppSettings["MisDbSqlQueryLastId"];
            misSqlQueryNewRecords = ConfigurationManager.AppSettings["MisDbSqlQueryNewRecords"];

            fbClient = new FBClient(
                misDbAddress,
                misDbName,
                misDbUser,
                misDbPassword);

            UpdateLastIdValue();
            LoggingSystem.LogMessageToFile("lastId: " + lastId);

            string base1CAddress  = ConfigurationManager.AppSettings["Base1CAddress"];
            string base1CBaseName = ConfigurationManager.AppSettings["Base1CBaseName"];
            string base1CUserId   = ConfigurationManager.AppSettings["Base1CUserId"];
            string base1CPassword = ConfigurationManager.AppSettings["Base1CPassword"];

            base1CSqlQueryTechnoMap = ConfigurationManager.AppSettings["Base1CSqlQueryTechnoMap"];

            base1CClient = new Base1CClient(
                base1CAddress,
                base1CBaseName,
                base1CUserId,
                base1CPassword);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: nibbler13/Inventory
        private static void Stop()
        {
            LoggingSystem.LogMessageToFile("------------------Stop------------------");

            if (serviceHost != null)
            {
                serviceHost.Close();
                serviceHost = null;
            }
        }
コード例 #5
0
ファイル: FBClient.cs プロジェクト: nibbler13/Inventory
        private bool IsConnectionOpened()
        {
            if (connection.State != ConnectionState.Open)
            {
                try {
                    connection.Open();
                } catch (Exception e) {
                    LoggingSystem.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
                }
            }

            return(connection.State == ConnectionState.Open);
        }
コード例 #6
0
ファイル: WcfServer.cs プロジェクト: nibbler13/Inventory
        public WcfServer()
        {
            LoggingSystem.LogMessageToFile("WcfServer constructor");

            Task.Run(() => {
                while (true)
                {
                    Thread.Sleep(3000);

                    List <EventDataType> events = eventCheck.GetNewEvents();
                    if (events.Count == 0)
                    {
                        continue;
                    }

                    foreach (EventDataType eventData in events)
                    {
                        LoggingSystem.LogMessageToFile("Notificate to: " + eventData.IpAddress);

                        Task.Run(() => {
                            bool isSended = false;
                            List <string> inactiveClients = new List <string>();

                            foreach (KeyValuePair <string, IWcfServiceCallback> client in clients)
                            {
                                if (!client.Key.Contains(eventData.IpAddress))
                                {
                                    continue;
                                }

                                try {
                                    client.Value.NotificateClient(eventData);
                                    isSended = true;
                                } catch (Exception e) {
                                    LoggingSystem.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
                                    inactiveClients.Add(client.Key);
                                }
                            }

                            LoggingSystem.LogMessageToFile("isSended: " + isSended);

                            foreach (string clientKey in inactiveClients)
                            {
                                clients.Remove(clientKey);
                            }
                        });
                    }
                }
            });
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: nibbler13/Inventory
        private static void Start(string[] args)
        {
            LoggingSystem.LogMessageToFile("------------------Start------------------");

            if (serviceHost != null)
            {
                serviceHost.Close();
            }

            serviceHost = new ServiceHost(typeof(WcfServer));
            try {
                serviceHost.Open();
            } catch (Exception e) {
                LoggingSystem.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
            }
        }
コード例 #8
0
ファイル: FBClient.cs プロジェクト: nibbler13/Inventory
        public FBClient(string ipAddress, string baseName, string user, string pass)
        {
            LoggingSystem.LogMessageToFile("Создание подключения к базе FB: " +
                                           ipAddress + ":" + baseName);

            FbConnectionStringBuilder cs = new FbConnectionStringBuilder {
                DataSource = ipAddress,
                Database   = baseName,
                UserID     = user,
                Password   = pass,
                Charset    = "NONE",
                Pooling    = false
            };

            connection = new FbConnection(cs.ToString());
            IsConnectionOpened();
        }
コード例 #9
0
ファイル: EventChecker.cs プロジェクト: nibbler13/Inventory
        private void UpdateLastIdValue()
        {
            DataTable lastIdTable = fbClient.GetDataTable(misSqlQueryLastId, new Dictionary <string, object>());

            lastId = 0;

            if (lastIdTable.Rows.Count == 0)
            {
                return;
            }

            try {
                lastId = Convert.ToUInt64(lastIdTable.Rows[0][0]);
            } catch (Exception e) {
                LoggingSystem.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
            }
        }
コード例 #10
0
ファイル: WcfServer.cs プロジェクト: nibbler13/Inventory
        public void RegisterClient(string userIdentifier)
        {
            if (string.IsNullOrEmpty(userIdentifier))
            {
                return;
            }

            LoggingSystem.LogMessageToFile("RegisterClient: " + userIdentifier);

            try {
                IWcfServiceCallback callback =
                    OperationContext.Current.GetCallbackChannel <IWcfServiceCallback>();
                lock (locker) {
                    if (clients.Keys.Contains(userIdentifier))
                    {
                        clients.Remove(userIdentifier);
                    }
                    clients.Add(userIdentifier, callback);
                }
            } catch (Exception e) {
                LoggingSystem.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
            }
        }
コード例 #11
0
ファイル: EventChecker.cs プロジェクト: nibbler13/Inventory
        public List <EventDataType> GetNewEvents()
        {
            List <EventDataType> events = new List <EventDataType>();

            DataTable eventTable = fbClient.GetDataTable(misSqlQueryNewRecords, new Dictionary <string, object>()
            {
                { "@id", lastId }
            });

            if (eventTable.Rows.Count == 0)
            {
                //LoggingSystem.LogMessageToFile("GetNewEvents: returned empty table");
                return(events);
            }

            if (eventTable.Rows.Count == 1)
            {
                try {
                    if (eventTable.Rows[0][0].ToString().Equals("-1"))
                    {
                        //LoggingSystem.LogMessageToFile("GetNewEvents: no new events");
                        return(events);
                    }
                } catch (Exception e) {
                    LoggingSystem.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
                }
            }

            Dictionary <string, EventDataType> orders = new Dictionary <string, EventDataType>();

            for (int i = 0; i < eventTable.Rows.Count; i++)
            {
                try {
                    if (i == 0)
                    {
                        lastId = Convert.ToUInt64(eventTable.Rows[i][0]);
                        continue;
                    }

                    string orderNo         = eventTable.Rows[i]["ORDERNO"].ToString();
                    string ipAddress       = eventTable.Rows[i]["IPADDRESS"].ToString();
                    string pid             = eventTable.Rows[i]["PID"].ToString();
                    string schCode         = eventTable.Rows[i]["SCHCODE"].ToString();
                    double schCount        = Convert.ToDouble(eventTable.Rows[i]["SCHCOUNT"]);
                    string schName         = eventTable.Rows[i]["SCHNAME"].ToString();
                    string doctorName      = eventTable.Rows[i]["DOCTORNAME"].ToString();
                    string clientName      = eventTable.Rows[i]["CLIENTNAME"].ToString();
                    string orderCreateDate = eventTable.Rows[i]["OCREATEDATE"].ToString();

                    DataTable serviceTechnoMap = base1CClient.GetDataTable(
                        base1CSqlQueryTechnoMap,
                        new Dictionary <string, object>()
                    {
                        { "@id", schCode }
                    });

                    if (serviceTechnoMap.Rows.Count == 0)
                    {
                        Console.WriteLine("GetTechnoMap: no data for: " + schCode + " | " + schName);
                        //
                        //continue;
                        //
                    }

                    List <EventDataType.Service.Material> materials = new List <EventDataType.Service.Material>();
                    foreach (DataRow row in serviceTechnoMap.Rows)
                    {
                        string idUslugi     = row["IdUslugi"].ToString();
                        string codUslugiV1C = row["CodUslugiV1C"].ToString();
                        string naimenovanie = row["Naimenovanie"].ToString();
                        double kol          = Convert.ToDouble(row["Kol"]);
                        string ed           = row["Ed"].ToString();

                        EventDataType.Service.Material material = new EventDataType.Service.Material()
                        {
                            IdMis = idUslugi,
                            Id1C  = codUslugiV1C,
                            Name  = naimenovanie,
                            Count = kol,
                            Unit  = ed
                        };

                        materials.Add(material);
                    }

                    materials = materials.OrderBy(m => m.Name).ToList();

                    EventDataType.Service service = new EventDataType.Service()
                    {
                        Id        = schCode,
                        Count     = schCount,
                        Name      = schName,
                        Materials = materials
                    };

                    if (orders.ContainsKey(orderNo))
                    {
                        orders[orderNo].Services.Add(service);
                        continue;
                    }

                    EventDataType eventData = new EventDataType()
                    {
                        IpAddress     = ipAddress,
                        MisProcessPid = pid,
                        CreateDate    = orderCreateDate,
                        ClientName    = clientName,
                        DoctorName    = doctorName,
                        OrderId       = orderNo
                    };

                    eventData.Services.Add(service);
                    orders.Add(orderNo, eventData);
                } catch (Exception e) {
                    LoggingSystem.LogMessageToFile(e.Message + Environment.NewLine + e.StackTrace);
                }
            }

            events = orders.Values.ToList();

            return(events);
        }