/// <summary>
        ///
        /// </summary>
        /// <param name="uniqueHandlerName">Can be name of APP, both syncronized processes must use the same name and it must be unique among the OS</param>
        /// <param name="SharmIPC">SharmIPC instance</param>
        /// <param name="bufferCapacity"></param>
        /// <param name="maxQueueSizeInBytes"></param>
        /// <param name="protocolVersion"></param>
        public SharedMemory(string uniqueHandlerName, SharmIpc SharmIPC, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000, tiesky.com.SharmIpc.eProtocolVersion protocolVersion = tiesky.com.SharmIpc.eProtocolVersion.V1)
        {
            this.SharmIPC            = SharmIPC;
            this.maxQueueSizeInBytes = maxQueueSizeInBytes;
            this.ProtocolVersion     = protocolVersion;


            //if (dataArrived == null)
            //    throw new Exception("tiesky.com.SharmIpc: dataArrived callback can't be empty");

            if (String.IsNullOrEmpty(uniqueHandlerName) || uniqueHandlerName.Length > 200)
            {
                throw new Exception("tiesky.com.SharmIpc: uniqueHandlerName can't be empty or more then 200 symbols");
            }

            if (bufferCapacity < 256)
            {
                bufferCapacity = 256;
            }

            if (bufferCapacity > 1000000)    //max 1MB
            {
                bufferCapacity = 1000000;
            }

            this.uniqueHandlerName = uniqueHandlerName;
            this.bufferCapacity    = bufferCapacity;

            try
            {
                mt = new Mutex(true, uniqueHandlerName + "SharmNet_MasterMutex");

                if (mt.WaitOne(500))
                {
                    instanceType = eInstanceType.Master;
                }
                else
                {
                    instanceType = eInstanceType.Slave;
                    if (mt != null)
                    {
                        //mt.ReleaseMutex();
                        mt.Close();
                        mt.Dispose();
                        mt = null;
                    }
                }
            }
            catch (System.Threading.AbandonedMutexException)
            {
                instanceType = eInstanceType.Master;
            }

            Console.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName);

            rwh = new ReaderWriterHandler(this);
        }
Exemple #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uniqueHandlerName">Can be name of APP, both syncronized processes must use the same name and it must be unique among the OS</param>
        /// /// <param name="SharmIPC">SharmIPC instance</param>
        /// <param name="bufferCapacity"></param>        
        public SharedMemory(string uniqueHandlerName, SharmIpc SharmIPC, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000)
        {
            this.SharmIPC = SharmIPC;

            //if (dataArrived == null)
            //    throw new Exception("tiesky.com.SharmIpc: dataArrived callback can't be empty");

            if (String.IsNullOrEmpty(uniqueHandlerName) || uniqueHandlerName.Length > 200)
                throw new Exception("tiesky.com.SharmIpc: uniqueHandlerName can't be empty or more then 200 symbols");

            if (bufferCapacity < 256)
                bufferCapacity = 256;

            if (bufferCapacity > 1000000)    //max 1MB
                bufferCapacity = 1000000;

            this.uniqueHandlerName = uniqueHandlerName;
            this.bufferCapacity = bufferCapacity;

            try
            {
                mt = new Mutex(true, uniqueHandlerName + "SharmNet_MasterMutex");

                if (mt.WaitOne(500))
                {
                    instanceType = eInstanceType.Master;
                }
                else
                {
                    instanceType = eInstanceType.Slave;
                    if (mt != null)
                    {
                        //mt.ReleaseMutex();
                       // mt.Close();
                        mt.Dispose();
                        mt = null;
                    }
                }
            }
            catch (System.Threading.AbandonedMutexException)
            {
                instanceType = eInstanceType.Master;
            }

            #if WINDOWS_UWP
            System.Diagnostics.Debug.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName);
            #else
            Console.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName);
            #endif

            rwh = new ReaderWriterHandler(this);
        }
        /// <summary>
        /// Serializes this instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public EntityObjectHierarchy Serialize <T>()
        {
            CalendarEventRecurrenceEntity recurrenceEntity = new CalendarEventRecurrenceEntity();

            recurrenceEntity.DayOfMonth = RPattern.ByMonthDay.Count != 0 ? RPattern.ByMonthDay[0] : 0;
            eBitDayOfWeek dayOfWeekMask = eBitDayOfWeek.Unknown;
            eInstanceType instance      = eInstanceType.InstanceFirst;

            //Primary key
            McRecurrencePattern mcRecurrencePattern = RPattern as McRecurrencePattern;

            if (mcRecurrencePattern != null)
            {
                recurrenceEntity.PrimaryKeyId = mcRecurrencePattern.MetaObjectId;
            }
            //Copy RPATTERN Parameters to entity property
            foreach (string paramName in RPattern.Parameters.Keys)
            {
                iCal2EntityMapping.MappingResult mapRes = iCal2EntityMapping.iCalProp2EntityProp <T>(paramName);
                if (mapRes != null && RPattern.Parameters.ContainsKey(paramName))
                {
                    foreach (string paramValue in ((Parameter)RPattern.Parameters[paramName]).Values)
                    {
                        recurrenceEntity[mapRes.Name] = EntityPropConverter.ToEntityProperty(mapRes.ValueType, paramValue);
                    }
                }
            }

            foreach (DaySpecifier daySpec in RPattern.ByDay)
            {
                if (daySpec.Num != int.MinValue)
                {
                    instance = (eInstanceType)daySpec.Num;
                }
                switch (daySpec.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    dayOfWeekMask |= eBitDayOfWeek.Sunday;
                    break;

                case DayOfWeek.Friday:
                    dayOfWeekMask |= eBitDayOfWeek.Friday;
                    break;

                case DayOfWeek.Monday:
                    dayOfWeekMask |= eBitDayOfWeek.Monday;
                    break;

                case DayOfWeek.Saturday:
                    dayOfWeekMask |= eBitDayOfWeek.Saturday;
                    break;

                case DayOfWeek.Thursday:
                    dayOfWeekMask |= eBitDayOfWeek.Thursday;
                    break;

                case DayOfWeek.Tuesday:
                    dayOfWeekMask |= eBitDayOfWeek.Tuesday;
                    break;

                case DayOfWeek.Wednesday:
                    dayOfWeekMask |= eBitDayOfWeek.Wednesday;
                    break;
                }
            }
            recurrenceEntity.DayOfWeekMask = (int)dayOfWeekMask;
            recurrenceEntity.Instance      = (int)instance;
            recurrenceEntity.Interval      = RPattern.Interval;

            eRecurrenceType recType = eRecurrenceType.RecursDaily;

            if (RPattern.Frequency == FrequencyType.Daily)
            {
                recType = eRecurrenceType.RecursDaily;
            }
            else if (RPattern.Frequency == FrequencyType.Weekly)
            {
                recType = eRecurrenceType.RecursWeekly;
            }
            else if (RPattern.Frequency == FrequencyType.Yearly)
            {
                recType = eRecurrenceType.RecursYearly;
            }
            //TODO: MOTH YEAR NTLR
            recurrenceEntity.RecurrenceType = (int)recType;
            recurrenceEntity.MonthOfYear    = RPattern.ByMonth.Count != 0 ? RPattern.ByMonth[0] : 0;
            if (RPattern.Until != null)
            {
                recurrenceEntity.PatternEndDate = DateTime.SpecifyKind(RPattern.Until.Value, DateTimeKind.Local);
            }
            recurrenceEntity.Occurrences = RPattern.Count == int.MinValue ? 0 : RPattern.Count;

            return(new EntityObjectHierarchy(recurrenceEntity));
        }