Ejemplo n.º 1
0
 public Request(int RequestId, byte[] data, bool SendResultBack, RequestCallback Callback = null)
 {
     this.RequestId = RequestId;
     this.syncObject = new SyncObject();
     this.PacketData = data;
     this.Async = Callback != null;
     this.Callback = Callback;
     this.SendResultBack = SendResultBack;
 }
Ejemplo n.º 2
0
        internal SyncObject RegisterRequest(ref int RequestId)
        {
            lock (Requests)
            {
                SyncObject syncObj = new SyncObject(this);
                FastRandom rnd = new FastRandom();

                do
                {
                    RequestId = rnd.Next();
                }
                while (Requests.ContainsKey(RequestId));

                Requests.Add(RequestId, syncObj);

                return syncObj;
            }
        }
Ejemplo n.º 3
0
		private static string Publish(DiskSdkClient client, string remotePath)
		{
			var sync = new SyncObject();

			Exception error = null;
			String result = null;

			EventHandler<GenericSdkEventArgs<string>> handler = (s, e) =>
			{
				if (e.Error == null)
					result = e.Result;
				else
					error = e.Error;

				sync.Pulse();
			};

			client.PublishCompleted += handler;
			client.PublishAsync(remotePath);

			sync.Wait();
			client.PublishCompleted -= handler;

			if (error != null)
				throw error;

			return result;
		}
Ejemplo n.º 4
0
		private static void UploadFile(DiskSdkClient client, string remotePath, string localPath)
		{
			var sync = new SyncObject();
			Exception error = null;

			client.UploadFileAsync(remotePath, File.OpenRead(localPath),
				new AsyncProgress((c, t) => { }),
				(us, ua) =>
				{
					error = ua.Error;
					sync.Pulse();
				});

			sync.Wait();

			if (error != null)
				throw error;
		}
Ejemplo n.º 5
0
		private static void TryCreateDirectory(DiskSdkClient client, string path)
		{
			var sync = new SyncObject();
			var items = Enumerable.Empty<DiskItemInfo>();

			Exception error = null;

			EventHandler<GenericSdkEventArgs<IEnumerable<DiskItemInfo>>> listHandler = (s, e) =>
			{
				if (e.Error != null)
					error = e.Error;
				else
					items = e.Result;

				sync.Pulse();
			};

			client.GetListCompleted += listHandler;
			client.GetListAsync();

			sync.Wait();
			client.GetListCompleted -= listHandler;

			if (error != null)
				throw error;

			if (items.Any(i => i.IsDirectory && i.OriginalFullPath.TrimEnd("/") == path))
				return;

			EventHandler<SdkEventArgs> createHandler = (s, e) =>
			{
				error = e.Error;
				sync.Pulse();
			};

			client.MakeFolderCompleted += createHandler;
			client.MakeDirectoryAsync(path);

			sync.Wait();
			client.MakeFolderCompleted -= createHandler;

			if (error != null)
				throw error;
		}
