Ejemplo n.º 1
0
        public List <Supplier> GetAllSuppliers()
        {
            var handler = HandlerFactory <Supplier> .GetHandler();

            List <Supplier> result = handler.GetAll();

            return(result);
        }
Ejemplo n.º 2
0
        public Supplier GetSupplier(int Id)
        {
            var handler = HandlerFactory <Supplier> .GetHandler();

            Supplier result = handler.GetById(Id);

            return(result);
        }
Ejemplo n.º 3
0
        public Product GetProduct(int Id)
        {
            var handler = HandlerFactory <Product> .GetHandler();

            Product result = handler.GetById(Id);

            return(result);
        }
Ejemplo n.º 4
0
        public List <Product> GetAllProducts()
        {
            var handler = HandlerFactory <Product> .GetHandler();

            List <Product> result = handler.GetAll();

            return(result);
        }
Ejemplo n.º 5
0
        private async Task DoWork(string message, IModel channel, ulong deliveryTag, GymOrganizerContext db)
        {
            if (string.IsNullOrEmpty(message))
            {
                Nack(channel, deliveryTag);
                return;
            }


            ProcessQueueHistory request = null;

            try
            {
                var queueRequestId = Guid.Parse(message);
                request = await db.ProcessQueuesHistory.Where(x => x.Id == queueRequestId).FirstOrDefaultAsync();


                using (GymOrganizerContext processContext = new GymOrganizerContext(this.settings.Data.Model.ConnectionString))
                {
                    IHandler handler = HandlerFactory.GetHandler(request.Type, this.loggerFactory, processContext, this.settings);

                    if (handler == null)
                    {
                        this.logger.LogError($"Method DoWork: Error processing request: {message}. Request type is not supported.");
                        Nack(channel, deliveryTag);
                    }

                    QueueResult response = await handler.Handle(request.Data);

                    response.TenantId       = request.TenantId;
                    response.UserId         = request.AddedById;
                    response.RequestOueueId = request.Id;


                    await NotifyApi(request, response);

                    Ack(channel, deliveryTag);

                    request.FinishedAt = DateTime.UtcNow;
                    request.Status     = Data.Enums.ResultStatus.Ok;
                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                this.logger.LogError($"Method DoWork: Error processing request: {message}. MEESAGE: {ex.Message}");
                if (request != null)
                {
                    request.Status      = Data.Enums.ResultStatus.Error;
                    request.FinishedAt  = DateTime.UtcNow;
                    request.ErrorMesage = ex.Message;
                    await db.SaveChangesAsync();
                }
                Nack(channel, deliveryTag);
            }
        }
Ejemplo n.º 6
0
        public ActionResult InvokeErrorHandler(string resource, string subResource)
        {
            var context = System.Web.HttpContext.Current;
            var factory = new HandlerFactory();

            var page = factory.GetHandler(context, Request.RequestType, Request.Url.ToString(), Request.PathInfo);

            page.ProcessRequest(context);

            return(null);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            List <string> listArgs = new List <string>(args);

            ValidatorArgument.Validate(listArgs);
            ValidatorEntryCommand.Validate(listArgs[0]);
            listArgs.RemoveAt(0);
            IHandler handler = HandlerFactory.GetHandler(args[0]);

            handler.Handle(listArgs);
        }
Ejemplo n.º 8
0
        public void TestFactory()
        {

            var mhandler = HandlerFactory.GetHandler('M');

            var dhandler = HandlerFactory.GetHandler('L');


            Assert.False(mhandler == null, "mhandler is null");
            Assert.False(dhandler == null, "dhandler is null");



        }
Ejemplo n.º 9
0
        /// <summary>
        /// Writes from the internal queue to the appropriate
        /// log handlers. The loghandler should be defined in the
        /// logger configuration file. The handler will be selected
        /// based on the source specified in the logevent object.
        /// </summary>
        private void WriteToHandler()
        {
            lock (m_qEvents.SyncRoot) //maybe locking _monitor would be good enough? in that case a generic Queue<LogEvent> could be used :)
            {
                try
                {
                    if (m_qEvents.Count > 0)
                    {
                        Debug.WriteLine("Entries found in queue, writing to handler.", "Logger.WriteToHandler");

                        HandlerFactory.SetCurrentAppName(m_sAppSourceName);

                        while (m_qEvents.Count > 0)
                        {
                            if (m_qEvents.Peek() != null)                        //debug: this check might not be needed, but added as a safety when using multithreading.
                            {
                                LogEvent oEvent = (LogEvent)m_qEvents.Dequeue(); //TODO: should probably add the event to the queue again if an exception occurs in the code below!

                                string sHandlerName = GetHandlerName(oEvent.Source, oEvent.Level);

                                if (sHandlerName.Length > 0)
                                {
                                    HandlerFactory.GetHandler(sHandlerName).Log(oEvent);
                                }
                            }
                            else
                            {
                                m_qEvents.Dequeue(); //debug: experienced null values in the queue during multithread stress test...
                            }
                        }

                        Debug.WriteLine("Done writing to handler.", "Logger.WriteToHandler");
                    }
                    else
                    {
                        Debug.WriteLine("No entries found in queue.", "Logger.WriteToHandler");
                    }
                }
                catch (Exception exp)
                {
                    //For now we call ExceptionWriter, this will stop the timer and null the queue
                    Debug.WriteLine("Exception in Logger.WriteToHandler: " + exp.Message, "Logger.WriteToHandler");
                    ExceptionWriter("An exception occured in Logger.WriteToHandler: " + exp.Message, exp);
                }
                finally
                {
                    HandlerFactory.DisposeAllHandlers();
                }
            }
        }
Ejemplo n.º 10
0
        private void app_PostResolveRequestCache(object sender, EventArgs e)
        {
            var app = (HttpApplication)sender;

            var match = Regex.Match(app.Context.Request.Path, FdRouteTable.RouteAddress);

            if (!match.Success)
            {
                return;
            }
            Hf.Match = match;
            var handler = Hf.GetHandler(app.Context, app.Request.RequestType, null, null);

            app.Context.RemapHandler(handler);
        }
Ejemplo n.º 11
0
        private void ParseFile()
        {
            var    directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var    path      = $"{directory}\\Resources\\crypto\\encrypted_jpg_01.jpg";
            string magic     = "__CLOUDSYNC_ENC__";

            byte[] magicBytes = Encoding.ASCII.GetBytes(magic);

            using FileStream fs   = new FileStream(path, FileMode.Open);
            using BinaryReader br = new BinaryReader(fs);

            byte[] value = br.ReadBytes(magicBytes.Length);
            Console.WriteLine(ByteArrayCompare(magicBytes, value));

            //check "__CLOUDSYNC_ENC__" Md5 hash
            value = br.ReadBytes(32);
            byte[] expectedMagicHash =
                Encoding.ASCII.GetBytes(BytesUtils.ByteArrayToLowerHexString(Md5(magicBytes)));
            Assert.AreEqual(expectedMagicHash, value);

            //
            HandlerFactory     handlerFactory   = new HandlerFactory();
            StringHandler      stringHandler    = new StringHandler();
            IntHandler         intHandler       = new IntHandler();
            ByteSteamHandler   byteSteamHandler = new ByteSteamHandler();
            OrderedDictHandler dictHandler      = new OrderedDictHandler(handlerFactory);

            handlerFactory.AddHandler(stringHandler);
            handlerFactory.AddHandler(dictHandler);
            handlerFactory.AddHandler(intHandler);
            handlerFactory.AddHandler(byteSteamHandler);

            byte metaTag = br.ReadByte();

            if (metaTag != 0x42)
            {
                throw new InvalidDataException();
            }

            IFileStreamHandler <IDictionary <string, object> > metaHandler =
                handlerFactory.GetHandler <IDictionary <string, object> >(metaTag);
            IDictionary <string, object> metaDict = metaHandler.Handle(br);

            if (!(metaDict.ContainsKey("type") && "metadata".Equals(metaDict["type"])))
            {
                throw new InvalidDataException();
            }

            FileMeta3 fileMeta = FileMeta3.fromDictionary(metaDict);

            Console.WriteLine(fileMeta);

            AsymmetricKeyParameter akp = CryptoUtils.readPemPk(this.privateKey);

            byte[] sessionKeyCharArray = CryptoUtils.RsaOaepDeciper(fileMeta.EncKey2, akp);

            string computedSessionKeyHash = CryptoUtils.SaltedMd5(
                fileMeta.SessionKeyHash.Substring(0, 10), sessionKeyCharArray);

            if (!fileMeta.SessionKeyHash.Equals(computedSessionKeyHash))
            {
                throw new InvalidDataException("key is incorrect");
            }

            //decrypt content
            byte[] sessionKey = BytesUtils.HexStringToByteArray(
                Encoding.ASCII.GetString(sessionKeyCharArray));
            Console.Write(sessionKey);
            ParametersWithIV keys =
                CryptoUtils.DeriveAESKeyParameters(sessionKey, null);
            AesCbcCryptor decryptor =
                new AesCbcCryptor(((KeyParameter)keys.Parameters).GetKey(), keys.GetIV());
            List <byte[]> decryptedData = new List <byte[]>();

            byte[] buf    = null;
            byte[] decBuf = null;
            IDictionary <string, object> dataResult = null;

            while (true)
            {
                byte dataTag = br.ReadByte();
                if (dataTag == 0x40)
                {
                    Console.WriteLine("come here");
                }

                if (dataTag != 0x42)
                {
                    decBuf = decryptor.DecryptBlock(buf, true);
                    decryptedData.Add(decBuf);
                    break;
                }

                if (buf != null)
                {
                    decBuf = decryptor.DecryptBlock(buf, false);
                    decryptedData.Add(decBuf);
                }

                IFileStreamHandler <IDictionary <string, object> > dataHandler =
                    handlerFactory.GetHandler <IDictionary <string, object> >(metaTag);
                dataResult = dataHandler.Handle(br);
                object typeValue = null;
                dataResult.TryGetValue("type", out typeValue);
                string typeValueString = typeValue as string;
                if (!"data".Equals(typeValueString))
                {
                    break;
                }

                buf = (byte[])dataResult["data"];
            }

            byte[] decData = CryptoUtils.Concat(decryptedData.ToArray());
            File.WriteAllBytes("z:\\123.jpg.lz4", decData);

            //last directory

            //TODO validate dataResult["type"] == "metadata"
            string fileMd5 = (string)dataResult["file_md5"];

            Console.Write(fileMd5);
        }
Ejemplo n.º 12
0
        public void InsertSupplier(Supplier p)
        {
            var handler = HandlerFactory <Supplier> .GetHandler();

            handler.Insert(p);
        }
Ejemplo n.º 13
0
        public void InsertProduct(Product p)
        {
            var handler = HandlerFactory <Product> .GetHandler();

            handler.Insert(p);
        }