Ejemplo n.º 6
0
        private void _Invoke(ref object RetObject, params object[] args)
        {
            if (args.Length < ArgumentTypes.Length) //check if a argument is using "params x[] args"
                throw new Exception("missing arguments");

            List<int> usedDelegates = new List<int>();
            PayloadWriter pw = new PayloadWriter();
            pw.WriteInteger(sharedClass.SharedId);
            pw.WriteInteger(MethodId);
            pw.WriteByte(isDelegate ? (byte)1 : (byte)0);

            if (isDelegate)
            {
                pw.WriteInteger(this.DelegateId);
                pw.WriteInteger(this.sharedClass.SharedId);
            }

            SmartSerializer serializer = new SmartSerializer();
            for (int i = 0; i < args.Length; i++)
            {
                object obj = ArgumentTypes[i].IsByRef ? null : args[i];

                if (DelegateIndex.ContainsKey(i))
                    obj = null;

                byte[] SerializedObj = serializer.Serialize(obj);
                pw.WriteInteger(SerializedObj.Length);
                pw.WriteBytes(SerializedObj);
            }

            for (int i = 0; i < DelegateIndex.Count; i++)
            {
                Delegate del = args[DelegateIndex.Keys[i]] as Delegate;

                if (del != null)
                {
                    if (del.Method == null)
                        throw new Exception("Target delegate is NULL");

                    int id = rnd.Next();
                    while(Delegates.ContainsKey(id))
                        id = rnd.Next();

                    pw.WriteByte(1);
                    SharedDelegate sharedDel = new SharedDelegate(del.Method, sharedClass, del.GetType(), id, del, this.MethodId);
                    sharedDel.sharedMethod.Unchecked = DelegateIndex.Values[i].isUnchecked;
                    sharedDel.sharedMethod.usePacketQueue = DelegateIndex.Values[i].UsePacketQueue;
                    sharedDel.sharedMethod.useUdp = DelegateIndex.Values[i].UseUDP;
                    sharedDel.sharedMethod.NoWaitingTime = DelegateIndex.Values[i].NoWaitingTime;
                    pw.WriteObject(sharedDel);

                    if (!isDelegate)
                    {
                        Delegates.Add(id, sharedDel);
                    }
                    continue;
                }
                pw.WriteByte(0);
            }

            if (Unchecked || useUdp)
            {
                //just execute the method and don't wait for response
                sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(0, pw.ToByteArray(), false));
            }
            else
            {
                SyncObject syncObject = null;
                Random rnd = new Random();
                int RequestId = rnd.Next();
                lock (sharedClass.connection.MethodRequests)
                {
                    while(sharedClass.connection.MethodRequests.ContainsKey(RequestId))
                        RequestId = rnd.Next();
                    syncObject = new SyncObject(sharedClass.connection.Connection.Connection);
                    sharedClass.connection.MethodRequests.Add(RequestId, syncObject);
                    sharedClass.connection.Connection.SendMessage(new MsgExecuteMethod(RequestId, pw.ToByteArray(), true));
                }
                RetObject = syncObject.Wait<ReturnResult>(null, 0);
            }

            /*if (callback != null)
            {
                sharedClass.connection.BeginSendRequest(pw, callback, true, this.usePacketQueue);
            }
            else
            {
                if (Unchecked || useUdp)
                {
                    //just don't wait till we received something back since it's a VOID anyway
                    sharedClass.connection.BeginSendRequest(pw, (object obj) => { }, false, this.usePacketQueue);
                }
                else
                {
                    RetObject = sharedClass.connection.SendRequest(pw, this.usePacketQueue);
                }
            }*/
            serializer = null;
        }
Ejemplo n.º 7
0
        public void AttachPilot(MyCharacter pilot, bool storeOriginalPilotWorld = true, bool calledFromInit = false)
        {
            System.Diagnostics.Debug.Assert(pilot != null);
            System.Diagnostics.Debug.Assert(m_pilot == null);

            m_pilot = pilot;
            m_pilot.OnMarkForClose += m_pilotClosedHandler;
            m_pilot.IsUsing         = this;

            //m_soundEmitter.OwnedBy = m_pilot;
            if (MyFakes.ENABLE_NEW_SOUNDS)
            {
                StartLoopSound();
            }

            if (storeOriginalPilotWorld)
            {
                m_pilotRelativeWorld = (Matrix)MatrixD.Multiply(pilot.WorldMatrix, this.PositionComp.GetWorldMatrixNormalizedInv());
                if (Sync.IsServer)
                {
                    var relativeEntry = new MyPositionAndOrientation(m_pilotRelativeWorld.Value);
                    SyncObject.SendPilotRelativeEntryUpdate(ref relativeEntry);
                }
            }

            if (pilot.InScene)
            {
                MyEntities.Remove(pilot);
            }

            m_pilot.Physics.Enabled = false;
            m_pilot.PositionComp.SetWorldMatrix(WorldMatrix);
            m_pilot.Physics.Clear();
            //m_pilot.SetPosition(GetPosition() - WorldMatrix.Forward * 0.5f);

            Hierarchy.AddChild(m_pilot, true, true);

            var gunEntity = m_pilot.CurrentWeapon as MyEntity;

            if (gunEntity != null)
            {
                var ob = gunEntity.GetObjectBuilder();
                m_pilotGunDefinition = ob.GetId();
            }
            else
            {
                m_pilotGunDefinition = null;
            }

            MyAnimationDefinition animationDefinition;
            MyDefinitionId        id = new MyDefinitionId(typeof(MyObjectBuilder_AnimationDefinition), BlockDefinition.CharacterAnimation);

            if (!MyDefinitionManager.Static.TryGetDefinition(id, out animationDefinition) && !MyFileSystem.FileExists(BlockDefinition.CharacterAnimation))
            {
                BlockDefinition.CharacterAnimation = null;
            }

            PlacePilotInSeat(pilot);
            m_rechargeSocket.PlugIn(m_pilot.SuitBattery);

            // Control should be handled elsewhere if we initialize the grid in the Init(...)
            if (!calledFromInit)
            {
                GiveControlToPilot();
            }
            m_pilot.SwitchToWeapon(null);
        }
Ejemplo n.º 8
0
 public void Cleanup(SyncObject obj)
 {
     Destroy(this);
 }
Ejemplo n.º 9
0
        public ComponentContainer(Application application)
        {
            s_logger.Info("Startup...");

            if (GeneralOptionsDataAccess.WpfRenderModeSoftwareOnly)
            {
                RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
            }

            _generalOptionsDataAccess = new GeneralOptionsDataAccess();

            _synchronizationStatus = new SynchronizationStatus();

            var generalOptions = _generalOptionsDataAccess.LoadOptions();

            _daslFilterProvider = new DaslFilterProvider(generalOptions.IncludeCustomMessageClasses);

            SetWpfLocale();

            ConfigureServicePointManager(generalOptions);
            ConfigureLogLevel(generalOptions.EnableDebugLog);

            _session = application.Session;

            _outlookAccountPasswordProvider =
                string.IsNullOrEmpty(_session.CurrentProfileName)
              ? NullOutlookAccountPasswordProvider.Instance
              : new OutlookAccountPasswordProvider(_session.CurrentProfileName, application.Version);

            _globalTimeZoneCache = new GlobalTimeZoneCache();

            EnsureSynchronizationContext();

            _applicationDataDirectory = Path.Combine(
                Environment.GetFolderPath(
                    generalOptions.StoreAppDataInRoamingFolder ? Environment.SpecialFolder.ApplicationData : Environment.SpecialFolder.LocalApplicationData),
                "CalDavSynchronizer");

            _optionsDataAccess = new OptionsDataAccess(
                Path.Combine(
                    _applicationDataDirectory,
                    GetOrCreateConfigFileName(_applicationDataDirectory, _session.CurrentProfileName)
                    ));
            _profileStatusesViewModel = new ProfileStatusesViewModel(this);
            _uiService = new UiService(_profileStatusesViewModel);

            _queryFolderStrategyWrapper = new OutlookFolderStrategyWrapper(QueryOutlookFolderByRequestingItemStrategy.Instance);

            _totalProgressFactory = new TotalProgressFactory(
                _uiService,
                generalOptions.ShowProgressBar,
                generalOptions.ThresholdForProgressDisplay,
                ExceptionHandler.Instance);


            _synchronizerFactory = new SynchronizerFactory(
                GetProfileDataDirectory,
                _totalProgressFactory,
                _session,
                _daslFilterProvider,
                _outlookAccountPasswordProvider,
                _globalTimeZoneCache,
                _queryFolderStrategyWrapper);

            _synchronizationReportRepository = CreateSynchronizationReportRepository();

            UpdateGeneralOptionDependencies(generalOptions);

            _scheduler = new Scheduler(
                _synchronizerFactory,
                this,
                EnsureSynchronizationContext,
                new FolderChangeWatcherFactory(
                    _session),
                _synchronizationStatus);

            var options = _optionsDataAccess.Load();

            EnsureCacheCompatibility(options);


            _profileStatusesViewModel.EnsureProfilesDisplayed(options);


            _availableVersionService          = new AvailableVersionService();
            _updateChecker                    = new UpdateChecker(_availableVersionService, () => _generalOptionsDataAccess.IgnoreUpdatesTilVersion);
            _updateChecker.NewerVersionFound += UpdateChecker_NewerVersionFound;
            _updateChecker.IsEnabled          = generalOptions.ShouldCheckForNewerVersions;

            _reportGarbageCollection = new ReportGarbageCollection(_synchronizationReportRepository, TimeSpan.FromDays(generalOptions.MaxReportAgeInDays));

            _trayNotifier = generalOptions.EnableTrayIcon ? new TrayNotifier(this) : NullTrayNotifer.Instance;

            try
            {
                using (var syncObjects = GenericComObjectWrapper.Create(_session.SyncObjects))
                {
                    if (syncObjects.Inner != null && syncObjects.Inner.Count > 0)
                    {
                        _syncObject = syncObjects.Inner[1];
                        if (generalOptions.TriggerSyncAfterSendReceive)
                        {
                            _syncObject.SyncEnd += SyncObject_SyncEnd;
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                s_logger.Error("Can't access SyncObjects", ex);
            }

            _categorySwitcher = new CategorySwitcher(_session, _daslFilterProvider, _queryFolderStrategyWrapper);
        }
Ejemplo n.º 10
0
 public void SetSyncModel(SyncObject syncObject)
 {
     SyncModel = syncObject;
 }